react-native-mytatva-rn-sdk 1.2.43 → 1.2.45

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.
@@ -29,337 +29,400 @@ import androidx.core.graphics.drawable.toDrawable
29
29
  import androidx.core.view.ViewCompat
30
30
  import androidx.core.view.WindowInsetsCompat
31
31
  import cgmblelib.utils.ConstantsLibrary
32
+ import com.facebook.react.bridge.Arguments
33
+ import com.facebook.react.bridge.CatalystInstance
34
+ import com.facebook.react.bridge.WritableMap
35
+ import com.facebook.react.modules.core.DeviceEventManagerModule
36
+ import com.mytatvarnsdk.CgmTrackyLibModule
32
37
  import com.mytatvarnsdk.base.BasePermissionActivity
33
38
  import com.mytatvarnsdk.databinding.ActivityPermissionBinding
34
39
  import com.mytatvarnsdk.databinding.BluetoothDialogBottomsheetBinding
35
40
  import com.mytatvarnsdk.databinding.ExitDialogBottomsheetBinding
41
+ import org.json.JSONObject
36
42
 
37
43
  class PermissionActivity : BasePermissionActivity() {
38
- private lateinit var binding: ActivityPermissionBinding
39
- private val LOCATION_REQUEST_CODE = 101
40
- private val BLUETOOTH_REQUEST_CODE = 102
41
-
42
- private val REQUEST_ENABLE_BT = 1
43
- private val bluetoothAdapter: BluetoothAdapter? by lazy {
44
- BluetoothAdapter.getDefaultAdapter()
45
- }
46
-
47
- override fun onCreate(savedInstanceState: Bundle?) {
48
- super.onCreate(savedInstanceState)
49
- binding = ActivityPermissionBinding.inflate(layoutInflater)
50
-
51
- enableEdgeToEdge()
52
- ViewCompat.setOnApplyWindowInsetsListener(binding.rlPopBottom) { v, insets ->
53
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
54
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
55
- insets
56
- }
57
- setContentView(binding.root)
58
-
59
- initialize()
60
- }
61
-
62
- override fun getPermission(): Array<out Array<out String?>?>? {
63
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
64
- return arrayOf<Array<String?>?>(ConstantsLibrary.BLUETOOTH_S)
65
- } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
66
- return arrayOf<Array<String?>?>(
67
- ConstantsLibrary.LOCAL_PERMISSION,
68
- ConstantsLibrary.BACKGROUND_LOCATION_Q
69
- )
70
- } else {
71
- return arrayOf<Array<String?>?>(ConstantsLibrary.LOCAL_PERMISSION)
72
- }
73
- }
44
+ private lateinit var binding: ActivityPermissionBinding
45
+ private val LOCATION_REQUEST_CODE = 101
46
+ private val BLUETOOTH_REQUEST_CODE = 102
74
47
 
75
- override fun onPermissionRequestSuccess() {
76
- }
48
+ private val REQUEST_ENABLE_BT = 1
49
+ private val bluetoothAdapter: BluetoothAdapter? by lazy {
50
+ BluetoothAdapter.getDefaultAdapter()
51
+ }
52
+ private val reactContext = CgmTrackyLibModule.mReactContext
77
53
 
78
- override fun onPermissionRequestFail(vararg permission: String?) {
79
- }
54
+ override fun onCreate(savedInstanceState: Bundle?) {
55
+ super.onCreate(savedInstanceState)
56
+ binding = ActivityPermissionBinding.inflate(layoutInflater)
80
57
 
81
- override fun onPermissionRequestFailForever(vararg permission: String?) {
82
- }
58
+ enableEdgeToEdge()
59
+ ViewCompat.setOnApplyWindowInsetsListener(binding.rlPopBottom) { v, insets ->
60
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
61
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
62
+ insets
63
+ }
64
+ setContentView(binding.root)
83
65
 
84
- fun isBluetoothPermissionGranted(context: Context): Boolean {
85
- return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
86
- val connectPermission = ContextCompat.checkSelfPermission(
87
- context,
88
- android.Manifest.permission.BLUETOOTH_CONNECT
89
- ) == PackageManager.PERMISSION_GRANTED
66
+ initialize()
67
+ }
90
68
 
91
- val scanPermission = ContextCompat.checkSelfPermission(
92
- context,
93
- android.Manifest.permission.BLUETOOTH_SCAN
94
- ) == PackageManager.PERMISSION_GRANTED
69
+ override fun getPermission(): Array<out Array<out String?>?>? {
70
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
71
+ return arrayOf<Array<String?>?>(ConstantsLibrary.BLUETOOTH_S)
72
+ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
73
+ return arrayOf<Array<String?>?>(
74
+ ConstantsLibrary.LOCAL_PERMISSION,
75
+ ConstantsLibrary.BACKGROUND_LOCATION_Q
76
+ )
77
+ } else {
78
+ return arrayOf<Array<String?>?>(ConstantsLibrary.LOCAL_PERMISSION)
79
+ }
80
+ }
95
81
 
