react-native-mytatva-rn-sdk 1.2.9 → 1.2.10

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.
@@ -107,7 +107,7 @@ class ConnectSensorActivity : BaseBleActivity() {
107
107
  }
108
108
  }
109
109
 
110
- fun manageErrorState(showError: Boolean) {
110
+ fun manageErrorState(showError: Boolean, errorStatus: String) {
111
111
  ProgressManagement.getInstance().dismissWait(this)
112
112
  if (showError) {
113
113
  binding.clFail.visibility = View.VISIBLE
@@ -138,6 +138,13 @@ class ConnectSensorActivity : BaseBleActivity() {
138
138
  )
139
139
  }
140
140
  }
141
+
142
+ if (errorStatus.isNotEmpty()) {
143
+ binding.tvReason.visibility = View.VISIBLE
144
+ binding.tvReason.text = "Reason - ${errorStatus}"
145
+ } else {
146
+ binding.tvReason.visibility = View.GONE
147
+ }
141
148
  } else {
142
149
  binding.commonButton.root.visibility = View.VISIBLE
143
150
  binding.clFail.visibility = View.GONE
@@ -278,7 +285,7 @@ class ConnectSensorActivity : BaseBleActivity() {
278
285
 
279
286
  override fun bindFail() {
280
287
  super.bindFail()
281
- manageErrorState(true)
288
+ manageErrorState(true, "Bind Fail")
282
289
  }
283
290
 
284
291
  override fun bindSuccess() {
@@ -291,43 +298,43 @@ class ConnectSensorActivity : BaseBleActivity() {
291
298
 
292
299
  override fun bluetoothStateOFF() {
293
300
  super.bluetoothStateOFF()
294
- manageErrorState(true)
301
+ manageErrorState(true, "Bluetooth Off")
295
302
 
296
303
  }
297
304
 
298
305
  override fun disconnect() {
299
306
  super.disconnect()
300
- manageErrorState(true)
307
+ manageErrorState(true, "Disconnected")
301
308
 
302
309
  }
303
310
 
304
311
  override fun disconnectForTimeout() {
305
312
  super.disconnectForTimeout()
306
- manageErrorState(true)
313
+ manageErrorState(true, "Disconnected")
307
314
 
308
315
  }
309
316
 
310
317
  override fun checkFailForLowPower() {
311
318
  super.checkFailForLowPower()
312
- manageErrorState(true)
319
+ manageErrorState(true, "Low Power")
313
320
 
314
321
  }
315
322
 
316
323
  override fun checkFailErrorTemperature() {
317
324
  super.checkFailErrorTemperature()
318
- manageErrorState(true)
325
+ manageErrorState(true, "Temperature Error")
319
326
 
320
327
  }
321
328
 
322
329
  override fun unbindReset() {
323
330
  super.unbindReset()
324
- manageErrorState(true)
331
+ manageErrorState(true, "Unbinded")
325
332
 
326
333
  }
327
334
 
328
335
  override fun unbindCommand() {
329
336
  super.unbindCommand()
330
- manageErrorState(true)
337
+ manageErrorState(true, "Unbinded")
331
338
 
332
339
  }
333
340
 
@@ -1,8 +1,10 @@
1
1
  package com.mytatvarnsdk.activity
2
2
 
3
3
  import android.Manifest
4
+ import android.annotation.SuppressLint
4
5
  import android.app.AlertDialog
5
6
  import android.app.Dialog
7
+ import android.bluetooth.BluetoothAdapter
6
8
  import android.content.Context
7
9
  import android.content.Intent
8
10
  import android.content.pm.PackageManager
@@ -14,9 +16,11 @@ import android.view.Gravity
14
16
  import android.view.View
15
17
  import android.view.ViewGroup
16
18
  import android.view.Window
19
+ import android.widget.Toast
17
20
  import androidx.activity.OnBackPressedCallback
18
21
  import androidx.activity.enableEdgeToEdge
19
22
  import androidx.annotation.RequiresApi
23
+ import androidx.annotation.RequiresPermission
20
24
  import androidx.core.app.ActivityCompat
21
25
  import androidx.core.content.ContextCompat
22
26
  import androidx.core.graphics.drawable.toDrawable
@@ -33,6 +37,11 @@ class PermissionActivity : BasePermissionActivity() {
33
37
  private val LOCATION_REQUEST_CODE = 101
34
38
  private val BLUETOOTH_REQUEST_CODE = 102
35
39
 
40
+ private val REQUEST_ENABLE_BT = 1
41
+ private val bluetoothAdapter: BluetoothAdapter? by lazy {
42
+ BluetoothAdapter.getDefaultAdapter()
43
+ }
44
+
36
45
  override fun onCreate(savedInstanceState: Bundle?) {
37
46
  super.onCreate(savedInstanceState)
38
47
  binding = ActivityPermissionBinding.inflate(layoutInflater)
@@ -104,8 +113,12 @@ class PermissionActivity : BasePermissionActivity() {
104
113
  }
105
114
 
106
115
 
116
+ @SuppressLint("MissingPermission")
107
117
  private fun initialize() {
108
- binding.switchBluetooth.isChecked = isBluetoothPermissionGranted(this)
118
+ bluetoothAdapter?.let {
119
+ binding.switchBluetooth.isChecked = isBluetoothPermissionGranted(this) && it.isEnabled
120
+ }
121
+
109
122
  binding.switchLocation.isChecked = isLocationPermissionGranted(this)
110
123
 
111
124
  binding.switchBluetooth.setOnCheckedChangeListener { _, isChecked ->
@@ -218,6 +231,7 @@ class PermissionActivity : BasePermissionActivity() {
218
231
  }
219
232
  }
220
233
 
234
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
221
235
  private fun requestBluetoothPermission() {
222
236
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
223
237
  val permissions = PermissionUtils.BLUETOOTH_S
@@ -279,11 +293,12 @@ class PermissionActivity : BasePermissionActivity() {
279
293
  }
280
294
 
281
295
  private fun updateProceedButtonState() {
282
- binding.commonButton.btnProceed.isEnabled = areAllPermissionsGranted()
283
- if (areAllPermissionsGranted()) {
296
+ if (areAllPermissionsGranted() && bluetoothAdapter!!.isEnabled) {
284
297
  binding.commonButton.btnProceed.alpha = 1f
298
+ binding.commonButton.btnProceed.isEnabled = true
285
299
  } else {
286
300
  binding.commonButton.btnProceed.alpha = 0.5f
301
+ binding.commonButton.btnProceed.isEnabled = false
287
302
  }
288
303
  }
289
304
 
@@ -298,6 +313,7 @@ class PermissionActivity : BasePermissionActivity() {
298
313
  }
299
314
  }
300
315
 
316
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
301
317
  override fun onRequestPermissionsResult(
302
318
  requestCode: Int,
303
319
  permissions: Array<out String>,
@@ -335,7 +351,17 @@ class PermissionActivity : BasePermissionActivity() {
335
351
  // Start location-based action
336
352
  }
337
353
 
354
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
338
355
  private fun onBluetoothPermissionGranted() {
356
+ if (bluetoothAdapter == null) {
357
+ Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show()
358
+ } else {
359
+ if (!bluetoothAdapter!!.isEnabled) {
360
+ val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
361
+ startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
362
+ }
363
+ }
364
+
339
365
  updateProceedButtonState()
340
366
  // Start Bluetooth device scan or connect
341
367
  }
@@ -345,6 +371,14 @@ class PermissionActivity : BasePermissionActivity() {
345
371
  updateProceedButtonState()
346
372
  }
347
373
 
374
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
375
+ super.onActivityResult(requestCode, resultCode, data)
376
+ if (requestCode == REQUEST_ENABLE_BT) {
377
+ if (resultCode == RESULT_OK) {
378
+ updateProceedButtonState()
379
+ }
380
+ }
381
+ }
348
382
  }
349
383
 
350
384
  object PermissionUtils {
@@ -20,6 +20,7 @@ import androidx.core.graphics.drawable.toDrawable
20
20
  import androidx.core.graphics.toColorInt
21
21
  import androidx.core.view.ViewCompat
22
22
  import androidx.core.view.WindowInsetsCompat
23
+ import androidx.core.view.isVisible
23
24
  import androidx.lifecycle.ViewModelProviders
24
25
  import cgmblelib.Enum.enumDevice
25
26
  import cgmblelib.ble.BleService
@@ -57,299 +58,306 @@ import java.util.Date
57
58
  import java.util.Locale
58
59
 
59
60
  class SearchTransmitterActivity : BaseBleActivity() {
60
- private lateinit var binding: ActivitySearchTransmitterBinding
61
- private val handler = Handler(Looper.getMainLooper())
62
- private var isSearching = true
63
- private var isTransmitterConnected = false
64
- private var transmitterDeviceInfo: PocDeviceAndRssi? = null
65
- private lateinit var mModel: MainActivityModel
66
- lateinit var authenticateSDKService: AuthenticateSDKService
67
- private val job = Job()
68
- private val scope = CoroutineScope(Dispatchers.IO + job)
69
- private var isForReconnect: Boolean = false
70
- private val reactContext = CgmTrackyLibModule.mReactContext
71
-
72
- override fun init() {
61
+ private lateinit var binding: ActivitySearchTransmitterBinding
62
+ private val handler = Handler(Looper.getMainLooper())
63
+ private var isSearching = true
64
+ private var isTransmitterConnected = false
65
+ private var transmitterDeviceInfo: PocDeviceAndRssi? = null
66
+ private lateinit var mModel: MainActivityModel
67
+ lateinit var authenticateSDKService: AuthenticateSDKService
68
+ private val job = Job()
69
+ private val scope = CoroutineScope(Dispatchers.IO + job)
70
+ private var isForReconnect: Boolean = false
71
+ private val reactContext = CgmTrackyLibModule.mReactContext
72
+
73
+ override fun init() {
74
+
75
+ }
76
+
77
+
78
+ override fun onCreate(savedInstanceState: Bundle?) {
79
+ super.onCreate(savedInstanceState)
80
+ binding = ActivitySearchTransmitterBinding.inflate(layoutInflater)
81
+ enableEdgeToEdge()
82
+ setContentView(binding.root)
83
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
84
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
85
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
86
+ insets
87
+ }
88
+
89
+ setupClickListeners()
90
+ setupInitialState()
91
+ startDeviceSearch()
92
+ }
93
+
94
+ override fun getPermission(): Array<out Array<out String?>?>? {
95
+ return arrayOfNulls<Array<String?>>(0)
96
+ }
97
+
98
+ override fun onPermissionRequestSuccess() {
99
+ }
100
+
101
+ override fun onPermissionRequestFail(vararg permission: String?) {
102
+ }
73
103
 
74
- }
75
-
76
-
77
- override fun onCreate(savedInstanceState: Bundle?) {
78
- super.onCreate(savedInstanceState)
79
- binding = ActivitySearchTransmitterBinding.inflate(layoutInflater)
80
- enableEdgeToEdge()
81
- setContentView(binding.root)
82
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
83
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
84
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
85
- insets
86
- }
87
-
88
- setupClickListeners()
89
- setupInitialState()
90
- startDeviceSearch()
91
- }
92
-
93
- override fun getPermission(): Array<out Array<out String?>?>? {
94
- return arrayOfNulls<Array<String?>>(0)
95
- }
96
-
97
- override fun onPermissionRequestSuccess() {
98
- }
99
-
100
- override fun onPermissionRequestFail(vararg permission: String?) {
101
- }
102
-
103
- override fun onPermissionRequestFailForever(vararg permission: String?) {
104
- }
105
-
106
- private fun setupInitialState() {
107
- isForReconnect = intent.getBooleanExtra("IsForReconnect", false)
108
-
109
- // Set initial states
110
- binding.searchingLayout.visibility = View.VISIBLE
111
- binding.connectedLayout.visibility = View.GONE
112
-
113
- binding.commonButton.btnProceed.isEnabled = false
114
- binding.commonButton.btnProceed.alpha = 0.5f
115
-
116
- Glide.with(this)
117
- .asGif()
118
- .load(R.drawable.success_anim)
119
- .into(binding.ivSuccess)
120
- }
121
-
122
- fun manageErrorState(showError: Boolean) {
123
- if (showError) {
124
- binding.clFail.visibility = View.VISIBLE
125
- binding.clMain.visibility = View.GONE
126
- binding.commonButton.root.visibility = View.GONE
127
-
128
- Glide.with(this)
129
- .asGif()
130
- .load(R.drawable.warning)
131
- .into(binding.ivGif)
132
-
133
- binding.btnSupport.tvProceed.text = "Contact Support"
134
- binding.btnRetry.tvProceed.text = "Retry"
135
-
136
- binding.btnWatchDemo.setOnClickListener {
137
-
138
- }
139
-
140
- binding.btnSupport.btnProceed.setOnClickListener {
141
- startActivity(Intent(this, HelpActivity::class.java))
142
- }
143
-
144
- binding.btnRetry.btnProceed.setOnClickListener {
145
- val intent = intent
146
- finish()
147
- startActivity(intent)
148
- }
149
- } else {
150
- binding.commonButton.root.visibility = View.VISIBLE
151
- binding.clFail.visibility = View.GONE
152
- binding.clMain.visibility = View.VISIBLE
153
- }
154
- }
155
-
156
- private fun openExitDialog() {
157
- val binding = ExitDialogBottomsheetBinding.inflate(layoutInflater)
158
-
159
- val dialog = Dialog(this)
160
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
161
- dialog.setContentView(binding.root)
162
-
163
- val window = dialog.window
164
- window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
165
- window?.setGravity(Gravity.BOTTOM)
166
- window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
167
-
168
- binding.btnExit.tvProceed.text = "Exit"
169
-
170
- binding.btnExit.root.setOnClickListener(View.OnClickListener { v: View? ->
171
- finish()
172
- dialog.dismiss()
173
- })
174
-
175
- binding.btnCancel.root.setOnClickListener(View.OnClickListener { v: View? ->
176
- dialog.dismiss()
177
- })
178
-
179
- binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
180
- dialog.dismiss()
181
- })
182
-
183
- dialog.show()
184
- }
185
-
186
-
187
- public override fun scanStart() {
188
- if (mPocDevice != null && mPocDevice.isBound) {
189
- ProgressManagement.getInstance().showWait(this, ProgressType.PROGRESSDIALOG_SCAN, null)
190
- }
191
- manageErrorState(false)
192
- }
193
-
194
-
195
- public override fun scanIn(device: PocDeviceAndRssi) {
196
- transmitterDeviceInfo = device
197
- if (isSearching) {
198
- deviceDetected(device)
199
- }
200
- manageErrorState(false)
201
- }
202
-
203
- public override fun scanEnd() {
204
- if (transmitterDeviceInfo == null) {
205
- manageErrorState(true)
206
- }
207
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> scanEnd")
208
- }
209
-
210
- override fun bluetoothStateOFF() {
211
- super.bluetoothStateOFF()
212
- manageErrorState(true)
213
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bluetoothStateOFF")
214
- }
215
-
216
- override fun failGPS() {
217
- super.failGPS()
218
- manageErrorState(true)
219
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failGPS")
220
- }
221
-
222
- override fun failLocal() {
223
- super.failLocal()
224
- manageErrorState(true)
225
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failLocal")
226
- }
227
-
228
- public override fun bindFail() {
229
- ProgressManagement.getInstance().dismissWait(this)
230
- manageErrorState(true)
231
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bindFail")
232
- }
233
-
234
- public override fun bindSuccess() {
235
- ProgressManagement.getInstance().dismissWait(this)
236
- }
237
-
238
- fun mapToDto(glucose: PocGlucose): GlucoseLog {
239
- val dto: GlucoseLog = GlucoseLog()
240
- dto.timeInMillis = glucose.getTimeInMillis()
241
- dto.countdownMinutes = glucose.getCountdownMinutes()
242
- dto.countdownHours = glucose.getCountdownHours()
243
- dto.countdownDays = glucose.getCountdownDays()
244
- dto.hypoglycemiaEarlyWarnMinutes = glucose.getHypoglycemiaEarlyWarnMinutes()
245
- dto.showGlucoseMG = glucose.getShowGlucoseMG()
246
- dto.glucoseId = glucose.getGlucoseId()
247
- dto.name = glucose.getName()
248
- dto.showGlucose = glucose.getShowGlucose()
249
- dto.Ib = glucose.getIb()
250
- dto.Iw = glucose.getIw()
251
- dto.T = glucose.getT()
252
- dto.year = glucose.getYear()
253
- dto.month = glucose.getMonth()
254
- dto.day = glucose.getDay()
255
- dto.hour = glucose.getHour()
256
- dto.minute = glucose.getMinute()
257
-
258
- // Convert byte[] to List<Integer>
259
- dto.bytes = ArrayList()
260
- for (b in glucose.getBytes()) {
261
- dto.bytes?.add(b.toInt() and 0xFF) // Prevent negative values
262
- }
263
-
264
- // Trend
265
- val trendObj: TrendObject = TrendObject()
266
- trendObj.trendId = glucose.getTrend().getTrendId()
267
- trendObj.drawableId = glucose.getTrend().getDrawableId()
268
- trendObj.widgetImg = glucose.getTrend().getWidgetImg()
269
- trendObj.apsChangeRate = glucose.getTrend().getApsChangeRate()
270
- dto.trendObject = trendObj
271
-
272
- // Status
273
- val statusObj: GlucoseStatusObject = GlucoseStatusObject()
274
- statusObj.statusId = glucose.getGlucoseStatus().getStatusId()
275
- dto.glucoseStatusObject = statusObj
276
-
277
- // Error
278
- val errorObj: ErrorObject = ErrorObject()
279
- errorObj.errorId = glucose.getErrorCode().getErrorId()
280
- errorObj.sound = glucose.getErrorCode().getSound().toString()
281
- dto.errorObject = errorObj
282
-
283
- return dto
284
- }
285
-
286
-
287
- public override fun disconnect() {
288
- ProgressManagement.getInstance().dismissWait(this)
289
- showShortToast(R.string.bt_connect_fail)
290
- manageErrorState(true)
291
- }
104
+ override fun onPermissionRequestFailForever(vararg permission: String?) {
105
+ }
292
106
 
293
- public override fun disconnectForTimeout() {
294
- ProgressManagement.getInstance().dismissWait(this)
295
- manageErrorState(true)
296
- Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> disconnectForTimeout")
297
- }
298
-
299
- public override fun checkFailForLowPower() {
300
- ProgressManagement.getInstance().dismissWait(this)
301
- WarnDialogUtils.getInstance().showWarnDialog(this, DialogType.TYPE_LOW_POWER)
302
- }
107
+ private fun setupInitialState() {
108
+ isForReconnect = intent.getBooleanExtra("IsForReconnect", false)
303
109
 
304
- public override fun checkFailErrorTemperature() {
305
- ProgressManagement.getInstance().dismissWait(this)
306
- }
110
+ // Set initial states
111
+ binding.searchingLayout.visibility = View.VISIBLE
112
+ binding.connectedLayout.visibility = View.GONE
307
113
 
308
- public override fun onlineLost() {
309
- showShortToast(R.string.online_lost)
310
- }
114
+ binding.commonButton.btnProceed.isEnabled = false
115
+ binding.commonButton.btnProceed.alpha = 0.5f
311
116
 
117
+ Glide.with(this)
118
+ .asGif()
119
+ .load(R.drawable.success_anim)
120
+ .into(binding.ivSuccess)
121
+ }
312
122
 
313
- private fun bind(device: PocDevice) {
314
- try {
315
- if (device.address != null) {
316
- ManageGattCallback.getInstance().ConnectViaAddress(device.address)
317
- ManageScanCallback.getInstance().stopLeScan()
318
- ProgressManagement.getInstance()
319
- .showWait(this, ProgressType.PROGRESSDIALOG_CONNECT, null)
320
- }
321
- } catch (e: Exception) {
322
- Log.d("bind::-> ", "bind: ${e.message}")
323
- }
123
+ fun manageErrorState(showError: Boolean, errorStatus: String) {
124
+ if (showError) {
125
+ binding.clFail.visibility = View.VISIBLE
126
+ binding.clMain.visibility = View.GONE
127
+ binding.commonButton.root.visibility = View.GONE
128
+
129
+ Glide.with(this)
130
+ .asGif()
131
+ .load(R.drawable.warning)
132
+ .into(binding.ivGif)
133
+
134
+ binding.btnSupport.tvProceed.text = "Contact Support"
135
+ binding.btnRetry.tvProceed.text = "Retry"
136
+
137
+ binding.btnWatchDemo.setOnClickListener {
138
+
139
+ }
140
+
141
+ binding.btnSupport.btnProceed.setOnClickListener {
142
+ startActivity(Intent(this, HelpActivity::class.java))
143
+ }
144
+
145
+ binding.btnRetry.btnProceed.setOnClickListener {
146
+ val intent = intent
147
+ finish()
148
+ startActivity(intent)
149
+ }
150
+
151
+ if (errorStatus.isNotEmpty()) {
152
+ binding.tvReason.visibility = View.VISIBLE
153
+ binding.tvReason.text = "Reason - ${errorStatus}"
154
+ } else {
155
+ binding.tvReason.visibility = View.GONE
156
+ }
157
+ } else {
158
+ binding.commonButton.root.visibility = View.VISIBLE
159
+ binding.clFail.visibility = View.GONE
160
+ binding.clMain.visibility = View.VISIBLE
161
+ }
162
+ }
163
+
164
+ private fun openExitDialog() {
165
+ val binding = ExitDialogBottomsheetBinding.inflate(layoutInflater)
166
+
167
+ val dialog = Dialog(this)
168
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
169
+ dialog.setContentView(binding.root)
170
+
171
+ val window = dialog.window
172
+ window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
173
+ window?.setGravity(Gravity.BOTTOM)
174
+ window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
175
+
176
+ binding.btnExit.tvProceed.text = "Exit"
177
+
178
+ binding.btnExit.root.setOnClickListener(View.OnClickListener { v: View? ->
179
+ finish()
180
+ dialog.dismiss()
181
+ })
182
+
183
+ binding.btnCancel.root.setOnClickListener(View.OnClickListener { v: View? ->
184
+ dialog.dismiss()
185
+ })
186
+
187
+ binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
188
+ dialog.dismiss()
189
+ })
190
+
191
+ dialog.show()
192
+ }
193
+
194
+
195
+ public override fun scanStart() {
196
+ if (mPocDevice != null && mPocDevice.isBound) {
197
+ ProgressManagement.getInstance().showWait(this, ProgressType.PROGRESSDIALOG_SCAN, null)
198
+ }
199
+ manageErrorState(false, "")
200
+ }
201
+
202
+
203
+ public override fun scanIn(device: PocDeviceAndRssi) {
204
+ transmitterDeviceInfo = device
205
+ if (isSearching) {
206
+ deviceDetected(device)
207
+ }
208
+ manageErrorState(false, "")
209
+ }
210
+
211
+ public override fun scanEnd() {
212
+ if (transmitterDeviceInfo == null && !binding.tvReason.isVisible) {
213
+ manageErrorState(false, "")
214
+ }
215
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> scanEnd")
216
+ }
217
+
218
+ override fun bluetoothStateOFF() {
219
+ super.bluetoothStateOFF()
220
+ manageErrorState(true, "Bluetooth Off")
221
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bluetoothStateOFF")
222
+ }
223
+
224
+ override fun failGPS() {
225
+ super.failGPS()
226
+ manageErrorState(true, "GPS Off")
227
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failGPS")
228
+ }
229
+
230
+ override fun failLocal() {
231
+ super.failLocal()
232
+ manageErrorState(true, "Something went wrong")
233
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> failLocal")
234
+ }
235
+
236
+ public override fun bindFail() {
237
+ ProgressManagement.getInstance().dismissWait(this)
238
+ manageErrorState(true, "Bind Failure")
239
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> bindFail")
240
+ }
241
+
242
+ public override fun bindSuccess() {
243
+ ProgressManagement.getInstance().dismissWait(this)
244
+ }
245
+
246
+ fun mapToDto(glucose: PocGlucose): GlucoseLog {
247
+ val dto: GlucoseLog = GlucoseLog()
248
+ dto.timeInMillis = glucose.getTimeInMillis()
249
+ dto.countdownMinutes = glucose.getCountdownMinutes()
250
+ dto.countdownHours = glucose.getCountdownHours()
251
+ dto.countdownDays = glucose.getCountdownDays()
252
+ dto.hypoglycemiaEarlyWarnMinutes = glucose.getHypoglycemiaEarlyWarnMinutes()
253
+ dto.showGlucoseMG = glucose.getShowGlucoseMG()
254
+ dto.glucoseId = glucose.getGlucoseId()
255
+ dto.name = glucose.getName()
256
+ dto.showGlucose = glucose.getShowGlucose()
257
+ dto.Ib = glucose.getIb()
258
+ dto.Iw = glucose.getIw()
259
+ dto.T = glucose.getT()
260
+ dto.year = glucose.getYear()
261
+ dto.month = glucose.getMonth()
262
+ dto.day = glucose.getDay()
263
+ dto.hour = glucose.getHour()
264
+ dto.minute = glucose.getMinute()
265
+
266
+ // Convert byte[] to List<Integer>
267
+ dto.bytes = ArrayList()
268
+ for (b in glucose.getBytes()) {
269
+ dto.bytes?.add(b.toInt() and 0xFF) // Prevent negative values
270
+ }
271
+
272
+ // Trend
273
+ val trendObj: TrendObject = TrendObject()
274
+ trendObj.trendId = glucose.getTrend().getTrendId()
275
+ trendObj.drawableId = glucose.getTrend().getDrawableId()
276
+ trendObj.widgetImg = glucose.getTrend().getWidgetImg()
277
+ trendObj.apsChangeRate = glucose.getTrend().getApsChangeRate()
278
+ dto.trendObject = trendObj
279
+
280
+ // Status
281
+ val statusObj: GlucoseStatusObject = GlucoseStatusObject()
282
+ statusObj.statusId = glucose.getGlucoseStatus().getStatusId()
283
+ dto.glucoseStatusObject = statusObj
284
+
285
+ // Error
286
+ val errorObj: ErrorObject = ErrorObject()
287
+ errorObj.errorId = glucose.getErrorCode().getErrorId()
288
+ errorObj.sound = glucose.getErrorCode().getSound().toString()
289
+ dto.errorObject = errorObj
290
+
291
+ return dto
292
+ }
293
+
294
+
295
+ public override fun disconnect() {
296
+ ProgressManagement.getInstance().dismissWait(this)
297
+ showShortToast(R.string.bt_connect_fail)
298
+ manageErrorState(true, "Disconnected")
299
+ }
300
+
301
+ public override fun disconnectForTimeout() {
302
+ ProgressManagement.getInstance().dismissWait(this)
303
+ manageErrorState(true, "Disconnected")
304
+ Log.d("Search Transmitter Error--> ", "Search Transmitter Error--> disconnectForTimeout")
305
+ }
306
+
307
+ public override fun checkFailForLowPower() {
308
+ ProgressManagement.getInstance().dismissWait(this)
309
+ WarnDialogUtils.getInstance().showWarnDialog(this, DialogType.TYPE_LOW_POWER)
310
+ }
311
+
312
+ public override fun checkFailErrorTemperature() {
313
+ ProgressManagement.getInstance().dismissWait(this)
314
+ }
315
+
316
+ public override fun onlineLost() {
317
+ showShortToast(R.string.online_lost)
318
+ }
319
+
320
+
321
+ private fun bind(device: PocDevice) {
322
+ try {
323
+ if (device.address != null) {
324
+ ManageGattCallback.getInstance().ConnectViaAddress(device.address)
325
+ ManageScanCallback.getInstance().stopLeScan()
326
+ ProgressManagement.getInstance()
327
+ .showWait(this, ProgressType.PROGRESSDIALOG_CONNECT, null)
328
+ }
329
+ } catch (e: Exception) {
330
+ Log.d("bind::-> ", "bind: ${e.message}")
331
+ }
332
+ }
333
+
334
+ private fun setupClickListeners() {
335
+ binding.toolbar.btnWhatsapp.setOnClickListener {
336
+ startActivity(Intent(this, HelpActivity::class.java))
337
+ }
338
+
339
+ binding.toolbar.btnClose.setOnClickListener {
340
+ openExitDialog()
341
+ }
342
+
343
+ // Watch Demo button
344
+ binding.toolbar.btnWatchDemo.setOnClickListener {
345
+ // Implement demo video functionality
346
+ }
347
+
348
+ // Connect button (visible when device is detected)
349
+ binding.btnConnect.setOnClickListener {
350
+ connectToTransmitter()
351
+ }
352
+
353
+ val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
354
+ override fun handleOnBackPressed() {
355
+ openExitDialog()
356
+ }
324
357
  }
358
+ onBackPressedDispatcher.addCallback(this, callback)
325
359
 
326
- private fun setupClickListeners() {
327
- binding.toolbar.btnWhatsapp.setOnClickListener {
328
- startActivity(Intent(this, HelpActivity::class.java))
329
- }
330
-
331
- binding.toolbar.btnClose.setOnClickListener {
332
- openExitDialog()
333
- }
334
-
335
- // Watch Demo button
336
- binding.toolbar.btnWatchDemo.setOnClickListener {
337
- // Implement demo video functionality
338
- }
339
-
340
- // Connect button (visible when device is detected)
341
- binding.btnConnect.setOnClickListener {
342
- connectToTransmitter()
343
- }
344
-
345
- val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
346
- override fun handleOnBackPressed() {
347
- openExitDialog()
348
- }
349
- }
350
- onBackPressedDispatcher.addCallback(this, callback)
351
-
352
- binding.commonButton.btnProceed.setOnClickListener {
360
+ binding.commonButton.btnProceed.setOnClickListener {
353
361
  // CoroutineScope(Dispatchers.IO).launch {
354
362
  // // This block runs in IO thread
355
363
  // val result = mModel.glucoseByTime
@@ -429,175 +437,175 @@ class SearchTransmitterActivity : BaseBleActivity() {
429
437
  // }
430
438
  // }
431
439
 
432
- if (isTransmitterConnected) {
433
- proceedToNextStep()
434
- }
435
- }
440
+ if (isTransmitterConnected) {
441
+ proceedToNextStep()
442
+ }
436
443
  }
444
+ }
437
445
 
438
446
 
439
- fun logLongJson(tag: String, message: String) {
440
- val maxLogSize = 4000
441
- for (i in 0..message.length / maxLogSize) {
442
- val start = i * maxLogSize
443
- val end = (i + 1) * maxLogSize
444
- if (start < message.length) {
445
- Log.d(tag, message.substring(start, minOf(end, message.length)))
446
- }
447
- }
447
+ fun logLongJson(tag: String, message: String) {
448
+ val maxLogSize = 4000
449
+ for (i in 0..message.length / maxLogSize) {
450
+ val start = i * maxLogSize
451
+ val end = (i + 1) * maxLogSize
452
+ if (start < message.length) {
453
+ Log.d(tag, message.substring(start, minOf(end, message.length)))
454
+ }
448
455
  }
456
+ }
449
457
 
450
- private fun startDeviceSearch() {
451
- mModel = ViewModelProviders.of(this)[MainActivityModel::class.java]
458
+ private fun startDeviceSearch() {
459
+ mModel = ViewModelProviders.of(this)[MainActivityModel::class.java]
452
460
 
453
- ReconnectManagement.getInstance()
454
- .reconnect(ReconnectManagement.ReconnectState.STATE_SCAN_AGAIN)
461
+ ReconnectManagement.getInstance()
462
+ .reconnect(ReconnectManagement.ReconnectState.STATE_SCAN_AGAIN)
455
463
 
456
- authenticateSDKService = AuthenticateSDKService(scope = scope)
464
+ authenticateSDKService = AuthenticateSDKService(scope = scope)
457
465
 
458
- isSearching = true
459
- isTransmitterConnected = false
466
+ isSearching = true
467
+ isTransmitterConnected = false
460
468
 
461
- // Show searching state
462
- binding.searchingLayout.visibility = View.VISIBLE
463
- binding.connectedLayout.visibility = View.GONE
469
+ // Show searching state
470
+ binding.searchingLayout.visibility = View.VISIBLE
471
+ binding.connectedLayout.visibility = View.GONE
464
472
 
465
- Glide.with(this)
466
- .asGif()
467
- .load(R.drawable.searching)
468
- .into(binding.progressSearch)
473
+ Glide.with(this)
474
+ .asGif()
475
+ .load(R.drawable.searching)
476
+ .into(binding.progressSearch)
469
477
 
470
- binding.commonButton.btnProceed.isEnabled = false
471
- binding.commonButton.btnProceed.alpha = 0.5f
472
- }
478
+ binding.commonButton.btnProceed.isEnabled = false
479
+ binding.commonButton.btnProceed.alpha = 0.5f
480
+ }
473
481
 
474
- private fun deviceDetected(device: PocDeviceAndRssi) {
475
- isSearching = false
482
+ private fun deviceDetected(device: PocDeviceAndRssi) {
483
+ isSearching = false
476
484
 
477
- // Animate the transition
478
- val fadeOut = AlphaAnimation(1.0f, 0.0f)
479
- fadeOut.duration = 300
480
- fadeOut.setAnimationListener(object : Animation.AnimationListener {
481
- override fun onAnimationStart(animation: Animation?) {}
485
+ // Animate the transition
486
+ val fadeOut = AlphaAnimation(1.0f, 0.0f)
487
+ fadeOut.duration = 300
488
+ fadeOut.setAnimationListener(object : Animation.AnimationListener {
489
+ override fun onAnimationStart(animation: Animation?) {}
482
490
 
483
- override fun onAnimationEnd(animation: Animation?) {
484
- binding.searchingLayout.visibility = View.GONE
491
+ override fun onAnimationEnd(animation: Animation?) {
492
+ binding.searchingLayout.visibility = View.GONE
485
493
 
486
- // Show the connected layout
487
- binding.connectedLayout.visibility = View.VISIBLE
488
- binding.tvSerialNumber.text = device.pocDevice.name
494
+ // Show the connected layout
495
+ binding.connectedLayout.visibility = View.VISIBLE
496
+ binding.tvSerialNumber.text = device.pocDevice.name
489
497
 
490
- // Fade in the connected layout
491
- val fadeIn = AlphaAnimation(0.0f, 1.0f)
492
- fadeIn.duration = 300
493
- binding.connectedLayout.startAnimation(fadeIn)
494
- }
498
+ // Fade in the connected layout
499
+ val fadeIn = AlphaAnimation(0.0f, 1.0f)
500
+ fadeIn.duration = 300
501
+ binding.connectedLayout.startAnimation(fadeIn)
502
+ }
495
503
 
496
- override fun onAnimationRepeat(animation: Animation?) {}
497
- })
504
+ override fun onAnimationRepeat(animation: Animation?) {}
505
+ })
498
506
 
499
- binding.searchingLayout.startAnimation(fadeOut)
500
- }
507
+ binding.searchingLayout.startAnimation(fadeOut)
508
+ }
501
509
 
502
- private fun connectToTransmitter() {
503
- isTransmitterConnected = true
510
+ private fun connectToTransmitter() {
511
+ isTransmitterConnected = true
504
512
 
505
- if (transmitterDeviceInfo != null) {
506
- Log.d("onDeviceConnect--->", "onDeviceConnect: " + transmitterDeviceInfo.toString())
507
- if (enumDevice.getEnumDevice(transmitterDeviceInfo!!.pocDevice.name).isAbleScanQRCode) {
508
- Log.d("onDeviceConnect--->", "isAbleScanQRCode")
509
- } else {
510
- bind(transmitterDeviceInfo!!.pocDevice)
511
- }
513
+ if (transmitterDeviceInfo != null) {
514
+ Log.d("onDeviceConnect--->", "onDeviceConnect: " + transmitterDeviceInfo.toString())
515
+ if (enumDevice.getEnumDevice(transmitterDeviceInfo!!.pocDevice.name).isAbleScanQRCode) {
516
+ Log.d("onDeviceConnect--->", "isAbleScanQRCode")
517
+ } else {
518
+ bind(transmitterDeviceInfo!!.pocDevice)
519
+ }
512
520
 
513
- binding.tvTransName.text = "Sno: ${transmitterDeviceInfo!!.pocDevice.name}"
521
+ binding.tvTransName.text = "Sno: ${transmitterDeviceInfo!!.pocDevice.name}"
514
522
 
515
- val formatter = SimpleDateFormat("hh:mm a", Locale.getDefault())
523
+ val formatter = SimpleDateFormat("hh:mm a", Locale.getDefault())
516
524
 
517
- binding.tvDateTime.text = "Connected on ${formatter.format(Date()).uppercase()}"
525
+ binding.tvDateTime.text = "Connected on ${formatter.format(Date()).uppercase()}"
518
526
 
519
- binding.clSuccess.visibility = View.VISIBLE
520
- binding.clMain.visibility = View.GONE
521
- binding.commonButton.btnProceed.isEnabled = true
522
- binding.commonButton.btnProceed.alpha = 1.0f
523
- binding.view2.background = ContextCompat.getDrawable(this, R.drawable.bg_green_progress)
524
- binding.tvDivide2.setTextColor("#299D6B".toColorInt())
525
- }
527
+ binding.clSuccess.visibility = View.VISIBLE
528
+ binding.clMain.visibility = View.GONE
529
+ binding.commonButton.btnProceed.isEnabled = true
530
+ binding.commonButton.btnProceed.alpha = 1.0f
531
+ binding.view2.background = ContextCompat.getDrawable(this, R.drawable.bg_green_progress)
532
+ binding.tvDivide2.setTextColor("#299D6B".toColorInt())
526
533
  }
534
+ }
527
535
 
528
- private fun proceedToNextStep() {
529
- if (isForReconnect) {
530
- sendDataToRN("")
531
- finish()
532
- } else {
533
- val intent = Intent(this, ConnectSensorActivity::class.java)
534
- intent.putExtra("transmitterDeviceInfo", transmitterDeviceInfo) // Serializable
535
- startActivity(intent)
536
- finish()
536
+ private fun proceedToNextStep() {
537
+ if (isForReconnect) {
538
+ sendDataToRN("")
539
+ finish()
540
+ } else {
541
+ val intent = Intent(this, ConnectSensorActivity::class.java)
542
+ intent.putExtra("transmitterDeviceInfo", transmitterDeviceInfo) // Serializable
543
+ startActivity(intent)
544
+ finish()
537
545
  // transmitterDeviceInfo?.let {
538
546
  // QRActivity.startQR(
539
547
  // this@SearchTransmitterActivity,
540
548
  // it.pocDevice
541
549
  // )
542
550
  // }
543
- }
544
551
  }
552
+ }
553
+
554
+ private fun sendDataToRN(data: String) {
555
+ if (reactContext != null) {
556
+ try {
557
+ val catalystInstance: CatalystInstance = reactContext.catalystInstance
558
+ val module = catalystInstance.getNativeModule(CgmTrackyLibModule::class.java)
545
559
 
546
- private fun sendDataToRN(data: String) {
547
- if (reactContext != null) {
548
- try {
549
- val catalystInstance: CatalystInstance = reactContext.catalystInstance
550
- val module = catalystInstance.getNativeModule(CgmTrackyLibModule::class.java)
551
-
552
- if (module == null) {
553
- sendDataToRNDirectly("", "WARM_PERIOD_STARTED")
554
- Log.d("sendDataToRN: ", "Module null")
555
- } else {
556
- module.sendDataToReact(data, "WARM_PERIOD_STARTED", "cgmDeviceEvent")
557
- Log.d("sendDataToRN: ", "Module is not null")
558
- }
559
- } catch (e: Exception) {
560
- Log.e("sendDataToRN: Error ", e.message.toString())
561
- }
560
+ if (module == null) {
561
+ sendDataToRNDirectly("", "WARM_PERIOD_STARTED")
562
+ Log.d("sendDataToRN: ", "Module null")
562
563
  } else {
563
- Log.e("TrackyActivity", "ReactApplicationContext is null")
564
+ module.sendDataToReact(data, "WARM_PERIOD_STARTED", "cgmDeviceEvent")
565
+ Log.d("sendDataToRN: ", "Module is not null")
564
566
  }
567
+ } catch (e: Exception) {
568
+ Log.e("sendDataToRN: Error ", e.message.toString())
569
+ }
570
+ } else {
571
+ Log.e("TrackyActivity", "ReactApplicationContext is null")
565
572
  }
573
+ }
566
574
 
567
575
 
568
- private fun sendDataToRNDirectly(data: String, status: String) {
569
- try {
570
- val map: WritableMap = Arguments.createMap().apply {
571
- putString("data", data)
572
- putString("status", status)
573
- }
576
+ private fun sendDataToRNDirectly(data: String, status: String) {
577
+ try {
578
+ val map: WritableMap = Arguments.createMap().apply {
579
+ putString("data", data)
580
+ putString("status", status)
581
+ }
574
582
 
575
- reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
576
- ?.emit("cgmDeviceEvent", map)
577
- } catch (e: Exception) {
578
- Log.e("sendDataToRNDirectly", "Error sending data to React", e)
579
- }
583
+ reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
584
+ ?.emit("cgmDeviceEvent", map)
585
+ } catch (e: Exception) {
586
+ Log.e("sendDataToRNDirectly", "Error sending data to React", e)
580
587
  }
588
+ }
581
589
 
582
- override fun onDestroy() {
583
- super.onDestroy()
584
- handler.removeCallbacksAndMessages(null)
585
- }
590
+ override fun onDestroy() {
591
+ super.onDestroy()
592
+ handler.removeCallbacksAndMessages(null)
593
+ }
586
594
 
587
- override fun onResume() {
588
- super.onResume()
589
- BleService.startService(this)
590
- }
595
+ override fun onResume() {
596
+ super.onResume()
597
+ BleService.startService(this)
598
+ }
591
599
 
592
- override fun setView(): Int {
593
- return R.layout.activity_search_transmitter
594
- }
600
+ override fun setView(): Int {
601
+ return R.layout.activity_search_transmitter
602
+ }
595
603
 
596
- override fun initViews() {
597
- }
604
+ override fun initViews() {
605
+ }
598
606
 
599
- override fun onClick(p0: View?) {
600
- }
607
+ override fun onClick(p0: View?) {
608
+ }
601
609
 
602
610
 
603
611
  }
@@ -345,6 +345,23 @@
345
345
  app:layout_constraintStart_toStartOf="parent"
346
346
  app:layout_constraintTop_toBottomOf="@id/ivGif" />
347
347
 
348
+
349
+ <TextView
350
+ android:id="@+id/tvReason"
351
+ android:layout_width="0dp"
352
+ android:layout_height="wrap_content"
353
+ android:layout_marginHorizontal="30dp"
354
+ android:layout_marginVertical="10dp"
355
+ android:fontFamily="@font/roboto_semibold"
356
+ android:gravity="center"
357
+ android:textAlignment="center"
358
+ android:textColor="#667085"
359
+ android:textSize="14sp"
360
+ android:visibility="gone"
361
+ app:layout_constraintEnd_toEndOf="parent"
362
+ app:layout_constraintStart_toStartOf="parent"
363
+ app:layout_constraintTop_toBottomOf="@id/tvFailTitle" />
364
+
348
365
  <TextView
349
366
  android:id="@+id/tvFailInstructions"
350
367
  android:layout_width="0dp"
@@ -359,7 +376,7 @@
359
376
  android:textSize="14sp"
360
377
  app:layout_constraintEnd_toEndOf="parent"
361
378
  app:layout_constraintStart_toStartOf="parent"
362
- app:layout_constraintTop_toBottomOf="@id/tvFailTitle" />
379
+ app:layout_constraintTop_toBottomOf="@id/tvReason" />
363
380
 
364
381
  <androidx.constraintlayout.widget.ConstraintLayout
365
382
  android:id="@+id/clBox"
@@ -122,6 +122,7 @@
122
122
  android:layout_height="0dp"
123
123
  android:layout_marginTop="16dp"
124
124
  android:orientation="vertical"
125
+ android:visibility="visible"
125
126
  app:layout_constraintBottom_toTopOf="@+id/commonButton"
126
127
  app:layout_constraintEnd_toEndOf="parent"
127
128
  app:layout_constraintStart_toStartOf="parent"
@@ -562,6 +563,23 @@
562
563
  app:layout_constraintStart_toStartOf="parent"
563
564
  app:layout_constraintTop_toBottomOf="@id/ivGif" />
564
565
 
566
+
567
+ <TextView
568
+ android:id="@+id/tvReason"
569
+ android:layout_width="0dp"
570
+ android:layout_height="wrap_content"
571
+ android:layout_marginHorizontal="30dp"
572
+ android:layout_marginVertical="10dp"
573
+ android:fontFamily="@font/roboto_semibold"
574
+ android:gravity="center"
575
+ android:textAlignment="center"
576
+ android:textColor="#667085"
577
+ android:textSize="14sp"
578
+ android:visibility="gone"
579
+ app:layout_constraintEnd_toEndOf="parent"
580
+ app:layout_constraintStart_toStartOf="parent"
581
+ app:layout_constraintTop_toBottomOf="@id/tvFailTitle" />
582
+
565
583
  <TextView
566
584
  android:id="@+id/tvFailInstructions"
567
585
  android:layout_width="0dp"
@@ -576,7 +594,7 @@
576
594
  android:textSize="14sp"
577
595
  app:layout_constraintEnd_toEndOf="parent"
578
596
  app:layout_constraintStart_toStartOf="parent"
579
- app:layout_constraintTop_toBottomOf="@id/tvFailTitle" />
597
+ app:layout_constraintTop_toBottomOf="@id/tvReason" />
580
598
 
581
599
  <androidx.constraintlayout.widget.ConstraintLayout
582
600
  android:id="@+id/clBox"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-mytatva-rn-sdk",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
4
4
  "description": "a package to inject data into visit health pwa",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",