mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-21 07:51:46 +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:
@@ -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) {
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user