From e4b26498075707d5d086c893698e7b01b3b166c6 Mon Sep 17 00:00:00 2001 From: Ayub Date: Tue, 23 Aug 2022 16:52:39 +0100 Subject: [PATCH 1/2] Shows prompt when Bluetooth is off and trying to add device When trying to add a Meshtastic device, the app will check if bluetooth is turned on, if it isn't then it will display a message. --- .../com/geeksville/mesh/ui/SettingsFragment.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index 3326883c6..bf24fa73b 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -1,5 +1,6 @@ package com.geeksville.mesh.ui +import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice import android.companion.CompanionDeviceManager import android.content.* @@ -475,6 +476,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { if (!myActivity.hasScanPermission()) { myActivity.requestScanPermission() } else { + checkBTEnabled() if (!scanModel.hasCompanionDeviceApi) checkLocationEnabled() scanLeDevice() } @@ -501,6 +503,18 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { } } + private fun checkBTEnabled( + warningReason: String = getString(R.string.requires_bluetooth) + ) { + + var btAdapter = BluetoothAdapter.getDefaultAdapter(); + + if (!(btAdapter.isEnabled())) { + warn("We need bluetooth") + showSnackbar(warningReason) + } + } + private val updateProgressFilter = IntentFilter(SoftwareUpdateService.ACTION_UPDATE_PROGRESS) private val updateProgressReceiver: BroadcastReceiver = object : BroadcastReceiver() { From 1251c76ff0a60ae60243b0deb0b8b1357f52c294 Mon Sep 17 00:00:00 2001 From: legendgroupv2 <73121875+legendgroupv2@users.noreply.github.com> Date: Tue, 30 Aug 2022 10:45:54 +0100 Subject: [PATCH 2/2] Changes how bluetooth state is checked for bluetooth check. Co-authored-by: Andre K --- app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt index bf24fa73b..68b7f44fb 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/SettingsFragment.kt @@ -506,10 +506,7 @@ class SettingsFragment : ScreenFragment("Settings"), Logging { private fun checkBTEnabled( warningReason: String = getString(R.string.requires_bluetooth) ) { - - var btAdapter = BluetoothAdapter.getDefaultAdapter(); - - if (!(btAdapter.isEnabled())) { + if (bluetoothViewModel.enabled.value == false) { warn("We need bluetooth") showSnackbar(warningReason) }