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

Commit b11dbc5

Browse files
committed
2020-02-18 Version 1.3.0: Added Bluetooth status check
1 parent ba554d8 commit b11dbc5

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ android {
1212
minSdkVersion 21
1313
targetSdkVersion 29
1414
versionCode 1
15-
versionName "1.2.0"
15+
versionName "1.3.0"
1616

1717
buildConfigField "String", "API_IMPL", "\"\""
1818
}

app/src/main/java/com/smlnskgmail/jaman/remotetemperaturecontrol/logic/monitor/MonitorFragment.kt

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,43 @@ class MonitorFragment : BaseFragment(), BtMonitorTarget {
3737
view: View,
3838
savedInstanceState: Bundle?
3939
) {
40-
if (BuildConfig.API_IMPL == "DEVICE_BT") {
41-
if (btIsEnabled()) {
42-
btAdapter = BluetoothAdapter.getDefaultAdapter()
43-
val btDevices = getBtDevices()
44-
if (btDevices.isNotEmpty()) {
45-
btMonitor = DeviceBtMonitor(this)
46-
showDevicesList(btDevices)
40+
btAdapter = BluetoothAdapter.getDefaultAdapter()
41+
if (bluetoothIsEnabled()) {
42+
@Suppress("ConstantConditionIf")
43+
if (BuildConfig.API_IMPL == "DEVICE_BT") {
44+
if (btIsEnabled()) {
45+
val btDevices = getBtDevices()
46+
if (btDevices.isNotEmpty()) {
47+
btMonitor = DeviceBtMonitor(this)
48+
showDevicesList(btDevices)
49+
} else {
50+
showBtDevicesNotFoundWarning()
51+
}
4752
} else {
48-
showBtDevicesNotFoundWarning()
53+
showBtDisabledWarning()
4954
}
5055
} else {
51-
showBtDisabledWarning()
56+
startInDebugMode()
57+
initializeButtons()
5258
}
5359
} else {
54-
startInDebugMode()
55-
initializeButtons()
60+
AppDialog.show(
61+
context!!,
62+
R.string.bluetooth_error_dialog_title,
63+
R.string.bluetooth_error_dialog_message,
64+
R.string.bluetooth_error_dialog_button_text,
65+
DialogInterface.OnClickListener { dialog, _ ->
66+
dialog.cancel()
67+
activity!!.finish()
68+
}
69+
)
5670
}
5771
}
5872

73+
private fun bluetoothIsEnabled(): Boolean {
74+
return btAdapter!!.isEnabled
75+
}
76+
5977
@SuppressLint("SetTextI18n")
6078
private fun startInDebugMode() {
6179
btMonitor = DebugBtMonitor(this)

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323
<!-- Messages -->
2424
<string name="message_bt_is_disabled">Bluetooth is disabled on this device! Please enable Bluetooth and restart app</string>
2525
<string name="message_no_available_devices">Cannot find available Bluetooth devices! Please add specified Bluetooth device and restart app</string>
26+
27+
<!-- Bluetooth error dialog -->
28+
<string name="bluetooth_error_dialog_title">Error</string>
29+
<string name="bluetooth_error_dialog_message">Enable Bluetooth and run app again</string>
30+
<string name="bluetooth_error_dialog_button_text">Exit</string>
2631
</resources>

0 commit comments

Comments
 (0)