react-native-mytatva-rn-sdk 1.2.8 → 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 {