1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-20 23:41:45 +02:00

Make it possible to disconnect bluetooth

by clicking on the bluetooth button when bluetooth is connected. As
requested in #235.
This commit is contained in:
Erik Johansson
2018-04-08 00:09:55 +02:00
parent d95976c7fe
commit c5431dfa2c
2 changed files with 15 additions and 6 deletions

View File

@@ -488,11 +488,14 @@ public class OpenScale {
return true;
}
public void stopSearchingForBluetooth() {
public boolean stopSearchingForBluetooth() {
if (btCom != null) {
btCom.stopSearching();
btCom = null;
Log.d("OpenScale", "Bluetooth Server explicit stopped!");
return true;
}
return false;
}
public void registerFragment(FragmentUpdateListener fragment) {

View File

@@ -430,24 +430,31 @@ public class MainActivity extends BaseAppCompatActivity
}
private void invokeSearchBluetoothDevice() {
if (OpenScale.getInstance(getApplicationContext()).getSelectedScaleUserId() == -1) {
final OpenScale openScale = OpenScale.getInstance(getApplicationContext());
if (openScale.getSelectedScaleUserId() == -1) {
showNoSelectedUserDialog();
return;
}
if (openScale.stopSearchingForBluetooth()) {
setBluetoothStatusIcon(R.drawable.ic_bluetooth_disabled);
return;
}
String deviceName = prefs.getString("btDeviceName", "-");
boolean permGrantedCoarseLocation = false;
// Check if Bluetooth 4.x is available
if (deviceName != "openScale_MCU") {
if (!deviceName.equals("openScale_MCU")) {
permGrantedCoarseLocation = PermissionHelper.requestBluetoothPermission(this, false);
} else {
permGrantedCoarseLocation = PermissionHelper.requestBluetoothPermission(this, true);
}
if (permGrantedCoarseLocation) {
if (deviceName == "-") {
if (deviceName.equals("-")) {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_no_device_set), Toast.LENGTH_SHORT).show();
return;
}
@@ -455,8 +462,7 @@ public class MainActivity extends BaseAppCompatActivity
Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_try_connection) + " " + deviceName, Toast.LENGTH_SHORT).show();
setBluetoothStatusIcon(R.drawable.ic_bluetooth_searching);
OpenScale.getInstance(getApplicationContext()).stopSearchingForBluetooth();
if (!OpenScale.getInstance(getApplicationContext()).startSearchingForBluetooth(deviceName, callbackBtHandler)) {
if (!openScale.startSearchingForBluetooth(deviceName, callbackBtHandler)) {
Toast.makeText(getApplicationContext(), deviceName + " " + getResources().getString(R.string.label_bt_device_no_support), Toast.LENGTH_SHORT).show();
}
}