96
- connectPermission && scanPermission
97
- } else {
98
- // For Android 11 and below, permission is granted at install time
99
- true
82
+ override fun onPermissionRequestSuccess() {
100
83
  }
101
- }
102
84
 
103
- fun isLocationPermissionGranted(context: Context): Boolean {
104
- val fineLocationGranted = ContextCompat.checkSelfPermission(
105
- context,
106
- android.Manifest.permission.ACCESS_FINE_LOCATION
107
- ) == PackageManager.PERMISSION_GRANTED
85
+ override fun onPermissionRequestFail(vararg permission: String?) {
86
+ }
108
87
 
109
- val coarseLocationGranted = ContextCompat.checkSelfPermission(
110
- context,
111
- android.Manifest.permission.ACCESS_COARSE_LOCATION
112
- ) == PackageManager.PERMISSION_GRANTED
88
+ override fun onPermissionRequestFailForever(vararg permission: String?) {
89
+ }
113
90
 
114
- return fineLocationGranted || coarseLocationGranted
115
- }
91
+ fun isBluetoothPermissionGranted(context: Context): Boolean {
92
+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
93
+ val connectPermission = ContextCompat.checkSelfPermission(
94
+ context,
95
+ android.Manifest.permission.BLUETOOTH_CONNECT
96
+ ) == PackageManager.PERMISSION_GRANTED
116
97
 
98
+ val scanPermission = ContextCompat.checkSelfPermission(
99
+ context,
100
+ android.Manifest.permission.BLUETOOTH_SCAN
101
+ ) == PackageManager.PERMISSION_GRANTED
117
102
 
118
- @SuppressLint("MissingPermission")
119
- private fun initialize() {
120
- bluetoothAdapter?.let {
121
- binding.switchBluetooth.isChecked = isBluetoothPermissionGranted(this) && it.isEnabled
103
+ connectPermission && scanPermission
104
+ } else {
105
+ // For Android 11 and below, permission is granted at install time
106
+ true
107
+ }
122
108
  }
123
109
 
124
- binding.switchLocation.isChecked = isLocationPermissionGranted(this)
110
+ fun isLocationPermissionGranted(context: Context): Boolean {
111
+ val fineLocationGranted = ContextCompat.checkSelfPermission(
112
+ context,
113
+ android.Manifest.permission.ACCESS_FINE_LOCATION
114
+ ) == PackageManager.PERMISSION_GRANTED
125
115
 
126
- binding.switchBluetooth.setOnCheckedChangeListener { _, isChecked ->
127
- if (isChecked) {
128
- requestBluetoothPermission()
129
- }
130
- }
116
+ val coarseLocationGranted = ContextCompat.checkSelfPermission(
117
+ context,
118
+ android.Manifest.permission.ACCESS_COARSE_LOCATION
119
+ ) == PackageManager.PERMISSION_GRANTED
131
120
 
132
- binding.switchLocation.setOnCheckedChangeListener { _, isChecked ->
133
- if (isChecked) {
134
- requestLocationPermission()
135
- }
121
+ return fineLocationGranted || coarseLocationGranted
136
122
  }
137
123
 
138
- binding.commonButton.btnProceed.setOnClickListener {
139
- startActivity(
140
- Intent(this@PermissionActivity, SearchTransmitterActivity::class.java).putExtra(
141
- "IsForReconnect",
142
- intent.getBooleanExtra("IsForReconnect", false)
143
- )
144
- )
145
- finish()
146
- }
147
124
 
148
- binding.toolbar.btnWhatsapp.setOnClickListener {
149
- startActivity(Intent(this, HelpActivity::class.java))
150
- }
125
+ @SuppressLint("MissingPermission")
126
+ private fun initialize() {
127
+ sendDataToRN("", "cgm_permissions_page_landing")
151
128
 
152
- binding.toolbar.btnWatchDemo.setOnClickListener {
153
- startActivity(
154
- Intent(this, VideoActivity::class.java).putExtra("VideoId", "r5Zemc4R044")
155
- )
156
- }
129
+ bluetoothAdapter?.let {
130
+ binding.switchBluetooth.isChecked = isBluetoothPermissionGranted(this) && it.isEnabled
131
+ }
157
132
 
158
- binding.tvKnowMore.setOnClickListener {
159
- openBluetoothDialog()
160
- }
133
+ binding.switchLocation.isChecked = isLocationPermissionGranted(this)
134
+
135
+ binding.switchBluetooth.setOnCheckedChangeListener { _, isChecked ->
136
+ if (isChecked) {
137
+ requestBluetoothPermission()
138
+ }
139
+ }
140
+
141
+ binding.switchLocation.setOnCheckedChangeListener { _, isChecked ->
142
+ if (isChecked) {
143
+ requestLocationPermission()
144
+ }
145
+ }
146
+
147
+ binding.commonButton.btnProceed.setOnClickListener {
148
+ val jsonObject = JSONObject()
149
+ jsonObject.put("bluetooth_toggle_status", "ON")
150
+ jsonObject.put("location_toggle_status", "ON")
151
+ sendDataToRN(jsonObject.toString(), "cgm_permissions_proceed_clicked")
152
+
153
+ startActivity(
154
+ Intent(this@PermissionActivity, SearchTransmitterActivity::class.java).putExtra(
155
+ "IsForReconnect",
156
+ intent.getBooleanExtra("IsForReconnect", false)
157
+ )
158
+ )
159
+ finish()
160
+ }
161
+
162
+ binding.toolbar.btnWhatsapp.setOnClickListener {
163
+ startActivity(
164
+ Intent(this, HelpActivity::class.java)
165
+ .putExtra("ScreenName", "Permission Screen")
166
+ )
167
+ }
168
+
169
+ binding.toolbar.btnWatchDemo.setOnClickListener {
170
+ sendDataToRN("", "cgm_watch_demo_clicked")
171
+
172
+ startActivity(
173
+ Intent(this, VideoActivity::class.java).putExtra("VideoId", "r5Zemc4R044")
174
+ )
175
+ }
176
+
177
+ binding.tvKnowMore.setOnClickListener {
178
+ openBluetoothDialog()
179
+ }
180
+
181
+ binding.toolbar.btnClose.setOnClickListener {
182
+ openExitDialog()
183
+ }
161
184
 
162
- binding.toolbar.btnClose.setOnClickListener {
163
- openExitDialog()
185
+ val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
186
+ override fun handleOnBackPressed() {
187
+ openExitDialog()
188
+ }
189
+ }
190
+ onBackPressedDispatcher.addCallback(this, callback)
164
191
  }
165
192
 
166
- val callback: OnBackPressedCallback = object : OnBackPressedCallback(true) {
167
- override fun handleOnBackPressed() {
168
- openExitDialog()
169
- }
193
+ private fun sendDataToRN(data: String, status: String) {
194
+ if (reactContext != null) {
195
+ try {
196
+ val catalystInstance: CatalystInstance = reactContext.catalystInstance
197
+ val module = catalystInstance.getNativeModule(CgmTrackyLibModule::class.java)
198
+
199
+ if (module == null) {
200
+ sendDataToRNDirectly(data, status)
201
+ Log.d("sendDataToRN: ", "Module null")
202
+ } else {
203
+ module.sendDataToReact(data, status, "cgmDeviceEvent")
204
+ Log.d("sendDataToRN: ", "Module is not null")
205
+ }
206
+ } catch (e: Exception) {
207
+ Log.e("sendDataToRN: Error ", e.message.toString())
208
+ }
209
+ } else {
210
+ Log.e("TrackyActivity", "ReactApplicationContext is null")
211
+ }
170
212
  }
171
- onBackPressedDispatcher.addCallback(this, callback)
172
- }
173
-
174
- private fun openBluetoothDialog() {
175
- val binding = BluetoothDialogBottomsheetBinding.inflate(layoutInflater)
176
-
177
- val dialog = Dialog(this)
178
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
179
- dialog.setContentView(binding.root)
180
-
181
- val window = dialog.window
182
- window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
183
- window?.setGravity(Gravity.BOTTOM)
184
- window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
185
-
186
- binding.tvKnowMore.setOnClickListener {
187
- val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
188
- data = Uri.fromParts("package", packageName, null)
189
- }
190
- startActivity(intent)
213
+
214
+
215
+ private fun sendDataToRNDirectly(data: String, status: String) {
216
+ try {
217
+ val map: WritableMap = Arguments.createMap().apply {
218
+ putString("data", data)
219
+ putString("status", status)
220
+ }
221
+
222
+ reactContext?.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
223
+ ?.emit("cgmDeviceEvent", map)
224
+ } catch (e: Exception) {
225
+ Log.e("sendDataToRNDirectly", "Error sending data to React", e)
226
+ }
191
227
  }
192
228
 
193
- binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
194
- dialog.dismiss()
195
- })
229
+ private fun openBluetoothDialog() {
230
+ val binding = BluetoothDialogBottomsheetBinding.inflate(layoutInflater)
196
231
 
197
- dialog.show()
198
- }
232
+ val dialog = Dialog(this)
233
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
234
+ dialog.setContentView(binding.root)
199
235
 
200
- private fun openExitDialog() {
201
- val binding = ExitDialogBottomsheetBinding.inflate(layoutInflater)
236
+ val window = dialog.window
237
+ window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
238
+ window?.setGravity(Gravity.BOTTOM)
239
+ window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
202
240
 
203
- val dialog = Dialog(this)
204
- dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
205
- dialog.setContentView(binding.root)
241
+ binding.tvKnowMore.setOnClickListener {
242
+ val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
243
+ data = Uri.fromParts("package", packageName, null)
244
+ }
245
+ startActivity(intent)
246
+ }
247
+
248
+ binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
249
+ dialog.dismiss()
250
+ })
206
251
 
