@dashx/react-native 0.1.25 → 1.0.3
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 +22 -149
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
- package/android/gradlew +34 -21
- package/android/gradlew.bat +24 -19
- package/android/src/main/AndroidManifest.xml +2 -8
- package/android/src/main/java/com/dashx/rn/sdk/DashXReactNativeModule.kt +248 -0
- package/android/src/main/java/com/dashx/rn/sdk/{DashXPackage.kt → DashXReactNativePackage.kt} +2 -1
- package/android/src/main/java/com/dashx/rn/sdk/util/ArrayUtil.java +131 -0
- package/android/src/main/java/com/dashx/rn/sdk/util/MapUtil.java +142 -0
- package/android/src/main/java/com/dashx/rn/sdk/{Utils.kt → util/Utils.kt} +5 -5
- package/index.js +68 -72
- package/ios/DashX.swift +110 -95
- package/ios/DashXReactNative-Bridging-Header.h +4 -0
- package/ios/DashXReactNative.m +25 -0
- package/ios/DashXReactNative.xcodeproj/project.pbxproj +280 -0
- package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/contents.xcworkspacedata +1 -1
- package/ios/{DashX.xcworkspace → DashXReactNative.xcworkspace}/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- package/package.json +6 -12
- package/DashX.podspec +0 -27
- package/android/README.md +0 -23
- package/android/src/main/java/com/dashx/rn/sdk/DashXActivityLifecycleCallbacks.kt +0 -93
- package/android/src/main/java/com/dashx/rn/sdk/DashXClientInterceptor.kt +0 -66
- package/android/src/main/java/com/dashx/rn/sdk/DashXExceptionHandler.kt +0 -28
- package/android/src/main/java/com/dashx/rn/sdk/DashXMessagingService.kt +0 -176
- package/android/src/main/java/com/dashx/rn/sdk/DashXModule.kt +0 -193
- package/android/src/main/java/com/dashx/rn/sdk/NotificationReceiver.kt +0 -17
- package/ios/API.swift +0 -2420
- package/ios/Constants.swift +0 -14
- package/ios/DashX.m +0 -17
- package/ios/DashX.xcodeproj/project.pbxproj +0 -356
- package/ios/DashX.xcodeproj/xcshareddata/xcschemes/DashX.xcscheme +0 -67
- package/ios/DashXAppDelegate.swift +0 -73
- package/ios/DashXApplicationLifecycleCallbacks.swift +0 -65
- package/ios/DashXClient.swift +0 -319
- package/ios/DashXData.swift +0 -19
- package/ios/DashXLog.swift +0 -44
- package/ios/DashXUIViewController.swift +0 -15
- package/ios/Network.swift +0 -74
- package/ios/README.md +0 -80
- package/ios/Utils.swift +0 -13
- package/ios/graphql/AddContent.graphql +0 -8
- package/ios/graphql/AddItemToCart.graphql +0 -33
- package/ios/graphql/EditContent.graphql +0 -8
- package/ios/graphql/FetchCart.graphql +0 -33
- package/ios/graphql/FetchContent.graphql +0 -3
- package/ios/graphql/IdentifyAccount.graphql +0 -5
- package/ios/graphql/SearchContent.graphql +0 -3
- package/ios/graphql/SubscribeContact.graphql +0 -6
- package/ios/graphql/TrackEvent.graphql +0 -5
- package/ios/schema.json +0 -37038
package/android/README.md
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Android Native Module
|
|
2
|
-
|
|
3
|
-
## Prerequisites
|
|
4
|
-
|
|
5
|
-
- NodeJS
|
|
6
|
-
- Android Studio
|
|
7
|
-
- Android SDK
|
|
8
|
-
|
|
9
|
-
## Development
|
|
10
|
-
|
|
11
|
-
- This native module uses DashX Android SDK to make API calls, so if you want to add any graphql requests add to [dashx-android](https://github.com/dashxhq/dashx-android).
|
|
12
|
-
|
|
13
|
-
- Make sure all the Node dependencies are installed:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
$ yarn
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
- To build this module:
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
$ ./gradlew build
|
|
23
|
-
```
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
import android.app.Activity
|
|
4
|
-
import android.app.Application
|
|
5
|
-
import android.content.Context
|
|
6
|
-
import android.content.pm.PackageManager
|
|
7
|
-
import android.os.Bundle
|
|
8
|
-
import com.facebook.react.bridge.Arguments
|
|
9
|
-
|
|
10
|
-
class DashXActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
|
11
|
-
private val dashXClient = DashXClientInterceptor.instance.getDashXClient()
|
|
12
|
-
private var startSession = System.currentTimeMillis().toDouble()
|
|
13
|
-
|
|
14
|
-
init {
|
|
15
|
-
dashXClient?.trackAppStarted()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
override fun onActivityPaused(activity: Activity) {
|
|
19
|
-
if (!lifecycleTrackingEnabled) {
|
|
20
|
-
return
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
dashXClient?.trackAppSession(System.currentTimeMillis().toDouble() - startSession)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
override fun onActivityResumed(activity: Activity) {
|
|
27
|
-
if (!lifecycleTrackingEnabled) {
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
startSession = System.currentTimeMillis().toDouble()
|
|
32
|
-
dashXClient?.trackAppStarted(fromBackground = true)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
override fun onActivityStarted(activity: Activity) {
|
|
36
|
-
if (!screenTrackingEnabled) {
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
val packageManager = activity.packageManager
|
|
41
|
-
val info = packageManager?.getActivityInfo(activity.componentName, PackageManager.GET_META_DATA)
|
|
42
|
-
val activityLabel = info?.loadLabel(packageManager)
|
|
43
|
-
activityLabel?.let { it -> dashXClient?.screen(it.toString(), hashMapOf()) }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override fun onActivityDestroyed(activity: Activity) {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
override fun onActivityStopped(activity: Activity) {
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
companion object {
|
|
63
|
-
private var dashXActivityLifecycleCallbacks: DashXActivityLifecycleCallbacks? = null
|
|
64
|
-
private var screenTrackingEnabled = false
|
|
65
|
-
private var lifecycleTrackingEnabled = false
|
|
66
|
-
|
|
67
|
-
private fun registerCallbacks(context: Context) {
|
|
68
|
-
dashXActivityLifecycleCallbacks = DashXActivityLifecycleCallbacks()
|
|
69
|
-
val application = context as Application
|
|
70
|
-
application.registerActivityLifecycleCallbacks(dashXActivityLifecycleCallbacks)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
fun enableActivityLifecycleTracking(context: Context) {
|
|
74
|
-
lifecycleTrackingEnabled = true
|
|
75
|
-
|
|
76
|
-
if (dashXActivityLifecycleCallbacks != null) {
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
registerCallbacks(context)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
fun enableScreenTracking(context: Context) {
|
|
84
|
-
screenTrackingEnabled = true
|
|
85
|
-
|
|
86
|
-
if (dashXActivityLifecycleCallbacks != null) {
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
registerCallbacks(context)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import com.dashx.sdk.DashXClient as DashX
|
|
5
|
-
import com.dashx.sdk.DashXLog
|
|
6
|
-
import com.facebook.react.bridge.*
|
|
7
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
8
|
-
import com.google.firebase.messaging.RemoteMessage
|
|
9
|
-
|
|
10
|
-
class DashXClientInterceptor private constructor() {
|
|
11
|
-
private val tag = DashXClientInterceptor::class.java.simpleName
|
|
12
|
-
|
|
13
|
-
private var client: com.dashx.sdk.DashXClient? = null
|
|
14
|
-
var reactApplicationContext: ReactApplicationContext? = null
|
|
15
|
-
private val dashXNotificationFilter = "DASHX_PN_TYPE"
|
|
16
|
-
|
|
17
|
-
fun createDashXClient(reactApplicationContext: ReactApplicationContext, publicKey: String, baseURI: String?, targetEnvironment: String?, targetInstallation: String?) {
|
|
18
|
-
this.reactApplicationContext = reactApplicationContext
|
|
19
|
-
client = DashX(reactApplicationContext.applicationContext, publicKey, baseURI, targetEnvironment, targetInstallation)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fun getDashXClient(): com.dashx.sdk.DashXClient? {
|
|
23
|
-
return client
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
fun handleMessage(remoteMessage: RemoteMessage) {
|
|
27
|
-
val notificationData = remoteMessage.getData()
|
|
28
|
-
|
|
29
|
-
DashXLog.d(tag, "Notification Data: " + notificationData)
|
|
30
|
-
|
|
31
|
-
val eventProperties: WritableMap = Arguments.createMap()
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
eventProperties.putMap("data", convertToWritableMap(notificationData, listOf(dashXNotificationFilter)))
|
|
35
|
-
} catch (e: Exception) {
|
|
36
|
-
e.printStackTrace()
|
|
37
|
-
DashXLog.d(tag, "Encountered an error while parsing notification data.")
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
val notification = remoteMessage.getNotification()
|
|
41
|
-
|
|
42
|
-
if (notification != null) {
|
|
43
|
-
val notificationProperties: WritableMap = Arguments.createMap()
|
|
44
|
-
notificationProperties.putString("title", notification.getTitle())
|
|
45
|
-
notificationProperties.putString("body", notification.getBody())
|
|
46
|
-
|
|
47
|
-
eventProperties.putMap("notification", notificationProperties)
|
|
48
|
-
|
|
49
|
-
DashXLog.d(tag, "onMessageReceived with Title: " + notification.getTitle() + " and Body: " + notification.getBody())
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
sendJsEvent("messageReceived", eventProperties)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private fun sendJsEvent(eventName: String, params: WritableMap) {
|
|
56
|
-
reactApplicationContext
|
|
57
|
-
?.getJSModule(RCTDeviceEventEmitter::class.java)
|
|
58
|
-
?.emit(eventName, params)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
companion object {
|
|
62
|
-
val instance: DashXClientInterceptor by lazy {
|
|
63
|
-
DashXClientInterceptor()
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
class DashXExceptionHandler(private val mainExceptionHandler: Thread.UncaughtExceptionHandler)
|
|
4
|
-
: Thread.UncaughtExceptionHandler {
|
|
5
|
-
private val dashXClient = DashXClientInterceptor.instance.getDashXClient()
|
|
6
|
-
|
|
7
|
-
companion object {
|
|
8
|
-
fun enable() {
|
|
9
|
-
val defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
|
10
|
-
if (defaultExceptionHandler is DashXExceptionHandler) {
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (defaultExceptionHandler != null) {
|
|
15
|
-
val dashXExceptionHandler = DashXExceptionHandler(defaultExceptionHandler)
|
|
16
|
-
Thread.setDefaultUncaughtExceptionHandler(dashXExceptionHandler)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override fun uncaughtException(thread: Thread, exception: Throwable) {
|
|
22
|
-
if (dashXClient != null) {
|
|
23
|
-
dashXClient.trackAppCrashed(exception)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
mainExceptionHandler.uncaughtException(thread, exception)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
import android.app.Activity
|
|
4
|
-
import android.app.ActivityManager
|
|
5
|
-
import android.app.Notification
|
|
6
|
-
import android.app.NotificationChannel
|
|
7
|
-
import android.app.NotificationManager
|
|
8
|
-
import android.app.PendingIntent
|
|
9
|
-
import android.content.Context
|
|
10
|
-
import android.content.Intent
|
|
11
|
-
import android.content.pm.PackageManager
|
|
12
|
-
import android.media.RingtoneManager
|
|
13
|
-
import android.os.Build
|
|
14
|
-
import android.widget.RemoteViews
|
|
15
|
-
import androidx.core.app.NotificationCompat
|
|
16
|
-
import androidx.core.app.NotificationManagerCompat
|
|
17
|
-
import com.dashx.sdk.DashXLog
|
|
18
|
-
import com.google.firebase.messaging.FirebaseMessagingService
|
|
19
|
-
import com.google.firebase.messaging.RemoteMessage
|
|
20
|
-
import com.google.gson.annotations.SerializedName
|
|
21
|
-
import com.google.gson.Gson
|
|
22
|
-
|
|
23
|
-
data class DashXPayload(
|
|
24
|
-
@SerializedName("id") val id: String,
|
|
25
|
-
@SerializedName("title") val title: String?,
|
|
26
|
-
@SerializedName("body") val body: String?,
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
class DashXMessagingService : FirebaseMessagingService() {
|
|
30
|
-
private val tag = DashXMessagingService::class.java.simpleName
|
|
31
|
-
private val dashXClient = DashXClientInterceptor.instance.getDashXClient()
|
|
32
|
-
private val notificationReceiverClass: Class<*> = NotificationReceiver::class.java
|
|
33
|
-
|
|
34
|
-
override fun onNewToken(token: String) {
|
|
35
|
-
super.onNewToken(token)
|
|
36
|
-
DashXLog.d(tag, "onNewToken: $token")
|
|
37
|
-
|
|
38
|
-
if (dashXClient != null) {
|
|
39
|
-
dashXClient.setDeviceToken(token)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
|
44
|
-
super.onMessageReceived(remoteMessage)
|
|
45
|
-
|
|
46
|
-
if (appInForeground()) {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
val dashxDataMap = remoteMessage.getData()["dashx"]
|
|
51
|
-
|
|
52
|
-
if (dashxDataMap != null) {
|
|
53
|
-
val gson = Gson()
|
|
54
|
-
var dashxData = gson.fromJson(dashxDataMap, DashXPayload::class.java)
|
|
55
|
-
|
|
56
|
-
val id = dashxData.id
|
|
57
|
-
val title = dashxData.title
|
|
58
|
-
val body = dashxData.body
|
|
59
|
-
|
|
60
|
-
if ((title != null) || (body != null)) {
|
|
61
|
-
createNotificationChannel()
|
|
62
|
-
|
|
63
|
-
NotificationManagerCompat.from(this)
|
|
64
|
-
.notify(id, 1, createNotification(id, title, body))
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
DashXClientInterceptor.instance.handleMessage(remoteMessage)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private fun createNotificationChannel() {
|
|
72
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
73
|
-
val channel = NotificationChannel(
|
|
74
|
-
CHANNEL_ID,
|
|
75
|
-
CHANNEL_NAME,
|
|
76
|
-
NotificationManager.IMPORTANCE_DEFAULT
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
channel.description = CHANNEL_DESCRIPTION
|
|
80
|
-
|
|
81
|
-
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
|
|
82
|
-
.createNotificationChannel(channel)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private fun createNotification(
|
|
87
|
-
id: String,
|
|
88
|
-
title: String?,
|
|
89
|
-
body: String?
|
|
90
|
-
) : Notification {
|
|
91
|
-
val pendingIntent = getNewPendingIntent()
|
|
92
|
-
|
|
93
|
-
val notificationBuilder = NotificationCompat.Builder(this, CHANNEL_ID)
|
|
94
|
-
.setSmallIcon(getSmallIcon())
|
|
95
|
-
.setContentTitle(title)
|
|
96
|
-
.setContentText(body)
|
|
97
|
-
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
98
|
-
.setContentIntent(pendingIntent)
|
|
99
|
-
.setAutoCancel(true)
|
|
100
|
-
|
|
101
|
-
return notificationBuilder.build()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
private fun getNewPendingIntent(): PendingIntent {
|
|
105
|
-
val context = getApplicationContext()
|
|
106
|
-
val pendingIntentFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
|
107
|
-
|
|
108
|
-
val intent = getNewBaseIntent()
|
|
109
|
-
|
|
110
|
-
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
|
111
|
-
|
|
112
|
-
if (launchIntent == null) {
|
|
113
|
-
return PendingIntent.getActivity(context, 1, intent, pendingIntentFlags)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Mimic launcher behaviour
|
|
117
|
-
launchIntent.setPackage(null)
|
|
118
|
-
launchIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
|
119
|
-
|
|
120
|
-
return PendingIntent.getActivities(
|
|
121
|
-
context,
|
|
122
|
-
1,
|
|
123
|
-
arrayOf(launchIntent, intent),
|
|
124
|
-
pendingIntentFlags
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private fun getNewBaseIntent(): Intent {
|
|
129
|
-
return Intent(
|
|
130
|
-
this,
|
|
131
|
-
notificationReceiverClass
|
|
132
|
-
).addFlags(
|
|
133
|
-
Intent.FLAG_ACTIVITY_SINGLE_TOP or
|
|
134
|
-
Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private fun getSmallIcon(): Int {
|
|
139
|
-
val context = getApplicationContext()
|
|
140
|
-
val ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA)
|
|
141
|
-
|
|
142
|
-
var smallIconInt: Int
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
val smallIcon = ai.metaData.get(DX_NOTIFICATION_ICON)
|
|
146
|
-
|
|
147
|
-
if (smallIcon == null) {
|
|
148
|
-
throw IllegalArgumentException()
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
smallIconInt = context.getResources().getIdentifier(smallIcon as String, "drawable", context.getPackageName())
|
|
152
|
-
|
|
153
|
-
if (smallIconInt == 0) {
|
|
154
|
-
throw IllegalArgumentException()
|
|
155
|
-
}
|
|
156
|
-
} catch (e: IllegalArgumentException) {
|
|
157
|
-
smallIconInt = ai.icon
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return smallIconInt
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
fun appInForeground(): Boolean {
|
|
164
|
-
val context = getApplicationContext()
|
|
165
|
-
val activityManager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
|
166
|
-
val runningAppProcesses = activityManager.runningAppProcesses ?: return false
|
|
167
|
-
return runningAppProcesses.any { it.processName == context.packageName && it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND }
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
companion object {
|
|
171
|
-
private const val CHANNEL_NAME = "DashX Notification"
|
|
172
|
-
private const val CHANNEL_DESCRIPTION = "DashX's default notification channel"
|
|
173
|
-
private const val CHANNEL_ID = "DASHX_NOTIFICATION_CHANNEL"
|
|
174
|
-
private const val DX_NOTIFICATION_ICON = "DX_NOTIFICATION_ICON"
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.*
|
|
4
|
-
import com.dashx.sdk.DashXLog
|
|
5
|
-
import com.google.android.gms.tasks.OnCompleteListener
|
|
6
|
-
import com.google.firebase.messaging.FirebaseMessaging
|
|
7
|
-
|
|
8
|
-
class DashXModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
9
|
-
private val tag = DashXModule::class.java.simpleName
|
|
10
|
-
private var interceptor: DashXClientInterceptor = DashXClientInterceptor.instance
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
override fun getName(): String {
|
|
14
|
-
return "DashX"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@ReactMethod
|
|
18
|
-
fun setLogLevel(logLevel: Int) {
|
|
19
|
-
DashXLog.setLogLevel(logLevel)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@ReactMethod
|
|
23
|
-
fun setup(options: ReadableMap) {
|
|
24
|
-
interceptor.createDashXClient(
|
|
25
|
-
reactContext,
|
|
26
|
-
options.getString("publicKey")!!,
|
|
27
|
-
options.getStringIfPresent("baseUri"),
|
|
28
|
-
options.getStringIfPresent("targetEnvironment"),
|
|
29
|
-
options.getStringIfPresent("targetInstallation")
|
|
30
|
-
)
|
|
31
|
-
interceptor.getDashXClient()?.generateAnonymousUid()
|
|
32
|
-
|
|
33
|
-
if (options.hasKey("trackAppLifecycleEvents") && options.getBoolean("trackAppLifecycleEvents")) {
|
|
34
|
-
DashXExceptionHandler.enable()
|
|
35
|
-
DashXActivityLifecycleCallbacks.enableActivityLifecycleTracking(reactContext.applicationContext)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (options.hasKey("trackScreenViews") && options.getBoolean("trackScreenViews")) {
|
|
39
|
-
DashXActivityLifecycleCallbacks.enableScreenTracking(reactContext.applicationContext)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
FirebaseMessaging.getInstance().getToken()
|
|
43
|
-
.addOnCompleteListener(OnCompleteListener { task ->
|
|
44
|
-
if (!task.isSuccessful) {
|
|
45
|
-
DashXLog.d(tag, "FirebaseMessaging.getInstance().getToken() failed: $task.exception")
|
|
46
|
-
return@OnCompleteListener
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
val token = task.getResult()
|
|
50
|
-
token?.let { it -> interceptor.getDashXClient()?.setDeviceToken(it) }
|
|
51
|
-
DashXLog.d(tag, "Firebase Initialised with: $token")
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@ReactMethod
|
|
56
|
-
fun identify(uid: String?, options: ReadableMap?) {
|
|
57
|
-
val optionsHashMap = options?.toHashMap()
|
|
58
|
-
interceptor.getDashXClient()?.identify(uid, optionsHashMap as HashMap<String, String>?)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@ReactMethod
|
|
62
|
-
fun reset() {
|
|
63
|
-
interceptor.getDashXClient()?.reset()
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@ReactMethod
|
|
67
|
-
fun track(event: String, data: ReadableMap?) {
|
|
68
|
-
val jsonData = try {
|
|
69
|
-
data?.toHashMap() as HashMap<String, String>
|
|
70
|
-
} catch (e: Exception) {
|
|
71
|
-
DashXLog.d(tag, e.message)
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
interceptor.getDashXClient()?.track(event, jsonData)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@ReactMethod
|
|
79
|
-
fun screen(screenName: String, data: ReadableMap?) {
|
|
80
|
-
interceptor.getDashXClient()?.screen(screenName, data?.toHashMap() as HashMap<String, String>)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@ReactMethod
|
|
84
|
-
fun setIdentityToken(identityToken: String) {
|
|
85
|
-
interceptor.getDashXClient()?.setIdentityToken(identityToken)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ReactMethod
|
|
89
|
-
fun fetchContent(urn: String, options: ReadableMap?, promise: Promise) {
|
|
90
|
-
interceptor.getDashXClient()?.fetchContent(
|
|
91
|
-
urn,
|
|
92
|
-
options?.getBooleanIfPresent("preview"),
|
|
93
|
-
options?.getStringIfPresent("language"),
|
|
94
|
-
options?.getArray("fields")?.toArrayList() as List<String>?,
|
|
95
|
-
options?.getArray("include")?.toArrayList() as List<String>?,
|
|
96
|
-
options?.getArray("exclude")?.toArrayList() as List<String>?,
|
|
97
|
-
onError = {
|
|
98
|
-
promise.reject("EUNSPECIFIED", it)
|
|
99
|
-
},
|
|
100
|
-
onSuccess = {
|
|
101
|
-
promise.resolve(convertJsonToMap(it))
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@ReactMethod
|
|
107
|
-
fun searchContent(contentType: String, options: ReadableMap?, promise: Promise) {
|
|
108
|
-
val jsonFilter = try {
|
|
109
|
-
convertMapToJson(options?.getMap("filter"))
|
|
110
|
-
} catch (e: Exception) {
|
|
111
|
-
DashXLog.d(tag, e.message)
|
|
112
|
-
throw Exception("Encountered an error while parsing filter")
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
val jsonOrder = try {
|
|
116
|
-
convertMapToJson(options?.getMap("order"))
|
|
117
|
-
} catch (e: Exception) {
|
|
118
|
-
DashXLog.d(tag, e.message)
|
|
119
|
-
throw Exception("Encountered an error while parsing order")
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
interceptor.getDashXClient()?.searchContent(
|
|
123
|
-
contentType,
|
|
124
|
-
options?.getString("returnType") ?: "all",
|
|
125
|
-
jsonFilter,
|
|
126
|
-
jsonOrder,
|
|
127
|
-
options?.getIntIfPresent("limit"),
|
|
128
|
-
options?.getBooleanIfPresent("preview"),
|
|
129
|
-
options?.getStringIfPresent("language"),
|
|
130
|
-
options?.getArray("fields")?.toArrayList() as List<String>?,
|
|
131
|
-
options?.getArray("include")?.toArrayList() as List<String>?,
|
|
132
|
-
options?.getArray("exclude")?.toArrayList() as List<String>?,
|
|
133
|
-
onError = {
|
|
134
|
-
promise.reject("EUNSPECIFIED", it)
|
|
135
|
-
},
|
|
136
|
-
onSuccess = { content ->
|
|
137
|
-
val readableArray = Arguments.createArray()
|
|
138
|
-
content.forEach {
|
|
139
|
-
readableArray.pushMap(convertJsonToMap(it))
|
|
140
|
-
}
|
|
141
|
-
promise.resolve(readableArray)
|
|
142
|
-
}
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
@ReactMethod
|
|
147
|
-
fun addItemToCart(
|
|
148
|
-
itemId: String,
|
|
149
|
-
pricingId: String,
|
|
150
|
-
quantity: String,
|
|
151
|
-
reset: Boolean? = false,
|
|
152
|
-
custom: ReadableMap? = null,
|
|
153
|
-
promise: Promise
|
|
154
|
-
) {
|
|
155
|
-
val jsonCustom = try {
|
|
156
|
-
convertMapToJson(custom)
|
|
157
|
-
} catch (e: Exception) {
|
|
158
|
-
DashXLog.d(tag, e.message)
|
|
159
|
-
throw Exception("Encountered an error while parsing custom")
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
interceptor.getDashXClient()?.addItemToCart(
|
|
163
|
-
itemId,
|
|
164
|
-
pricingId,
|
|
165
|
-
quantity,
|
|
166
|
-
reset ?: false,
|
|
167
|
-
jsonCustom,
|
|
168
|
-
onError = {
|
|
169
|
-
promise.reject("EUNSPECIFIED", it)
|
|
170
|
-
},
|
|
171
|
-
onSuccess = { content ->
|
|
172
|
-
promise.resolve(convertJsonToMap(content))
|
|
173
|
-
}
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
@ReactMethod
|
|
178
|
-
fun fetchCart(promise: Promise) {
|
|
179
|
-
interceptor.getDashXClient()?.fetchCart(
|
|
180
|
-
onError = {
|
|
181
|
-
promise.reject("EUNSPECIFIED", it)
|
|
182
|
-
},
|
|
183
|
-
onSuccess = { content ->
|
|
184
|
-
promise.resolve(convertJsonToMap(content))
|
|
185
|
-
}
|
|
186
|
-
)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
@ReactMethod
|
|
190
|
-
fun subscribe() {
|
|
191
|
-
interceptor.getDashXClient()?.subscribe()
|
|
192
|
-
}
|
|
193
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
package com.dashx.rn.sdk
|
|
2
|
-
|
|
3
|
-
import android.app.Activity
|
|
4
|
-
import android.content.Intent
|
|
5
|
-
import android.os.Bundle
|
|
6
|
-
|
|
7
|
-
class NotificationReceiver : Activity() {
|
|
8
|
-
override fun onCreate(savedInstanceState: Bundle?) {
|
|
9
|
-
super.onCreate(savedInstanceState)
|
|
10
|
-
finish()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
override fun onNewIntent(intent: Intent) {
|
|
14
|
-
super.onNewIntent(intent)
|
|
15
|
-
finish()
|
|
16
|
-
}
|
|
17
|
-
}
|