Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

Commit

Permalink
2020-02-18 Version 1.3.0: Added Bluetooth status check
Browse files Browse the repository at this point in the history
  • Loading branch information
fartem committed Feb 18, 2020
1 parent ba554d8 commit b11dbc5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.2.0"
versionName "1.3.0"

buildConfigField "String", "API_IMPL", "\"\""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,43 @@ class MonitorFragment : BaseFragment(), BtMonitorTarget {
view: View,
savedInstanceState: Bundle?
) {
if (BuildConfig.API_IMPL == "DEVICE_BT") {
if (btIsEnabled()) {
btAdapter = BluetoothAdapter.getDefaultAdapter()
val btDevices = getBtDevices()
if (btDevices.isNotEmpty()) {
btMonitor = DeviceBtMonitor(this)
showDevicesList(btDevices)
btAdapter = BluetoothAdapter.getDefaultAdapter()
if (bluetoothIsEnabled()) {
@Suppress("ConstantConditionIf")
if (BuildConfig.API_IMPL == "DEVICE_BT") {
if (btIsEnabled()) {
val btDevices = getBtDevices()
if (btDevices.isNotEmpty()) {
btMonitor = DeviceBtMonitor(this)
showDevicesList(btDevices)
} else {
showBtDevicesNotFoundWarning()
}
} else {
showBtDevicesNotFoundWarning()
showBtDisabledWarning()
}
} else {
showBtDisabledWarning()
startInDebugMode()
initializeButtons()
}
} else {
startInDebugMode()
initializeButtons()
AppDialog.show(
context!!,
R.string.bluetooth_error_dialog_title,
R.string.bluetooth_error_dialog_message,
R.string.bluetooth_error_dialog_button_text,
DialogInterface.OnClickListener { dialog, _ ->
dialog.cancel()
activity!!.finish()
}
)
}
}

private fun bluetoothIsEnabled(): Boolean {
return btAdapter!!.isEnabled
}

@SuppressLint("SetTextI18n")
private fun startInDebugMode() {
btMonitor = DebugBtMonitor(this)
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
<!-- Messages -->
<string name="message_bt_is_disabled">Bluetooth is disabled on this device! Please enable Bluetooth and restart app</string>
<string name="message_no_available_devices">Cannot find available Bluetooth devices! Please add specified Bluetooth device and restart app</string>

<!-- Bluetooth error dialog -->
<string name="bluetooth_error_dialog_title">Error</string>
<string name="bluetooth_error_dialog_message">Enable Bluetooth and run app again</string>
<string name="bluetooth_error_dialog_button_text">Exit</string>
</resources>

0 comments on commit b11dbc5

Please sign in to comment.