reactnative-plugin-appice 1.7.10 → 1.7.12

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.
@@ -114,8 +114,7 @@ dependencies {
114
114
  annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.3.1"
115
115
 
116
116
  //appice
117
- implementation 'appice.io.android:sdk:2.5.76'
118
- //implementation files('libs/libsdk-release.aar')
117
+ implementation 'appice.io.android:sdk:2.5.78'
119
118
 
120
119
  //glide
121
120
  implementation "com.github.bumptech.glide:glide:4.11.0"
@@ -5,7 +5,6 @@
5
5
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
6
6
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7
7
  <uses-permission android:name="android.permission.INTERNET" />
8
-
9
8
  <uses-permission android:name="android.permission.VIBRATE" />
10
9
 
11
10
  <uses-permission android:name="android.permission.WAKE_LOCK" />
@@ -1,6 +1,9 @@
1
1
  package com.reactlibrary;
2
2
 
3
+ import android.content.Context;
4
+
3
5
  import com.facebook.react.bridge.Arguments;
6
+ import com.facebook.react.bridge.Callback;
4
7
  import com.facebook.react.bridge.ReadableArray;
5
8
  import com.facebook.react.bridge.ReadableMap;
6
9
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
@@ -12,6 +15,7 @@ import java.util.ArrayList;
12
15
  import java.util.HashMap;
13
16
  import java.util.Iterator;
14
17
  import java.util.Map;
18
+
15
19
  import org.json.JSONException;
16
20
  import org.json.JSONObject;
17
21
 
@@ -21,7 +25,7 @@ import semusi.activitysdk.User;
21
25
  public class AppICEUtils {
22
26
  private static final String TAG = "AppICEUtils";
23
27
 
24
- public static WritableMap convertClassToWritableMap(AppICEInboxMessage inboxMessage){
28
+ public static WritableMap convertClassToWritableMap(AppICEInboxMessage inboxMessage) {
25
29
  WritableMap inboxObject = Arguments.createMap();
26
30
  try {
27
31
  if (inboxMessage != null) {
@@ -35,17 +39,20 @@ public class AppICEUtils {
35
39
  inboxObject.putString(EnumConstants.INBOX_MESSAGE.getValue(), inboxMessage.getMessageBody());
36
40
  inboxObject.putString(EnumConstants.INBOX_MESSAGE_ICON.getValue(), inboxMessage.getMessageIcon());
37
41
  inboxObject.putMap(EnumConstants.INBOX_CUSTOM_DATA.getValue(), toWritableMap(inboxMessage.getCustomData()));
38
- }
39
- }catch (Throwable throwable){}
42
+ }
43
+ } catch (Throwable throwable) {
44
+ }
40
45
  return inboxObject;
41
46
  }
42
- /**
47
+
48
+ /**
43
49
  * This method accept object of native User class (semusi.activitysdk.User)
44
50
  * and convert to WritableMap for hybrid side
51
+ *
45
52
  * @param user object of native User class
46
53
  * @return WritableMap
47
54
  */
48
- public static WritableMap convertUserClassToWritableMap(User user){
55
+ public static WritableMap convertUserClassToWritableMap(User user) {
49
56
  WritableMap userObject = Arguments.createMap();
50
57
  try {
51
58
  if (user != null) {
@@ -67,6 +74,7 @@ public class AppICEUtils {
67
74
  }
68
75
  return userObject;
69
76
  }
77
+
70
78
  public static WritableMap toWritableMap(Map<String, Object> map) {
71
79
  WritableMap writableMap = Arguments.createMap();
72
80
  Iterator iterator = map.entrySet().iterator();
@@ -151,7 +159,7 @@ public class AppICEUtils {
151
159
  }
152
160
  return array;
153
161
  }
154
-
162
+
155
163
  /**
156
164
  * @param propsMap took data from js and iterate it and store in hashmap
157
165
  * @return map of the props data
@@ -173,10 +181,10 @@ public class AppICEUtils {
173
181
  props.put(key, propsMap.getBoolean(key));
174
182
  } else if (readableType == ReadableType.Number) {
175
183
  try {
176
- props.put(key, propsMap.getDouble(key));
184
+ props.put(key, propsMap.getInt(key));
177
185
  } catch (Throwable t) {
178
186
  try {
179
- props.put(key, propsMap.getInt(key));
187
+ props.put(key, propsMap.getDouble(key));
180
188
  } catch (Throwable t1) {
181
189
  AppICEUtils.printLog(TAG, "Unhandled ReadableType.Number from ReadableMap");
182
190
  }
@@ -191,7 +199,44 @@ public class AppICEUtils {
191
199
  return props;
192
200
  }
193
201
 
194
- public static void printLog(String TAG, String message){
195
- System.out.println(TAG+", "+message);
202
+ public static JSONObject toJSONObject(ReadableMap readableMap) {
203
+ JSONObject jsonObject = new JSONObject();
204
+
205
+ try {
206
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
207
+
208
+ while (iterator.hasNextKey()) {
209
+ String key = iterator.nextKey();
210
+ ReadableType type = readableMap.getType(key);
211
+
212
+ switch (type) {
213
+ case Null:
214
+ jsonObject.put(key, null);
215
+ break;
216
+ case Boolean:
217
+ jsonObject.put(key, readableMap.getBoolean(key));
218
+ break;
219
+ case Number:
220
+ jsonObject.put(key, readableMap.getDouble(key));
221
+ break;
222
+ case String:
223
+ jsonObject.put(key, readableMap.getString(key));
224
+ break;
225
+ case Map:
226
+ jsonObject.put(key, toJSONObject(readableMap.getMap(key)));
227
+ break;
228
+ }
229
+ }
230
+ }catch (Throwable t){
231
+ return jsonObject;
232
+ }
233
+
234
+ return jsonObject;
235
+ }
236
+
237
+
238
+
239
+ public static void printLog(String TAG, String message) {
240
+ System.out.println(TAG + ", " + message);
196
241
  }
197
242
  }
@@ -2,6 +2,10 @@ package com.reactlibrary;
2
2
 
3
3
  import static com.reactlibrary.AppICEUtils.arrayListStringFromReadableArray;
4
4
  import static com.reactlibrary.AppICEUtils.eventPropsFromReadableMap;
5
+ import static com.reactlibrary.StringConstants.MEDIA_DATA;
6
+ import static com.reactlibrary.StringConstants.MEDIA_THUMBNAIL;
7
+ import static com.reactlibrary.StringConstants.MEDIA_TYPE;
8
+ import static com.reactlibrary.StringConstants.MEDIA_URL;
5
9
 
6
10
  import android.content.Context;
7
11
  import android.content.Intent;
@@ -30,10 +34,14 @@ import androidx.annotation.NonNull;
30
34
  import androidx.annotation.Nullable;
31
35
 
32
36
  import com.facebook.react.bridge.ReadableArray;
37
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
33
38
  import com.facebook.react.bridge.WritableArray;
34
39
  import com.facebook.react.bridge.WritableMap;
35
40
  import com.facebook.react.modules.core.DeviceEventManagerModule;
36
41
 
42
+ import org.json.JSONException;
43
+ import org.json.JSONObject;
44
+
37
45
  public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
38
46
  private static ReactApplicationContext context = null;
39
47
  private static final String TAG = "AppIceReactPlugin";
@@ -235,25 +243,25 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
235
243
 
236
244
  try {
237
245
  if (map.containsKey(EnumConstants.APPICE_DATE_OF_BIRTH.getValue())) {
238
- Object age = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
239
- if (age != null) {
240
- user.setDob((Integer) age);
246
+ Object dob = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
247
+ if (dob != null) {
248
+ user.setDob((Integer) dob);
241
249
  }
242
250
  }
243
251
  } catch (Exception e) {
244
252
  AppICEUtils.printLog(TAG, "setUser: dob issue " + e.getMessage());
245
253
  }
246
-
247
254
  try {
248
- if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION.getValue())) {
249
- Object ed = map.get(EnumConstants.APPICE_USER_EDUCATION.getValue());
250
- if (ed != null) {
251
- user.setEducationType(ed.toString());
255
+ if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue())) {
256
+ Object edt = map.get(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
257
+ if (edt != null) {
258
+ user.setEducationType(edt.toString());
252
259
  }
253
260
  }
254
261
  } catch (Exception e) {
255
- AppICEUtils.printLog(TAG, "setUser: ed issue " + e.getMessage());
256
- }
262
+ AppICEUtils.printLog(TAG, "setEducationType: edt issue " + e.getMessage());
263
+ }
264
+
257
265
 
258
266
  try {
259
267
  if (map.containsKey(EnumConstants.APPICE_USER_GENDER.getValue())) {
@@ -355,22 +363,15 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
355
363
  * @Callback will recive Map<String, Object> object
356
364
  */
357
365
  @ReactMethod
358
- public void getMediaData(ReadableMap inboxMessage,String mediayKey,Callback callback) {
359
-
360
- Context context = getReactApplicationContext();
361
- AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),context);
362
- if (inboxMessageInstance != null) {
363
- Map<String, Object> map = inboxMessageInstance.getMediaData(mediayKey);
364
- if (map != null) {
365
- callback.invoke(AppICEUtils.toWritableMap(map), null);
366
- } else {
367
- callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
368
- }
369
- } else {
370
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
366
+ public void getMediaData(ReadableMap inboxMessage, String mediayKey, Callback callback) {
367
+ try {
368
+ Context context = getReactApplicationContext();
369
+ getMediaApiHelper(inboxMessage,null, MEDIA_DATA, mediayKey, callback, context);
370
+ } catch (Throwable e) {
371
371
  }
372
372
  }
373
373
 
374
+
374
375
  /**
375
376
  * To get Media URL from getMediaData
376
377
  * inboxMessage {AppICEInboxMessage as a ReadableMap}
@@ -378,52 +379,37 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
378
379
  * @callback callback will receive mediaUrl{string}
379
380
  */
380
381
  @ReactMethod
381
- public void getMediaUrl(ReadableMap inboxMessage,ReadableMap mediaData,Callback callback) {
382
- Context context = getReactApplicationContext();
383
- AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),context);
384
- if(inboxMessageInstance != null){
385
- String mediaUrl = inboxMessageInstance.getMediaUrl(AppICEUtils.eventPropsFromReadableMap(mediaData));
386
- callback.invoke(mediaUrl, null);
387
- } else{
388
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
389
- }
382
+ public void getMediaUrl(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
383
+ Context context = getReactApplicationContext();
384
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_URL,"", callback, context);
390
385
  }
391
- /**
392
- * To get Media type from customdata
386
+
387
+ /**
388
+ * To get Media type from customdata
393
389
  * inboxMessage {AppICEInboxMessage as a ReadableMap}
394
390
  * mediaData customData : this we will recived from getmediadata callback
391
+ *
395
392
  * @callback callback will receive mediaType{string}
396
393
  */
397
394
  @ReactMethod
398
- public void getMediaType(ReadableMap inboxMessage,ReadableMap mediaData,Callback callback) {
399
- Context context = getReactApplicationContext();
400
- AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),context);
401
- if(inboxMessageInstance != null){
402
- String mediaType = inboxMessageInstance.getMediaType(AppICEUtils.eventPropsFromReadableMap(mediaData));
403
- callback.invoke(mediaType, null);
404
- } else{
405
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
406
- }
395
+ public void getMediaType(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
396
+ Context context = getReactApplicationContext();
397
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_TYPE, "", callback, context);
407
398
  }
399
+
408
400
  /**
409
- * To get Media Thumbnail from customdata
401
+ * To get Media Thumbnail from customdata
410
402
  * inboxMessage {AppICEInboxMessage as a ReadableMap}
411
403
  * mediaData customData : this we will recived from getmediadata callback
404
+ *
412
405
  * @callback callback will receive Thumbnail{string}
413
406
  */
414
407
  @ReactMethod
415
- public void getMediaThumbnail(ReadableMap inboxMessage,ReadableMap mediaData,Callback callback) {
416
- Context context = getReactApplicationContext();
417
- AppICEInboxMessage inboxMessageInstance = AppICEInboxMessage.getAppICEInboxMessage(inboxMessage.toString(),context);
418
- if(inboxMessageInstance != null){
419
- String mediaThumbnail = inboxMessageInstance.getMediaThumbnail(AppICEUtils.eventPropsFromReadableMap(mediaData));
420
- callback.invoke(mediaThumbnail, null);
421
- } else{
422
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
423
- }
408
+ public void getMediaThumbnail(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
409
+ Context context = getReactApplicationContext();
410
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_THUMBNAIL, "",callback, context);
424
411
  }
425
412
 
426
-
427
413
  //======================
428
414
  // LISTENER
429
415
  //======================
@@ -493,8 +479,11 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
493
479
  Context context = getReactApplicationContext();
494
480
  WritableArray writableArray = Arguments.createArray();
495
481
  try {
496
- // convert ReadableArray (Hybrid) to ArrayList<String> (Native)
497
- ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
482
+ ArrayList<String> finalValues = null;
483
+ if (userIds != null) {
484
+ // convert ReadableArray (Hybrid) to ArrayList<String> (Native)
485
+ finalValues = arrayListStringFromReadableArray(userIds);
486
+ }
498
487
  // get list of user class object from native sdk
499
488
  List<User> users = ContextSdk.getUser(finalValues,context);
500
489
  for (int i = 0; i < users.size(); i++) {
@@ -508,7 +497,7 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
508
497
  callback.invoke(e.getMessage());
509
498
  }
510
499
  }
511
- /**
500
+ /**
512
501
  * To sync up data with server
513
502
  * callback will have boolean true or false
514
503
  */
@@ -695,4 +684,66 @@ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
695
684
  AppICEUtils.printLog(TAG, "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!" + e);
696
685
  }
