react-native-move-sdk 0.1.5 → 0.2.1
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 +21 -22
- package/android/build.gradle +45 -39
- package/android/gradle/wrapper/gradle-wrapper.properties +4 -1
- package/android/gradle.properties +8 -4
- package/android/src/main/java/in/dolph/move/sdk/MoveExtensions.kt +44 -0
- package/android/src/main/java/in/dolph/move/sdk/MoveNotificationConfig.kt +26 -26
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkConfig.kt +8 -13
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkModule.kt +137 -27
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkPackage.kt +1 -1
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkRepository.kt +171 -162
- package/android/src/main/java/in/dolph/move/sdk/NativeMoveSdkWrapper.kt +184 -84
- package/android/src/test/java/io/dolphin/move/MoveWrapperTest.kt +157 -0
- package/ios/MoveSdk-Bridging-Header.h +1 -0
- package/ios/MoveSdk.xcodeproj/project.pbxproj +6 -8
- package/ios/NativeModule/{DolphinSdk.h → MoveSdk.h} +21 -7
- package/ios/NativeModule/MoveSdk.swift +607 -0
- package/lib/commonjs/index.js +105 -111
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +105 -111
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +38 -39
- package/package.json +1 -1
- package/react-native-move-sdk.podspec +3 -1
- package/src/index.ts +163 -191
- package/ios/NativeModule/DolphinSdk.swift +0 -357
- package/ios/NativeModule/DolphinSdkDemoReactNative-Bridging-Header.h +0 -8
|
@@ -3,24 +3,26 @@ package `in`.dolph.move.sdk
|
|
|
3
3
|
import android.annotation.SuppressLint
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.util.Log
|
|
6
|
-
import com.facebook.react.bridge.Arguments
|
|
7
6
|
import com.facebook.react.bridge.Promise
|
|
8
7
|
import com.facebook.react.bridge.ReadableArray
|
|
9
|
-
import
|
|
8
|
+
import io.dolphin.move.AssistanceCallState
|
|
10
9
|
import io.dolphin.move.DrivingService
|
|
11
10
|
import io.dolphin.move.MoveAuth
|
|
12
11
|
import io.dolphin.move.MoveAuthState
|
|
12
|
+
import io.dolphin.move.MoveConfig
|
|
13
13
|
import io.dolphin.move.MoveConfigurationError
|
|
14
|
+
import io.dolphin.move.MoveDetectionService
|
|
14
15
|
import io.dolphin.move.MoveSdk
|
|
15
16
|
import io.dolphin.move.MoveSdkState
|
|
17
|
+
import io.dolphin.move.MoveServiceFailure
|
|
18
|
+
import io.dolphin.move.MoveServiceWarning
|
|
16
19
|
import io.dolphin.move.MoveTripState
|
|
17
|
-
import io.dolphin.move.OtherService
|
|
18
|
-
import io.dolphin.move.TimelineDetectionService
|
|
19
20
|
import io.dolphin.move.WalkingService
|
|
20
21
|
|
|
21
22
|
@SuppressLint("StaticFieldLeak", "MissingPermission")
|
|
22
23
|
class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener,
|
|
23
|
-
MoveSdk.InitializeListener, MoveSdk.TripStateListener, MoveSdk.AuthStateUpdateListener
|
|
24
|
+
MoveSdk.InitializeListener, MoveSdk.TripStateListener, MoveSdk.AuthStateUpdateListener,
|
|
25
|
+
MoveSdk.MoveLogCallback, MoveSdk.MoveErrorListener, MoveSdk.MoveWarningListener {
|
|
24
26
|
|
|
25
27
|
companion object {
|
|
26
28
|
|
|
@@ -39,31 +41,50 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
39
41
|
|
|
40
42
|
private var delegate: MoveSdkModule? = null
|
|
41
43
|
|
|
42
|
-
fun
|
|
43
|
-
val
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
fun init(context: Context) {
|
|
45
|
+
val moveSdk = MoveSdk.init(context.applicationContext)
|
|
46
|
+
|
|
47
|
+
moveSdk.sdkStateListener(this)
|
|
48
|
+
moveSdk.tripStateListener(this)
|
|
49
|
+
moveSdk.authStateUpdateListener(this)
|
|
50
|
+
moveSdk.initializationListener(this)
|
|
51
|
+
moveSdk.setLogListener(this)
|
|
48
52
|
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
moveSdk.setServiceErrorListener(this)
|
|
54
|
+
moveSdk.setServiceWarningListener(this)
|
|
51
55
|
|
|
56
|
+
// Initialize notifications by default (might be overwritten by setup)
|
|
52
57
|
val config: MoveSdkConfig = configRepository.loadConfig()
|
|
53
|
-
|
|
58
|
+
try {
|
|
59
|
+
moveSdk.recognitionNotification(config.recognitionNotification.toAndroidNotification(context))
|
|
60
|
+
moveSdk.tripNotification(config.tripNotification.toAndroidNotification(context))
|
|
61
|
+
} catch (t: Throwable) {
|
|
62
|
+
/**
|
|
63
|
+
* TODO Find cause, maybe channelID 0?
|
|
64
|
+
* Caused by: java.lang.IllegalArgumentException
|
|
65
|
+
at android.os.Parcel.createExceptionOrNull(Parcel.java:2429)
|
|
66
|
+
at android.os.Parcel.createException(Parcel.java:2409)
|
|
67
|
+
at android.os.Parcel.readException(Parcel.java:2392)
|
|
68
|
+
at android.os.Parcel.readException(Parcel.java:2334)
|
|
69
|
+
at android.app.INotificationManager$Stub$Proxy.createNotificationChannels(INotificationManager.java:3933)
|
|
70
|
+
*/
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
fun allowMockLocations(allowMockLocations: Boolean) {
|
|
75
|
+
MoveSdk.get()?.allowMockLocations(allowMockLocations)
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
@SuppressLint("MissingPermission")
|
|
57
|
-
fun
|
|
58
|
-
|
|
79
|
+
fun setup(
|
|
80
|
+
userId: String,
|
|
59
81
|
accessToken: String,
|
|
60
82
|
refreshToken: String,
|
|
61
|
-
|
|
83
|
+
projectId: Int,
|
|
62
84
|
// Config
|
|
63
85
|
timelineDetectionServices: ReadableArray,
|
|
64
86
|
drivingServices: ReadableArray,
|
|
65
87
|
walkingServices: ReadableArray,
|
|
66
|
-
otherServices: ReadableArray,
|
|
67
88
|
// Platform config
|
|
68
89
|
recognitionNotificationTitle: String,
|
|
69
90
|
recognitionNotificationText: String,
|
|
@@ -75,29 +96,37 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
75
96
|
tripNotificationChannelId: String,
|
|
76
97
|
tripNotificationChannelName: String,
|
|
77
98
|
tripNotificationChannelDescription: String,
|
|
78
|
-
allowMockLocations: Boolean,
|
|
79
99
|
promise: Promise?
|
|
80
100
|
) {
|
|
81
101
|
|
|
82
|
-
val timelineDetectionServicesToUse = mutableListOf<
|
|
102
|
+
val timelineDetectionServicesToUse = mutableListOf<MoveDetectionService>()
|
|
83
103
|
val drivingServicesToUse = mutableListOf<DrivingService>()
|
|
84
104
|
val walkingServicesToUse = mutableListOf<WalkingService>()
|
|
85
|
-
val otherServicesToUse = mutableListOf<OtherService>()
|
|
86
|
-
|
|
87
|
-
timelineDetectionServices.toArrayList().forEach {
|
|
88
|
-
timelineDetectionServicesToUse.add(TimelineDetectionService.valueOf("$it"))
|
|
89
|
-
}
|
|
90
105
|
|
|
91
106
|
walkingServices.toArrayList().forEach {
|
|
92
|
-
|
|
107
|
+
try {
|
|
108
|
+
walkingServicesToUse.add(WalkingService.valueOf(it.toString().snakeToLowerCamelCase()))
|
|
109
|
+
} catch (t: Throwable) {
|
|
110
|
+
t.printStackTrace()
|
|
111
|
+
}
|
|
93
112
|
}
|
|
94
113
|
|
|
95
114
|
drivingServices.toArrayList().forEach {
|
|
96
|
-
|
|
115
|
+
try {
|
|
116
|
+
drivingServicesToUse.add(DrivingService.valueOf(it.toString().snakeToLowerCamelCase()))
|
|
117
|
+
} catch (t: Throwable) {
|
|
118
|
+
t.printStackTrace()
|
|
119
|
+
}
|
|
97
120
|
}
|
|
98
121
|
|
|
99
|
-
|
|
100
|
-
|
|
122
|
+
timelineDetectionServices.toArrayList().forEach { service ->
|
|
123
|
+
timelineDetectionServicesToUse.add(
|
|
124
|
+
valueOfMoveDetectionService(
|
|
125
|
+
service.toString(),
|
|
126
|
+
drivingServicesToUse,
|
|
127
|
+
walkingServicesToUse
|
|
128
|
+
)
|
|
129
|
+
)
|
|
101
130
|
}
|
|
102
131
|
|
|
103
132
|
val recognitionNotification = MoveNotificationConfig(
|
|
@@ -114,55 +143,42 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
114
143
|
tripNotificationChannelName,
|
|
115
144
|
tripNotificationChannelDescription,
|
|
116
145
|
)
|
|
146
|
+
// TODO - just use recognition notification for now
|
|
147
|
+
val walkingNotification = recognitionNotification
|
|
117
148
|
|
|
118
149
|
try {
|
|
119
150
|
Log.d(MoveSdkModule.LOG_TAG, "MOVE SDK Version " + MoveSdk.version)
|
|
120
151
|
|
|
152
|
+
val moveAuth = MoveAuth(
|
|
153
|
+
userId = userId,
|
|
154
|
+
accessToken = accessToken,
|
|
155
|
+
refreshToken = refreshToken,
|
|
156
|
+
projectId = projectId.toLong(),
|
|
157
|
+
)
|
|
158
|
+
val moveConfig = MoveConfig(timelineDetectionServicesToUse)
|
|
159
|
+
val moveSdk = MoveSdk.setup(moveAuth, moveConfig)
|
|
160
|
+
|
|
121
161
|
val moveSdkConfig = MoveSdkConfig(
|
|
122
|
-
auth = MoveAuth(
|
|
123
|
-
contractId = contractId,
|
|
124
|
-
accessToken = accessToken,
|
|
125
|
-
refreshToken = refreshToken,
|
|
126
|
-
productId = productId.toLong(),
|
|
127
|
-
),
|
|
128
162
|
timelineDetectionServices = timelineDetectionServicesToUse,
|
|
129
|
-
|
|
130
|
-
walkingServices = walkingServicesToUse,
|
|
131
|
-
otherServices = otherServicesToUse,
|
|
132
|
-
tripNotification = tripNotification,
|
|
163
|
+
auth = moveAuth,
|
|
133
164
|
recognitionNotification = recognitionNotification,
|
|
134
|
-
|
|
165
|
+
tripNotification = tripNotification,
|
|
166
|
+
walkingNotification = walkingNotification
|
|
135
167
|
)
|
|
136
|
-
|
|
137
168
|
configRepository.storeConfig(moveSdkConfig)
|
|
138
|
-
|
|
169
|
+
|
|
170
|
+
moveSdk.tripNotification(recognitionNotification.toAndroidNotification(context))
|
|
171
|
+
moveSdk.recognitionNotification(tripNotification.toAndroidNotification(context))
|
|
172
|
+
moveSdk.walkingLocationNotification(walkingNotification.toAndroidNotification(context))
|
|
139
173
|
|
|
140
174
|
promise?.resolve(PROMISE_OK)
|
|
141
175
|
} catch (t: Throwable) {
|
|
142
|
-
promise?.reject(
|
|
176
|
+
promise?.reject(Exception("SETUP_ERROR"))
|
|
143
177
|
}
|
|
144
178
|
}
|
|
145
179
|
|
|
146
|
-
private fun initialize(config: MoveSdkConfig) {
|
|
147
|
-
MoveSdk.Builder()
|
|
148
|
-
.authentication(config.auth)
|
|
149
|
-
.initializationListener(this)
|
|
150
|
-
.sdkStateListener(this)
|
|
151
|
-
.authStateUpdateListener(this)
|
|
152
|
-
.tripStateListener(this)
|
|
153
|
-
.timelineDetectionService(config.timelineDetectionServices)
|
|
154
|
-
.drivingServices(config.drivingServices)
|
|
155
|
-
.walkingServices(config.walkingServices)
|
|
156
|
-
.otherServices(config.otherServices)
|
|
157
|
-
.recognitionNotification(config.tripNotification.toAndroidNotification(context))
|
|
158
|
-
.tripNotification(config.recognitionNotification.toAndroidNotification(context))
|
|
159
|
-
.allowMockLocations(config.allowMockLocations)
|
|
160
|
-
.consoleLogging(true)
|
|
161
|
-
.init(context)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
180
|
fun resolveError() {
|
|
165
|
-
|
|
181
|
+
MoveSdk.get()?.resolveError()
|
|
166
182
|
}
|
|
167
183
|
|
|
168
184
|
fun startAutomaticDetection() {
|
|
@@ -187,6 +203,14 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
187
203
|
MoveSdk.get()?.forceTripRecognition()
|
|
188
204
|
}
|
|
189
205
|
|
|
206
|
+
fun getErrors(): List<MoveServiceFailure>? {
|
|
207
|
+
return MoveSdk.get()?.getServiceErrors()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
fun getWarnings(): List<MoveServiceWarning>? {
|
|
211
|
+
return MoveSdk.get()?.getServiceWarnings()
|
|
212
|
+
}
|
|
213
|
+
|
|
190
214
|
fun keepInForeground(enabled: Boolean) {
|
|
191
215
|
MoveSdk.get()?.keepInForeground(enabled)
|
|
192
216
|
}
|
|
@@ -211,7 +235,7 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
211
235
|
|
|
212
236
|
fun getState(promise: Promise) {
|
|
213
237
|
MoveSdk.get()?.let {
|
|
214
|
-
promise.resolve(it.getSdkState().toString())
|
|
238
|
+
promise.resolve(it.getSdkState().toString().toSnakeCase())
|
|
215
239
|
} ?: promise.resolve(null)
|
|
216
240
|
}
|
|
217
241
|
|
|
@@ -221,20 +245,47 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
221
245
|
} ?: promise.resolve(MoveTripState.UNKNOWN.toString())
|
|
222
246
|
}
|
|
223
247
|
|
|
248
|
+
fun initiateAssistanceCall(promise: Promise) {
|
|
249
|
+
MoveSdk.get()?.initiateAssistanceCall(object : MoveSdk.AssistanceStateListener {
|
|
250
|
+
override fun onAssistanceStateChanged(assistanceState: AssistanceCallState) {
|
|
251
|
+
if (assistanceState == AssistanceCallState.SUCCESS) {
|
|
252
|
+
promise.resolve(true)
|
|
253
|
+
} else {
|
|
254
|
+
promise.reject(Exception(assistanceState.name.toSnakeCase()))
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}) ?: promise.reject(Exception("ASSISTANCE_CALL_ERROR"))
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
fun geocode(latitude: Double, longitude: Double, promise: Promise) {
|
|
261
|
+
MoveSdk.get()?.let {
|
|
262
|
+
it.geocode(latitude, longitude) { result ->
|
|
263
|
+
val error = result.error
|
|
264
|
+
if (error != null) {
|
|
265
|
+
promise.reject(Exception(error.name.toSnakeCase()))
|
|
266
|
+
} else {
|
|
267
|
+
val address = result.address
|
|
268
|
+
promise.resolve(address)
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
} ?: promise.reject(Exception("GEOCODE_ERROR"))
|
|
272
|
+
}
|
|
273
|
+
|
|
224
274
|
override fun onError(error: MoveConfigurationError) {
|
|
225
|
-
val data =
|
|
226
|
-
data
|
|
275
|
+
val data = mutableMapOf<Any, Any>()
|
|
276
|
+
data[ARGUMENT_ERROR] = error.toString().toSnakeCase()
|
|
227
277
|
emitDeviceEvent(EVENT_INIT_ERROR, data)
|
|
228
278
|
}
|
|
229
279
|
|
|
230
280
|
override fun onStateChanged(sdk: MoveSdk, state: MoveSdkState) {
|
|
231
|
-
val data =
|
|
232
|
-
|
|
233
|
-
data.putString(ARGUMENT_STATE, state.toString())
|
|
281
|
+
val data = mutableMapOf<Any, Any>()
|
|
282
|
+
data[ARGUMENT_STATE] = state.toString().toSnakeCase()
|
|
234
283
|
|
|
284
|
+
/**
|
|
285
|
+
* There is no SDK State Error anymore
|
|
235
286
|
if (state is MoveSdkState.Error) {
|
|
236
|
-
|
|
237
|
-
}
|
|
287
|
+
data.putString(ARGUMENT_ERROR_REASON, state.reason.toString())
|
|
288
|
+
}**/
|
|
238
289
|
emitDeviceEvent(EVENT_MOVE_STATE, data)
|
|
239
290
|
|
|
240
291
|
if (state is MoveSdkState.Ready) {
|
|
@@ -250,8 +301,8 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
250
301
|
}
|
|
251
302
|
|
|
252
303
|
override fun onTripStateChanged(tripState: MoveTripState) {
|
|
253
|
-
val data =
|
|
254
|
-
data
|
|
304
|
+
val data = mutableMapOf<Any, Any>()
|
|
305
|
+
data[ARGUMENT_STATE] = tripState.toString().toSnakeCase()
|
|
255
306
|
emitDeviceEvent(EVENT_TRIP_STATE, data)
|
|
256
307
|
}
|
|
257
308
|
|
|
@@ -266,8 +317,8 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
266
317
|
productId: Int
|
|
267
318
|
) {
|
|
268
319
|
val auth = MoveAuth(
|
|
269
|
-
|
|
270
|
-
|
|
320
|
+
projectId = productId.toLong(),
|
|
321
|
+
userId = contractId,
|
|
271
322
|
accessToken = accessToken,
|
|
272
323
|
refreshToken = refreshToken,
|
|
273
324
|
)
|
|
@@ -275,8 +326,8 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
275
326
|
configRepository.storeAuth(auth)
|
|
276
327
|
|
|
277
328
|
MoveSdk.get()?.updateAuth(auth) { configurationError ->
|
|
278
|
-
val data =
|
|
279
|
-
data
|
|
329
|
+
val data = mutableMapOf<Any, Any>()
|
|
330
|
+
data[ARGUMENT_ERROR] = configurationError.toString()
|
|
280
331
|
emitDeviceEvent(EVENT_INIT_ERROR, data)
|
|
281
332
|
}
|
|
282
333
|
}
|
|
@@ -288,20 +339,69 @@ class NativeMoveSdkWrapper(private val context: Context) : MoveSdk.StateListener
|
|
|
288
339
|
}
|
|
289
340
|
|
|
290
341
|
override fun onAuthStateUpdate(state: MoveAuthState) {
|
|
291
|
-
val data =
|
|
292
|
-
data
|
|
342
|
+
val data = mutableMapOf<Any, Any>()
|
|
343
|
+
data[ARGUMENT_STATE] = state.toString().toSnakeCase()
|
|
344
|
+
/**
|
|
345
|
+
* No need to store anything any more
|
|
293
346
|
if (state is MoveAuthState.VALID) {
|
|
294
|
-
|
|
295
|
-
|
|
347
|
+
data.putString(ARGUMENT_ACCESS_TOKEN, state.auth.accessToken)
|
|
348
|
+
data.putString(ARGUMENT_REFRESH_TOKEN, state.auth.refreshToken)
|
|
296
349
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
350
|
+
// Only store valid auth here
|
|
351
|
+
configRepository.storeAuth(state.auth)
|
|
352
|
+
}**/
|
|
300
353
|
|
|
301
354
|
emitDeviceEvent(EVENT_AUTH_STATE, data)
|
|
302
355
|
}
|
|
303
356
|
|
|
304
|
-
private fun emitDeviceEvent(eventName: String, eventData:
|
|
357
|
+
private fun emitDeviceEvent(eventName: String, eventData: Map<Any, Any>) {
|
|
358
|
+
delegate?.emitDeviceEvent(eventName, eventData)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
private fun emitDeviceEvent(eventName: String, eventData: Array<Any>) {
|
|
305
362
|
delegate?.emitDeviceEvent(eventName, eventData)
|
|
306
363
|
}
|
|
364
|
+
|
|
365
|
+
override fun onLogReceived(eventName: String, value: String?) {
|
|
366
|
+
// TBD
|
|
367
|
+
val data = mutableMapOf<Any, Any>()
|
|
368
|
+
data[ARGUMENT_LOG] = "$eventName ${value ?: ""}".trim()
|
|
369
|
+
emitDeviceEvent(EVENT_INIT_ERROR, data)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
override fun onMoveError(serviceFailures: List<MoveServiceFailure>) {
|
|
373
|
+
val data = mutableMapOf<Any, Any>()
|
|
374
|
+
data[ARGUMENT_ERRORS] = serviceFailures.failuresToArray()
|
|
375
|
+
emitDeviceEvent(EVENT_ERRORS, data)
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
override fun onMoveWarning(serviceWarnings: List<MoveServiceWarning>) {
|
|
379
|
+
val data = mutableMapOf<Any, Any>()
|
|
380
|
+
data[ARGUMENT_WARNINGS] = serviceWarnings.warningsToArray()
|
|
381
|
+
emitDeviceEvent(EVENT_WARNINGS, data)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
fun List<MoveServiceFailure>.failuresToArray(): Array<Any> {
|
|
386
|
+
val data = mutableListOf<Any>()
|
|
387
|
+
forEach {
|
|
388
|
+
val map = mutableMapOf<String, Any>()
|
|
389
|
+
map["service"] = it.service.name().toSnakeCase()
|
|
390
|
+
map["reasons"] =
|
|
391
|
+
it.reasons.map { reason -> reason.name.toSnakeCase() }
|
|
392
|
+
data.add(map)
|
|
393
|
+
}
|
|
394
|
+
return data.toTypedArray()
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
fun List<MoveServiceWarning>.warningsToArray(): Array<Any> {
|
|
398
|
+
val data = mutableListOf<Any>()
|
|
399
|
+
forEach {
|
|
400
|
+
val map = mutableMapOf<String, Any?>()
|
|
401
|
+
map["service"] = it.service?.name()?.toSnakeCase()
|
|
402
|
+
map["reasons"] =
|
|
403
|
+
it.warnings.map { reason -> reason.name.toSnakeCase() }
|
|
404
|
+
data.add(map)
|
|
405
|
+
}
|
|
406
|
+
return data.toTypedArray()
|
|
307
407
|
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
package io.dolphin.move
|
|
2
|
+
|
|
3
|
+
import `in`.dolph.move.sdk.EVENT_AUTH_BATTERY_PERMISSION
|
|
4
|
+
import `in`.dolph.move.sdk.EVENT_AUTH_OVERLAY_PERMISSION
|
|
5
|
+
import `in`.dolph.move.sdk.MoveSdkModule
|
|
6
|
+
import `in`.dolph.move.sdk.NativeMoveSdkWrapper
|
|
7
|
+
import `in`.dolph.move.sdk.failuresToArray
|
|
8
|
+
import `in`.dolph.move.sdk.toSnakeCase
|
|
9
|
+
import android.content.Context
|
|
10
|
+
import android.content.SharedPreferences
|
|
11
|
+
import com.facebook.react.bridge.Promise
|
|
12
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
13
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
14
|
+
import com.nhaarman.mockitokotlin2.any
|
|
15
|
+
import com.nhaarman.mockitokotlin2.mock
|
|
16
|
+
import com.nhaarman.mockitokotlin2.times
|
|
17
|
+
import com.nhaarman.mockitokotlin2.verify
|
|
18
|
+
import com.nhaarman.mockitokotlin2.whenever
|
|
19
|
+
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
20
|
+
import org.junit.After
|
|
21
|
+
import org.junit.Assert
|
|
22
|
+
import org.junit.Before
|
|
23
|
+
import org.junit.Ignore
|
|
24
|
+
import org.junit.Test
|
|
25
|
+
|
|
26
|
+
@ExperimentalCoroutinesApi
|
|
27
|
+
class MoveWrapperTest {
|
|
28
|
+
|
|
29
|
+
@Before
|
|
30
|
+
fun setup(): Unit {
|
|
31
|
+
Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@After
|
|
35
|
+
fun teardown(): Unit {
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
fun `test sdk state snake case`(): Unit {
|
|
40
|
+
|
|
41
|
+
Assert.assertEquals("READY", MoveSdkState.Ready.name.toSnakeCase())
|
|
42
|
+
Assert.assertEquals("RUNNING", MoveSdkState.Running.name.toSnakeCase())
|
|
43
|
+
Assert.assertEquals("UNINITIALISED", MoveSdkState.Uninitialised.name.toSnakeCase())
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Test
|
|
47
|
+
fun `test trip state snake case`(): Unit {
|
|
48
|
+
|
|
49
|
+
Assert.assertEquals("UNKNOWN", MoveTripState.UNKNOWN.name)
|
|
50
|
+
Assert.assertEquals("UNKNOWN", MoveTripState.UNKNOWN.name.toSnakeCase())
|
|
51
|
+
Assert.assertEquals("DRIVING", MoveTripState.DRIVING.name)
|
|
52
|
+
Assert.assertEquals("IDLE", MoveTripState.IDLE.name)
|
|
53
|
+
Assert.assertEquals("IGNORED", MoveTripState.IGNORED.name)
|
|
54
|
+
Assert.assertEquals("HALT", MoveTripState.HALT.name)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@Test
|
|
58
|
+
fun `test errors`(): Unit {
|
|
59
|
+
|
|
60
|
+
val errors: List<MoveServiceFailure> = mutableListOf(
|
|
61
|
+
MoveServiceFailure(
|
|
62
|
+
service = MoveDetectionService.Driving(),
|
|
63
|
+
reasons = listOf(MoveError.PhonePermissionMissing, MoveError.LocationPermissionMissing)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
val failuresToArray = errors.failuresToArray()
|
|
67
|
+
failuresToArray.toString()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
fun `test device event naming`(): Unit {
|
|
72
|
+
|
|
73
|
+
Assert.assertEquals("MOVE_SDK_PERMISSION_OVERLAY", EVENT_AUTH_OVERLAY_PERMISSION.toSnakeCase())
|
|
74
|
+
Assert.assertEquals(
|
|
75
|
+
"MOVE_SDK_PERMISSION_BATTERY_OPTIMIZATION",
|
|
76
|
+
EVENT_AUTH_BATTERY_PERMISSION.toSnakeCase()
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@Ignore("Writeable* classes cannot be tested")
|
|
81
|
+
@Test
|
|
82
|
+
fun `test device events`(): Unit {
|
|
83
|
+
|
|
84
|
+
val context: Context = mock()
|
|
85
|
+
val promise: Promise = mock()
|
|
86
|
+
val sharedPrefs: SharedPreferences = mock()
|
|
87
|
+
|
|
88
|
+
val reactContext: ReactApplicationContext = mock()
|
|
89
|
+
whenever(context.getSharedPreferences(any(), any())).thenReturn(sharedPrefs)
|
|
90
|
+
whenever(reactContext.applicationContext).thenReturn(context)
|
|
91
|
+
|
|
92
|
+
val deviceEventModule: DeviceEventManagerModule.RCTDeviceEventEmitter = mock()
|
|
93
|
+
val targetClass = DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
|
|
94
|
+
whenever(reactContext.getJSModule(targetClass)).thenReturn(
|
|
95
|
+
deviceEventModule
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
val moveSdkModule = MoveSdkModule(reactContext)
|
|
99
|
+
moveSdkModule.emitDeviceEvent("Move-SdkEvent", emptyArray())
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Test
|
|
103
|
+
fun `test reject assistance call`(): Unit {
|
|
104
|
+
|
|
105
|
+
val context: Context = mock()
|
|
106
|
+
val promise: Promise = mock()
|
|
107
|
+
val sharedPrefs: SharedPreferences = mock()
|
|
108
|
+
|
|
109
|
+
whenever(context.getSharedPreferences(any(), any())).thenReturn(sharedPrefs)
|
|
110
|
+
whenever(context.applicationContext).thenReturn(context)
|
|
111
|
+
|
|
112
|
+
val nativeMoveSdkWrapper = NativeMoveSdkWrapper(context)
|
|
113
|
+
nativeMoveSdkWrapper.initiateAssistanceCall(promise)
|
|
114
|
+
verify(promise, times(1)).reject(any<Throwable>())
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Test
|
|
118
|
+
fun `test auth state snake case`(): Unit {
|
|
119
|
+
|
|
120
|
+
Assert.assertEquals("UNKNOWN", MoveAuthState.UNKNOWN.name)
|
|
121
|
+
Assert.assertEquals(
|
|
122
|
+
"EXPIRED",
|
|
123
|
+
MoveAuthState.EXPIRED(
|
|
124
|
+
MoveAuth(
|
|
125
|
+
projectId = 1,
|
|
126
|
+
userId = "",
|
|
127
|
+
accessToken = "",
|
|
128
|
+
refreshToken = ""
|
|
129
|
+
)
|
|
130
|
+
).name
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@Test
|
|
135
|
+
fun `test snake to camel`(): Unit {
|
|
136
|
+
|
|
137
|
+
Assert.assertEquals("READY", MoveSdkState.Ready.name.toSnakeCase())
|
|
138
|
+
Assert.assertEquals("RUNNING", MoveSdkState.Running.name.toSnakeCase())
|
|
139
|
+
Assert.assertEquals("UNINITIALISED", MoveSdkState.Uninitialised.name.toSnakeCase())
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@Test
|
|
143
|
+
fun `test error to snake`(): Unit {
|
|
144
|
+
Assert.assertEquals(
|
|
145
|
+
"PHONE_PERMISSION_MISSING",
|
|
146
|
+
MoveError.PhonePermissionMissing.name.toSnakeCase()
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Test
|
|
151
|
+
fun `test warning to snake`(): Unit {
|
|
152
|
+
Assert.assertEquals(
|
|
153
|
+
"ACTIVITY_PERMISSION_MISSING",
|
|
154
|
+
MoveWarning.ActivityPermissionMissing.name.toSnakeCase()
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
objects = {
|
|
8
8
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
|
-
|
|
10
|
+
ABD6EADC2906D6FE00BAC83D /* MoveSdk.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABD6EADB2906D6FE00BAC83D /* MoveSdk.swift */; };
|
|
11
11
|
/* End PBXBuildFile section */
|
|
12
12
|
|
|
13
13
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
@@ -23,10 +23,9 @@
|
|
|
23
23
|
/* End PBXCopyFilesBuildPhase section */
|
|
24
24
|
|
|
25
25
|
/* Begin PBXFileReference section */
|
|
26
|
-
09A2803825DA82E000603CBF /* DolphinSdk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DolphinSdk.h; sourceTree = "<group>"; };
|
|
27
|
-
09A2803925DA82E000603CBF /* DolphinSdkDemoReactNative-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DolphinSdkDemoReactNative-Bridging-Header.h"; sourceTree = "<group>"; };
|
|
28
|
-
09A2803A25DA82E000603CBF /* DolphinSdk.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DolphinSdk.swift; sourceTree = "<group>"; };
|
|
29
26
|
134814201AA4EA6300B7C361 /* libMoveSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMoveSdk.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
27
|
+
ABD6EADA2906D6FE00BAC83D /* MoveSdk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoveSdk.h; sourceTree = "<group>"; };
|
|
28
|
+
ABD6EADB2906D6FE00BAC83D /* MoveSdk.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MoveSdk.swift; sourceTree = "<group>"; };
|
|
30
29
|
F4FF95D5245B92E700C19C63 /* MoveSdk-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MoveSdk-Bridging-Header.h"; sourceTree = "<group>"; };
|
|
31
30
|
/* End PBXFileReference section */
|
|
32
31
|
|
|
@@ -44,9 +43,8 @@
|
|
|
44
43
|
09A2803725DA82E000603CBF /* NativeModule */ = {
|
|
45
44
|
isa = PBXGroup;
|
|
46
45
|
children = (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
09A2803A25DA82E000603CBF /* DolphinSdk.swift */,
|
|
46
|
+
ABD6EADA2906D6FE00BAC83D /* MoveSdk.h */,
|
|
47
|
+
ABD6EADB2906D6FE00BAC83D /* MoveSdk.swift */,
|
|
50
48
|
);
|
|
51
49
|
path = NativeModule;
|
|
52
50
|
sourceTree = "<group>";
|
|
@@ -125,7 +123,7 @@
|
|
|
125
123
|
isa = PBXSourcesBuildPhase;
|
|
126
124
|
buildActionMask = 2147483647;
|
|
127
125
|
files = (
|
|
128
|
-
|
|
126
|
+
ABD6EADC2906D6FE00BAC83D /* MoveSdk.swift in Sources */,
|
|
129
127
|
);
|
|
130
128
|
runOnlyForDeploymentPostprocessing = 0;
|
|
131
129
|
};
|
|
@@ -5,30 +5,38 @@
|
|
|
5
5
|
|
|
6
6
|
@interface DolphinSdkInternal: RCTEventEmitter
|
|
7
7
|
+(void)initIfPossibleWithLaunchOptions:(NSDictionary *) launchOptions;
|
|
8
|
+
+(void)performBackgroundFetch: (void (^)(UIBackgroundFetchResult))completionHandler;
|
|
8
9
|
-(void)sendAppEvent:(NSString *) eventInfo;
|
|
9
10
|
@end
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
@interface RCT_EXTERN_MODULE(
|
|
13
|
+
@interface RCT_EXTERN_MODULE(RCTMoveSdk, DolphinSdkInternal)
|
|
13
14
|
|
|
14
|
-
RCT_EXTERN_METHOD(
|
|
15
|
+
RCT_EXTERN_METHOD(setup: (NSString *)contractId
|
|
15
16
|
accessToken: (NSString *)accessToken
|
|
16
17
|
refreshToken: (NSString *)refreshToken
|
|
17
18
|
productId: (NSInteger *)productId
|
|
18
|
-
|
|
19
|
+
timelineDetectionServices: (NSArray<NSString> *)timelineDetectionServices
|
|
19
20
|
drivingServices: (NSArray<NSString> *)drivingServices
|
|
20
21
|
walkingServices: (NSArray<NSString> *)walkingServices
|
|
21
|
-
otherServices: (NSArray<NSString> *)otherServices
|
|
22
22
|
resolve: (RCTPromiseResolveBlock)resolve
|
|
23
|
-
reject: (RCTPromiseRejectBlock)reject
|
|
24
|
-
)
|
|
23
|
+
reject: (RCTPromiseRejectBlock)reject)
|
|
25
24
|
|
|
26
25
|
RCT_EXTERN_METHOD(getState: (RCTPromiseResolveBlock)resolve
|
|
27
26
|
rejecter: (RCTPromiseRejectBlock)reject)
|
|
28
27
|
|
|
29
28
|
RCT_EXTERN_METHOD(getTripState: (RCTPromiseResolveBlock)resolve
|
|
30
29
|
rejecter: (RCTPromiseRejectBlock)reject)
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
RCT_EXTERN_METHOD(getWarnings: (RCTPromiseResolveBlock)resolve
|
|
32
|
+
rejecter: (RCTPromiseRejectBlock)reject)
|
|
33
|
+
|
|
34
|
+
RCT_EXTERN_METHOD(getErrors: (RCTPromiseResolveBlock)resolve
|
|
35
|
+
rejecter: (RCTPromiseRejectBlock)reject)
|
|
36
|
+
|
|
37
|
+
RCT_EXTERN_METHOD(initiateAssistanceCall: (RCTPromiseResolveBlock)resolve
|
|
38
|
+
rejecter: (RCTPromiseRejectBlock)reject)
|
|
39
|
+
|
|
32
40
|
RCT_EXTERN_METHOD(startAutomaticDetection)
|
|
33
41
|
|
|
34
42
|
RCT_EXTERN_METHOD(stopAutomaticDetection)
|
|
@@ -54,6 +62,12 @@ RCT_EXTERN_METHOD(updateAuth: (NSString *)contractId
|
|
|
54
62
|
resolver: (RCTPromiseResolveBlock)resolve
|
|
55
63
|
rejecter: (RCTPromiseRejectBlock)reject)
|
|
56
64
|
|
|
65
|
+
RCT_EXTERN_METHOD(geocode: (double)latitude: (double)longitude
|
|
66
|
+
resolver: (RCTPromiseResolveBlock)resolve
|
|
67
|
+
rejecter: (RCTPromiseRejectBlock)reject)
|
|
68
|
+
|
|
57
69
|
RCT_EXTERN_METHOD(resolveError)
|
|
58
70
|
|
|
71
|
+
RCT_EXTERN_METHOD(requestMotionPermission)
|
|
72
|
+
|
|
59
73
|
@end
|