1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 09:17:29 +01:00

Improved UX when Bluetooth is disabled mid-scan

This commit is contained in:
TaaviE 2020-08-02 21:55:16 +03:00
parent 9627360fac
commit d7ce49a2f3

View File

@ -543,22 +543,27 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
private void startOldBTLEDiscovery() { private void startOldBTLEDiscovery() {
LOG.info("Starting old BLE discovery"); LOG.info("Starting old BLE discovery");
setIsScanning(Scanning.SCANNING_BLE);
handler.removeMessages(0, stopRunnable); handler.removeMessages(0, stopRunnable);
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION); handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
adapter.startLeScan(leScanCallback); if(adapter.startLeScan(leScanCallback)) {
LOG.info("Old Bluetooth LE scan started successfully");
setIsScanning(Scanning.SCANNING_BLE);
bluetoothLEProgress.setVisibility(View.VISIBLE); bluetoothLEProgress.setVisibility(View.VISIBLE);
} else {
LOG.info("Old Bluetooth LE scan starting failed");
setIsScanning(Scanning.SCANNING_OFF);
bluetoothLEProgress.setVisibility(View.GONE);
}
} }
private void stopOldBLEDiscovery() { private void stopOldBLEDiscovery() {
if (adapter != null) { if (adapter != null) {
adapter.stopLeScan(leScanCallback); adapter.stopLeScan(leScanCallback);
setIsScanning(Scanning.SCANNING_OFF);
LOG.info("Stopped old BLE discovery"); LOG.info("Stopped old BLE discovery");
} }
setIsScanning(Scanning.SCANNING_OFF);
bluetoothLEProgress.setVisibility(View.GONE); bluetoothLEProgress.setVisibility(View.GONE);
} }
@ -568,7 +573,6 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void startBTLEDiscovery() { private void startBTLEDiscovery() {
LOG.info("Starting BLE discovery"); LOG.info("Starting BLE discovery");
setIsScanning(Scanning.SCANNING_BLE);
handler.removeMessages(0, stopRunnable); handler.removeMessages(0, stopRunnable);
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION); handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
@ -577,6 +581,8 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
// not really required. // not really required.
adapter.getBluetoothLeScanner().startScan(null, getScanSettings(), getScanCallback()); adapter.getBluetoothLeScanner().startScan(null, getScanSettings(), getScanCallback());
LOG.debug("Bluetooth LE discovery started successfully");
setIsScanning(Scanning.SCANNING_BLE);
bluetoothLEProgress.setVisibility(View.VISIBLE); bluetoothLEProgress.setVisibility(View.VISIBLE);
} }
@ -618,7 +624,7 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
handler.removeMessages(0, stopRunnable); handler.removeMessages(0, stopRunnable);
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION); handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
if (adapter.startDiscovery()) { if (adapter.startDiscovery()) {
LOG.debug("Discovery starting successful"); LOG.debug("Discovery started successfully");
bluetoothProgress.setVisibility(View.VISIBLE); bluetoothProgress.setVisibility(View.VISIBLE);
setIsScanning(what); setIsScanning(what);
} else { } else {
@ -663,8 +669,11 @@ public class DiscoveryActivity extends AbstractGBActivity implements AdapterView
} else { } else {
this.adapter = null; this.adapter = null;
startButton.setEnabled(false); startButton.setEnabled(false);
bluetoothProgress.setVisibility(View.GONE);
bluetoothLEProgress.setVisibility(View.GONE);
} }
setIsScanning(Scanning.SCANNING_OFF);
discoveryFinished(); discoveryFinished();
} }