reteno-react-native-sdk 1.8.0 → 2.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/android/build.gradle +1 -1
- package/android/src/main/AndroidManifest.xml +8 -1
- package/android/src/main/java/com/retenosdk/RetenoCustomReceiverInAppData.java +1 -11
- package/android/src/main/java/com/retenosdk/RetenoMessagingService.java +5 -0
- package/android/src/main/java/com/retenosdk/RetenoSdkModule.java +199 -109
- package/android/src/main/java/com/retenosdk/RetenoUserAttributes.java +22 -2
- package/ios/RetenoSdk.m +4 -0
- package/ios/RetenoSdk.swift +214 -12
- package/ios/RetenoUserAttributes.swift +3 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +38 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/reteno-react-native-sdk.podspec +1 -1
- package/src/index.ts +66 -1
- package/android/src/main/java/com/retenosdk/RetenoReactNativeApplication.java +0 -7
package/android/build.gradle
CHANGED
|
@@ -72,7 +72,7 @@ dependencies {
|
|
|
72
72
|
//noinspection GradleDynamicVersion
|
|
73
73
|
implementation "com.facebook.react:react-native"
|
|
74
74
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
75
|
-
implementation 'com.reteno:fcm:2.9.
|
|
75
|
+
implementation 'com.reteno:fcm:2.9.5'
|
|
76
76
|
implementation "com.google.firebase:firebase-messaging:23.1.0"
|
|
77
77
|
implementation "com.google.firebase:firebase-messaging-ktx:23.1.0"
|
|
78
78
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
xmlns:tools="http://schemas.android.com/tools"
|
|
3
3
|
package="com.retenosdk">
|
|
4
4
|
<application>
|
|
5
|
+
<service
|
|
6
|
+
android:name="com.retenosdk.RetenoMessagingService"
|
|
7
|
+
android:exported="false">
|
|
8
|
+
<intent-filter>
|
|
9
|
+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
|
10
|
+
</intent-filter>
|
|
11
|
+
</service>
|
|
12
|
+
|
|
5
13
|
<receiver
|
|
6
14
|
android:name="com.retenosdk.RetenoPushReceiver"
|
|
7
15
|
android:enabled="true"
|
|
@@ -33,4 +41,3 @@
|
|
|
33
41
|
tools:replace="android:value" />
|
|
34
42
|
</application>
|
|
35
43
|
</manifest>
|
|
36
|
-
|
|
@@ -8,8 +8,6 @@ import android.os.Bundle;
|
|
|
8
8
|
import android.net.Uri;
|
|
9
9
|
import android.webkit.URLUtil;
|
|
10
10
|
|
|
11
|
-
import com.facebook.react.bridge.ReactContext;
|
|
12
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
13
11
|
import com.facebook.react.bridge.Arguments;
|
|
14
12
|
import com.facebook.react.bridge.WritableMap;
|
|
15
13
|
|
|
@@ -66,18 +64,10 @@ public class RetenoCustomReceiverInAppData extends BroadcastReceiver {
|
|
|
66
64
|
eventData.putMap("customData", customDataMap);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
ReactContext reactContext = null;
|
|
70
|
-
try {
|
|
71
|
-
reactContext = ((RetenoReactNativeApplication) context.getApplicationContext())
|
|
72
|
-
.getReactContext();
|
|
73
|
-
} catch (Exception e) {
|
|
74
|
-
// Log but continue - event will be queued
|
|
75
|
-
}
|
|
76
|
-
|
|
77
67
|
RetenoEventQueue.getInstance().dispatch(
|
|
78
68
|
"reteno-in-app-custom-data-received",
|
|
79
69
|
eventData,
|
|
80
|
-
|
|
70
|
+
RetenoSdkModule.getSharedReactContext()
|
|
81
71
|
);
|
|
82
72
|
}
|
|
83
73
|
}
|
|
@@ -5,6 +5,8 @@ import androidx.annotation.Nullable;
|
|
|
5
5
|
import android.content.Context;
|
|
6
6
|
import android.content.Intent;
|
|
7
7
|
import android.os.Bundle;
|
|
8
|
+
import android.os.Handler;
|
|
9
|
+
import android.os.Looper;
|
|
8
10
|
|
|
9
11
|
import androidx.annotation.NonNull;
|
|
10
12
|
|
|
@@ -16,11 +18,13 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
16
18
|
import com.facebook.react.bridge.ReactMethod;
|
|
17
19
|
import com.facebook.react.bridge.ReadableMap;
|
|
18
20
|
import com.facebook.react.bridge.ReadableArray;
|
|
21
|
+
import com.facebook.react.bridge.ReadableType;
|
|
19
22
|
import com.facebook.react.bridge.WritableMap;
|
|
20
23
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
21
24
|
import com.facebook.react.bridge.WritableArray;
|
|
22
25
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
23
|
-
import com.reteno.core.
|
|
26
|
+
import com.reteno.core.Reteno;
|
|
27
|
+
import com.reteno.core.RetenoConfig;
|
|
24
28
|
import com.reteno.core.data.remote.model.recommendation.get.Recoms;
|
|
25
29
|
import com.reteno.core.domain.callback.appinbox.RetenoResultCallback;
|
|
26
30
|
import com.reteno.core.domain.model.appinbox.AppInboxMessages;
|
|
@@ -31,6 +35,7 @@ import com.reteno.core.domain.model.recommendation.get.RecomRequest;
|
|
|
31
35
|
import com.reteno.core.domain.model.recommendation.post.RecomEvent;
|
|
32
36
|
import com.reteno.core.domain.model.recommendation.post.RecomEventType;
|
|
33
37
|
import com.reteno.core.domain.model.recommendation.post.RecomEvents;
|
|
38
|
+
import com.reteno.core.domain.model.event.LifecycleTrackingOptions;
|
|
34
39
|
import com.reteno.core.features.appinbox.AppInboxStatus;
|
|
35
40
|
import com.reteno.core.view.iam.callback.InAppData;
|
|
36
41
|
import com.reteno.core.view.iam.callback.InAppCloseData;
|
|
@@ -59,6 +64,8 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
59
64
|
public static final String NAME = "RetenoSdk";
|
|
60
65
|
private static final String PREFS_NAME = "RetenoPrefs";
|
|
61
66
|
private static final String AUTO_OPEN_LINKS_KEY = "autoOpenLinks";
|
|
67
|
+
private static volatile boolean sdkInitialized = false;
|
|
68
|
+
private static volatile ReactApplicationContext sharedReactContext;
|
|
62
69
|
ReactApplicationContext context;
|
|
63
70
|
|
|
64
71
|
public static boolean isAutoOpenLinksEnabled(Context context) {
|
|
@@ -66,9 +73,14 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
66
73
|
return prefs.getBoolean(AUTO_OPEN_LINKS_KEY, true); // default true
|
|
67
74
|
}
|
|
68
75
|
|
|
76
|
+
public static ReactApplicationContext getSharedReactContext() {
|
|
77
|
+
return sharedReactContext;
|
|
78
|
+
}
|
|
79
|
+
|
|
69
80
|
public RetenoSdkModule(ReactApplicationContext reactContext) {
|
|
70
81
|
super(reactContext);
|
|
71
82
|
context = reactContext;
|
|
83
|
+
sharedReactContext = reactContext;
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
@Override
|
|
@@ -91,20 +103,158 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
91
103
|
|
|
92
104
|
@ReactMethod
|
|
93
105
|
public void setDeviceToken(String deviceToken, Promise promise) {
|
|
106
|
+
promise.resolve(true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@ReactMethod
|
|
110
|
+
public synchronized void initialize(ReadableMap payload, Promise promise) {
|
|
111
|
+
if (sdkInitialized) {
|
|
112
|
+
promise.resolve(true);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
String apiKey = (payload != null && payload.hasKey("apiKey") && !payload.isNull("apiKey"))
|
|
117
|
+
? payload.getString("apiKey")
|
|
118
|
+
: null;
|
|
119
|
+
|
|
120
|
+
if (apiKey == null || apiKey.trim().isEmpty()) {
|
|
121
|
+
promise.reject("100", "Missing argument: apiKey");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
boolean debugMode = payload != null && payload.hasKey("isDebugMode")
|
|
127
|
+
&& !payload.isNull("isDebugMode") && payload.getBoolean("isDebugMode");
|
|
128
|
+
boolean pauseInAppMessages = payload != null && payload.hasKey("pauseInAppMessages")
|
|
129
|
+
&& !payload.isNull("pauseInAppMessages") && payload.getBoolean("pauseInAppMessages");
|
|
130
|
+
|
|
131
|
+
RetenoConfig.Builder builder = new RetenoConfig.Builder()
|
|
132
|
+
.accessKey(apiKey.trim())
|
|
133
|
+
.setDebug(debugMode);
|
|
134
|
+
|
|
135
|
+
if (pauseInAppMessages) {
|
|
136
|
+
builder.pauseInAppMessages(true);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
com.facebook.react.bridge.Dynamic lifecycleDynamic = null;
|
|
140
|
+
if (payload != null && payload.hasKey("lifecycleTrackingOptions")) {
|
|
141
|
+
lifecycleDynamic = payload.getDynamic("lifecycleTrackingOptions");
|
|
142
|
+
}
|
|
143
|
+
LifecycleTrackingOptions lifecycleOptions = parseLifecycleTrackingOption(lifecycleDynamic);
|
|
144
|
+
if (payload != null && payload.hasKey("lifecycleTrackingOptions") && lifecycleOptions == null) {
|
|
145
|
+
promise.reject(
|
|
146
|
+
"InvalidArgument",
|
|
147
|
+
"Invalid argument: lifecycleTrackingOptions. Expected 'ALL', 'NONE', or lifecycle options object."
|
|
148
|
+
);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (lifecycleOptions != null) {
|
|
152
|
+
builder.lifecycleTrackingOptions(lifecycleOptions);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (payload != null && payload.hasKey("sessionDurationSeconds") && !payload.isNull("sessionDurationSeconds")) {
|
|
156
|
+
double sessionDurationSeconds = payload.getDouble("sessionDurationSeconds");
|
|
157
|
+
if (sessionDurationSeconds > 0D) {
|
|
158
|
+
builder.sessionDuration((long) (sessionDurationSeconds * 1000L));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
sdkInitialized = true;
|
|
163
|
+
|
|
164
|
+
Runnable initTask = () -> {
|
|
165
|
+
try {
|
|
166
|
+
Reteno.initWithConfig(builder.build());
|
|
167
|
+
promise.resolve(true);
|
|
168
|
+
} catch (Exception e) {
|
|
169
|
+
sdkInitialized = false;
|
|
170
|
+
promise.reject("Reteno Android SDK initialize Error", e);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
if (Looper.myLooper() == Looper.getMainLooper()) {
|
|
175
|
+
initTask.run();
|
|
176
|
+
} else {
|
|
177
|
+
new Handler(Looper.getMainLooper()).post(initTask);
|
|
178
|
+
}
|
|
179
|
+
} catch (Exception e) {
|
|
180
|
+
sdkInitialized = false;
|
|
181
|
+
promise.reject("Reteno Android SDK initialize Error", e);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private LifecycleTrackingOptions parseLifecycleTrackingOption(@Nullable com.facebook.react.bridge.Dynamic value) {
|
|
186
|
+
if (value == null || value.isNull()) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
ReadableType type = value.getType();
|
|
191
|
+
if (type == ReadableType.String) {
|
|
192
|
+
String raw = value.asString();
|
|
193
|
+
if (raw == null) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
String normalized = raw.trim().toUpperCase();
|
|
197
|
+
if ("ALL".equals(normalized)) {
|
|
198
|
+
return new LifecycleTrackingOptions(true, true, true, true, true);
|
|
199
|
+
}
|
|
200
|
+
if ("NONE".equals(normalized)) {
|
|
201
|
+
return new LifecycleTrackingOptions(false, false, false, false, false);
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (type != ReadableType.Map) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
ReadableMap map = value.asMap();
|
|
211
|
+
|
|
212
|
+
boolean appLifecycleEnabled = map.hasKey("appLifecycleEnabled")
|
|
213
|
+
? map.getBoolean("appLifecycleEnabled")
|
|
214
|
+
: true;
|
|
215
|
+
boolean foregroundLifecycleEnabled = map.hasKey("foregroundLifecycleEnabled")
|
|
216
|
+
? map.getBoolean("foregroundLifecycleEnabled")
|
|
217
|
+
: false;
|
|
218
|
+
boolean pushSubscriptionEnabled = map.hasKey("pushSubscriptionEnabled")
|
|
219
|
+
? map.getBoolean("pushSubscriptionEnabled")
|
|
220
|
+
: true;
|
|
221
|
+
|
|
222
|
+
boolean legacySessionEventsEnabled = map.hasKey("sessionEventsEnabled")
|
|
223
|
+
? map.getBoolean("sessionEventsEnabled")
|
|
224
|
+
: true;
|
|
225
|
+
boolean sessionStartEventsEnabled = map.hasKey("sessionStartEventsEnabled")
|
|
226
|
+
? map.getBoolean("sessionStartEventsEnabled")
|
|
227
|
+
: legacySessionEventsEnabled;
|
|
228
|
+
|
|
229
|
+
boolean sessionEndEventsEnabled;
|
|
230
|
+
if (map.hasKey("sessionEndEventsEnabled")) {
|
|
231
|
+
sessionEndEventsEnabled = map.getBoolean("sessionEndEventsEnabled");
|
|
232
|
+
} else if (map.hasKey("sessionEventsEnabled")) {
|
|
233
|
+
sessionEndEventsEnabled = legacySessionEventsEnabled;
|
|
234
|
+
} else {
|
|
235
|
+
sessionEndEventsEnabled = false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return new LifecycleTrackingOptions(
|
|
239
|
+
appLifecycleEnabled,
|
|
240
|
+
foregroundLifecycleEnabled,
|
|
241
|
+
pushSubscriptionEnabled,
|
|
242
|
+
sessionStartEventsEnabled,
|
|
243
|
+
sessionEndEventsEnabled
|
|
244
|
+
);
|
|
94
245
|
}
|
|
95
246
|
|
|
96
247
|
@ReactMethod
|
|
97
248
|
public void setUserAttributes(ReadableMap payload, Promise promise) {
|
|
98
249
|
String externalUserId = payload.getString("externalUserId");
|
|
99
|
-
User user = RetenoUserAttributes.buildUserFromPayload(payload);
|
|
100
250
|
if (externalUserId == null) {
|
|
101
251
|
promise.reject("Parsing error", "externalUserId cannot be null");
|
|
102
252
|
return;
|
|
103
253
|
}
|
|
104
254
|
|
|
105
255
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
256
|
+
User user = RetenoUserAttributes.buildUserFromPayload(payload);
|
|
257
|
+
getRetenoInstance()
|
|
108
258
|
.setUserAttributes(externalUserId, user);
|
|
109
259
|
} catch (Exception e) {
|
|
110
260
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -119,34 +269,18 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
119
269
|
}
|
|
120
270
|
|
|
121
271
|
public static void onRetenoPushReceived(Context context, Intent intent) {
|
|
122
|
-
ReactContext reactContext = null;
|
|
123
|
-
try {
|
|
124
|
-
reactContext = ((RetenoReactNativeApplication) context.getApplicationContext())
|
|
125
|
-
.getReactContext();
|
|
126
|
-
} catch (Exception e) {
|
|
127
|
-
Log.w(NAME, "Could not get ReactContext for push received", e);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
272
|
RetenoEventQueue.getInstance().dispatch(
|
|
131
273
|
"reteno-push-received",
|
|
132
274
|
parseIntent(intent),
|
|
133
|
-
|
|
275
|
+
sharedReactContext
|
|
134
276
|
);
|
|
135
277
|
}
|
|
136
278
|
|
|
137
279
|
public static void onRetenoPushClicked(Context context, Intent intent) {
|
|
138
|
-
ReactContext reactContext = null;
|
|
139
|
-
try {
|
|
140
|
-
reactContext = ((RetenoReactNativeApplication) context.getApplicationContext())
|
|
141
|
-
.getReactContext();
|
|
142
|
-
} catch (Exception e) {
|
|
143
|
-
Log.w(NAME, "Could not get ReactContext for push clicked", e);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
280
|
RetenoEventQueue.getInstance().dispatch(
|
|
147
281
|
"reteno-push-clicked",
|
|
148
282
|
parseIntent(intent),
|
|
149
|
-
|
|
283
|
+
sharedReactContext
|
|
150
284
|
);
|
|
151
285
|
}
|
|
152
286
|
|
|
@@ -215,8 +349,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
215
349
|
@ReactMethod
|
|
216
350
|
public void logEvent(ReadableMap payload, Promise promise) {
|
|
217
351
|
try {
|
|
218
|
-
(
|
|
219
|
-
.getRetenoInstance()
|
|
352
|
+
getRetenoInstance()
|
|
220
353
|
.logEvent(RetenoEvent.buildEventFromPayload(payload));
|
|
221
354
|
} catch (Exception e) {
|
|
222
355
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -231,11 +364,9 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
231
364
|
@ReactMethod
|
|
232
365
|
public void setAnonymousUserAttributes(ReadableMap payload, Promise promise) {
|
|
233
366
|
|
|
234
|
-
UserAttributesAnonymous anonymousUser = RetenoUserAttributes.buildAnonymousUserFromPayload(payload);
|
|
235
|
-
|
|
236
367
|
try {
|
|
237
|
-
|
|
238
|
-
|
|
368
|
+
UserAttributesAnonymous anonymousUser = RetenoUserAttributes.buildAnonymousUserFromPayload(payload);
|
|
369
|
+
getRetenoInstance()
|
|
239
370
|
.setAnonymousUserAttributes(anonymousUser);
|
|
240
371
|
} catch (Exception e) {
|
|
241
372
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -252,8 +383,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
252
383
|
@ReactMethod
|
|
253
384
|
public void forcePushData(Promise promise) {
|
|
254
385
|
try {
|
|
255
|
-
(
|
|
256
|
-
.getRetenoInstance().forcePushData();
|
|
386
|
+
getRetenoInstance().forcePushData();
|
|
257
387
|
promise.resolve(true);
|
|
258
388
|
} catch (Exception e) {
|
|
259
389
|
promise.reject("Reteno Android SDK forcePushData Error", e);
|
|
@@ -263,8 +393,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
263
393
|
@ReactMethod
|
|
264
394
|
public void pauseInAppMessages(Boolean isPaused, Promise promise) {
|
|
265
395
|
try {
|
|
266
|
-
(
|
|
267
|
-
.getRetenoInstance()
|
|
396
|
+
getRetenoInstance()
|
|
268
397
|
.pauseInAppMessages(isPaused);
|
|
269
398
|
promise.resolve(true);
|
|
270
399
|
} catch (Exception e) {
|
|
@@ -292,13 +421,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
292
421
|
}
|
|
293
422
|
|
|
294
423
|
try {
|
|
295
|
-
|
|
296
|
-
if (currentActivity == null) {
|
|
297
|
-
promise.reject("ActivityUnavailable", "Current activity is not available");
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
((RetenoApplication) currentActivity.getApplication())
|
|
301
|
-
.getRetenoInstance()
|
|
424
|
+
getRetenoInstance()
|
|
302
425
|
.setInAppMessagesPauseBehaviour(parsedBehaviour);
|
|
303
426
|
promise.resolve(true);
|
|
304
427
|
} catch (Exception e) {
|
|
@@ -319,13 +442,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
319
442
|
User user = RetenoUserAttributes.buildUserFromPayload(payload);
|
|
320
443
|
|
|
321
444
|
try {
|
|
322
|
-
|
|
323
|
-
if (currentActivity == null) {
|
|
324
|
-
promise.reject("ActivityUnavailable", "Current activity is not available");
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
((RetenoApplication) currentActivity.getApplication())
|
|
328
|
-
.getRetenoInstance()
|
|
445
|
+
getRetenoInstance()
|
|
329
446
|
.setMultiAccountUserAttributes(externalUserId, user);
|
|
330
447
|
} catch (Exception e) {
|
|
331
448
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -340,8 +457,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
340
457
|
@ReactMethod
|
|
341
458
|
public void updatePushPermissionStatusAndroid(Promise promise) {
|
|
342
459
|
try {
|
|
343
|
-
(
|
|
344
|
-
.getRetenoInstance().updatePushPermissionStatus();
|
|
460
|
+
getRetenoInstance().updatePushPermissionStatus();
|
|
345
461
|
promise.resolve(true);
|
|
346
462
|
} catch (Exception e) {
|
|
347
463
|
promise.reject("Reteno Android SDK forcePushData Error", e);
|
|
@@ -349,9 +465,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
349
465
|
}
|
|
350
466
|
|
|
351
467
|
private void sendEventToJS(String eventName, WritableMap eventData) {
|
|
352
|
-
|
|
353
|
-
.getReactContext();
|
|
354
|
-
RetenoEventQueue.getInstance().dispatch(eventName, eventData, reactContext);
|
|
468
|
+
RetenoEventQueue.getInstance().dispatch(eventName, eventData, sharedReactContext);
|
|
355
469
|
}
|
|
356
470
|
|
|
357
471
|
private Procedure<Bundle> pushDismissedListener;
|
|
@@ -486,8 +600,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
486
600
|
sendEventToJS("reteno-on-in-app-error", eventData);
|
|
487
601
|
}
|
|
488
602
|
};
|
|
489
|
-
(
|
|
490
|
-
.getRetenoInstance().setInAppLifecycleCallback(inAppLifecycleCallback);
|
|
603
|
+
getRetenoInstance().setInAppLifecycleCallback(inAppLifecycleCallback);
|
|
491
604
|
promise.resolve(true);
|
|
492
605
|
} catch (Exception e) {
|
|
493
606
|
promise.reject("Reteno Android SDK setInAppLifecycleCallback Error", e);
|
|
@@ -498,7 +611,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
498
611
|
public void removeInAppLifecycleCallback(Promise promise) {
|
|
499
612
|
try {
|
|
500
613
|
if (inAppLifecycleCallback != null) {
|
|
501
|
-
|
|
614
|
+
getRetenoInstance().setInAppLifecycleCallback(null);
|
|
502
615
|
inAppLifecycleCallback = null;
|
|
503
616
|
}
|
|
504
617
|
promise.resolve(true);
|
|
@@ -537,8 +650,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
537
650
|
|
|
538
651
|
RecomRequest request = new RecomRequest(productIds, categoryId, fields, null);
|
|
539
652
|
|
|
540
|
-
(
|
|
541
|
-
.getRetenoInstance().getRecommendation().fetchRecommendation(recomVariantId, request, RetenoRecommendationsResponse.class, new GetRecommendationResponseCallback<RetenoRecommendationsResponse>() {
|
|
653
|
+
getRetenoInstance().getRecommendation().fetchRecommendation(recomVariantId, request, RetenoRecommendationsResponse.class, new GetRecommendationResponseCallback<RetenoRecommendationsResponse>() {
|
|
542
654
|
@Override
|
|
543
655
|
public void onSuccess(@NonNull Recoms<RetenoRecommendationsResponse> response) {
|
|
544
656
|
List<WritableMap> recoms = new ArrayList<>();
|
|
@@ -606,8 +718,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
606
718
|
|
|
607
719
|
RecomEvents recomEvents = new RecomEvents(recomVariantId, events);
|
|
608
720
|
|
|
609
|
-
(
|
|
610
|
-
.getRetenoInstance().getRecommendation().logRecommendations(recomEvents);
|
|
721
|
+
getRetenoInstance().getRecommendation().logRecommendations(recomEvents);
|
|
611
722
|
|
|
612
723
|
promise.resolve(true);
|
|
613
724
|
} catch (IllegalArgumentException e) {
|
|
@@ -641,8 +752,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
641
752
|
}
|
|
642
753
|
|
|
643
754
|
try {
|
|
644
|
-
(
|
|
645
|
-
.getRetenoInstance()
|
|
755
|
+
getRetenoInstance()
|
|
646
756
|
.getAppInbox()
|
|
647
757
|
.getAppInboxMessages(page, pageSize, status, new RetenoResultCallback<AppInboxMessages>() {
|
|
648
758
|
@Override
|
|
@@ -680,8 +790,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
680
790
|
@ReactMethod
|
|
681
791
|
public void getAppInboxMessagesCount(Promise promise) {
|
|
682
792
|
try {
|
|
683
|
-
(
|
|
684
|
-
.getRetenoInstance()
|
|
793
|
+
getRetenoInstance()
|
|
685
794
|
.getAppInbox()
|
|
686
795
|
.getAppInboxMessagesCount(new RetenoResultCallback<Integer>() {
|
|
687
796
|
@Override
|
|
@@ -702,8 +811,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
702
811
|
@ReactMethod
|
|
703
812
|
public void markAsOpened(String messageId, Promise promise) {
|
|
704
813
|
try {
|
|
705
|
-
(
|
|
706
|
-
.getRetenoInstance()
|
|
814
|
+
getRetenoInstance()
|
|
707
815
|
.getAppInbox()
|
|
708
816
|
.markAsOpened(messageId);
|
|
709
817
|
promise.resolve(true);
|
|
@@ -715,8 +823,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
715
823
|
@ReactMethod
|
|
716
824
|
public void markAllAsOpened(Promise promise) {
|
|
717
825
|
try {
|
|
718
|
-
(
|
|
719
|
-
.getRetenoInstance()
|
|
826
|
+
getRetenoInstance()
|
|
720
827
|
.getAppInbox()
|
|
721
828
|
.markAllMessagesAsOpened(new RetenoResultCallback<Unit>() {
|
|
722
829
|
@Override
|
|
@@ -737,8 +844,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
737
844
|
@ReactMethod
|
|
738
845
|
public void unsubscribeAllMessagesCountChanged(Promise promise) {
|
|
739
846
|
try {
|
|
740
|
-
(
|
|
741
|
-
.getRetenoInstance().getAppInbox().unsubscribeAllMessagesCountChanged();
|
|
847
|
+
getRetenoInstance().getAppInbox().unsubscribeAllMessagesCountChanged();
|
|
742
848
|
messagesCountChangedCallback = null;
|
|
743
849
|
promise.resolve(null);
|
|
744
850
|
} catch (Exception e) {
|
|
@@ -769,8 +875,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
769
875
|
};
|
|
770
876
|
|
|
771
877
|
try {
|
|
772
|
-
(
|
|
773
|
-
.getRetenoInstance().getAppInbox().subscribeOnMessagesCountChanged(messagesCountChangedCallback);
|
|
878
|
+
getRetenoInstance().getAppInbox().subscribeOnMessagesCountChanged(messagesCountChangedCallback);
|
|
774
879
|
promise.resolve(null);
|
|
775
880
|
} catch (Exception e) {
|
|
776
881
|
promise.reject("SubscriptionError", e);
|
|
@@ -781,12 +886,10 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
781
886
|
public void unsubscribeMessagesCountChanged(Promise promise) {
|
|
782
887
|
try {
|
|
783
888
|
if (messagesCountChangedCallback != null) {
|
|
784
|
-
(
|
|
785
|
-
.getRetenoInstance().getAppInbox().unsubscribeMessagesCountChanged(messagesCountChangedCallback);
|
|
889
|
+
getRetenoInstance().getAppInbox().unsubscribeMessagesCountChanged(messagesCountChangedCallback);
|
|
786
890
|
messagesCountChangedCallback = null;
|
|
787
891
|
} else {
|
|
788
|
-
(
|
|
789
|
-
.getRetenoInstance().getAppInbox().unsubscribeAllMessagesCountChanged();
|
|
892
|
+
getRetenoInstance().getAppInbox().unsubscribeAllMessagesCountChanged();
|
|
790
893
|
}
|
|
791
894
|
promise.resolve(null);
|
|
792
895
|
} catch (Exception e) {
|
|
@@ -797,9 +900,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
797
900
|
@ReactMethod
|
|
798
901
|
public void initializeEventHandler(Promise promise) {
|
|
799
902
|
try {
|
|
800
|
-
|
|
801
|
-
.getReactContext();
|
|
802
|
-
RetenoEventQueue.getInstance().setInitialized(reactContext);
|
|
903
|
+
RetenoEventQueue.getInstance().setInitialized(sharedReactContext);
|
|
803
904
|
setupRetenoNotificationsListeners();
|
|
804
905
|
promise.resolve(true);
|
|
805
906
|
} catch (Exception e) {
|
|
@@ -807,6 +908,16 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
807
908
|
}
|
|
808
909
|
}
|
|
809
910
|
|
|
911
|
+
private Reteno getRetenoInstance() {
|
|
912
|
+
Reteno reteno = Reteno.getInstance();
|
|
913
|
+
if (reteno == null) {
|
|
914
|
+
throw new IllegalStateException(
|
|
915
|
+
"Reteno SDK is not initialized. Call initialize(apiKey) before using SDK methods."
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
return reteno;
|
|
919
|
+
}
|
|
920
|
+
|
|
810
921
|
@ReactMethod
|
|
811
922
|
public void setAutoOpenLinks(boolean enabled, Promise promise) {
|
|
812
923
|
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
@@ -831,8 +942,7 @@ public void logEcomEventProductViewed(ReadableMap payload, Promise promise) {
|
|
|
831
942
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
832
943
|
return;
|
|
833
944
|
}
|
|
834
|
-
(
|
|
835
|
-
.getRetenoInstance()
|
|
945
|
+
getRetenoInstance()
|
|
836
946
|
.logEcommerceEvent(event);
|
|
837
947
|
} catch (Exception e) {
|
|
838
948
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -851,8 +961,7 @@ public void logEcomEventProductCategoryViewed(ReadableMap payload, Promise promi
|
|
|
851
961
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
852
962
|
return;
|
|
853
963
|
}
|
|
854
|
-
(
|
|
855
|
-
.getRetenoInstance()
|
|
964
|
+
getRetenoInstance()
|
|
856
965
|
.logEcommerceEvent(event);
|
|
857
966
|
} catch (Exception e) {
|
|
858
967
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -871,8 +980,7 @@ public void logEcomEventProductAddedToWishlist(ReadableMap payload, Promise prom
|
|
|
871
980
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
872
981
|
return;
|
|
873
982
|
}
|
|
874
|
-
(
|
|
875
|
-
.getRetenoInstance()
|
|
983
|
+
getRetenoInstance()
|
|
876
984
|
.logEcommerceEvent(event);
|
|
877
985
|
} catch (Exception e) {
|
|
878
986
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -891,8 +999,7 @@ public void logEcomEventCartUpdated(ReadableMap payload, Promise promise) {
|
|
|
891
999
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
892
1000
|
return;
|
|
893
1001
|
}
|
|
894
|
-
(
|
|
895
|
-
.getRetenoInstance()
|
|
1002
|
+
getRetenoInstance()
|
|
896
1003
|
.logEcommerceEvent(event);
|
|
897
1004
|
} catch (Exception e) {
|
|
898
1005
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -911,8 +1018,7 @@ public void logEcomEventOrderCreated(ReadableMap payload, Promise promise) {
|
|
|
911
1018
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
912
1019
|
return;
|
|
913
1020
|
}
|
|
914
|
-
(
|
|
915
|
-
.getRetenoInstance()
|
|
1021
|
+
getRetenoInstance()
|
|
916
1022
|
.logEcommerceEvent(event);
|
|
917
1023
|
} catch (Exception e) {
|
|
918
1024
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -931,8 +1037,7 @@ public void logEcomEventOrderUpdated(ReadableMap payload, Promise promise) {
|
|
|
931
1037
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
932
1038
|
return;
|
|
933
1039
|
}
|
|
934
|
-
(
|
|
935
|
-
.getRetenoInstance()
|
|
1040
|
+
getRetenoInstance()
|
|
936
1041
|
.logEcommerceEvent(event);
|
|
937
1042
|
} catch (Exception e) {
|
|
938
1043
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -951,8 +1056,7 @@ public void logEcomEventOrderDelivered(ReadableMap payload, Promise promise) {
|
|
|
951
1056
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
952
1057
|
return;
|
|
953
1058
|
}
|
|
954
|
-
(
|
|
955
|
-
.getRetenoInstance()
|
|
1059
|
+
getRetenoInstance()
|
|
956
1060
|
.logEcommerceEvent(event);
|
|
957
1061
|
} catch (Exception e) {
|
|
958
1062
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -971,8 +1075,7 @@ public void logEcomEventOrderCancelled(ReadableMap payload, Promise promise) {
|
|
|
971
1075
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
972
1076
|
return;
|
|
973
1077
|
}
|
|
974
|
-
(
|
|
975
|
-
.getRetenoInstance()
|
|
1078
|
+
getRetenoInstance()
|
|
976
1079
|
.logEcommerceEvent(event);
|
|
977
1080
|
} catch (Exception e) {
|
|
978
1081
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -991,8 +1094,7 @@ public void logEcomEventSearchRequest(ReadableMap payload, Promise promise) {
|
|
|
991
1094
|
promise.reject("Payload Error", "Payload cannot be null");
|
|
992
1095
|
return;
|
|
993
1096
|
}
|
|
994
|
-
(
|
|
995
|
-
.getRetenoInstance()
|
|
1097
|
+
getRetenoInstance()
|
|
996
1098
|
.logEcommerceEvent(event);
|
|
997
1099
|
} catch (Exception e) {
|
|
998
1100
|
promise.reject("Reteno Android SDK Error", e);
|
|
@@ -1034,13 +1136,7 @@ public void logEcomEventSearchRequest(ReadableMap payload, Promise promise) {
|
|
|
1034
1136
|
@ReactMethod
|
|
1035
1137
|
public void pausePushInAppMessages(Boolean isPaused, Promise promise) {
|
|
1036
1138
|
try {
|
|
1037
|
-
|
|
1038
|
-
if (currentActivity == null) {
|
|
1039
|
-
promise.reject("ActivityUnavailable", "Current activity is not available");
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
((RetenoApplication) currentActivity.getApplication())
|
|
1043
|
-
.getRetenoInstance()
|
|
1139
|
+
getRetenoInstance()
|
|
1044
1140
|
.pausePushInAppMessages(isPaused);
|
|
1045
1141
|
promise.resolve(true);
|
|
1046
1142
|
} catch (Exception e) {
|
|
@@ -1068,13 +1164,7 @@ public void logEcomEventSearchRequest(ReadableMap payload, Promise promise) {
|
|
|
1068
1164
|
}
|
|
1069
1165
|
|
|
1070
1166
|
try {
|
|
1071
|
-
|
|
1072
|
-
if (currentActivity == null) {
|
|
1073
|
-
promise.reject("ActivityUnavailable", "Current activity is not available");
|
|
1074
|
-
return;
|
|
1075
|
-
}
|
|
1076
|
-
((RetenoApplication) currentActivity.getApplication())
|
|
1077
|
-
.getRetenoInstance()
|
|
1167
|
+
getRetenoInstance()
|
|
1078
1168
|
.setPushInAppMessagesPauseBehaviour(parsedBehaviour);
|
|
1079
1169
|
promise.resolve(true);
|
|
1080
1170
|
} catch (Exception e) {
|