207
- val window = dialog.window
208
- window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
209
- window?.setGravity(Gravity.BOTTOM)
210
- window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
252
+ dialog.show()
253
+ }
211
254
 
212
- binding.btnExit.tvProceed.text = "Exit"
255
+ private fun openExitDialog() {
256
+ val binding = ExitDialogBottomsheetBinding.inflate(layoutInflater)
213
257
 
214
- binding.btnExit.root.setOnClickListener(View.OnClickListener { v: View? ->
215
- finish()
216
- dialog.dismiss()
217
- })
258
+ val dialog = Dialog(this)
259
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
260
+ dialog.setContentView(binding.root)
218
261
 
219
- binding.btnCancel.root.setOnClickListener(View.OnClickListener { v: View? ->
220
- dialog.dismiss()
221
- })
262
+ val window = dialog.window
263
+ window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
264
+ window?.setGravity(Gravity.BOTTOM)
265
+ window?.setBackgroundDrawable(Color.TRANSPARENT.toDrawable())
222
266
 
223
- binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
224
- dialog.dismiss()
225
- })
267
+ binding.btnExit.tvProceed.text = "Exit"
226
268
 
227
- dialog.show()
228
- }
269
+ binding.btnExit.root.setOnClickListener(View.OnClickListener { v: View? ->
270
+ finish()
271
+ dialog.dismiss()
272
+ })
229
273
 