697
686
  }
687
+ private static AppICEInboxMessage getMediaPreProcessing(ReadableMap inboxMessage,Context context) {
688
+ AppICEInboxMessage appICEInboxMessage = null;
689
+ JSONObject inboxJSON = AppICEUtils.toJSONObject(inboxMessage);
690
+ if (inboxJSON != null && inboxJSON.length()>0) {
691
+ appICEInboxMessage = AppICEInboxMessage.getAppICEInboxMessage(inboxJSON.toString(), context);
692
+ if (appICEInboxMessage != null) {
693
+ return appICEInboxMessage;
694
+ }
695
+ }
696
+ return appICEInboxMessage;
697
+ }
698
+
699
+ public static void getMediaApiHelper(ReadableMap inboxMessage, ReadableMap mediaData, String type, String mediayKey, Callback callback, Context context){
700
+
701
+ AppICEInboxMessage appICEInboxMessage = getMediaPreProcessing(inboxMessage, context);
702
+ if (appICEInboxMessage != null) {
703
+ switch (type) {
704
+ case "mediaType": {
705
+ if (mediaData != null){
706
+ String mediaType = appICEInboxMessage.getMediaType(AppICEUtils.eventPropsFromReadableMap(mediaData));
707
+ callback.invoke(mediaType, null);
708
+ }else
709
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
710
+ break;
711
+ }
712
+
713
+ case "mediaUrl": {
714
+ if (mediaData != null) {
715
+ String mediaUrl = appICEInboxMessage.getMediaUrl(AppICEUtils.eventPropsFromReadableMap(mediaData));
716
+ callback.invoke(mediaUrl, null);
717
+ }else
718
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
719
+ break;
720
+ }
721
+
722
+ case "mediaThumbnail": {
723
+ if (mediaData != null) {
724
+ String mediaThumbnail = appICEInboxMessage.getMediaThumbnail(AppICEUtils.eventPropsFromReadableMap(mediaData));
725
+ callback.invoke(mediaThumbnail, null);
726
+ }else
727
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
728
+ break;
729
+ }
730
+
731
+ case "mediaData":{
732
+ if (mediayKey != null) {
733
+ Map<String, Object> map = appICEInboxMessage.getMediaData(mediayKey);
734
+ if (map != null) {
735
+ callback.invoke(AppICEUtils.toWritableMap(map), null);
736
+ } else {
737
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
738
+ }
739
+ }else{
740
+ callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
741
+ }
742
+ }
743
+ }
744
+ }else {
745
+ callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
746
+ }
747
+
748
+ }
698
749
  }
