@sentiance-react-native/core 6.0.0-beta.9
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/README.md +24 -0
- package/android/build.gradle +17 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +2 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/package-json-reader.gradle +62 -0
- package/android/sentiance-version-finder.gradle +17 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceConverter.java +364 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceEmitter.java +46 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceHelper.java +207 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentianceModule.java +529 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/SentiancePackage.java +30 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/UserLinker.java +34 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceEmitter.java +59 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/base/AbstractSentianceModule.java +33 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/ErrorCodes.java +16 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/SentianceUtils.java +160 -0
- package/android/src/main/java/com/sentiance/react/bridge/core/utils/UserCreationCompletionHandler.java +31 -0
- package/ios/RNSentianceCore+Converter.h +46 -0
- package/ios/RNSentianceCore+Converter.m +986 -0
- package/ios/RNSentianceCore.h +29 -0
- package/ios/RNSentianceCore.m +1036 -0
- package/ios/RNSentianceCore.podspec +24 -0
- package/ios/RNSentianceCore.xcodeproj/project.pbxproj +290 -0
- package/ios/RNSentianceErrorCodes.h +20 -0
- package/ios/RNSentianceErrorCodes.m +22 -0
- package/ios/RNSentianceHelper.h +31 -0
- package/ios/RNSentianceHelper.m +38 -0
- package/ios/RNSentianceNativeInitialization.h +6 -0
- package/ios/RNSentianceNativeInitialization.m +56 -0
- package/lib/core.js +64 -0
- package/lib/index.d.ts +198 -0
- package/lib/index.js +194 -0
- package/lib/utils.js +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core.utils;
|
|
2
|
+
|
|
3
|
+
import android.app.Notification;
|
|
4
|
+
import android.app.NotificationChannel;
|
|
5
|
+
import android.app.NotificationManager;
|
|
6
|
+
import android.app.PendingIntent;
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.content.Intent;
|
|
9
|
+
import android.content.pm.ApplicationInfo;
|
|
10
|
+
import android.content.pm.PackageManager;
|
|
11
|
+
import android.os.Build;
|
|
12
|
+
|
|
13
|
+
import androidx.core.app.NotificationCompat;
|
|
14
|
+
|
|
15
|
+
import java.lang.ref.WeakReference;
|
|
16
|
+
|
|
17
|
+
public class SentianceUtils {
|
|
18
|
+
|
|
19
|
+
public static final int SENTIANCE_FALLBACK_NOTIFICATION_ID = 2123874432;
|
|
20
|
+
public static final String SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_NAME = "Sentiance";
|
|
21
|
+
public static final String SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_ID = "Sentiance";
|
|
22
|
+
|
|
23
|
+
public static final String SENTIANCE_NOTIFICATION_ID = "com.sentiance.react.bridge.notification_id";
|
|
24
|
+
public static final String SENTIANCE_NOTIFICATION_TITLE = "com.sentiance.react.bridge.notification_title";
|
|
25
|
+
public static final String SENTIANCE_NOTIFICATION_ICON = "com.sentiance.react.bridge.notification_icon";
|
|
26
|
+
public static final String SENTIANCE_NOTIFICATION_CHANNEL_ID = "com.sentiance.react.bridge.channel_id";
|
|
27
|
+
public static final String SENTIANCE_NOTIFICATION_CHANNEL_NAME = "com.sentiance.react.bridge.notification_channel_name";
|
|
28
|
+
public static final String SENTIANCE_NOTIFICATION_NOTIFICATION_TEXT = "com.sentiance.react.bridge.notification_text";
|
|
29
|
+
|
|
30
|
+
public static Notification createNotificationFromManifestData(WeakReference<Context> weakContext,
|
|
31
|
+
String title, String message) {
|
|
32
|
+
Context context = weakContext.get();
|
|
33
|
+
if (context == null) return null;
|
|
34
|
+
|
|
35
|
+
String channelName = SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_NAME;
|
|
36
|
+
String channelId = SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_ID;
|
|
37
|
+
int icon = context.getApplicationInfo().icon;
|
|
38
|
+
|
|
39
|
+
ApplicationInfo info;
|
|
40
|
+
try {
|
|
41
|
+
info = context.getPackageManager().getApplicationInfo(
|
|
42
|
+
context.getPackageName(), PackageManager.GET_META_DATA);
|
|
43
|
+
channelName = getStringMetadataFromManifest(weakContext, info,
|
|
44
|
+
SENTIANCE_NOTIFICATION_CHANNEL_NAME, SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_NAME);
|
|
45
|
+
icon = getIntMetadataFromManifest(info, SENTIANCE_NOTIFICATION_ICON, icon);
|
|
46
|
+
channelId = getStringMetadataFromManifest(weakContext, info,
|
|
47
|
+
SENTIANCE_NOTIFICATION_CHANNEL_ID, SENTIANCE_FALLBACK_NOTIFICATION_CHANNEL_ID);
|
|
48
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
49
|
+
e.printStackTrace();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return createNotification(weakContext, getLaunchActivityPendingIntent(context),
|
|
53
|
+
title, message, channelName, channelId, icon);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@SuppressWarnings({"unused", "WeakerAccess"})
|
|
57
|
+
public static Notification createNotificationFromManifestData(WeakReference<Context> weakContext) {
|
|
58
|
+
Context context = weakContext.get();
|
|
59
|
+
if (context == null) return null;
|
|
60
|
+
|
|
61
|
+
String appName = context.getApplicationInfo().loadLabel(context.getPackageManager()).toString();
|
|
62
|
+
String channelName = "Sentiance";
|
|
63
|
+
int icon = context.getApplicationInfo().icon;
|
|
64
|
+
String channelId = "Sentiance";
|
|
65
|
+
String title = appName + " is running";
|
|
66
|
+
String message = "Touch to open";
|
|
67
|
+
|
|
68
|
+
ApplicationInfo info;
|
|
69
|
+
try {
|
|
70
|
+
info = context.getPackageManager().getApplicationInfo(
|
|
71
|
+
context.getPackageName(), PackageManager.GET_META_DATA);
|
|
72
|
+
title = getStringMetadataFromManifest(weakContext, info,
|
|
73
|
+
SENTIANCE_NOTIFICATION_TITLE, title);
|
|
74
|
+
message = getStringMetadataFromManifest(weakContext, info, SENTIANCE_NOTIFICATION_NOTIFICATION_TEXT, message);
|
|
75
|
+
channelName = getStringMetadataFromManifest(weakContext, info, SENTIANCE_NOTIFICATION_CHANNEL_NAME, channelName);
|
|
76
|
+
icon = getIntMetadataFromManifest(info, SENTIANCE_NOTIFICATION_ICON, icon);
|
|
77
|
+
channelId = getStringMetadataFromManifest(weakContext, info, SENTIANCE_NOTIFICATION_CHANNEL_ID, channelId);
|
|
78
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
79
|
+
e.printStackTrace();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return createNotification(weakContext, getLaunchActivityPendingIntent(context), title, message, channelName,
|
|
83
|
+
channelId, icon);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public static int getSentianceNotificationId(WeakReference<Context> weakContext) {
|
|
87
|
+
Context context = weakContext.get();
|
|
88
|
+
if (context == null) {
|
|
89
|
+
return SENTIANCE_FALLBACK_NOTIFICATION_ID;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
ApplicationInfo info = context.getPackageManager().getApplicationInfo(
|
|
94
|
+
context.getPackageName(), PackageManager.GET_META_DATA);
|
|
95
|
+
return getIntMetadataFromManifest(info, SENTIANCE_NOTIFICATION_ID, SENTIANCE_FALLBACK_NOTIFICATION_ID);
|
|
96
|
+
} catch (PackageManager.NameNotFoundException e) {
|
|
97
|
+
e.printStackTrace();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return SENTIANCE_FALLBACK_NOTIFICATION_ID;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private static Notification createNotification(WeakReference<Context> weakContext, PendingIntent pendingIntent,
|
|
104
|
+
String title, String message, String channelName, String channelId,
|
|
105
|
+
Integer icon) {
|
|
106
|
+
Context context = weakContext.get();
|
|
107
|
+
if (context == null) return null;
|
|
108
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
|
109
|
+
NotificationChannel channel = new NotificationChannel(channelId,
|
|
110
|
+
channelName, NotificationManager.IMPORTANCE_LOW);
|
|
111
|
+
channel.setShowBadge(false);
|
|
112
|
+
NotificationManager notificationManager =
|
|
113
|
+
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
|
114
|
+
if (notificationManager != null)
|
|
115
|
+
notificationManager.createNotificationChannel(channel);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return new NotificationCompat.Builder(context, channelId)
|
|
119
|
+
.setContentTitle(title)
|
|
120
|
+
.setContentText(message)
|
|
121
|
+
.setContentIntent(pendingIntent)
|
|
122
|
+
.setShowWhen(false)
|
|
123
|
+
.setSmallIcon(icon)
|
|
124
|
+
.setPriority(NotificationCompat.PRIORITY_MIN)
|
|
125
|
+
.build();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private static PendingIntent getLaunchActivityPendingIntent(Context context) {
|
|
129
|
+
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
|
130
|
+
if (launchIntent == null) {
|
|
131
|
+
launchIntent = new Intent();
|
|
132
|
+
}
|
|
133
|
+
launchIntent.setPackage(null);
|
|
134
|
+
int pendingFlags = (Build.VERSION.SDK_INT >= 31) ? PendingIntent.FLAG_IMMUTABLE : 0;
|
|
135
|
+
return PendingIntent.getActivity(context, 0, launchIntent, pendingFlags);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static String getStringMetadataFromManifest(WeakReference<Context> weakContext,
|
|
139
|
+
ApplicationInfo info, String name, String defaultValue) {
|
|
140
|
+
Context context = weakContext.get();
|
|
141
|
+
if (context == null) return null;
|
|
142
|
+
Object obj = info.metaData.get(name);
|
|
143
|
+
if (obj instanceof String) {
|
|
144
|
+
return (String) obj;
|
|
145
|
+
} else if (obj instanceof Integer) {
|
|
146
|
+
return context.getString((Integer) obj);
|
|
147
|
+
} else {
|
|
148
|
+
return defaultValue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private static int getIntMetadataFromManifest(ApplicationInfo info, String name, int defaultValue) {
|
|
153
|
+
Object obj = info.metaData.get(name);
|
|
154
|
+
if (obj instanceof Integer) {
|
|
155
|
+
return (Integer) obj;
|
|
156
|
+
} else {
|
|
157
|
+
return defaultValue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.sentiance.react.bridge.core.utils;
|
|
2
|
+
|
|
3
|
+
import static com.sentiance.react.bridge.core.utils.ErrorCodes.E_SDK_CREATE_USER_ERROR;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.Promise;
|
|
8
|
+
import com.sentiance.react.bridge.core.SentianceConverter;
|
|
9
|
+
import com.sentiance.sdk.pendingoperation.OnCompleteListener;
|
|
10
|
+
import com.sentiance.sdk.pendingoperation.PendingOperation;
|
|
11
|
+
import com.sentiance.sdk.usercreation.UserCreationError;
|
|
12
|
+
import com.sentiance.sdk.usercreation.UserCreationResult;
|
|
13
|
+
|
|
14
|
+
public class UserCreationCompletionHandler implements OnCompleteListener<UserCreationResult, UserCreationError> {
|
|
15
|
+
|
|
16
|
+
private final Promise promise;
|
|
17
|
+
|
|
18
|
+
public UserCreationCompletionHandler(Promise promise) {
|
|
19
|
+
this.promise = promise;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public void onComplete(@NonNull PendingOperation<UserCreationResult, UserCreationError> pendingOperation) {
|
|
24
|
+
if (pendingOperation.isSuccessful()) {
|
|
25
|
+
promise.resolve(SentianceConverter.convertUserCreationResult(pendingOperation.getResult()));
|
|
26
|
+
} else {
|
|
27
|
+
promise.reject(E_SDK_CREATE_USER_ERROR,
|
|
28
|
+
SentianceConverter.stringifyUserCreationError(pendingOperation.getError()));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RNSentiance+Converter.h
|
|
3
|
+
// RNSentiance
|
|
4
|
+
//
|
|
5
|
+
// Created by Sebouh Aguehian on 10/10/2021.
|
|
6
|
+
// Copyright © 2021 Facebook. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
#import "RNSentianceCore.h"
|
|
9
|
+
|
|
10
|
+
@interface RNSentianceCore (Converter)
|
|
11
|
+
|
|
12
|
+
- (NSDictionary*) convertUserContextToDict:(SENTUserContext*) userContext;
|
|
13
|
+
- (NSMutableArray*) convertUserContextCriteriaToArray:(SENTUserContextUpdateCriteria)criteriaMask;
|
|
14
|
+
- (NSDictionary*) convertUserCreationResult:(SENTUserCreationResult*) userCreationResult;
|
|
15
|
+
- (NSString*) stringifyUserCreationError:(SENTUserCreationError*) userCreationError;
|
|
16
|
+
- (NSString*)convertStartStatusToString:(SENTStartStatus) status;
|
|
17
|
+
- (NSString*)convertDetectionStatusToString:(SENTDetectionStatus) detectionStatus;
|
|
18
|
+
- (NSDictionary*)convertUserActivityToDict:(SENTUserActivity*)userActivity;
|
|
19
|
+
- (NSDictionary*)convertSdkStatusToDict:(SENTSDKStatus*) status;
|
|
20
|
+
- (NSDictionary*)convertInstallIdToDict:(NSString*) installId;
|
|
21
|
+
- (NSDictionary*)convertTokenToDict:(NSString*) token;
|
|
22
|
+
- (NSString*)convertInitIssueToString:(SENTInitIssue) issue;
|
|
23
|
+
- (NSString*)convertQuotaStatusToString:(SENTQuotaStatus) status;
|
|
24
|
+
- (NSString*)convertLocationPermissionToString:(SENTLocationPermission) status;
|
|
25
|
+
- (NSString*)convertInitStateToString:(SENTSDKInitState) state;
|
|
26
|
+
- (NSString*)convertUserActivityTypeToString:(SENTUserActivityType) activityType;
|
|
27
|
+
- (NSString*)convertTripTypeToString:(SENTTripType) tripType;
|
|
28
|
+
- (NSDictionary*)convertVehicleCrashEventToDict:(SENTVehicleCrashEvent*) crashEvent;
|
|
29
|
+
- (NSDictionary *)convertUserLinkingResult:(SENTUserLinkingResult *)userLinkingResult;
|
|
30
|
+
- (NSString *)stringifyUserLinkingError:(SENTUserLinkingError *)userLinkingError;
|
|
31
|
+
- (NSDictionary *)convertResetResult:(SENTResetResult *)resetResult;
|
|
32
|
+
- (NSString *)stringifyResetError:(SENTResetError *)resetError;
|
|
33
|
+
- (NSDictionary *)convertStartTripResult:(SENTStartTripResult *)startTripResult;
|
|
34
|
+
- (NSString *)stringifyStartTripError:(SENTStartTripError *)startTripError;
|
|
35
|
+
- (NSDictionary *)convertStopTripResult:(SENTStopTripResult *)stopTripResult;
|
|
36
|
+
- (NSString *)stringifyStopTripError:(SENTStopTripError *)stopTripError;
|
|
37
|
+
- (NSDictionary *)convertRequestUserAccessTokenResult:(SENTUserAccessTokenResult *)userAccessTokenResult;
|
|
38
|
+
- (NSString *)stringifyRequestUserAccessTokenError:(SENTUserAccessTokenError *)userAccessTokenError;
|
|
39
|
+
- (NSDictionary *)convertSubmitDetectionsResult:(SENTSubmitDetectionsResult *)submitDetectionsResult;
|
|
40
|
+
- (NSString *)stringifySubmitDetectionsError:(SENTSubmitDetectionsError *)submitDetectionsError;
|
|
41
|
+
- (NSDictionary *)convertEnableDetectionsResult:(SENTEnableDetectionsResult *)enableDetectionsResult;
|
|
42
|
+
- (NSString *)stringifyEnableDetectionsError:(SENTEnableDetectionsError *)enableDetectionsError;
|
|
43
|
+
- (NSDictionary *)convertDisableDetectionsResult:(SENTDisableDetectionsResult *)disableDetectionsResult;
|
|
44
|
+
- (NSString *)stringifyDisableDetectionsError:(SENTDisableDetectionsError *)disableDetectionsError;
|
|
45
|
+
- (NSString *)stringifyUserContextError:(SENTRequestUserContextError *)userContextError;
|
|
46
|
+
@end
|