Remove callbacks when scanning finished in RileyLink selection
This commit is contained in:
parent
12ea97aa6f
commit
051e811571
1 changed files with 9 additions and 8 deletions
|
@ -68,9 +68,15 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity {
|
||||||
private BluetoothLeScanner bleScanner;
|
private BluetoothLeScanner bleScanner;
|
||||||
private LeDeviceListAdapter deviceListAdapter;
|
private LeDeviceListAdapter deviceListAdapter;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
|
|
||||||
public boolean scanning;
|
public boolean scanning;
|
||||||
|
|
||||||
|
private final Runnable stopScanAfterTimeoutRunnable = () -> {
|
||||||
|
if (scanning) {
|
||||||
|
stopLeDeviceScan();
|
||||||
|
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); // Reconnect current RL
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -242,13 +248,7 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity {
|
||||||
deviceListAdapter.clear();
|
deviceListAdapter.clear();
|
||||||
deviceListAdapter.notifyDataSetChanged();
|
deviceListAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
// Stops scanning after a pre-defined scan period.
|
handler.postDelayed(stopScanAfterTimeoutRunnable, SCAN_PERIOD_MILLIS);
|
||||||
handler.postDelayed(() -> {
|
|
||||||
if (scanning) {
|
|
||||||
stopLeDeviceScan();
|
|
||||||
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); // Reconnect current RL
|
|
||||||
}
|
|
||||||
}, SCAN_PERIOD_MILLIS);
|
|
||||||
|
|
||||||
buttonStartScan.setEnabled(false);
|
buttonStartScan.setEnabled(false);
|
||||||
buttonStopScan.setVisibility(View.VISIBLE);
|
buttonStopScan.setVisibility(View.VISIBLE);
|
||||||
|
@ -267,6 +267,7 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "stopLeDeviceScan: Scanning Stop");
|
aapsLogger.debug(LTag.PUMPBTCOMM, "stopLeDeviceScan: Scanning Stop");
|
||||||
Toast.makeText(this, R.string.riley_link_ble_config_scan_finished, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.riley_link_ble_config_scan_finished, Toast.LENGTH_SHORT).show();
|
||||||
|
handler.removeCallbacks(stopScanAfterTimeoutRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonStartScan.setEnabled(true);
|
buttonStartScan.setEnabled(true);
|
||||||
|
|
Loading…
Reference in a new issue