@@ -117,10 +117,7 @@ public enum EnumConstants {
117
117
  return UserInfoConstants.EDUCATION_TYPE;
118
118
  }
119
119
 
120
- case "APPICE_USER_EDUCATION":{
121
- return "ed";
122
- }
123
-
120
+
124
121
  case "APPICE_USER_GENDER":{
125
122
  return UserInfoConstants.GENDER;
126
123
  }
@@ -150,7 +147,7 @@ public enum EnumConstants {
150
147
  }
151
148
 
152
149
  case "INBOX_TITLE":{
153
- return AppICEConstants.TITLE;
150
+ return "title";
154
151
  }
155
152
 
156
153
  case "INBOX_MESSAGE_STATUS":{
@@ -1,5 +1,10 @@
1
1
  package com.reactlibrary;
2
- public class StringConstants{
3
- public static final String FAILED_RETRIVE_MEDIA_DATA = "Failed to retrieve media data";
4
- public static final String INVALID_INBOX_FORMAT = "Invalid inbox message format";
2
+ public interface StringConstants{
3
+ String FAILED_RETRIVE_MEDIA_DATA = "Failed to retrieve media data";
4
+ String INVALID_INBOX_FORMAT = "Invalid inbox message format";
5
+
6
+ String MEDIA_URL = "mediaUrl";
7
+ String MEDIA_TYPE = "mediaType";
8
+ String MEDIA_THUMBNAIL = "mediaThumbnail";
9
+ String MEDIA_DATA = "mediaData";
5
10
  }