From 0114f010e35b719eb5e28102a5b65a5729ca04e6 Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Wed, 4 Dec 2024 00:44:18 +0300 Subject: [PATCH] bluetooth: smoother checks (fixes #2090) (#2154) Co-authored-by: dogi --- .../io/treehouses/remote/bases/FragmentViewModel.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/FragmentViewModel.kt b/app/src/main/kotlin/io/treehouses/remote/bases/FragmentViewModel.kt index 62fda3ece..206d3e11e 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/FragmentViewModel.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/FragmentViewModel.kt @@ -110,9 +110,14 @@ open class FragmentViewModel(application: Application) : AndroidViewModel(applic * Load the bluetooth service and update the handler and connection status */ fun loadBT() { - mChatService = getApplication().getCurrentBluetoothService()!! - mChatService.updateHandler(mHandler) - _connectionStatus.value = mChatService.state + val bluetoothService = getApplication().getCurrentBluetoothService() + if (bluetoothService != null) { + mChatService = bluetoothService + mChatService.updateHandler(mHandler) + _connectionStatus.value = mChatService.state + } else { + _connectionStatus.value = Constants.STATE_NONE + } } /**