274
+ binding.btnCancel.root.setOnClickListener(View.OnClickListener { v: View? ->
275
+ dialog.dismiss()
276
+ })
230
277
 
231
- private fun requestForegroundLocationPermission() {
232
- val locationPermissions = PermissionUtils.LOCAL_PERMISSION
278
+ binding.closeButton.setOnClickListener(View.OnClickListener { v: View? ->
279
+ dialog.dismiss()
280
+ })
233
281
 
234
- if (hasPermissions(locationPermissions)) {
235
- onForegroundLocationGranted()
236
- } else {
237
- ActivityCompat.requestPermissions(
238
- this,
239
- locationPermissions,
240
- LOCATION_REQUEST_CODE
241
- )
282
+ dialog.show()
242
283
  }
243
- }
244
-
245
- private fun requestLocationPermission() {
246
- val permissions = mutableListOf(*PermissionUtils.LOCAL_PERMISSION)
247
-
248
- val permissionArray = permissions.toTypedArray()
249
-
250
- if (hasPermissions(permissionArray)) {
251
- onLocationPermissionGranted()
252
- } else {
253
- val rationaleNeeded = permissionArray.any {
254
- ActivityCompat.shouldShowRequestPermissionRationale(this, it)
255
- }
256
-
257
- if (rationaleNeeded) {
258
- showPermissionRationale(
259
- title = "Location Permission Needed",
260
- message = "We need location access for Bluetooth scanning.",
261
- onProceed = {
262
- ActivityCompat.requestPermissions(this, permissionArray, LOCATION_REQUEST_CODE)
263
- }
264
- )
265
- } else {
266
- ActivityCompat.requestPermissions(this, permissionArray, LOCATION_REQUEST_CODE)
267
- }
284
+
285
+
286
+ private fun requestForegroundLocationPermission() {
287
+ val locationPermissions = PermissionUtils.LOCAL_PERMISSION
288
+
289
+ if (hasPermissions(locationPermissions)) {
290
+ onForegroundLocationGranted()
291
+ } else {
292
+ ActivityCompat.requestPermissions(
293
+ this,
294
+ locationPermissions,
295
+ LOCATION_REQUEST_CODE
296
+ )
297
+ }
268
298
  }
269
- }
270
-
271
- @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
272
- private fun requestBluetoothPermission() {
273
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
274
- val permissions = PermissionUtils.BLUETOOTH_S
275
-
276
- if (hasPermissions(permissions)) {
277
- onBluetoothPermissionGranted()
278
- } else {
279
- val rationaleNeeded = permissions.any {
280
- ActivityCompat.shouldShowRequestPermissionRationale(this, it)
299
+
300
+ private fun requestLocationPermission() {
301
+ val permissions = mutableListOf(*PermissionUtils.LOCAL_PERMISSION)
302
+
303
+ val permissionArray = permissions.toTypedArray()
304
+
305
+ if (hasPermissions(permissionArray)) {
306
+ onLocationPermissionGranted()
307
+ } else {
308
+ val rationaleNeeded = permissionArray.any {
309
+ ActivityCompat.shouldShowRequestPermissionRationale(this, it)
310
+ }
311
+
312
+ if (rationaleNeeded) {
313
+ showPermissionRationale(
314
+ title = "Location Permission Needed",
315
+ message = "We need location access for Bluetooth scanning.",
316
+ onProceed = {
317
+ ActivityCompat.requestPermissions(
318
+ this,
319
+ permissionArray,
320
+ LOCATION_REQUEST_CODE
321
+ )
322
+ }
323
+ )
324
+ } else {
325
+ ActivityCompat.requestPermissions(this, permissionArray, LOCATION_REQUEST_CODE)
326
+ }
281
327
  }
328
+ }
282
329
 
283
- if (rationaleNeeded) {
284
- showPermissionRationale(
285
- title = "Bluetooth Permission Needed",
286
- message = "We need Bluetooth access to connect your device.",
287
- onProceed = {
288
- ActivityCompat.requestPermissions(this, permissions, BLUETOOTH_REQUEST_CODE)
330
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
331
+ private fun requestBluetoothPermission() {
332
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
333
+ val permissions = PermissionUtils.BLUETOOTH_S
334
+
335
+ if (hasPermissions(permissions)) {
336
+ onBluetoothPermissionGranted()
337
+ } else {
338
+ val rationaleNeeded = permissions.any {
339
+ ActivityCompat.shouldShowRequestPermissionRationale(this, it)
340
+ }
341
+
342
+ if (rationaleNeeded) {
343
+ showPermissionRationale(
344
+ title = "Bluetooth Permission Needed",
345
+ message = "We need Bluetooth access to connect your device.",
346
+ onProceed = {
347
+ ActivityCompat.requestPermissions(
348
+ this,
349
+ permissions,
350
+ BLUETOOTH_REQUEST_CODE
351
+ )
352
+ }
353
+ )
354
+ } else {
355
+ ActivityCompat.requestPermissions(this, permissions, BLUETOOTH_REQUEST_CODE)
356
+ }
289
357
  }
290
- )
291
358
  } else {
292
- ActivityCompat.requestPermissions(this, permissions, BLUETOOTH_REQUEST_CODE)
359
+ onBluetoothPermissionGranted()
293
360
  }
294
- }
295
- } else {
296
- onBluetoothPermissionGranted()
297
361
  }
298
- }
299
362
 
300
- private fun showPermissionRationale(title: String, message: String, onProceed: () -> Unit) {
301
- AlertDialog.Builder(this)
302
- .setTitle(title)
303
- .setMessage(message)
304
- .setPositiveButton("OK") { _, _ -> onProceed() }
305
- .setNegativeButton("Cancel", null)
306
- .show()
307
- }
363
+ private fun showPermissionRationale(title: String, message: String, onProceed: () -> Unit) {
364
+ AlertDialog.Builder(this)
365
+ .setTitle(title)
366
+ .setMessage(message)
367
+ .setPositiveButton("OK") { _, _ -> onProceed() }
368
+ .setNegativeButton("Cancel", null)
369
+ .show()
370
+ }
308
371
 
309
372
 
310
- private fun hasPermissions(permissions: Array<String>): Boolean {
311
- return permissions.all {
312
- ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
373
+ private fun hasPermissions(permissions: Array<String>): Boolean {
374
+ return permissions.all {
375
+ ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
376
+ }
313
377
  }
314
- }
315
378
 
316
- private fun areAllPermissionsGranted(): Boolean {
317
- val requiredPermissions = mutableListOf<String>()
379
+ private fun areAllPermissionsGranted(): Boolean {
380
+ val requiredPermissions = mutableListOf<String>()
318
381
 
319
- // Add Bluetooth permissions
320
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
321
- requiredPermissions.addAll(PermissionUtils.BLUETOOTH_S)
322
- }
382
+ // Add Bluetooth permissions
383
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
384
+ requiredPermissions.addAll(PermissionUtils.BLUETOOTH_S)
385
+ }
323
386
 
324
- // Add location permissions
325
- requiredPermissions.addAll(PermissionUtils.LOCAL_PERMISSION)
387
+ // Add location permissions
388
+ requiredPermissions.addAll(PermissionUtils.LOCAL_PERMISSION)
326
389
 
327
- return requiredPermissions.all {
328
- ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
390
+ return requiredPermissions.all {
391
+ ContextCompat.checkSelfPermission(this, it) == PackageManager.PERMISSION_GRANTED
392
+ }
329
393
  }
330
- }
331
-
332
- private fun updateProceedButtonState() {
333
- if (areAllPermissionsGranted() && bluetoothAdapter!!.isEnabled) {
334
- binding.commonButton.btnProceed.alpha = 1f
335
- binding.commonButton.btnProceed.isEnabled = true
336
- } else {
337
- binding.commonButton.btnProceed.alpha = 0.5f
338
- binding.commonButton.btnProceed.isEnabled = false
394
+
395
+ private fun updateProceedButtonState() {
396
+ if (areAllPermissionsGranted() && bluetoothAdapter!!.isEnabled) {
397
+ binding.commonButton.btnProceed.alpha = 1f
398
+ binding.commonButton.btnProceed.isEnabled = true
399
+ } else {
400
+ binding.commonButton.btnProceed.alpha = 0.5f
401
+ binding.commonButton.btnProceed.isEnabled = false
402
+ }
339
403
  }
340
- }
341
404
 
342
- private fun onForegroundLocationGranted() {
343
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
344
- ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
345
- != PackageManager.PERMISSION_GRANTED
346
- ) {
347
- onLocationPermissionGranted()
348
- } else {
349
- Log.d("Permission", "All location permissions granted")
405
+ private fun onForegroundLocationGranted() {
406
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&
407
+ ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)
408
+ != PackageManager.PERMISSION_GRANTED
409
+ ) {
410
+ onLocationPermissionGranted()
411
+ } else {
412
+ Log.d("Permission", "All location permissions granted")
413
+ }
350
414
  }
351
- }
352
-
353
- @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
354
- override fun onRequestPermissionsResult(
355
- requestCode: Int,
356
- permissions: Array<out String>,
357
- grantResults: IntArray
358
- ) {
359
- super.onRequestPermissionsResult(requestCode, permissions, grantResults)
360
- val allGranted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
361
-
362
- when (requestCode) {
415
+
416
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
417
+ override fun onRequestPermissionsResult(
418
+ requestCode: Int,
419
+ permissions: Array<out String>,
420
+ grantResults: IntArray
421
+ ) {
422
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
423
+ val allGranted = grantResults.all { it == PackageManager.PERMISSION_GRANTED }
424
+
425
+ when (requestCode) {
363
426
  // LOCATION_REQUEST_CODE -> {
364
427
  // if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
365
428
  // onForegroundLocationGranted()
@@ -368,71 +431,71 @@ class PermissionActivity : BasePermissionActivity() {
368
431
  // }
369
432
  // }
370
433
 
371
- LOCATION_REQUEST_CODE -> {
372
- if (allGranted) {
373
- onLocationPermissionGranted()
374
- }
375
- }
434
+ LOCATION_REQUEST_CODE -> {
435
+ if (allGranted) {
436
+ onLocationPermissionGranted()
437
+ }
438
+ }
376
439
 
377
- BLUETOOTH_REQUEST_CODE -> {
378
- if (allGranted) {
379
- onBluetoothPermissionGranted()
440
+ BLUETOOTH_REQUEST_CODE -> {
441
+ if (allGranted) {
442
+ onBluetoothPermissionGranted()
443
+ }
444
+ }
380
445
  }
381
- }
446
+ updateProceedButtonState()
382
447
  }
383
- updateProceedButtonState()
384
- }
385
-
386
- private fun onLocationPermissionGranted() {
387
- updateProceedButtonState()
388
- // Start location-based action
389
- }
390
-
391
- @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
392
- private fun onBluetoothPermissionGranted() {
393
- if (bluetoothAdapter == null) {
394
- Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show()
395
- } else {
396
- if (!bluetoothAdapter!!.isEnabled) {
397
- val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
398
- startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
399
- }
448
+
449
+ private fun onLocationPermissionGranted() {
450
+ updateProceedButtonState()
451
+ // Start location-based action
400
452
  }
401
453
 
402
- updateProceedButtonState()
403
- // Start Bluetooth device scan or connect
404
- }
454
+ @RequiresPermission(Manifest.permission.BLUETOOTH_CONNECT)
455
+ private fun onBluetoothPermissionGranted() {
456
+ if (bluetoothAdapter == null) {
457
+ Toast.makeText(this, "Bluetooth not supported", Toast.LENGTH_SHORT).show()
458
+ } else {
459
+ if (!bluetoothAdapter!!.isEnabled) {
460
+ val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
461
+ startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
462
+ }
463
+ }
405
464
 
406
- override fun onResume() {
407
- super.onResume()
408
- updateProceedButtonState()
409
- }
465
+ updateProceedButtonState()
466
+ // Start Bluetooth device scan or connect
467
+ }
410
468
 
411
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
412
- super.onActivityResult(requestCode, resultCode, data)
413
- if (requestCode == REQUEST_ENABLE_BT) {
414
- if (resultCode == RESULT_OK) {
469
+ override fun onResume() {
470
+ super.onResume()
415
471
  updateProceedButtonState()
416
- }
417
472
  }
418
- }
473
+
474
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
475
+ super.onActivityResult(requestCode, resultCode, data)
476
+ if (requestCode == REQUEST_ENABLE_BT) {
477
+ if (resultCode == RESULT_OK) {
478
+ updateProceedButtonState()
479
+ }
480
+ }
481
+ }
419
482
  }
420
483
 
421
484
  object PermissionUtils {
422
- @RequiresApi(Build.VERSION_CODES.S)
423
- val BLUETOOTH_S = arrayOf(
424
- Manifest.permission.BLUETOOTH_ADVERTISE,
425
- Manifest.permission.BLUETOOTH_CONNECT,
426
- Manifest.permission.BLUETOOTH_SCAN
427
- )
428
-
429
- val LOCAL_PERMISSION = arrayOf(
430
- Manifest.permission.ACCESS_FINE_LOCATION,
431
- Manifest.permission.ACCESS_COARSE_LOCATION
432
- )
433
-
434
-
435
- val CAMERA_PERMISSION = arrayOf(
436
- Manifest.permission.CAMERA
437
- )
485
+ @RequiresApi(Build.VERSION_CODES.S)
486
+ val BLUETOOTH_S = arrayOf(
487
+ Manifest.permission.BLUETOOTH_ADVERTISE,
488
+ Manifest.permission.BLUETOOTH_CONNECT,
489
+ Manifest.permission.BLUETOOTH_SCAN
490
+ )
491
+
492
+ val LOCAL_PERMISSION = arrayOf(
493
+ Manifest.permission.ACCESS_FINE_LOCATION,
494
+ Manifest.permission.ACCESS_COARSE_LOCATION
495
+ )
496
+
497
+
498
+ val CAMERA_PERMISSION = arrayOf(
499
+ Manifest.permission.CAMERA
500
+ )
438
501
  }