react-native-mytatva-rn-sdk 1.2.51 → 1.2.53
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/src/main/java/cgmblelib/base/BApplication.java +57 -57
- package/android/src/main/java/cgmblelib/ble/BleService.java +1 -1
- package/android/src/main/java/cgmblelib/ble/gattcallback/BleGattCallback.java +1 -1
- package/android/src/main/java/cgmblelib/database/dao/DaoDevice.java +4 -0
- package/android/src/main/java/cgmblelib/database/dao/DaoGlucose.java +334 -332
- package/android/src/main/java/cgmblelib/database/repository/RepositoryDevice.java +5 -0
- package/android/src/main/java/cgmblelib/database/repository/RepositoryGlucose.java +167 -162
- package/android/src/main/java/cgmblelib/database/source/SourceDevice.java +2 -0
- package/android/src/main/java/cgmblelib/database/source/SourceGlucose.java +2 -0
- package/android/src/main/java/cgmblelib/database/source/db/DeviceDBDataSource.java +171 -165
- package/android/src/main/java/cgmblelib/database/source/db/GlucoseDBDataSource.java +305 -296
- package/android/src/main/java/cgmblelib/utils/SharedPreferencesLibraryUtil.java +66 -44
- package/android/src/main/java/com/mytatvarnsdk/CgmTrackyLibModule.kt +125 -81
- package/android/src/main/java/com/mytatvarnsdk/MainApplication.kt +2 -2
- package/android/src/main/java/com/mytatvarnsdk/activity/ConnectSensorActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PermissionActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PlaceSensorActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/PlaceTransmitterActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/activity/SearchTransmitterActivity.kt +3 -4
- package/android/src/main/java/com/mytatvarnsdk/activity/SensorConnectSuccessActivity.kt +8 -5
- package/android/src/main/java/com/mytatvarnsdk/activity/StartCGMActivity.kt +1 -1
- package/android/src/main/java/com/mytatvarnsdk/model/BaseViewModel.java +88 -84
- package/android/src/main/java/com/mytatvarnsdk/network/AuthenticateSDKService.kt +197 -197
- package/android/src/main/java/com/mytatvarnsdk/utils/TatvaEncryptionConfig.kt +1 -1
- package/ios/Database/KLTBluetoothManager.m +8 -0
- package/ios/Database/KLTDatabaseHandler.m +43 -26
- package/ios/Database/KLTLocalSettingManager.h +3 -0
- package/ios/MyReactNativeBridge.m +27 -15
- package/ios/Support/API.swift +8 -8
- package/ios/ViewControllers/AttachTransmitterViewController.swift +1 -1
- package/ios/ViewModel/FinalViewModel.swift +11 -9
- package/lib/commonjs/CGMConnect.js +12 -12
- package/lib/commonjs/CGMConnect.js.map +1 -1
- package/lib/module/CGMConnect.js +13 -13
- package/lib/module/CGMConnect.js.map +1 -1
- package/lib/typescript/CGMConnect.d.ts +6 -6
- package/package.json +2 -2
- package/src/CGMConnect.ts +78 -55
|
@@ -10,60 +10,82 @@ import cgmblelib.qr.QRInformation;
|
|
|
10
10
|
|
|
11
11
|
public class SharedPreferencesLibraryUtil {
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
BSharedPreferences prefsHelper;
|
|
14
|
+
private final String QRInfo = "QRInformation";
|
|
15
|
+
private final String SyncMeta = "SyncMeta";
|
|
16
|
+
private final String PatientId = "PatientId";
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
public SharedPreferencesLibraryUtil(Context context) {
|
|
20
|
+
prefsHelper = BSharedPreferences.getInstance(context);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public QRInformation getQRInformation() {
|
|
24
|
+
try {
|
|
25
|
+
String message = prefsHelper.getData(QRInfo);
|
|
26
|
+
if (message == null || message.isEmpty()) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return new Gson().fromJson(message, QRInformation.class);
|
|
30
|
+
} catch (Exception e) {
|
|
31
|
+
Log.d("Error => ", "getQRInformation: " + e.getMessage());
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Log.d("Error => ", "getQRInformation: " + e.getMessage());
|
|
31
|
-
return null;
|
|
36
|
+
|
|
37
|
+
public void setQRInformation(String transmitterName, String qrmessage, float K, float R, String sensor) {
|
|
38
|
+
try {
|
|
39
|
+
Log.d("Error => ", "setQRInformation: " + transmitterName + qrmessage + K + R + sensor);
|
|
40
|
+
prefsHelper.saveData(QRInfo, new Gson().toJson(new QRInformation(transmitterName, qrmessage, R, K, sensor)));
|
|
41
|
+
} catch (Exception e) {
|
|
42
|
+
Log.d("Error => ", "setQRInformation: " + e.getMessage());
|
|
43
|
+
}
|
|
32
44
|
}
|
|
33
|
-
}
|
|
34
45
|
|
|
46
|
+
public void setLastSyncData(SyncMeta syncMeta) {
|
|
47
|
+
try {
|
|
48
|
+
prefsHelper.saveData(SyncMeta, new Gson().toJson(syncMeta));
|
|
49
|
+
} catch (Exception e) {
|
|
50
|
+
Log.d("Error => ", "setLastSyncData: " + e.getMessage());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
35
53
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
public SyncMeta getLastSyncData() {
|
|
55
|
+
try {
|
|
56
|
+
String message = prefsHelper.getData(SyncMeta);
|
|
57
|
+
if (message == null || message.isEmpty()) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return new Gson().fromJson(message, SyncMeta.class);
|
|
61
|
+
} catch (Exception e) {
|
|
62
|
+
Log.d("Error => ", "getLastSyncData: " + e.getMessage());
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
42
65
|
}
|
|
43
|
-
}
|
|
44
66
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
public void setLastPatientId(String patientId) {
|
|
68
|
+
try {
|
|
69
|
+
prefsHelper.saveData(PatientId, patientId);
|
|
70
|
+
} catch (Exception e) {
|
|
71
|
+
Log.d("Error => ", "setLastUserId: " + e.getMessage());
|
|
72
|
+
}
|
|
50
73
|
}
|
|
51
|
-
}
|
|
52
74
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
75
|
+
public String getLastPatientId() {
|
|
76
|
+
try {
|
|
77
|
+
String message = prefsHelper.getData(PatientId);
|
|
78
|
+
if (message == null || message.isEmpty()) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return message;
|
|
82
|
+
} catch (Exception e) {
|
|
83
|
+
Log.d("Error => ", "getLastUserId: " + e.getMessage());
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
63
86
|
}
|
|
64
|
-
}
|
|
65
87
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
public void clearQRInformation() {
|
|
89
|
+
prefsHelper.saveData(QRInfo, null);
|
|
90
|
+
}
|
|
69
91
|
}
|
|
@@ -2,15 +2,10 @@ package com.mytatvarnsdk
|
|
|
2
2
|
|
|
3
3
|
import android.app.Application
|
|
4
4
|
import android.bluetooth.BluetoothAdapter
|
|
5
|
-
import android.bluetooth.BluetoothManager
|
|
6
|
-
import android.content.Context
|
|
7
5
|
import android.content.Intent
|
|
8
|
-
import android.content.pm.PackageManager
|
|
9
|
-
import android.os.Build
|
|
10
6
|
import android.os.Handler
|
|
11
7
|
import android.os.Looper
|
|
12
8
|
import android.util.Log
|
|
13
|
-
import androidx.core.content.ContextCompat
|
|
14
9
|
import androidx.lifecycle.Observer
|
|
15
10
|
import androidx.lifecycle.ViewModelProvider
|
|
16
11
|
import androidx.lifecycle.ViewModelStore
|
|
@@ -31,9 +26,6 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
|
31
26
|
import com.google.gson.Gson
|
|
32
27
|
import com.google.gson.GsonBuilder
|
|
33
28
|
import com.mytatvarnsdk.activity.HelpActivity
|
|
34
|
-
import com.mytatvarnsdk.activity.PermissionActivity
|
|
35
|
-
import com.mytatvarnsdk.activity.PermissionUtils
|
|
36
|
-
import com.mytatvarnsdk.activity.SearchTransmitterActivity
|
|
37
29
|
import com.mytatvarnsdk.activity.StartCGMActivity
|
|
38
30
|
import com.mytatvarnsdk.model.AllCGMLogRequest
|
|
39
31
|
import com.mytatvarnsdk.model.CgmLog
|
|
@@ -94,6 +86,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
94
86
|
companion object {
|
|
95
87
|
var mReactContext: ReactApplicationContext? = null
|
|
96
88
|
var userToken: String = ""
|
|
89
|
+
var env: String = ""
|
|
97
90
|
}
|
|
98
91
|
|
|
99
92
|
override fun getName(): String {
|
|
@@ -101,9 +94,10 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
101
94
|
}
|
|
102
95
|
|
|
103
96
|
@ReactMethod
|
|
104
|
-
fun observeDeviceStatus(token: String) {
|
|
97
|
+
fun observeDeviceStatus(token: String, envType: String) {
|
|
105
98
|
try {
|
|
106
99
|
userToken = token
|
|
100
|
+
env = envType
|
|
107
101
|
|
|
108
102
|
// Reset previous state
|
|
109
103
|
lastDeviceStatus = null
|
|
@@ -112,7 +106,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
112
106
|
Handler(Looper.getMainLooper()).post {
|
|
113
107
|
mModel.device.observeForever { device ->
|
|
114
108
|
if (device != null) {
|
|
115
|
-
postEventDataToAPI(device, "", device.qrMessage ?: "")
|
|
109
|
+
postEventDataToAPI(device, "", device.qrMessage ?: "", envType)
|
|
116
110
|
Log.d("observeDeviceStatus: ", device.toString())
|
|
117
111
|
}
|
|
118
112
|
}
|
|
@@ -123,9 +117,15 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
123
117
|
}
|
|
124
118
|
|
|
125
119
|
@ReactMethod
|
|
126
|
-
fun observeTransmitterUnbindStatus(
|
|
120
|
+
fun observeTransmitterUnbindStatus(
|
|
121
|
+
token: String,
|
|
122
|
+
apiResponse: String?,
|
|
123
|
+
patientId: String,
|
|
124
|
+
envType: String
|
|
125
|
+
) {
|
|
127
126
|
try {
|
|
128
127
|
if (apiResponse != null && apiResponse.isNotEmpty()) {
|
|
128
|
+
env = envType
|
|
129
129
|
userToken = token
|
|
130
130
|
|
|
131
131
|
/*authenticateSDKService.getCGMData(
|
|
@@ -192,6 +192,15 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
192
192
|
val startDate = sensor.startDate
|
|
193
193
|
val endDate = sensor.endDate
|
|
194
194
|
val sensorId = sensor.sensorId
|
|
195
|
+
val currentPatientId = patientId
|
|
196
|
+
|
|
197
|
+
val lastPatientId = prefsHelper.lastPatientId
|
|
198
|
+
val lastSensorId = prefsHelper.qrInformation.sensor
|
|
199
|
+
|
|
200
|
+
if (lastPatientId != null && lastSensorId != null && (lastPatientId != currentPatientId || lastSensorId != sensorId)) {
|
|
201
|
+
mModel.clearAllGlucoseAndDeviceData()
|
|
202
|
+
return
|
|
203
|
+
}
|
|
195
204
|
|
|
196
205
|
if (isCurrentDateInRange(startDate, endDate)) {
|
|
197
206
|
println("Current date is in range")
|
|
@@ -204,14 +213,17 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
204
213
|
postEventDataToAPI(
|
|
205
214
|
pocDevice,
|
|
206
215
|
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
207
|
-
pocDevice.qrMessage
|
|
216
|
+
pocDevice.qrMessage, envType
|
|
208
217
|
)
|
|
218
|
+
} else {
|
|
219
|
+
prefsHelper.lastPatientId = currentPatientId
|
|
220
|
+
prefsHelper.qrInformation.sensor = sensorId
|
|
209
221
|
}
|
|
210
222
|
} else {
|
|
211
223
|
postEventDataToAPI(
|
|
212
224
|
pocDevice,
|
|
213
225
|
DeviceStatus.TRANSMITTER_DISCONNECT.id,
|
|
214
|
-
sensorId
|
|
226
|
+
sensorId, envType
|
|
215
227
|
)
|
|
216
228
|
}
|
|
217
229
|
|
|
@@ -231,7 +243,12 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
231
243
|
private var isDebounceTimerActive: Boolean = false
|
|
232
244
|
|
|
233
245
|
|
|
234
|
-
private fun postEventDataToAPI(
|
|
246
|
+
private fun postEventDataToAPI(
|
|
247
|
+
device: PocDevice?,
|
|
248
|
+
mStatus: String,
|
|
249
|
+
sensorId: String?,
|
|
250
|
+
envType: String
|
|
251
|
+
) {
|
|
235
252
|
apiScope.launch {
|
|
236
253
|
try {
|
|
237
254
|
val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter()
|
|
@@ -257,7 +274,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
257
274
|
debounceDeviceTimer?.schedule(object : TimerTask() {
|
|
258
275
|
override fun run() {
|
|
259
276
|
isDebounceTimerActive = false
|
|
260
|
-
callEventAPI(device, status, sensorId)
|
|
277
|
+
callEventAPI(device, status, sensorId, envType)
|
|
261
278
|
}
|
|
262
279
|
}, 1 * 60 * 1000) // 1 minutes in milliseconds
|
|
263
280
|
|
|
@@ -270,7 +287,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
270
287
|
|
|
271
288
|
Log.d("Debounce", "Timer cancelled, event triggered immediately")
|
|
272
289
|
|
|
273
|
-
callEventAPI(device, status, sensorId)
|
|
290
|
+
callEventAPI(device, status, sensorId, envType)
|
|
274
291
|
}
|
|
275
292
|
|
|
276
293
|
} catch (e: Exception) {
|
|
@@ -279,7 +296,12 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
279
296
|
}
|
|
280
297
|
}
|
|
281
298
|
|
|
282
|
-
private fun callEventAPI(
|
|
299
|
+
private fun callEventAPI(
|
|
300
|
+
device: PocDevice?,
|
|
301
|
+
status: String,
|
|
302
|
+
sensorId: String?,
|
|
303
|
+
envType: String
|
|
304
|
+
) {
|
|
283
305
|
Log.d("Device event Status", "Last Device event lastDeviceStatus API: $lastDeviceStatus")
|
|
284
306
|
|
|
285
307
|
if (status.isNotEmpty() && status != lastDeviceStatus) {
|
|
@@ -301,7 +323,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
301
323
|
}
|
|
302
324
|
|
|
303
325
|
authenticateSDKService.postDeviceData(
|
|
304
|
-
environment = TATVA_ENVIRONMENT.PROD,
|
|
326
|
+
environment = if (envType.lowercase() == "uat") TATVA_ENVIRONMENT.STAGE else TATVA_ENVIRONMENT.PROD,
|
|
305
327
|
data = obj.toString(),
|
|
306
328
|
token = userToken,
|
|
307
329
|
loaderListener = object : LoaderListener {
|
|
@@ -324,7 +346,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
324
346
|
}
|
|
325
347
|
|
|
326
348
|
@ReactMethod
|
|
327
|
-
fun startCgmTracky(token: String) {
|
|
349
|
+
fun startCgmTracky(token: String, envType: String) {
|
|
328
350
|
try {
|
|
329
351
|
userToken = token
|
|
330
352
|
val intent = Intent(currentActivity, StartCGMActivity::class.java)
|
|
@@ -346,7 +368,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
346
368
|
}
|
|
347
369
|
|
|
348
370
|
@ReactMethod
|
|
349
|
-
fun reconnectCgmTracky(token: String) {
|
|
371
|
+
fun reconnectCgmTracky(token: String, envType: String) {
|
|
350
372
|
try {
|
|
351
373
|
userToken = token
|
|
352
374
|
currentActivity?.startActivity(
|
|
@@ -372,9 +394,10 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
372
394
|
|
|
373
395
|
|
|
374
396
|
@ReactMethod
|
|
375
|
-
fun observeGlucoseData(token: String) {
|
|
397
|
+
fun observeGlucoseData(token: String, isForClear: Boolean = false, envType: String) {
|
|
376
398
|
try {
|
|
377
399
|
userToken = token
|
|
400
|
+
env = envType
|
|
378
401
|
|
|
379
402
|
// Ensure we're not already observing
|
|
380
403
|
if (isObserving && glucoseObserver != null) {
|
|
@@ -416,7 +439,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
416
439
|
}
|
|
417
440
|
|
|
418
441
|
if ((pocGlucose != null && lastSyncData == null) || (pocGlucose != null && lastSyncData != null && dataAge <= 4 * 60 * 1000L)) {
|
|
419
|
-
handleGlucoseData(pocGlucose)
|
|
442
|
+
handleGlucoseData(pocGlucose, envType)
|
|
420
443
|
Log.d(
|
|
421
444
|
"observeGlucoseData",
|
|
422
445
|
"Received glucose data - processing"
|
|
@@ -426,7 +449,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
426
449
|
} else {
|
|
427
450
|
|
|
428
451
|
Handler(Looper.getMainLooper()).postDelayed({
|
|
429
|
-
observeAllGlucoseData(userToken)
|
|
452
|
+
observeAllGlucoseData(userToken, isForClear, envType)
|
|
430
453
|
}, 100)
|
|
431
454
|
Log.d(
|
|
432
455
|
"observeGlucoseData",
|
|
@@ -459,7 +482,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
459
482
|
}
|
|
460
483
|
}
|
|
461
484
|
|
|
462
|
-
private fun handleGlucoseData(pocGlucose: PocGlucose) {
|
|
485
|
+
private fun handleGlucoseData(pocGlucose: PocGlucose, envType: String) {
|
|
463
486
|
try {
|
|
464
487
|
// Additional safety check
|
|
465
488
|
if (pocGlucose.glucoseId == null) {
|
|
@@ -483,7 +506,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
483
506
|
Log.d("Glucose data 3 min==> ", "Glucose data 3 min==> final Json: $json")
|
|
484
507
|
|
|
485
508
|
authenticateSDKService.postCGMData(
|
|
486
|
-
environment = TATVA_ENVIRONMENT.PROD,
|
|
509
|
+
environment = if (envType.lowercase() == "uat") TATVA_ENVIRONMENT.STAGE else TATVA_ENVIRONMENT.PROD,
|
|
487
510
|
data = json,
|
|
488
511
|
token = userToken,
|
|
489
512
|
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
@@ -505,7 +528,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
505
528
|
}
|
|
506
529
|
} else {
|
|
507
530
|
Log.d("handleGlucoseData", "Glucose data has error: ${pocGlucose.errorCode}")
|
|
508
|
-
handleGlucoseError(pocGlucose)
|
|
531
|
+
handleGlucoseError(pocGlucose, envType)
|
|
509
532
|
}
|
|
510
533
|
} catch (e: Exception) {
|
|
511
534
|
Log.e("handleGlucoseData", "Error handling glucose data: ${e.message}")
|
|
@@ -514,7 +537,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
514
537
|
}
|
|
515
538
|
|
|
516
539
|
// Extract error handling logic
|
|
517
|
-
private fun handleGlucoseError(pocGlucose: PocGlucose) {
|
|
540
|
+
private fun handleGlucoseError(pocGlucose: PocGlucose, envType: String) {
|
|
518
541
|
try {
|
|
519
542
|
// Additional safety check for deviceId
|
|
520
543
|
if (pocGlucose.deviceId == null) {
|
|
@@ -546,7 +569,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
546
569
|
}
|
|
547
570
|
}
|
|
548
571
|
|
|
549
|
-
postEventDataToAPI(it, statusId, it.qrMessage)
|
|
572
|
+
postEventDataToAPI(it, statusId, it.qrMessage, envType)
|
|
550
573
|
} ?: run {
|
|
551
574
|
Log.e(
|
|
552
575
|
"handleGlucoseError",
|
|
@@ -559,75 +582,89 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
559
582
|
}
|
|
560
583
|
}
|
|
561
584
|
|
|
562
|
-
|
|
563
585
|
@ReactMethod
|
|
564
|
-
fun observeAllGlucoseData(token: String) {
|
|
586
|
+
fun observeAllGlucoseData(token: String, isForClear: Boolean = false, envType: String) {
|
|
565
587
|
Log.d("function call", "observeAllGlucoseData")
|
|
588
|
+
|
|
566
589
|
if (isBatchProcessing) {
|
|
567
590
|
Log.d("observeAllGlucoseData", "Batch processing in progress, skipping duplicate call")
|
|
568
591
|
return
|
|
569
592
|
}
|
|
570
|
-
userToken = token
|
|
571
|
-
|
|
572
|
-
// FIX: Ensure proper cleanup and reset state
|
|
573
|
-
stopObservingGlucoseData()
|
|
574
|
-
|
|
575
|
-
// Add a small delay to ensure cleanup is complete
|
|
576
|
-
Handler(Looper.getMainLooper()).postDelayed({
|
|
577
|
-
try {
|
|
578
|
-
val lastSyncData = prefsHelper.lastSyncData
|
|
579
|
-
Log.d("lastSyncData: ", Gson().toJson(lastSyncData).toString())
|
|
580
|
-
val currentTime = System.currentTimeMillis()
|
|
581
|
-
var dataAge = System.currentTimeMillis()
|
|
582
|
-
|
|
583
|
-
if (prefsHelper.lastSyncData != null) {
|
|
584
|
-
dataAge = currentTime - prefsHelper.lastSyncData.timeInMillis
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
if (lastSyncData != null && dataAge > 3 * 60 * 1000L) {
|
|
588
|
-
isBatchProcessing = true
|
|
589
|
-
CoroutineScope(Dispatchers.IO).launch {
|
|
590
|
-
|
|
591
|
-
val glucoseData = mModel.getGlucoseBetweenTime(lastSyncData.timeInMillis)
|
|
592
593
|
|
|
594
|
+
userToken = token
|
|
595
|
+
env = envType
|
|
593
596
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
598
|
+
// Step 1: Clear DB first if needed
|
|
599
|
+
if (isForClear) {
|
|
600
|
+
mModel.clearAllGlucoseAndDeviceData() // suspend or blocking DB operation
|
|
601
|
+
}
|
|
597
602
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
Log.d(
|
|
602
|
-
"observeAllGlucoseData",
|
|
603
|
-
"No historical data found, starting live observation"
|
|
604
|
-
)
|
|
603
|
+
// Step 2: Back to main thread to stop observers and proceed
|
|
604
|
+
withContext(Dispatchers.Main) {
|
|
605
|
+
stopObservingGlucoseData()
|
|
605
606
|
|
|
606
|
-
|
|
607
|
-
|
|
607
|
+
Handler(Looper.getMainLooper()).postDelayed({
|
|
608
|
+
try {
|
|
609
|
+
val lastSyncData = prefsHelper.lastSyncData
|
|
610
|
+
Log.d("lastSyncData: ", Gson().toJson(lastSyncData).toString())
|
|
611
|
+
|
|
612
|
+
val currentTime = System.currentTimeMillis()
|
|
613
|
+
val dataAge =
|
|
614
|
+
if (lastSyncData != null) currentTime - lastSyncData.timeInMillis else 0L
|
|
615
|
+
|
|
616
|
+
if (lastSyncData != null && dataAge > 3 * 60 * 1000L) {
|
|
617
|
+
isBatchProcessing = true
|
|
618
|
+
CoroutineScope(Dispatchers.IO).launch {
|
|
619
|
+
val glucoseData =
|
|
620
|
+
mModel.getGlucoseBetweenTime(lastSyncData.timeInMillis)
|
|
621
|
+
|
|
622
|
+
Log.d("observeAllGlucoseData: ", glucoseData.toString())
|
|
623
|
+
Log.d("Last sync time: ", lastSyncData.lastSyncTime.toString())
|
|
624
|
+
Log.d("current time: ", System.currentTimeMillis().toString())
|
|
625
|
+
|
|
626
|
+
if (!glucoseData.isNullOrEmpty()) {
|
|
627
|
+
processBatchDataAndStartObserver(
|
|
628
|
+
glucoseData,
|
|
629
|
+
isForClear,
|
|
630
|
+
envType
|
|
631
|
+
)
|
|
632
|
+
} else {
|
|
633
|
+
Log.d(
|
|
634
|
+
"observeAllGlucoseData",
|
|
635
|
+
"No historical data found, starting live observation"
|
|
636
|
+
)
|
|
637
|
+
withContext(Dispatchers.Main) {
|
|
638
|
+
observeGlucoseData(userToken, isForClear, envType)
|
|
639
|
+
}
|
|
640
|
+
}
|
|
608
641
|
}
|
|
642
|
+
} else {
|
|
643
|
+
isBatchProcessing = false
|
|
644
|
+
observeGlucoseData(userToken, isForClear, envType)
|
|
609
645
|
}
|
|
646
|
+
} catch (e: Exception) {
|
|
647
|
+
isBatchProcessing = false
|
|
648
|
+
observeGlucoseData(userToken, isForClear, envType)
|
|
610
649
|
}
|
|
611
|
-
}
|
|
612
|
-
isBatchProcessing = false
|
|
613
|
-
observeGlucoseData(userToken)
|
|
614
|
-
}
|
|
615
|
-
} catch (e: Exception) {
|
|
616
|
-
isBatchProcessing = false
|
|
617
|
-
observeGlucoseData(userToken)
|
|
650
|
+
}, 100)
|
|
618
651
|
}
|
|
619
|
-
}
|
|
652
|
+
}
|
|
620
653
|
}
|
|
621
654
|
|
|
622
655
|
// New method to handle batch processing and ensure proper sequencing
|
|
623
|
-
private suspend fun processBatchDataAndStartObserver(
|
|
656
|
+
private suspend fun processBatchDataAndStartObserver(
|
|
657
|
+
dataList: List<PocGlucose>,
|
|
658
|
+
isForClear: Boolean = false,
|
|
659
|
+
envType: String
|
|
660
|
+
) {
|
|
624
661
|
try {
|
|
625
662
|
Log.d(
|
|
626
663
|
"processBatchDataAndStartObserver",
|
|
627
664
|
"Starting batch processing with ${dataList.size} records"
|
|
628
665
|
)
|
|
629
666
|
|
|
630
|
-
val success = processBatchDataSynchronously(dataList)
|
|
667
|
+
val success = processBatchDataSynchronously(dataList, envType)
|
|
631
668
|
|
|
632
669
|
if (success) {
|
|
633
670
|
Log.d("processBatchDataAndStartObserver", "Batch processing completed successfully")
|
|
@@ -643,7 +680,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
643
680
|
"processBatchDataAndStartObserver",
|
|
644
681
|
"Starting live observer after batch completion"
|
|
645
682
|
)
|
|
646
|
-
observeGlucoseData(userToken)
|
|
683
|
+
observeGlucoseData(userToken, isForClear, envType)
|
|
647
684
|
} else {
|
|
648
685
|
Log.d(
|
|
649
686
|
"processBatchDataAndStartObserver",
|
|
@@ -658,7 +695,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
658
695
|
isBatchProcessing = false
|
|
659
696
|
withContext(Dispatchers.Main) {
|
|
660
697
|
if (!isObserving) {
|
|
661
|
-
observeGlucoseData(userToken)
|
|
698
|
+
observeGlucoseData(userToken, isForClear, envType)
|
|
662
699
|
}
|
|
663
700
|
}
|
|
664
701
|
}
|
|
@@ -694,7 +731,10 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
694
731
|
}
|
|
695
732
|
|
|
696
733
|
// Updated batch processing method with better sync control
|
|
697
|
-
private suspend fun processBatchDataSynchronously(
|
|
734
|
+
private suspend fun processBatchDataSynchronously(
|
|
735
|
+
dataList: List<PocGlucose>,
|
|
736
|
+
envType: String
|
|
737
|
+
): Boolean {
|
|
698
738
|
if (dataList.isEmpty()) {
|
|
699
739
|
Log.d("processBatchDataSynchronously", "No data to upload")
|
|
700
740
|
return true
|
|
@@ -762,7 +802,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
762
802
|
)
|
|
763
803
|
logLongJson("Batch $index JSON=>>> ", json)
|
|
764
804
|
|
|
765
|
-
val uploadSuccessful = uploadBatchSynchronously(json, index)
|
|
805
|
+
val uploadSuccessful = uploadBatchSynchronously(json, index, envType)
|
|
766
806
|
|
|
767
807
|
if (uploadSuccessful) {
|
|
768
808
|
lastSyncedRecord = batch.lastOrNull()
|
|
@@ -789,7 +829,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
789
829
|
// Handle error status for the last processed record
|
|
790
830
|
lastSyncedRecord?.let { record ->
|
|
791
831
|
if (record.errorCode != enumError.NONE) {
|
|
792
|
-
handleGlucoseError(record)
|
|
832
|
+
handleGlucoseError(record, envType)
|
|
793
833
|
}
|
|
794
834
|
}
|
|
795
835
|
|
|
@@ -838,11 +878,15 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
838
878
|
}
|
|
839
879
|
|
|
840
880
|
// Helper method for synchronous batch upload
|
|
841
|
-
private suspend fun uploadBatchSynchronously(
|
|
881
|
+
private suspend fun uploadBatchSynchronously(
|
|
882
|
+
json: String,
|
|
883
|
+
batchIndex: Int,
|
|
884
|
+
envType: String
|
|
885
|
+
): Boolean {
|
|
842
886
|
return suspendCoroutine { continuation ->
|
|
843
887
|
try {
|
|
844
888
|
authenticateSDKService.postCGMData(
|
|
845
|
-
environment = TATVA_ENVIRONMENT.PROD,
|
|
889
|
+
environment = if (envType.lowercase() == "uat") TATVA_ENVIRONMENT.STAGE else TATVA_ENVIRONMENT.PROD,
|
|
846
890
|
data = json,
|
|
847
891
|
token = userToken,
|
|
848
892
|
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
@@ -39,8 +39,8 @@ class MainApplication : BApplication(), ReactApplication {
|
|
|
39
39
|
super.onCreate()
|
|
40
40
|
Log.d("MainApplication", "MainApplication onCreate called")
|
|
41
41
|
SoLoader.init(this, false)
|
|
42
|
-
BleService.startService(this)
|
|
43
|
-
BSharedPreferences.init(this)
|
|
42
|
+
// BleService.startService(this)
|
|
43
|
+
// BSharedPreferences.init(this)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
override fun getReactNativeHost(): ReactNativeHost {
|
|
@@ -92,7 +92,7 @@ class ConnectSensorActivity : BaseBleActivity() {
|
|
|
92
92
|
|
|
93
93
|
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
94
94
|
startActivity(
|
|
95
|
-
Intent(this, HelpActivity::class.java).putExtra("ScreenName", "Sensor
|
|
95
|
+
Intent(this, HelpActivity::class.java).putExtra("ScreenName", "Sensor page")
|
|
96
96
|
)
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -170,7 +170,7 @@ class PermissionActivity : BasePermissionActivity() {
|
|
|
170
170
|
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
171
171
|
startActivity(
|
|
172
172
|
Intent(this, HelpActivity::class.java)
|
|
173
|
-
.putExtra("ScreenName", "
|
|
173
|
+
.putExtra("ScreenName", "connection journey page")
|
|
174
174
|
)
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -62,7 +62,7 @@ class PlaceSensorActivity : AppCompatActivity() {
|
|
|
62
62
|
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
63
63
|
startActivity(
|
|
64
64
|
Intent(this, HelpActivity::class.java)
|
|
65
|
-
.putExtra("ScreenName", "
|
|
65
|
+
.putExtra("ScreenName", "Sensor page")
|
|
66
66
|
)
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -70,7 +70,7 @@ class PlaceTransmitterActivity : AppCompatActivity() {
|
|
|
70
70
|
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
71
71
|
startActivity(
|
|
72
72
|
Intent(this, HelpActivity::class.java)
|
|
73
|
-
.putExtra("ScreenName", "
|
|
73
|
+
.putExtra("ScreenName", "Transmitter page")
|
|
74
74
|
)
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -151,7 +151,7 @@ class SearchTransmitterActivity : BaseBleActivity() {
|
|
|
151
151
|
binding.btnSupport.btnProceed.setOnClickListener {
|
|
152
152
|
startActivity(
|
|
153
153
|
Intent(this, HelpActivity::class.java)
|
|
154
|
-
.putExtra("ScreenName", "Transmitter
|
|
154
|
+
.putExtra("ScreenName", "Transmitter page")
|
|
155
155
|
)
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -234,8 +234,7 @@ class SearchTransmitterActivity : BaseBleActivity() {
|
|
|
234
234
|
manageErrorState(false, "")
|
|
235
235
|
} else {
|
|
236
236
|
sendDataToRN("", "cgm_transmitter_detection_failed")
|
|
237
|
-
|
|
238
|
-
manageErrorState(true, "")
|
|
237
|
+
manageErrorState(true, "Timeout")
|
|
239
238
|
}
|
|
240
239
|
Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> scanEnd")
|
|
241
240
|
}
|
|
@@ -326,7 +325,7 @@ class SearchTransmitterActivity : BaseBleActivity() {
|
|
|
326
325
|
binding.toolbar.btnWhatsapp.setOnClickListener {
|
|
327
326
|
startActivity(
|
|
328
327
|
Intent(this, HelpActivity::class.java)
|
|
329
|
-
.putExtra("ScreenName", "Transmitter
|
|
328
|
+
.putExtra("ScreenName", "Transmitter page")
|
|
330
329
|
)
|
|
331
330
|
}
|
|
332
331
|
|