react-native-mytatva-rn-sdk 1.2.71 → 1.2.72
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.
|
@@ -363,7 +363,9 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
363
363
|
fun startCgmTracky(token: String, envType: String) {
|
|
364
364
|
try {
|
|
365
365
|
userToken = token
|
|
366
|
+
env = envType.lowercase()
|
|
366
367
|
val intent = Intent(currentActivity, StartCGMActivity::class.java)
|
|
368
|
+
intent.putExtra("envType", env)
|
|
367
369
|
currentActivity?.startActivity(intent)
|
|
368
370
|
} catch (e: Exception) {
|
|
369
371
|
Log.e("startCgmTracky", "startCgmTracky: ${e.message}")
|
|
@@ -385,11 +387,12 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
385
387
|
fun reconnectCgmTracky(token: String, envType: String) {
|
|
386
388
|
try {
|
|
387
389
|
userToken = token
|
|
390
|
+
env = envType.lowercase()
|
|
388
391
|
currentActivity?.startActivity(
|
|
389
392
|
Intent(currentActivity, StartCGMActivity::class.java).putExtra(
|
|
390
393
|
"IsForReconnect",
|
|
391
394
|
true
|
|
392
|
-
)
|
|
395
|
+
).putExtra("envType", env)
|
|
393
396
|
)
|
|
394
397
|
} catch (e: Exception) {
|
|
395
398
|
Log.e("reconnectCgmTracky", "reconnectCgmTracky: ${e.message}")
|
|
@@ -495,7 +498,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
495
498
|
|
|
496
499
|
// Check for duplicate using glucoseId
|
|
497
500
|
val glucoseId = pocGlucose.glucoseId ?: continue
|
|
498
|
-
|
|
501
|
+
|
|
499
502
|
if (!processedGlucoseIds.add(glucoseId)) {
|
|
500
503
|
Log.d("triggerDataUpload", "Already processed: $glucoseId, skipping")
|
|
501
504
|
continue
|
|
@@ -518,7 +521,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
518
521
|
// Put it back in queue for batch to handle
|
|
519
522
|
pendingDataQueue.offer(pocGlucose)
|
|
520
523
|
Log.d("triggerDataUpload", "Old data detected, triggering batch: $glucoseId")
|
|
521
|
-
|
|
524
|
+
|
|
522
525
|
// Trigger batch process on main thread
|
|
523
526
|
withContext(Dispatchers.Main) {
|
|
524
527
|
observeAllGlucoseData(userToken, false, envType)
|
|
@@ -543,40 +546,40 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
543
546
|
Log.d("handleGlucoseData", "Processing glucose data: ${pocGlucose.glucoseId}")
|
|
544
547
|
|
|
545
548
|
if (pocGlucose.errorCode == enumError.NONE) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
val request: GlucoseLogRequest =
|
|
552
|
-
GlucoseLogRequest(vendor = "GoodFlip", logs = logs)
|
|
553
|
-
val gson: Gson = GsonBuilder().create()
|
|
554
|
-
val json = gson.toJson(request)
|
|
555
|
-
|
|
556
|
-
Log.d("Glucose data 3 min==> ", "Glucose data 3 min==> final Json: $json")
|
|
557
|
-
|
|
558
|
-
authenticateSDKService.postCGMData(
|
|
559
|
-
environment = if (envType.lowercase() == "uat") TATVA_ENVIRONMENT.STAGE else TATVA_ENVIRONMENT.PROD,
|
|
560
|
-
data = json,
|
|
561
|
-
token = userToken,
|
|
562
|
-
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
563
|
-
override fun onResponseSuccess(response: String) {
|
|
564
|
-
updateSyncMetadata(pocGlucose)
|
|
565
|
-
Log.d("CGM Data", "Single glucose data uploaded successfully")
|
|
566
|
-
}
|
|
549
|
+
/* if (pocGlucose.showGlucoseMG > 0) { */
|
|
550
|
+
val dto: GlucoseLog = mapToDto(pocGlucose)
|
|
551
|
+
val logs: ArrayList<GlucoseLog> = ArrayList()
|
|
552
|
+
logs.add(dto)
|
|
567
553
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
554
|
+
val request: GlucoseLogRequest =
|
|
555
|
+
GlucoseLogRequest(vendor = "GoodFlip", logs = logs)
|
|
556
|
+
val gson: Gson = GsonBuilder().create()
|
|
557
|
+
val json = gson.toJson(request)
|
|
558
|
+
|
|
559
|
+
Log.d("Glucose data 3 min==> ", "Glucose data 3 min==> final Json: $json")
|
|
560
|
+
|
|
561
|
+
authenticateSDKService.postCGMData(
|
|
562
|
+
environment = if (envType.lowercase() == "uat") TATVA_ENVIRONMENT.STAGE else TATVA_ENVIRONMENT.PROD,
|
|
563
|
+
data = json,
|
|
564
|
+
token = userToken,
|
|
565
|
+
responseListener = object : AuthenticateSDKService.ResponseListener {
|
|
566
|
+
override fun onResponseSuccess(response: String) {
|
|
567
|
+
updateSyncMetadata(pocGlucose)
|
|
568
|
+
Log.d("CGM Data", "Single glucose data uploaded successfully")
|
|
571
569
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
570
|
+
|
|
571
|
+
override fun onResponseFail() {
|
|
572
|
+
Log.e("CGM Data", "Failed to upload single glucose data")
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
)
|
|
576
|
+
/* } */
|
|
577
|
+
/* else {
|
|
578
|
+
Log.d(
|
|
579
|
+
"handleGlucoseData",
|
|
580
|
+
"Glucose value is 0 or negative: ${pocGlucose.showGlucoseMG}"
|
|
581
|
+
)
|
|
582
|
+
} */
|
|
580
583
|
} else {
|
|
581
584
|
Log.d("handleGlucoseData", "Glucose data has error: ${pocGlucose.errorCode}")
|
|
582
585
|
handleGlucoseError(pocGlucose, envType)
|
|
@@ -653,7 +656,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
653
656
|
while (pendingDataQueue.isNotEmpty()) {
|
|
654
657
|
pendingDataQueue.poll()?.let { pendingData.add(it) }
|
|
655
658
|
}
|
|
656
|
-
|
|
659
|
+
|
|
657
660
|
if (pendingData.isNotEmpty()) {
|
|
658
661
|
Log.d("observeAllGlucoseData", "Found ${pendingData.size} items in pending queue")
|
|
659
662
|
}
|
|
@@ -668,7 +671,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
668
671
|
val glucoseData = mModel.getGlucoseBetweenTime(lastSyncData.timeInMillis)
|
|
669
672
|
|
|
670
673
|
Log.d("observeAllGlucoseData", "Retrieved ${glucoseData?.size ?: 0} records from DB")
|
|
671
|
-
|
|
674
|
+
|
|
672
675
|
// Combine database data with pending queue data
|
|
673
676
|
val allData = mutableListOf<PocGlucose>()
|
|
674
677
|
glucoseData?.let { allData.addAll(it) }
|
|
@@ -687,7 +690,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
687
690
|
sortedGlucoseData.take(5).forEachIndexed { i, data ->
|
|
688
691
|
Log.d("AFTER Sort [$i]", "timeInMillis: ${data.timeInMillis}, glucoseId: ${data.glucoseId}")
|
|
689
692
|
}
|
|
690
|
-
|
|
693
|
+
|
|
691
694
|
if (sortedGlucoseData.isNotEmpty()) {
|
|
692
695
|
Log.d("observeAllGlucoseData", "✅ Sorted ${sortedGlucoseData.size} records chronologically")
|
|
693
696
|
Log.d("observeAllGlucoseData", "Oldest: ${sortedGlucoseData.first().timeInMillis}")
|
|
@@ -722,7 +725,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
722
725
|
}
|
|
723
726
|
}
|
|
724
727
|
}
|
|
725
|
-
|
|
728
|
+
|
|
726
729
|
withContext(Dispatchers.Main) {
|
|
727
730
|
if (!isObserving) {
|
|
728
731
|
observeGlucoseData(userToken, isForClear, envType)
|
|
@@ -760,7 +763,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
760
763
|
}
|
|
761
764
|
|
|
762
765
|
// Don't reset flag here - it's reset in observeAllGlucoseData's finally block
|
|
763
|
-
|
|
766
|
+
|
|
764
767
|
// Ensure we're on main thread and not already observing
|
|
765
768
|
withContext(Dispatchers.Main) {
|
|
766
769
|
if (!isObserving) {
|
|
@@ -813,7 +816,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
813
816
|
// Cancel all coroutines
|
|
814
817
|
debounceJob?.cancel()
|
|
815
818
|
debounceJob = null
|
|
816
|
-
|
|
819
|
+
|
|
817
820
|
uploadJob?.cancel()
|
|
818
821
|
uploadJob = null
|
|
819
822
|
|
|
@@ -826,7 +829,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
826
829
|
// Clear processed IDs and pending queue
|
|
827
830
|
processedGlucoseIds.clear()
|
|
828
831
|
pendingDataQueue.clear()
|
|
829
|
-
|
|
832
|
+
|
|
830
833
|
// Reset batch processing flag
|
|
831
834
|
isBatchProcessing.set(false)
|
|
832
835
|
|
|
@@ -847,20 +850,20 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
847
850
|
try {
|
|
848
851
|
val context = reactApplicationContext
|
|
849
852
|
val logFiles = mutableListOf<String>()
|
|
850
|
-
|
|
853
|
+
|
|
851
854
|
// Get the primary log folder path
|
|
852
855
|
val externalFilesDir = context.getExternalFilesDir(android.os.Environment.DIRECTORY_DOCUMENTS)
|
|
853
856
|
val primaryFolder = externalFilesDir?.absolutePath
|
|
854
|
-
|
|
857
|
+
|
|
855
858
|
// Get the fallback log folder path
|
|
856
|
-
val fallbackFolder = android.os.Environment.getExternalStorageDirectory().absolutePath +
|
|
857
|
-
|
|
858
|
-
|
|
859
|
+
val fallbackFolder = android.os.Environment.getExternalStorageDirectory().absolutePath +
|
|
860
|
+
File.separatorChar + "PocData" + File.separatorChar + "logger"
|
|
861
|
+
|
|
859
862
|
// Check primary folder
|
|
860
863
|
if (primaryFolder != null) {
|
|
861
864
|
val primaryDir = File(primaryFolder)
|
|
862
865
|
if (primaryDir.exists() && primaryDir.isDirectory) {
|
|
863
|
-
val files = primaryDir.listFiles { file ->
|
|
866
|
+
val files = primaryDir.listFiles { file ->
|
|
864
867
|
file.isFile && file.name.endsWith(".csv")
|
|
865
868
|
}
|
|
866
869
|
files?.forEach { file ->
|
|
@@ -868,11 +871,11 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
868
871
|
}
|
|
869
872
|
}
|
|
870
873
|
}
|
|
871
|
-
|
|
874
|
+
|
|
872
875
|
// Check fallback folder
|
|
873
876
|
val fallbackDir = File(fallbackFolder)
|
|
874
877
|
if (fallbackDir.exists() && fallbackDir.isDirectory) {
|
|
875
|
-
val files = fallbackDir.listFiles { file ->
|
|
878
|
+
val files = fallbackDir.listFiles { file ->
|
|
876
879
|
file.isFile && file.name.endsWith(".csv")
|
|
877
880
|
}
|
|
878
881
|
files?.forEach { file ->
|
|
@@ -882,17 +885,17 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
882
885
|
}
|
|
883
886
|
}
|
|
884
887
|
}
|
|
885
|
-
|
|
888
|
+
|
|
886
889
|
Log.d("getCgmLogFiles", "Found ${logFiles.size} log files")
|
|
887
|
-
|
|
890
|
+
|
|
888
891
|
// Convert list to WritableArray
|
|
889
892
|
val resultArray = Arguments.createArray()
|
|
890
893
|
logFiles.forEach { path ->
|
|
891
894
|
resultArray.pushString(path)
|
|
892
895
|
}
|
|
893
|
-
|
|
896
|
+
|
|
894
897
|
promise.resolve(resultArray)
|
|
895
|
-
|
|
898
|
+
|
|
896
899
|
} catch (e: Exception) {
|
|
897
900
|
Log.e("getCgmLogFiles", "Error getting log files: ${e.message}")
|
|
898
901
|
promise.reject("ERROR_GET_LOG_FILES", e.message, e)
|
|
@@ -1035,7 +1038,7 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
1035
1038
|
fun stopObservingGlucoseData() {
|
|
1036
1039
|
stopObservingGlucoseDataInternal()
|
|
1037
1040
|
}
|
|
1038
|
-
|
|
1041
|
+
|
|
1039
1042
|
// Internal method that doesn't clear the queue (used during restarts)
|
|
1040
1043
|
private fun stopObservingGlucoseDataInternal() {
|
|
1041
1044
|
Log.d("stopObservingGlucoseData", "Stopping glucose data observation")
|
|
@@ -1110,10 +1113,10 @@ class CgmTrackyLibModule(reactContext: ReactApplicationContext) :
|
|
|
1110
1113
|
it.glucoseId
|
|
1111
1114
|
)
|
|
1112
1115
|
prefsHelper?.lastSyncData = syncData
|
|
1113
|
-
|
|
1116
|
+
|
|
1114
1117
|
// Mark this glucose ID as processed
|
|
1115
1118
|
it.glucoseId?.let { id -> processedGlucoseIds.add(id) }
|
|
1116
|
-
|
|
1119
|
+
|
|
1117
1120
|
Log.d(
|
|
1118
1121
|
"Sync Metadata",
|
|
1119
1122
|
"Sync metadata updated: glucoseId=${it.glucoseId}, time=${it.timeInMillis}"
|
|
@@ -54,6 +54,9 @@ class StartCGMActivity : AppCompatActivity() {
|
|
|
54
54
|
|
|
55
55
|
private fun init() {
|
|
56
56
|
isForReconnect = intent.getBooleanExtra("IsForReconnect", false)
|
|
57
|
+
val envType = intent.getStringExtra("envType") ?: "prod"
|
|
58
|
+
|
|
59
|
+
// Use envType as needed
|
|
57
60
|
|
|
58
61
|
sendDataToRN("", "cgm_start_connection_landing")
|
|
59
62
|
|
|
@@ -19,6 +19,7 @@ import kotlinx.coroutines.CoroutineScope
|
|
|
19
19
|
import kotlinx.coroutines.launch
|
|
20
20
|
import okhttp3.MediaType.Companion.toMediaType
|
|
21
21
|
import okhttp3.RequestBody.Companion.toRequestBody
|
|
22
|
+
import retrofit2.HttpException
|
|
22
23
|
|
|
23
24
|
class AuthenticateSDKService(val scope: CoroutineScope) {
|
|
24
25
|
|
|
@@ -158,6 +159,13 @@ class AuthenticateSDKService(val scope: CoroutineScope) {
|
|
|
158
159
|
|
|
159
160
|
Log.d("API Response", "API response: $decryptedResponse")
|
|
160
161
|
|
|
162
|
+
} catch (e: HttpException) {
|
|
163
|
+
if (e.code() == 401) {
|
|
164
|
+
Log.d("API Error", "401 Unauthorized - Token: $token")
|
|
165
|
+
// Further handling if necessary
|
|
166
|
+
} else {
|
|
167
|
+
throw e
|
|
168
|
+
}
|
|
161
169
|
} catch (e: Exception) {
|
|
162
170
|
e.printStackTrace()
|
|
163
171
|
Log.d("API Response", "Exception: ${e.message}")
|