react-native-mytatva-rn-sdk 1.2.48 → 1.2.49

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.
Files changed (28) hide show
  1. package/android/src/main/java/com/mytatvarnsdk/CgmTrackyLibModule.kt +17 -25
  2. package/android/src/main/java/com/mytatvarnsdk/activity/BtManageActivity.java +345 -345
  3. package/android/src/main/java/com/mytatvarnsdk/activity/ConnectSensorActivity.kt +17 -38
  4. package/android/src/main/java/com/mytatvarnsdk/activity/ExitJourneyBottomSheet.kt +51 -51
  5. package/android/src/main/java/com/mytatvarnsdk/activity/PermissionActivity.kt +10 -5
  6. package/android/src/main/java/com/mytatvarnsdk/activity/PlaceSensorActivity.kt +4 -5
  7. package/android/src/main/java/com/mytatvarnsdk/activity/PlaceTransmitterActivity.kt +4 -5
  8. package/android/src/main/java/com/mytatvarnsdk/activity/QRActivity.kt +96 -92
  9. package/android/src/main/java/com/mytatvarnsdk/activity/SearchTransmitterActivity.kt +1 -1
  10. package/android/src/main/java/com/mytatvarnsdk/activity/SensorConnectSuccessActivity.kt +1 -1
  11. package/android/src/main/java/com/mytatvarnsdk/activity/StartCGMActivity.kt +4 -2
  12. package/android/src/main/java/com/mytatvarnsdk/activity/VideoActivity.kt +0 -1
  13. package/android/src/main/java/com/mytatvarnsdk/utils/TatvaEncryptionConfig.kt +0 -5
  14. package/ios/Database/KLTBluetoothManager.m +9 -4
  15. package/ios/Database/KLTDatabaseHandler.m +53 -6
  16. package/ios/MyReactNativeBridge.h +4 -1
  17. package/ios/MyReactNativeBridge.m +433 -191
  18. package/ios/Support/API.swift +0 -1
  19. package/ios/Support/Global.swift +12 -0
  20. package/ios/ViewControllers/AttachTransmitterViewController.swift +33 -2
  21. package/ios/ViewControllers/ChatWithExpertViewController.swift +33 -3
  22. package/ios/ViewControllers/ConnectToSensorViewController.swift +101 -12
  23. package/ios/ViewControllers/ConnectToTransmitterViewController.swift +121 -5
  24. package/ios/ViewControllers/ProvidePermissionViewController.swift +37 -5
  25. package/ios/ViewControllers/PutOnTheSensorViewController.swift +22 -2
  26. package/ios/ViewControllers/StartConnectionViewController.swift +31 -3
  27. package/ios/ViewModel/FinalViewModel.swift +155 -48
  28. package/package.json +1 -1
@@ -6,6 +6,7 @@
6
6
  //
7
7
 
8
8
  import Foundation
9
+
9
10
  @objc public class FinalViewModelManager: NSObject {
10
11
  @objc public static let shared = FinalViewModelManager()
11
12
  @objc let viewModel = FinalViewModel()
@@ -86,7 +87,7 @@ import Foundation
86
87
  completion(nil, error)
87
88
  return
88
89
  }
