@customerglu/react-native-customerglu 2.1.2-1.0-beta → 3.0.0-beta-1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -15
- package/README.md +2 -2
- package/ReactNativeCustomerglu.podspec +42 -0
- package/android/build.gradle +78 -33
- package/android/generated/java/com/customerglu/reactnativecustomerglu/NativeReactNativeCustomergluSpec.java +144 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNReactNativeCustomergluSpec-generated.cpp +188 -0
- package/android/generated/jni/RNReactNativeCustomergluSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNReactNativeCustomergluSpec/RNReactNativeCustomergluSpecJSI-generated.cpp +237 -0
- package/android/generated/jni/react/renderer/components/RNReactNativeCustomergluSpec/RNReactNativeCustomergluSpecJSI.h +305 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -6
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/BannerView.kt +76 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/BannerViewManager.kt +19 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/CGEmbededView.kt +102 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/CGEmbededViewManager.kt +18 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/RnCustomergluModule.kt +698 -0
- package/android/src/main/java/com/customerglu/reactnativecustomerglu/RnCustomergluPackage.kt +41 -0
- package/ios/Rncustomerglu.h +6 -0
- package/ios/Rncustomerglu.mm +18 -0
- package/ios/generated/RNReactNativeCustomergluSpec/RNReactNativeCustomergluSpec-generated.mm +221 -0
- package/ios/generated/RNReactNativeCustomergluSpec/RNReactNativeCustomergluSpec.h +106 -0
- package/ios/generated/RNReactNativeCustomergluSpecJSI-generated.cpp +237 -0
- package/ios/generated/RNReactNativeCustomergluSpecJSI.h +305 -0
- package/lib/commonjs/NativeReactNativeCustomerglu.js +9 -0
- package/lib/commonjs/NativeReactNativeCustomerglu.js.map +1 -0
- package/lib/commonjs/index.js +28 -191
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeReactNativeCustomerglu.js +5 -0
- package/lib/module/NativeReactNativeCustomerglu.js.map +1 -0
- package/lib/module/index.js +30 -164
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeReactNativeCustomerglu.d.ts +33 -0
- package/lib/typescript/commonjs/src/NativeReactNativeCustomerglu.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +35 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeReactNativeCustomerglu.d.ts +33 -0
- package/lib/typescript/module/src/NativeReactNativeCustomerglu.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +35 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +91 -45
- package/react-native.config.js +12 -0
- package/src/NativeReactNativeCustomerglu.ts +36 -0
- package/src/index.tsx +73 -217
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -89
- package/android/src/main/java/com/reactnativerncustomerglu/Bannerwidget/Bannerwidget/BannerWidgetViewGroupManager.java +0 -40
- package/android/src/main/java/com/reactnativerncustomerglu/Bannerwidget/Bannerwidget/bannerWidget.java +0 -43
- package/android/src/main/java/com/reactnativerncustomerglu/Bannerwidget/wrapperview/WrapperView.java +0 -61
- package/android/src/main/java/com/reactnativerncustomerglu/CGUtils.java +0 -13
- package/android/src/main/java/com/reactnativerncustomerglu/EmbedBannerwidget/EWrapperview/EWrapperView.java +0 -61
- package/android/src/main/java/com/reactnativerncustomerglu/EmbedBannerwidget/EmbedBannerwidget/EBannerWidget.java +0 -35
- package/android/src/main/java/com/reactnativerncustomerglu/EmbedBannerwidget/EmbedBannerwidget/EBannerWidgetVGManager.java +0 -40
- package/android/src/main/java/com/reactnativerncustomerglu/RncustomergluModule.java +0 -1033
- package/android/src/main/java/com/reactnativerncustomerglu/RncustomergluPackage.java +0 -35
- package/android/src/main/res/drawable/bottom_sheet_edges.xml +0 -7
- package/android/src/main/res/drawable/floating_close_layout.xml +0 -10
- package/android/src/main/res/drawable/ic_arrow_back.xml +0 -5
- package/android/src/main/res/drawable/ic_back.xml +0 -10
- package/android/src/main/res/drawable/ic_delete_bin.xml +0 -5
- package/android/src/main/res/drawable/ic_delete_bin_red.xml +0 -5
- package/android/src/main/res/drawable/ij.png +0 -0
- package/android/src/main/res/drawable/notification.png +0 -0
- package/android/src/main/res/drawable/progress_bg.xml +0 -33
- package/android/src/main/res/values/colors.xml +0 -13
- package/android/src/main/res/values/themes.xml +0 -15
- package/android/src/main/res/xml/provider_path.xml +0 -4
- package/ios/CustomPlayer.m +0 -30
- package/ios/Rncustomerglu-Bridging-Header.h +0 -4
- package/ios/Rncustomerglu.m +0 -83
- package/ios/Rncustomerglu.swift +0 -647
- package/ios/Rncustomerglu.xcodeproj/project.pbxproj +0 -293
- package/ios/Rncustomerglu.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
- package/ios/Rncustomerglu.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/lib/typescript/index.d.ts +0 -62
- package/react-native-customerglu.podspec +0 -23
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
package com.customerglu.reactnativecustomerglu
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
+
import android.R
|
|
6
|
+
import android.content.BroadcastReceiver
|
|
7
|
+
import android.content.Context
|
|
8
|
+
import android.content.Intent
|
|
9
|
+
import android.content.IntentFilter
|
|
10
|
+
import android.content.pm.PackageManager
|
|
11
|
+
import android.os.Build
|
|
12
|
+
import android.os.Handler
|
|
13
|
+
import android.os.Looper
|
|
14
|
+
import android.util.Log
|
|
15
|
+
import androidx.core.content.ContextCompat
|
|
16
|
+
import com.customerglu.sdk.CustomerGlu
|
|
17
|
+
import com.customerglu.sdk.Interface.CampaignValidListener
|
|
18
|
+
import com.customerglu.sdk.Interface.DataListner
|
|
19
|
+
import com.customerglu.sdk.Modal.NudgeConfiguration
|
|
20
|
+
import com.customerglu.sdk.Utils.CGConstants
|
|
21
|
+
import com.customerglu.sdk.Utils.Comman
|
|
22
|
+
import com.customerglu.sdk.pip.PIPHelper
|
|
23
|
+
|
|
24
|
+
import com.facebook.react.bridge.Arguments
|
|
25
|
+
import com.facebook.react.bridge.Promise
|
|
26
|
+
import com.facebook.react.bridge.ReactMethod
|
|
27
|
+
import com.facebook.react.bridge.ReadableArray
|
|
28
|
+
import com.facebook.react.bridge.ReadableMap
|
|
29
|
+
import com.facebook.react.bridge.ReadableType
|
|
30
|
+
import com.facebook.react.bridge.UiThreadUtil.runOnUiThread
|
|
31
|
+
import com.facebook.react.bridge.WritableArray
|
|
32
|
+
import com.facebook.react.bridge.WritableMap
|
|
33
|
+
import com.facebook.react.bridge.WritableNativeArray
|
|
34
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
35
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
36
|
+
import com.google.gson.Gson
|
|
37
|
+
import com.google.gson.reflect.TypeToken
|
|
38
|
+
import org.json.JSONArray
|
|
39
|
+
import org.json.JSONException
|
|
40
|
+
import org.json.JSONObject
|
|
41
|
+
import java.util.Date
|
|
42
|
+
import kotlin.math.roundToInt
|
|
43
|
+
@ReactModule(name = RnCustomergluModule.NAME)
|
|
44
|
+
class RnCustomergluModule(reactContext: ReactApplicationContext) :
|
|
45
|
+
NativeReactNativeCustomergluSpec(reactContext) {
|
|
46
|
+
val TAG:String = "CUSTOMERGLU"
|
|
47
|
+
val ANALYTICS_BROADCAST_ACTION = "CUSTOMERGLU_ANALYTICS_EVENT"
|
|
48
|
+
val DEEPLINK_BROADCAST_ACTION = "CUSTOMERGLU_DEEPLINK_EVENT"
|
|
49
|
+
val BANNER_BROADCAST_ACTION = "CUSTOMERGLU_BANNER_LOADED"
|
|
50
|
+
val INVALID_CAMPAIGN_BROADCAST_ACTION = "CG_INVALID_CAMPAIGN_ID"
|
|
51
|
+
val BANNER_HEIGHT_BROADCAST_ACTION = "CGBANNER_FINAL_HEIGHT"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
var mContext: ReactApplicationContext? = null
|
|
55
|
+
var mReceiver: BroadcastReceiver? = null
|
|
56
|
+
var Myclassname: String = ""
|
|
57
|
+
|
|
58
|
+
override fun getName(): String {
|
|
59
|
+
return NAME
|
|
60
|
+
}
|
|
61
|
+
@ReactMethod
|
|
62
|
+
override fun addListener(eventName: String) {
|
|
63
|
+
Log.d(TAG, "addListener called for $eventName")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactMethod
|
|
67
|
+
override fun removeListeners(count: Double) {
|
|
68
|
+
Log.d(TAG, "removeListeners called with count: $count")
|
|
69
|
+
}
|
|
70
|
+
init {
|
|
71
|
+
mContext = reactContext;
|
|
72
|
+
CustomerGlu.getInstance().showEntryPoint(reactApplicationContext.currentActivity,"CG_SCREEN");
|
|
73
|
+
registerBroadcastReceiver()
|
|
74
|
+
}
|
|
75
|
+
private fun registerBroadcastReceiver() {
|
|
76
|
+
Log.d(TAG, "Registering broadcast receiver for action: $ANALYTICS_BROADCAST_ACTION")
|
|
77
|
+
|
|
78
|
+
mReceiver = object : BroadcastReceiver() {
|
|
79
|
+
override fun onReceive(context: Context, intent: Intent) {
|
|
80
|
+
if (intent.action == ANALYTICS_BROADCAST_ACTION) {
|
|
81
|
+
val data = intent.getStringExtra("data") ?: ""
|
|
82
|
+
Log.d(TAG, "Received broadcast event with data: $data")
|
|
83
|
+
|
|
84
|
+
// Create a WritableMap to send to React Native
|
|
85
|
+
val jsonObject = JSONObject(data)
|
|
86
|
+
val map: WritableMap? = jsonToWritableMap(jsonObject)
|
|
87
|
+
if (map != null) {
|
|
88
|
+
sendEventToJs("CUSTOMERGLU_ANALYTICS_EVENT", map)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Send the event to JS
|
|
92
|
+
//sendEventToJs("onCustomerGluAnalyticsEvent", params)
|
|
93
|
+
}
|
|
94
|
+
if (intent.action == DEEPLINK_BROADCAST_ACTION) {
|
|
95
|
+
val data = intent.getStringExtra("data") ?: ""
|
|
96
|
+
Log.d(TAG, "Received broadcast event with data: $data")
|
|
97
|
+
|
|
98
|
+
// Create a WritableMap to send to React Native
|
|
99
|
+
val jsonObject = JSONObject(data)
|
|
100
|
+
val map: WritableMap? = jsonToWritableMap(jsonObject)
|
|
101
|
+
if (map != null) {
|
|
102
|
+
sendEventToJs("CUSTOMERGLU_DEEPLINK_EVENT", map)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
if (intent.action == BANNER_BROADCAST_ACTION) {
|
|
107
|
+
val data = intent.getStringExtra("data") ?: ""
|
|
108
|
+
Log.d(TAG, "Received broadcast event with data: $data")
|
|
109
|
+
|
|
110
|
+
// Create a WritableMap to send to React Native
|
|
111
|
+
val jsonObject = JSONObject(data)
|
|
112
|
+
val map: WritableMap? = jsonToWritableMap(jsonObject)
|
|
113
|
+
if (map != null) {
|
|
114
|
+
sendEventToJs("CUSTOMERGLU_BANNER_LOADED", map)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Send the event to JS
|
|
118
|
+
//sendEventToJs("onCustomerGluAnalyticsEvent", params)
|
|
119
|
+
}
|
|
120
|
+
if (intent.action == BANNER_HEIGHT_BROADCAST_ACTION) {
|
|
121
|
+
val data = intent.getStringExtra("data") ?: ""
|
|
122
|
+
Log.d(TAG, "Received broadcast event with data: $data")
|
|
123
|
+
|
|
124
|
+
// Create a WritableMap to send to React Native
|
|
125
|
+
val jsonObject = JSONObject(data)
|
|
126
|
+
val map: WritableMap? = jsonToWritableMap(jsonObject)
|
|
127
|
+
if (map != null) {
|
|
128
|
+
sendEventToJs("CGBANNER_FINAL_HEIGHT", map)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Send the event to JS
|
|
132
|
+
//sendEventToJs("onCustomerGluAnalyticsEvent", params)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (intent.action == INVALID_CAMPAIGN_BROADCAST_ACTION) {
|
|
136
|
+
val data = intent.getStringExtra("data") ?: ""
|
|
137
|
+
Log.d(TAG, "Received broadcast event with data: $data")
|
|
138
|
+
|
|
139
|
+
// Create a WritableMap to send to React Native
|
|
140
|
+
val jsonObject = JSONObject(data)
|
|
141
|
+
val map: WritableMap? = jsonToWritableMap(jsonObject)
|
|
142
|
+
if (map != null) {
|
|
143
|
+
sendEventToJs("CG_INVALID_CAMPAIGN_ID", map)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Send the event to JS
|
|
147
|
+
//sendEventToJs("onCustomerGluAnalyticsEvent", params)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Register the broadcast receiver
|
|
154
|
+
val intentFilter = IntentFilter().apply {
|
|
155
|
+
addAction(ANALYTICS_BROADCAST_ACTION)
|
|
156
|
+
addAction(DEEPLINK_BROADCAST_ACTION)
|
|
157
|
+
addAction(BANNER_BROADCAST_ACTION)
|
|
158
|
+
addAction(INVALID_CAMPAIGN_BROADCAST_ACTION)
|
|
159
|
+
addAction(BANNER_HEIGHT_BROADCAST_ACTION)
|
|
160
|
+
}
|
|
161
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
|
|
162
|
+
reactApplicationContext.registerReceiver(
|
|
163
|
+
mReceiver,
|
|
164
|
+
intentFilter,
|
|
165
|
+
Context.RECEIVER_EXPORTED // Use NOT_EXPORTED since this is for internal app communication
|
|
166
|
+
)
|
|
167
|
+
} else {
|
|
168
|
+
reactApplicationContext.registerReceiver(mReceiver, intentFilter,Context.RECEIVER_EXPORTED )
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Don't forget to unregister the receiver when the module is destroyed
|
|
173
|
+
override fun invalidate() {
|
|
174
|
+
// This is called when the TurboModule is destroyed
|
|
175
|
+
if (mReceiver != null) {
|
|
176
|
+
try {
|
|
177
|
+
reactApplicationContext.unregisterReceiver(mReceiver)
|
|
178
|
+
} catch (e: IllegalArgumentException) {
|
|
179
|
+
// Receiver might not be registered
|
|
180
|
+
Log.e(TAG, "Error unregistering receiver: ${e.message}")
|
|
181
|
+
}
|
|
182
|
+
mReceiver = null
|
|
183
|
+
}
|
|
184
|
+
super.invalidate()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private fun sendEventToJs(eventName: String, map: WritableMap) {
|
|
188
|
+
try {
|
|
189
|
+
reactApplicationContext.getJSModule<DeviceEventManagerModule.RCTDeviceEventEmitter>(
|
|
190
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
191
|
+
.emit(eventName, map)
|
|
192
|
+
} catch (e: java.lang.Exception) {
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
@ReactMethod
|
|
196
|
+
override fun registerDevice(map: ReadableMap?, promise: Promise) {
|
|
197
|
+
map?.let {
|
|
198
|
+
Handler(Looper.getMainLooper()).postDelayed({
|
|
199
|
+
val jsonObject = convertMapToJson(it)
|
|
200
|
+
val userData: HashMap<String, Any> = Gson().fromJson(jsonObject.toString(), object : TypeToken<HashMap<String, Any>>() {}.type)
|
|
201
|
+
Log.d(TAG, "userdata----> $userData ${Date().time}")
|
|
202
|
+
CustomerGlu.getInstance().registerDevice(reactApplicationContext, userData, object :
|
|
203
|
+
DataListner {
|
|
204
|
+
// this method registers the user
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
override fun onSuccess(p0: kotlin.Boolean?) {
|
|
208
|
+
Log.d(TAG, "Registered!... ${Date().time}")
|
|
209
|
+
promise.resolve(true)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
override fun onFail(message: String) {
|
|
213
|
+
Log.d(TAG, "Registeration Failed!... $message")
|
|
214
|
+
promise.resolve(false)
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
}, 500)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
@ReactMethod
|
|
222
|
+
override fun UpdateUserAttributes(map: ReadableMap?) {
|
|
223
|
+
if (map != null) {
|
|
224
|
+
val jsonObject = convertMapToJson(map)
|
|
225
|
+
val userData: MutableMap<String, Any> = Gson().fromJson(
|
|
226
|
+
jsonObject.toString(),
|
|
227
|
+
object : TypeToken<HashMap<String, Any>>() {}.type
|
|
228
|
+
) ?: mutableMapOf()
|
|
229
|
+
|
|
230
|
+
CustomerGlu.getInstance().updateUserAttributes(reactApplicationContext, userData)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
override fun dataClear() {
|
|
235
|
+
CustomerGlu.getInstance().clearGluData(currentActivity)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
override fun sendData(readableMap: ReadableMap?) {
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
if (readableMap != null) {
|
|
242
|
+
try {
|
|
243
|
+
var evnt = ""
|
|
244
|
+
val obj = convertMapToJson(readableMap)
|
|
245
|
+
Log.e(TAG, "request----- $obj")
|
|
246
|
+
if (obj!!.has("eventName")) {
|
|
247
|
+
evnt = obj!!["eventName"] as String
|
|
248
|
+
}
|
|
249
|
+
if (obj!!.has("eventProperties")) {
|
|
250
|
+
val eventProperties = obj!!["eventProperties"]
|
|
251
|
+
if (eventProperties is JSONObject) {
|
|
252
|
+
Log.e(TAG, "data>>>>>----- " + eventProperties)
|
|
253
|
+
CustomerGlu.getInstance().sendEvent(
|
|
254
|
+
reactApplicationContext, evnt, jsonToMap(
|
|
255
|
+
eventProperties
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
val s: Map<String, Any> = HashMap()
|
|
261
|
+
CustomerGlu.getInstance().sendEvent(reactApplicationContext, evnt, s)
|
|
262
|
+
}
|
|
263
|
+
} catch (e: JSONException) {
|
|
264
|
+
e.printStackTrace()
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
override fun openWallet(readableMap: ReadableMap?) {
|
|
270
|
+
try {
|
|
271
|
+
if (readableMap != null) {
|
|
272
|
+
if (readableMap.hasKey("nudgeConfiguration")) {
|
|
273
|
+
Log.e(TAG, "openwallet-----" + readableMap.toString())
|
|
274
|
+
|
|
275
|
+
val nudgeConfigurationdata: JSONObject
|
|
276
|
+
val nudgeConfiguration = NudgeConfiguration()
|
|
277
|
+
val obj = convertMapToJson(readableMap)
|
|
278
|
+
nudgeConfigurationdata = obj!!.getJSONObject("nudgeConfiguration")
|
|
279
|
+
if (nudgeConfigurationdata.has("layout")) {
|
|
280
|
+
nudgeConfiguration.layout = nudgeConfigurationdata.getString("layout")
|
|
281
|
+
}
|
|
282
|
+
if (nudgeConfigurationdata.has("opacity")) {
|
|
283
|
+
nudgeConfiguration.opacity = nudgeConfigurationdata.getString("opacity").toDouble()
|
|
284
|
+
}
|
|
285
|
+
if (nudgeConfigurationdata.has("closeOnDeepLink")) {
|
|
286
|
+
nudgeConfiguration.isCloseOnDeepLink =
|
|
287
|
+
nudgeConfigurationdata.getBoolean("closeOnDeepLink")
|
|
288
|
+
}
|
|
289
|
+
if (nudgeConfigurationdata.has("absoluteHeight")) {
|
|
290
|
+
nudgeConfiguration.absoluteHeight =
|
|
291
|
+
nudgeConfigurationdata.getString("absoluteHeight").toDouble()
|
|
292
|
+
}
|
|
293
|
+
if (nudgeConfigurationdata.has("relativeHeight")) {
|
|
294
|
+
nudgeConfiguration.relativeHeight =
|
|
295
|
+
nudgeConfigurationdata.getString("relativeHeight").toDouble()
|
|
296
|
+
}
|
|
297
|
+
CustomerGlu.getInstance().openWallet(reactApplicationContext, nudgeConfiguration)
|
|
298
|
+
} else {
|
|
299
|
+
CustomerGlu.getInstance().openWallet(reactApplicationContext)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} catch (e: JSONException) {
|
|
303
|
+
e.printStackTrace()
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
override fun initCGSDK(obj: String?) {
|
|
308
|
+
CustomerGlu.getInstance().initializeSdk(getReactApplicationContext(),obj);
|
|
309
|
+
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
override fun loadCampaignById(id: String?, readableMap: ReadableMap?) {
|
|
313
|
+
Log.e(TAG, "loadCampaignById-----" + readableMap.toString())
|
|
314
|
+
try {
|
|
315
|
+
val nudgeConfigurationdata: JSONObject
|
|
316
|
+
val nudgeConfiguration = NudgeConfiguration()
|
|
317
|
+
if (readableMap != null) {
|
|
318
|
+
if (readableMap.hasKey("nudgeConfiguration")) {
|
|
319
|
+
val obj = convertMapToJson(readableMap)
|
|
320
|
+
nudgeConfigurationdata = obj!!.getJSONObject("nudgeConfiguration")
|
|
321
|
+
if (nudgeConfigurationdata.has("layout")) {
|
|
322
|
+
nudgeConfiguration.layout = nudgeConfigurationdata.getString("layout")
|
|
323
|
+
}
|
|
324
|
+
if (nudgeConfigurationdata.has("opacity")) {
|
|
325
|
+
nudgeConfiguration.opacity = nudgeConfigurationdata.getString("opacity").toDouble()
|
|
326
|
+
}
|
|
327
|
+
if (nudgeConfigurationdata.has("closeOnDeepLink")) {
|
|
328
|
+
nudgeConfiguration.isCloseOnDeepLink =
|
|
329
|
+
nudgeConfigurationdata.getBoolean("closeOnDeepLink")
|
|
330
|
+
}
|
|
331
|
+
if (nudgeConfigurationdata.has("absoluteHeight")) {
|
|
332
|
+
nudgeConfiguration.absoluteHeight =
|
|
333
|
+
nudgeConfigurationdata.getString("absoluteHeight").toDouble()
|
|
334
|
+
}
|
|
335
|
+
if (nudgeConfigurationdata.has("relativeHeight")) {
|
|
336
|
+
nudgeConfiguration.relativeHeight =
|
|
337
|
+
nudgeConfigurationdata.getString("relativeHeight").toDouble()
|
|
338
|
+
}
|
|
339
|
+
CustomerGlu.getInstance().loadCampaignById(reactApplicationContext, id, nudgeConfiguration)
|
|
340
|
+
} else {
|
|
341
|
+
CustomerGlu.getInstance().loadCampaignById(reactApplicationContext, id)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
} catch (e: JSONException) {
|
|
345
|
+
e.printStackTrace()
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
override fun loadCampaignWithUrl(url: String?, readableMap: ReadableMap?) {
|
|
350
|
+
Log.e(TAG, "loadCampaignByUrl-----" + readableMap.toString())
|
|
351
|
+
try {
|
|
352
|
+
val nudgeConfigurationdata: JSONObject
|
|
353
|
+
val nudgeConfiguration = NudgeConfiguration()
|
|
354
|
+
if (readableMap != null) {
|
|
355
|
+
if (readableMap.hasKey("nudgeConfiguration")) {
|
|
356
|
+
val obj = convertMapToJson(readableMap)
|
|
357
|
+
nudgeConfigurationdata = obj!!.getJSONObject("nudgeConfiguration")
|
|
358
|
+
if (nudgeConfigurationdata.has("layout")) {
|
|
359
|
+
nudgeConfiguration.layout = nudgeConfigurationdata.getString("layout")
|
|
360
|
+
}
|
|
361
|
+
if (nudgeConfigurationdata.has("opacity")) {
|
|
362
|
+
nudgeConfiguration.opacity = nudgeConfigurationdata.getString("opacity").toDouble()
|
|
363
|
+
}
|
|
364
|
+
if (nudgeConfigurationdata.has("closeOnDeepLink")) {
|
|
365
|
+
nudgeConfiguration.isCloseOnDeepLink =
|
|
366
|
+
nudgeConfigurationdata.getBoolean("closeOnDeepLink")
|
|
367
|
+
}
|
|
368
|
+
if (nudgeConfigurationdata.has("absoluteHeight")) {
|
|
369
|
+
nudgeConfiguration.absoluteHeight =
|
|
370
|
+
nudgeConfigurationdata.getString("absoluteHeight").toDouble()
|
|
371
|
+
}
|
|
372
|
+
if (nudgeConfigurationdata.has("relativeHeight")) {
|
|
373
|
+
nudgeConfiguration.relativeHeight =
|
|
374
|
+
nudgeConfigurationdata.getString("relativeHeight").toDouble()
|
|
375
|
+
}
|
|
376
|
+
CustomerGlu.getInstance()
|
|
377
|
+
.displayCGNudge(reactApplicationContext, url, "", nudgeConfiguration)
|
|
378
|
+
} else {
|
|
379
|
+
CustomerGlu.getInstance()
|
|
380
|
+
.displayCGNudge(reactApplicationContext, url, "", nudgeConfiguration)
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
} catch (e: JSONException) {
|
|
384
|
+
e.printStackTrace()
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
override fun enableAnalytic(b: Boolean) {
|
|
389
|
+
CustomerGlu.getInstance().enableAnalyticsEvent(b);
|
|
390
|
+
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
override fun allowAnonymousRegistration(b: Boolean) {
|
|
394
|
+
CustomerGlu.getInstance().allowAnonymousRegistration(b);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
override fun gluSDKDebuggingMode(b: Boolean) {
|
|
398
|
+
CustomerGlu.getInstance().gluSDKDebuggingMode(getCurrentActivity(), b);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
override fun enableEntryPoints(b: Boolean) {
|
|
402
|
+
CustomerGlu.getInstance().enableEntryPoints(getCurrentActivity(), b);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
override fun isFcmApn(id: Boolean) {
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
override fun UpdateProfile(map: ReadableMap?) {
|
|
410
|
+
if (map != null) {
|
|
411
|
+
val jsonObject = convertMapToJson(map)
|
|
412
|
+
|
|
413
|
+
val userData: MutableMap<String, Any> = Gson().fromJson<HashMap<String, Any>>(
|
|
414
|
+
jsonObject.toString(),
|
|
415
|
+
object : TypeToken<HashMap<String, Any>>() {}.type
|
|
416
|
+
) ?: mutableMapOf() // Ensure it's not null
|
|
417
|
+
|
|
418
|
+
CustomerGlu.getInstance()
|
|
419
|
+
.updateProfile(reactApplicationContext, userData, object : DataListner {
|
|
420
|
+
override fun onSuccess(registerModal: Boolean) {
|
|
421
|
+
Log.d(TAG, "Profile Updated!...")
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
override fun onFail(message: String) {
|
|
425
|
+
Log.d(TAG, "Profile Not Updated!...$message")
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
override fun DisplayCustomerGluNotification() {
|
|
432
|
+
TODO("Not yet implemented")
|
|
433
|
+
}
|
|
434
|
+
private fun getAppIcon(context: Context): Int {
|
|
435
|
+
try {
|
|
436
|
+
val ai = context.packageManager.getApplicationInfo(
|
|
437
|
+
context.packageName, PackageManager.GET_META_DATA
|
|
438
|
+
)
|
|
439
|
+
val bundle = ai.metaData
|
|
440
|
+
val myAPIKey = bundle.getInt("CUSTOMERGLU_NOTIFICATION_ICON")
|
|
441
|
+
return myAPIKey
|
|
442
|
+
} catch (e: Exception) {
|
|
443
|
+
Comman.printErrorLogs(e.toString())
|
|
444
|
+
return 0
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
override fun DisplayCGNotification(obj: ReadableMap?, autoclosewebview: Boolean?) {
|
|
448
|
+
val jsonObject = convertMapToJson(obj)
|
|
449
|
+
if (getAppIcon(reactApplicationContext) !== 0) {
|
|
450
|
+
CustomerGlu.getInstance().displayCustomerGluNotification(
|
|
451
|
+
reactApplicationContext, jsonObject, getAppIcon(reactApplicationContext), 0.5,
|
|
452
|
+
autoclosewebview!!
|
|
453
|
+
)
|
|
454
|
+
} else {
|
|
455
|
+
CustomerGlu.getInstance().displayCustomerGluNotification(
|
|
456
|
+
reactApplicationContext, jsonObject, R.drawable.ic_notification_overlay, 0.5,
|
|
457
|
+
autoclosewebview!!
|
|
458
|
+
)
|
|
459
|
+
} }
|
|
460
|
+
|
|
461
|
+
override fun DisplayCGBackgroundNotification(obj: ReadableMap?, autoclosewebview: Boolean?) {
|
|
462
|
+
val jsonObject = convertMapToJson(obj)
|
|
463
|
+
Log.d(TAG, "DisplayCGBackgroundNotification---$jsonObject $autoclosewebview")
|
|
464
|
+
CustomerGlu.getInstance().displayCustomerGluBackgroundNotification(
|
|
465
|
+
reactApplicationContext, jsonObject,
|
|
466
|
+
autoclosewebview!!
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
override fun SetCurrentClassName(clname: String?, promise: Promise?) {
|
|
471
|
+
if (clname != null) {
|
|
472
|
+
this.Myclassname = clname
|
|
473
|
+
runOnUiThread(Runnable {
|
|
474
|
+
CustomerGlu.getInstance().setScreenName(reactApplicationContext, clname)
|
|
475
|
+
})
|
|
476
|
+
}else{
|
|
477
|
+
Log.e(TAG,"Class Name is Null")
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
override fun setApnFcmToken(a: String?, b: String?) {
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
override fun getBannerHeight(promise: Promise?) {
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
override fun addMarginsForPIP(horizontal: Double, vertical: Double, type: String?) {
|
|
489
|
+
if (type.equals("px")) {
|
|
490
|
+
CustomerGlu.getInstance().addMarginForPIP(horizontal.roundToInt(), vertical.roundToInt(), PIPHelper.DISPLAY_UNIT_TYPE.PX);
|
|
491
|
+
}else{
|
|
492
|
+
CustomerGlu.getInstance().addMarginForPIP(horizontal.roundToInt(), vertical.roundToInt(), PIPHelper.DISPLAY_UNIT_TYPE.DP);
|
|
493
|
+
|
|
494
|
+
} }
|
|
495
|
+
|
|
496
|
+
override fun addDelayForPIP(delay: Double) {
|
|
497
|
+
CustomerGlu.getInstance().addDelayForPIP(delay.toInt());
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
override fun setOpenWalletAsFallback(value: Boolean) {
|
|
501
|
+
CustomerGlu.getInstance().openWalletAsFallback(value);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
override fun isCampaignValid(campaignId: String?, dataFlag: String?, promise: Promise?) {
|
|
505
|
+
var flag = CGConstants.DATA_FLAG.API
|
|
506
|
+
|
|
507
|
+
if (dataFlag.equals("CACHE")) {
|
|
508
|
+
flag = CGConstants.DATA_FLAG.CACHED
|
|
509
|
+
}
|
|
510
|
+
CustomerGlu.getInstance().isCampaignValid(campaignId, flag, object : CampaignValidListener {
|
|
511
|
+
override fun validCampaign() {
|
|
512
|
+
promise!!.resolve(true)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
override fun invalidCampaign() {
|
|
516
|
+
promise!!.resolve(false)
|
|
517
|
+
}
|
|
518
|
+
}) }
|
|
519
|
+
|
|
520
|
+
override fun getCampaignStatus(campaignId: String?, dataFlag: String?, promise: Promise?) {
|
|
521
|
+
var flag = CGConstants.DATA_FLAG.API
|
|
522
|
+
|
|
523
|
+
if (dataFlag.equals("CACHE")) {
|
|
524
|
+
flag = CGConstants.DATA_FLAG.CACHED
|
|
525
|
+
}
|
|
526
|
+
CustomerGlu.getInstance().getCampaignStatus(
|
|
527
|
+
campaignId, CGConstants.DATA_FLAG.API
|
|
528
|
+
) { campaignState -> promise!!.resolve(campaignState.toString()) }
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
@Throws(JSONException::class)
|
|
533
|
+
fun jsonToMap(json: JSONObject): Map<String?, Any?> {
|
|
534
|
+
var retMap: Map<String?, Any?> = HashMap()
|
|
535
|
+
if (json !== JSONObject.NULL) {
|
|
536
|
+
retMap = toMap(json)
|
|
537
|
+
}
|
|
538
|
+
return retMap
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
@Throws(JSONException::class)
|
|
542
|
+
fun toMap(`object`: JSONObject): Map<String?, Any?> {
|
|
543
|
+
val map: MutableMap<String?, Any?> = HashMap()
|
|
544
|
+
val keysItr = `object`.keys()
|
|
545
|
+
while (keysItr.hasNext()) {
|
|
546
|
+
val key = keysItr.next()
|
|
547
|
+
var value = `object`[key]
|
|
548
|
+
|
|
549
|
+
if (value is JSONArray) {
|
|
550
|
+
value = toList(value)
|
|
551
|
+
} else if (value is JSONObject) {
|
|
552
|
+
value = toMap(value)
|
|
553
|
+
}
|
|
554
|
+
map[key] = value
|
|
555
|
+
}
|
|
556
|
+
return map
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
@Throws(JSONException::class)
|
|
560
|
+
fun toList(array: JSONArray): List<Any> {
|
|
561
|
+
val list: MutableList<Any> = ArrayList()
|
|
562
|
+
for (i in 0 until array.length()) {
|
|
563
|
+
var value = array[i]
|
|
564
|
+
if (value is JSONArray) {
|
|
565
|
+
value = toList(value)
|
|
566
|
+
} else if (value is JSONObject) {
|
|
567
|
+
value = toMap(value)
|
|
568
|
+
}
|
|
569
|
+
list.add(value)
|
|
570
|
+
}
|
|
571
|
+
return list
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
private fun convertMapToJson(readableMap: ReadableMap?): JSONObject? {
|
|
575
|
+
val jsonObject = JSONObject()
|
|
576
|
+
if (readableMap == null) {
|
|
577
|
+
return null
|
|
578
|
+
}
|
|
579
|
+
val iterator = readableMap.keySetIterator()
|
|
580
|
+
if (!iterator.hasNextKey()) {
|
|
581
|
+
return null
|
|
582
|
+
}
|
|
583
|
+
while (iterator.hasNextKey()) {
|
|
584
|
+
val key = iterator.nextKey()
|
|
585
|
+
val readableType = readableMap.getType(key)
|
|
586
|
+
Log.e(TAG, "readableType$readableType $readableMap")
|
|
587
|
+
try {
|
|
588
|
+
when (readableType) {
|
|
589
|
+
ReadableType.Null -> jsonObject.put(key, null)
|
|
590
|
+
ReadableType.Boolean -> jsonObject.put(key, readableMap.getBoolean(key))
|
|
591
|
+
ReadableType.Number -> // Can be int or double.
|
|
592
|
+
jsonObject.put(key, readableMap.getInt(key))
|
|
593
|
+
|
|
594
|
+
ReadableType.String -> jsonObject.put(key, readableMap.getString(key))
|
|
595
|
+
ReadableType.Array -> jsonObject.put(key, convertArrayToJson(readableMap.getArray(key)))
|
|
596
|
+
ReadableType.Map -> jsonObject.put(key, convertMapToJson(readableMap.getMap(key)))
|
|
597
|
+
else -> {}
|
|
598
|
+
}
|
|
599
|
+
} catch (ex: JSONException) {
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return jsonObject
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
@Throws(JSONException::class)
|
|
606
|
+
private fun convertArrayToJson(readableArray: ReadableArray?): JSONArray {
|
|
607
|
+
val array = JSONArray()
|
|
608
|
+
for (i in 0 until readableArray!!.size()) {
|
|
609
|
+
when (readableArray!!.getType(i)) {
|
|
610
|
+
ReadableType.Null -> {}
|
|
611
|
+
ReadableType.Boolean -> array.put(readableArray!!.getBoolean(i))
|
|
612
|
+
ReadableType.Number -> array.put(readableArray!!.getDouble(i))
|
|
613
|
+
ReadableType.String -> array.put(readableArray!!.getString(i))
|
|
614
|
+
ReadableType.Map -> array.put(convertMapToJson(readableArray!!.getMap(i)))
|
|
615
|
+
ReadableType.Array -> array.put(convertArrayToJson(readableArray!!.getArray(i)))
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
return array
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
fun jsonToWritableMap(jsonObject: JSONObject?): WritableMap? {
|
|
623
|
+
val writableMap: WritableMap = WritableNativeMap()
|
|
624
|
+
if (jsonObject == null) {
|
|
625
|
+
return null
|
|
626
|
+
}
|
|
627
|
+
val iterator = jsonObject.keys()
|
|
628
|
+
if (!iterator.hasNext()) {
|
|
629
|
+
return null
|
|
630
|
+
}
|
|
631
|
+
while (iterator.hasNext()) {
|
|
632
|
+
val key = iterator.next()
|
|
633
|
+
try {
|
|
634
|
+
val value = jsonObject[key]
|
|
635
|
+
if (value == null) {
|
|
636
|
+
writableMap.putNull(key)
|
|
637
|
+
} else if (value is Boolean) {
|
|
638
|
+
writableMap.putBoolean(key, value)
|
|
639
|
+
} else if (value is Int) {
|
|
640
|
+
writableMap.putInt(key, value)
|
|
641
|
+
} else if (value is Double) {
|
|
642
|
+
writableMap.putDouble(key, value)
|
|
643
|
+
} else if (value is String) {
|
|
644
|
+
writableMap.putString(key, value)
|
|
645
|
+
} else if (value is JSONObject) {
|
|
646
|
+
writableMap.putMap(key, jsonToWritableMap(value))
|
|
647
|
+
} else if (value is JSONArray) {
|
|
648
|
+
writableMap.putArray(key, jsonArrayToWritableArray(value))
|
|
649
|
+
}
|
|
650
|
+
} catch (ex: JSONException) {
|
|
651
|
+
// Do nothing and fail silently
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
return writableMap
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
fun jsonArrayToWritableArray(jsonArray: JSONArray?): WritableArray? {
|
|
659
|
+
val writableArray: WritableArray = WritableNativeArray()
|
|
660
|
+
|
|
661
|
+
if (jsonArray == null) {
|
|
662
|
+
return null
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (jsonArray.length() <= 0) {
|
|
666
|
+
return null
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
for (i in 0 until jsonArray.length()) {
|
|
670
|
+
try {
|
|
671
|
+
val value = jsonArray[i]
|
|
672
|
+
if (value == null) {
|
|
673
|
+
writableArray.pushNull()
|
|
674
|
+
} else if (value is Boolean) {
|
|
675
|
+
writableArray.pushBoolean(value)
|
|
676
|
+
} else if (value is Int) {
|
|
677
|
+
writableArray.pushInt(value)
|
|
678
|
+
} else if (value is Double) {
|
|
679
|
+
writableArray.pushDouble(value)
|
|
680
|
+
} else if (value is String) {
|
|
681
|
+
writableArray.pushString(value)
|
|
682
|
+
} else if (value is JSONObject) {
|
|
683
|
+
writableArray.pushMap(jsonToWritableMap(value))
|
|
684
|
+
} else if (value is JSONArray) {
|
|
685
|
+
writableArray.pushArray(jsonArrayToWritableArray(value))
|
|
686
|
+
}
|
|
687
|
+
} catch (e: JSONException) {
|
|
688
|
+
// Do nothing and fail silently
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
return writableArray
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
companion object {
|
|
696
|
+
const val NAME = "Rncustomerglu"
|
|
697
|
+
}
|
|
698
|
+
}
|