react-native-mytatva-rn-sdk 1.2.19 → 1.2.21

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