89
-
90
+ UserDefaults.standard.set(sensorId, forKey: "sensorId")
90
91
  let baseResponse: [String: Any] = [
91
92
  "sensorId": sensorId,
92
93
  "startDate": startDate,
@@ -105,7 +106,7 @@ import Foundation
105
106
  startDate: String,
106
107
  endDate: String
107
108
  ) -> [String: Any] {
108
- var updatedResponse = response
109
+ let updatedResponse = response
109
110
 
110
111
  if viewModel.isCurrentDateInRange(startDate: startDate, endDate: endDate) {
111
112
  print("Current date is in range")
@@ -137,19 +138,24 @@ import Foundation
137
138
  class FinalViewModel: NSObject {
138
139
  var initialPeriod = 0
139
140
  var totalSeconds : TimeInterval = 60 * 60
140
-
141
141
  let manager: KLTBluetoothManager!
142
-
143
142
  var countdownTimer: Timer?
144
143
  var startScanTimer: Timer?
145
-
146
144
  let debouncer = EnumDebouncer<CGMConnectionStatus>()
147
-
145
+
146
+ var lastBluetoothStatus: BluetoothManagerStatus = .disconnected
147
+ var delayedDisconnectTimer: Timer?
148
+
149
+
148
150
  @objc public override init() {
149
151
  self.manager = KLTBluetoothManager.shared()
150
152
  super.init()
151
153
  debouncer.onDebounceSuccess = { value in
154
+ print("Blutooth is------------------->>>>>>>>>> \(value)")
152
155
  API.shared.sendStatus(status: value)
156
+ // if value == .errorCommon {
157
+ // self.manager.startScan()
158
+ // }
153
159
  print("Same type held for an hour!")
154
160
  }
155
161
  }
@@ -157,8 +163,9 @@ class FinalViewModel: NSObject {
157
163
  @objc public func initialize() {
158
164
  //getStatus()
159
165
  startCountDown()
160
-
166
+
161
167
  if ((manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
168
+
162
169
  manager.startScan()
163
170
  debouncer.update(with: .disconnected)
164
171
  } else {
@@ -169,7 +176,7 @@ class FinalViewModel: NSObject {
169
176
  else {
170
177
  //self.manager.closeBleSensor()
171
178
  //manager.startScan()
172
- debouncer.update(with: .disconnected)
179
+ // debouncer.update(with: .disconnected)
173
180
  //debouncer.update(with: .transmitterDisconnectBox)
174
181
  }
175
182
  }
@@ -334,6 +341,7 @@ class FinalViewModel: NSObject {
334
341
 
335
342
  private func uploadBatch(batches: [[ReceiveData]], index: Int) {
336
343
  guard index < batches.count else {
344
+ print("====================================> All batches uploaded")
337
345
  print("✅ All batches uploaded")
338
346
  return
339
347
  }
@@ -342,7 +350,9 @@ class FinalViewModel: NSObject {
342
350
  let cgmLogs = batch.map { ReceiveDataToLog(data: $0) }
343
351
  let payload = Payload(logs: cgmLogs)
344
352
 
353
+ print("====================================> called uploadBatch")
345
354
  API.shared.postCGMData(environment: .stage, data: payload) {
355
+ print("====================================> uploaded successfully")
346
356
  print("✅ Batch \(index + 1) uploaded successfully")
347
357
  KLTDatabaseHandler.shared().deleteReceiveDataArray(batch)
348
358
  self.uploadBatch(batches: batches, index: index + 1)
@@ -360,7 +370,7 @@ class FinalViewModel: NSObject {
360
370
  if let device = KLTBluetoothManager.shared().currentDevice {
361
371
  let arrayFromInitial = KLTDatabaseHandler.shared().queryReceiveData(with: device, needUserBG: true) as! [ReceiveData]
362
372
  print(arrayFromInitial)
363
- print("===> arrayFromInitial count: ", arrayFromInitial.count)
373
+ print("======================> arrayFromInitial count: ", arrayFromInitial.count)
364
374
  self.uploadData(data: arrayFromInitial)
365
375
  }
366
376
  }
@@ -453,12 +463,11 @@ class FinalViewModel: NSObject {
453
463
  //countDownValueLabel.text =
454
464
  }
455
465
 
456
- override func observeValue(
457
- forKeyPath keyPath: String?,
458
- of object: Any?,
459
- change: [NSKeyValueChangeKey : Any]?,
460
- context: UnsafeMutableRawPointer?
461
- ) {
466
+ override func observeValue(forKeyPath keyPath: String?,
467
+ of object: Any?,
468
+ change: [NSKeyValueChangeKey : Any]?,
469
+ context: UnsafeMutableRawPointer?) {
470
+
462
471
  guard keyPath == "status",
463
472
  let newValue = change?[.newKey] as? Int,
464
473
  let status = BluetoothManagerStatus(rawValue: newValue) else {
@@ -467,60 +476,156 @@ class FinalViewModel: NSObject {
467
476
 
468
477
  print("===>device status is -> \(status)")
469
478
 
479
+ // Cancel any pending delayed disconnect if state changes
480
+ // if status != .disconnected, delayedDisconnectTimer != nil {
481
+ // delayedDisconnectTimer?.invalidate()
482
+ // delayedDisconnectTimer = nil
483
+ // print("===> Cancelled delayed disconnect due to state change to \(status)")
484
+ // }
485
+
470
486
  switch status {
471
487
 
472
488
  case .disconnected:
489
+ print("lastBluetoothStatus-------->> \(lastBluetoothStatus)")
490
+ if lastBluetoothStatus == .connected {
491
+ print("===> Previously connected, delaying disconnect for 1 minute")
492
+ self.lastBluetoothStatus = .disconnected
493
+ delayedDisconnectTimer = Timer.scheduledTimer(withTimeInterval: 60.0, repeats: false) { [weak self] _ in
494
+ guard let self = self else { return }
495
+ print("lastBluetoothStatus-------->> \(lastBluetoothStatus)")
496
+ if self.lastBluetoothStatus == .disconnected {
497
+ self.debouncer.update(with: CGMConnectionStatus.disconnected)
498
+ print("===> 1 minute passed, confirmed disconnected")
499
+ } else {
500
+ print("===> Status changed in between, ignoring disconnect")
501
+ }
502
+ self.delayedDisconnectTimer?.invalidate()
503
+ self.delayedDisconnectTimer = nil
504
+ }
505
+ } else {
506
+ print("===> Not previously connected, immediate disconnect")
507
+ lastBluetoothStatus = .disconnected
508
+ delayedDisconnectTimer?.invalidate()
509
+ delayedDisconnectTimer = nil
510
+ debouncer.update(with: CGMConnectionStatus.disconnected)
511
+ }
512
+
473
513
  if KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
474
- // Unbind then disconnect
475
514
  endBleSensorCycle()
476
- } else {
477
- if UserDefaults.standard.integer(forKey: "bgmode") != 1 {
478
- manager.startScan()
479
- }
515
+ } else if UserDefaults.standard.integer(forKey: "bgmode") != 1 {
516
+ manager.startScan()
480
517
  }
481
- //API.shared.sendStatus(status: .disconnected)
482
- print("===>device is disconnected")
483
- debouncer.update(with: CGMConnectionStatus.disconnected)
484
- case .tryToConnect:
485
- // if UserDefaults.standard.integer(forKey: "bgmode") != 1 {
486
- // DispatchQueue.main.asyncAfter(deadline: .now() + 20) {
487
- // self.manager.startScan()
488
- // }
489
- // }
490
- break
518
+
491
519
  case .connected:
520
+ lastBluetoothStatus = .connected
492
521
  if let timer = startScanTimer {
493
522
  timer.invalidate()
494
523
  startScanTimer = nil
524
+ print("--------------------------- startScanTimer is nil")
495
525
  }
496
- //API.shared.sendStatus(status: .connected)
497
- print("===>device is connected")
526
+
498
527
  debouncer.update(with: CGMConnectionStatus.connected)
528
+
499
529
  case .timeOut:
500
- // if !KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
501
- // startScanTimer = Timer.scheduledTimer(timeInterval: 20,
502
- // target: self,
503
- // selector: #selector(startScan),
504
- // userInfo: nil,
505
- // repeats: false)
506
- // }
507
- print("===>time out")
508
- break
530
+ lastBluetoothStatus = .timeOut
531
+ if !KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
532
+ startScanTimer = Timer.scheduledTimer(timeInterval: 20,
533
+ target: self,
534
+ selector: #selector(startScan),
535
+ userInfo: nil,
536
+ repeats: false)
537
+ }
538
+
509
539
  case .sensorLostPower:
540
+ lastBluetoothStatus = .sensorLostPower
510
541
  sensorLostPower()
511
- print("===>sensor lost power")
542
+
512
543
  case .updateBindWatchSuccess:
513
- //KLTLaunchConfiguration.sharedManager.bindSuccessRootViewController()
544
+ lastBluetoothStatus = .updateBindWatchSuccess
514
545
  startCountDown()
515
- print("===>Success done")
546
+
516
547
  case .closed:
517
- debouncer.update(with: CGMConnectionStatus.transmitterDisconnectBox)
518
- //API.shared.sendStatus(status: .transmitterDisconnectBox)
519
- print("===>closed")
548
+ lastBluetoothStatus = .closed
549
+ debouncer.update(with: CGMConnectionStatus.transmitterDisconnect)
550
+
520
551
  default:
521
552
  break
522
553
  }
554
+
523
555
  }
556
+
557
+
558
+ // override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
559
+ // guard keyPath == "status",
560
+ // let newValue = change?[.newKey] as? Int,
561
+ // let status = BluetoothManagerStatus(rawValue: newValue) else {
562
+ // return
563
+ // }
564
+ //
565
+ // print("===>device status is -> \(status)")
566
+ //
567
+ // switch status {
568
+ //
569
+ // case .disconnected:
570
+ // if KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
571
+ // // Unbind then disconnect
572
+ // endBleSensorCycle()
573
+ // } else {
574
+ // if UserDefaults.standard.integer(forKey: "bgmode") != 1 {
575
+ // manager.startScan()
576
+ // }
577
+ // }
578
+ // //API.shared.sendStatus(status: .disconnected)
579
+ // print("===>device is disconnected")
580
+ //
581
+ // debouncer.update(with: CGMConnectionStatus.disconnected)
582
+ //
583
+ // case .tryToConnect:
584
+ // // if UserDefaults.standard.integer(forKey: "bgmode") != 1 {
585
+ // // DispatchQueue.main.asyncAfter(deadline: .now() + 20) {
586
+ // // self.manager.startScan()
587
+ // // }
588
+ // // }
589
+ // break
590
+ // case .connected:
591
+ // if let timer = startScanTimer {
592
+ // timer.invalidate()
593
+ // startScanTimer = nil
594
+ // print("--------------------------- startScanTimer is nil")
595
+ // }
596
+ // //API.shared.sendStatus(status: .connected)
597
+ // print("===>device is connected")
598
+ // debouncer.update(with: CGMConnectionStatus.connected)
599
+ // case .timeOut:
600
+ // if !KLTLocalSettingManager.shareInstance().canConnectOtherDevice {
601
+ // startScanTimer = Timer.scheduledTimer(timeInterval: 20,
602
+ // target: self,
603
+ // selector: #selector(startScan),
604
+ // userInfo: nil,
605
+ // repeats: false)
606
+ // }
607
+ // print("===>time out")
608
+ //
609
+ // case .sensorLostPower:
610
+ // sensorLostPower()
611
+ // print("===>sensor lost power")
612
+ // case .updateBindWatchSuccess:
613
+ // //KLTLaunchConfiguration.sharedManager.bindSuccessRootViewController()
614
+ // startCountDown()
615
+ // print("===>Success done")
616
+ // case .closed:
617
+ // debouncer.update(with: CGMConnectionStatus.transmitterDisconnect)
618
+ // //API.shared.sendStatus(status: .transmitterDisconnectBox)
619
+ // print("===>closed")
620
+ // default:
621
+ // break
622
+ // }
623
+ // }
624
+
625
+ // if ((self.manager.connectedPeripheral == nil) && !KLTLocalSettingManager.shareInstance().canConnectOtherDevice) {
626
+ // self.manager.startScan()
627
+ // self.debouncer.update(with: .disconnected)
628
+ // }
524
629
 
525
630
  func sensorLostPower() {
526
631
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
@@ -530,7 +635,9 @@ class FinalViewModel: NSObject {
530
635
  }
531
636
 
532
637
  @objc func startScan() {
638
+ print("--------------------------- Scanning inprocess")
533
639
  manager.startScan()
640
+ //debouncer.update(with: .disconnected)
534
641
  }
535
642
 
536
643
  func endBleSensorCycle() {
@@ -549,7 +656,6 @@ class FinalViewModel: NSObject {
549
656
 
550
657
  struct KLTDateFormatter {
551
658
  static let shared = KLTDateFormatter()
552
-
553
659
  private let calendar = Calendar(identifier: .gregorian)
554
660
  private let locale = Locale(identifier: "en_GB")
555
661
 
@@ -612,6 +718,7 @@ struct KLTDateFormatter {
612
718
  return getWholeString(from: date)
613
719
  }
614
720
  }
721
+
615
722
  extension String {
616
723
  func klt_contains(_ other: String) -> Bool {
617
724
  return self.range(of: other) != nil
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mytatva-rn-sdk",
3
- "version": "1.2.48",
3
+ "version": "1.2.49",
4
4
  "description": "a package to inject data into visit health pwa",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",