react-native-move-sdk 0.1.4 → 0.2.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/README.md +1 -1
- 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 -38
- package/package.json +1 -1
- package/react-native-move-sdk.podspec +3 -1
- package/src/index.ts +163 -190
- package/ios/NativeModule/DolphinSdk.swift +0 -357
- package/ios/NativeModule/DolphinSdkDemoReactNative-Bridging-Header.h +0 -8
|
@@ -4,8 +4,7 @@ import android.content.Context
|
|
|
4
4
|
import android.content.SharedPreferences
|
|
5
5
|
import io.dolphin.move.DrivingService
|
|
6
6
|
import io.dolphin.move.MoveAuth
|
|
7
|
-
import io.dolphin.move.
|
|
8
|
-
import io.dolphin.move.TimelineDetectionService
|
|
7
|
+
import io.dolphin.move.MoveDetectionService
|
|
9
8
|
import io.dolphin.move.WalkingService
|
|
10
9
|
|
|
11
10
|
private const val SHARED_PREF_NAME = "move-react"
|
|
@@ -13,14 +12,12 @@ private const val SHARED_PREF_NAME = "move-react"
|
|
|
13
12
|
private const val PROPERTY_TIMELINE_SERVICES = "timelineDetectionServices"
|
|
14
13
|
private const val PROPERTY_DRIVING_SERVICES = "drivingServices"
|
|
15
14
|
private const val PROPERTY_WALKING_SERVICES = "walkingServices"
|
|
16
|
-
private const val PROPERTY_OTHER_SERVICES = "otherServices"
|
|
17
15
|
|
|
18
16
|
private const val PROPERTY_PRODUCT_ID = "productId"
|
|
19
|
-
private const val
|
|
17
|
+
private const val PROPERTY_USER_ID = "contractId"
|
|
20
18
|
private const val PROPERTY_ACCESS_TOKEN = "accessToken"
|
|
21
19
|
private const val PROPERTY_REFRESH_TOKEN = "refreshToken"
|
|
22
20
|
|
|
23
|
-
private const val PROPERTY_ALLOW_MOCK = "allowMockLocations"
|
|
24
21
|
private const val PROPERTY_STARTED = "isInRunningState"
|
|
25
22
|
|
|
26
23
|
private const val PROPERTY_NOTIFICATION_TITLE = "NotificationTitle"
|
|
@@ -31,164 +28,176 @@ private const val PROPERTY_NOTIFICATION_CHANNELDESCRIPTION = "NotificationChanne
|
|
|
31
28
|
|
|
32
29
|
private const val NOTIFICATION_RECOGNITION = "recognition"
|
|
33
30
|
private const val NOTIFICATION_TRIP = "trip"
|
|
31
|
+
private const val NOTIFICATION_WALKING = "walking"
|
|
34
32
|
|
|
35
33
|
class MoveSdkConfigRepository(context: Context) {
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return MoveNotificationConfig(
|
|
175
|
-
title = notificationTitle,
|
|
176
|
-
text = notificationText,
|
|
177
|
-
channelId = notificationChannelId,
|
|
178
|
-
channelName = notificationChannelName,
|
|
179
|
-
channelDescription = notificationChannelDescription
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
fun storeRunningState(running: Boolean) {
|
|
184
|
-
sharedPreferences.edit().putBoolean(PROPERTY_STARTED, running).apply()
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
fun loadRunningState(): Boolean {
|
|
188
|
-
return sharedPreferences.getBoolean(PROPERTY_STARTED, false)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
fun clear() {
|
|
192
|
-
sharedPreferences.edit().clear().apply()
|
|
193
|
-
}
|
|
35
|
+
private val sharedPreferences: SharedPreferences =
|
|
36
|
+
context.applicationContext.getSharedPreferences(
|
|
37
|
+
SHARED_PREF_NAME,
|
|
38
|
+
Context.MODE_PRIVATE
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
fun storeConfig(config: MoveSdkConfig) {
|
|
42
|
+
|
|
43
|
+
// Persist data for native init next app start
|
|
44
|
+
val editor = sharedPreferences.edit()
|
|
45
|
+
editor.putStringSet(
|
|
46
|
+
PROPERTY_TIMELINE_SERVICES,
|
|
47
|
+
config.timelineDetectionServices.map { service -> service.name() }.toSet()
|
|
48
|
+
)
|
|
49
|
+
editor.apply()
|
|
50
|
+
|
|
51
|
+
storeAuth(config.auth)
|
|
52
|
+
|
|
53
|
+
// Platform config
|
|
54
|
+
val recognitionNotification = config.recognitionNotification
|
|
55
|
+
storeNotificationConfig(NOTIFICATION_RECOGNITION, recognitionNotification)
|
|
56
|
+
|
|
57
|
+
val tripNotification = config.tripNotification
|
|
58
|
+
storeNotificationConfig(NOTIFICATION_TRIP, tripNotification)
|
|
59
|
+
|
|
60
|
+
val walkingNotification = config.walkingNotification
|
|
61
|
+
storeNotificationConfig(NOTIFICATION_WALKING, walkingNotification)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private fun storeNotificationConfig(
|
|
65
|
+
prefix: String,
|
|
66
|
+
recognitionNotification: MoveNotificationConfig
|
|
67
|
+
) {
|
|
68
|
+
val editor = sharedPreferences.edit()
|
|
69
|
+
editor.putString(prefix + PROPERTY_NOTIFICATION_TITLE, recognitionNotification.title)
|
|
70
|
+
editor.putString(prefix + PROPERTY_NOTIFICATION_TEXT, recognitionNotification.text)
|
|
71
|
+
editor.putString(
|
|
72
|
+
prefix + PROPERTY_NOTIFICATION_CHANNELID,
|
|
73
|
+
recognitionNotification.channelId
|
|
74
|
+
)
|
|
75
|
+
editor.putString(
|
|
76
|
+
prefix + PROPERTY_NOTIFICATION_CHANNELNAME,
|
|
77
|
+
recognitionNotification.channelName
|
|
78
|
+
)
|
|
79
|
+
editor.putString(
|
|
80
|
+
prefix + PROPERTY_NOTIFICATION_CHANNELDESCRIPTION,
|
|
81
|
+
recognitionNotification.channelDescription
|
|
82
|
+
)
|
|
83
|
+
editor.apply()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fun storeAuth(auth: MoveAuth) {
|
|
87
|
+
// Persist data for native init next app start
|
|
88
|
+
val editor = sharedPreferences.edit()
|
|
89
|
+
editor.putInt(PROPERTY_PRODUCT_ID, auth.projectId.toInt())
|
|
90
|
+
editor.putString(PROPERTY_USER_ID, auth.userId)
|
|
91
|
+
editor.putString(PROPERTY_ACCESS_TOKEN, auth.accessToken)
|
|
92
|
+
editor.putString(PROPERTY_REFRESH_TOKEN, auth.refreshToken)
|
|
93
|
+
editor.apply()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fun loadConfig(): MoveSdkConfig {
|
|
97
|
+
|
|
98
|
+
val projectId = sharedPreferences.getInt(PROPERTY_PRODUCT_ID, 0)
|
|
99
|
+
val userId = sharedPreferences.getString(PROPERTY_USER_ID, "") ?: ""
|
|
100
|
+
val accessToken: String = sharedPreferences.getString(PROPERTY_ACCESS_TOKEN, "") ?: ""
|
|
101
|
+
val refreshToken = sharedPreferences.getString(PROPERTY_REFRESH_TOKEN, "") ?: ""
|
|
102
|
+
|
|
103
|
+
// Config
|
|
104
|
+
|
|
105
|
+
/*
|
|
106
|
+
val drivingServices: List<DrivingService> =
|
|
107
|
+
sharedPreferences.getStringSet(PROPERTY_DRIVING_SERVICES, emptySet())?.map { service ->
|
|
108
|
+
DrivingService.valueOf(service)
|
|
109
|
+
} ?: emptyList()
|
|
110
|
+
|
|
111
|
+
val walkingServices: List<WalkingService> =
|
|
112
|
+
sharedPreferences.getStringSet(PROPERTY_WALKING_SERVICES, emptySet())?.map { service ->
|
|
113
|
+
WalkingService.valueOf(service)
|
|
114
|
+
} ?: emptyList()
|
|
115
|
+
|
|
116
|
+
val timelineDetectionServices: List<MoveDetectionService> = emptyList()
|
|
117
|
+
sharedPreferences.getStringSet(PROPERTY_TIMELINE_SERVICES, emptySet())?.map { service ->
|
|
118
|
+
valueOfMoveDetectionService(service, drivingServices, walkingServices)
|
|
119
|
+
} ?: emptyList()
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
val recognitionNotification = loadNotificationConfig(NOTIFICATION_RECOGNITION)
|
|
123
|
+
val tripNotification = loadNotificationConfig(NOTIFICATION_TRIP)
|
|
124
|
+
val walkingNotification = loadNotificationConfig(NOTIFICATION_WALKING)
|
|
125
|
+
|
|
126
|
+
return MoveSdkConfig(
|
|
127
|
+
auth = MoveAuth(
|
|
128
|
+
userId = userId,
|
|
129
|
+
accessToken = accessToken,
|
|
130
|
+
refreshToken = refreshToken,
|
|
131
|
+
projectId = projectId.toLong(),
|
|
132
|
+
),
|
|
133
|
+
timelineDetectionServices = emptyList(),
|
|
134
|
+
tripNotification = tripNotification,
|
|
135
|
+
recognitionNotification = recognitionNotification,
|
|
136
|
+
walkingNotification = walkingNotification
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private fun loadNotificationConfig(prefix: String): MoveNotificationConfig {
|
|
141
|
+
val notificationTitle: String =
|
|
142
|
+
sharedPreferences.getString(prefix + PROPERTY_NOTIFICATION_TITLE, "") ?: ""
|
|
143
|
+
val notificationText: String =
|
|
144
|
+
sharedPreferences.getString(prefix + PROPERTY_NOTIFICATION_TEXT, "") ?: ""
|
|
145
|
+
val notificationChannelId: String =
|
|
146
|
+
sharedPreferences.getString(prefix + PROPERTY_NOTIFICATION_CHANNELID, "") ?: ""
|
|
147
|
+
val notificationChannelName: String =
|
|
148
|
+
sharedPreferences.getString(prefix + PROPERTY_NOTIFICATION_CHANNELNAME, "") ?: ""
|
|
149
|
+
val notificationChannelDescription: String =
|
|
150
|
+
sharedPreferences.getString(prefix + PROPERTY_NOTIFICATION_CHANNELDESCRIPTION, "") ?: ""
|
|
151
|
+
|
|
152
|
+
return MoveNotificationConfig(
|
|
153
|
+
title = notificationTitle,
|
|
154
|
+
text = notificationText,
|
|
155
|
+
channelId = notificationChannelId,
|
|
156
|
+
channelName = notificationChannelName,
|
|
157
|
+
channelDescription = notificationChannelDescription
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
fun storeRunningState(running: Boolean) {
|
|
162
|
+
sharedPreferences.edit().putBoolean(PROPERTY_STARTED, running).apply()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fun loadRunningState(): Boolean {
|
|
166
|
+
return sharedPreferences.getBoolean(PROPERTY_STARTED, false)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fun clear() {
|
|
170
|
+
sharedPreferences.edit().clear().apply()
|
|
171
|
+
}
|
|
194
172
|
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Resolve a sealed object by its name
|
|
176
|
+
*/
|
|
177
|
+
internal fun valueOfMoveDetectionService(
|
|
178
|
+
it: String,
|
|
179
|
+
drivingServices: List<DrivingService>,
|
|
180
|
+
walkingServices: List<WalkingService>
|
|
181
|
+
) =
|
|
182
|
+
if (it.equalsService(MoveDetectionService.Driving())) {
|
|
183
|
+
MoveDetectionService.Driving(drivingServices)
|
|
184
|
+
} else if (it.equalsService(MoveDetectionService.Walking())) {
|
|
185
|
+
MoveDetectionService.Walking(walkingServices)
|
|
186
|
+
} else if (it.equalsService(MoveDetectionService.Cycling)) {
|
|
187
|
+
MoveDetectionService.Cycling
|
|
188
|
+
} else if (it.equalsService(MoveDetectionService.Places)) {
|
|
189
|
+
MoveDetectionService.Places
|
|
190
|
+
} else if (it.equalsService(MoveDetectionService.PublicTransport)) {
|
|
191
|
+
MoveDetectionService.PublicTransport
|
|
192
|
+
} else if (it.equalsService(MoveDetectionService.PointsOfInterest)) {
|
|
193
|
+
MoveDetectionService.PointsOfInterest
|
|
194
|
+
} else if (it.equalsService(MoveDetectionService.AssistanceCall)) {
|
|
195
|
+
MoveDetectionService.AssistanceCall
|
|
196
|
+
} else if (it.equalsService(MoveDetectionService.AutomaticImpactDetection)) {
|
|
197
|
+
MoveDetectionService.AutomaticImpactDetection
|
|
198
|
+
} else {
|
|
199
|
+
// default case?
|
|
200
|
+
throw IllegalArgumentException("$it is not known, use one of " + MoveDetectionService::class.sealedSubclasses.joinToString { kClass ->
|
|
201
|
+
kClass.simpleName?.toSnakeCase() ?: ""
|
|
202
|
+
})
|
|
203
|
+
}
|