From 051e811571a01dedd8ce7f1291eced7786e705ec Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sat, 26 Dec 2020 18:24:00 +0100 Subject: [PATCH] Remove callbacks when scanning finished in RileyLink selection --- .../dialog/RileyLinkBLEConfigActivity.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEConfigActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEConfigActivity.java index 1613d026aa..7a65e186ee 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEConfigActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEConfigActivity.java @@ -68,9 +68,15 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity { private BluetoothLeScanner bleScanner; private LeDeviceListAdapter deviceListAdapter; private Handler handler; - public boolean scanning; + private final Runnable stopScanAfterTimeoutRunnable = () -> { + if (scanning) { + stopLeDeviceScan(); + rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); // Reconnect current RL + } + }; + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -242,13 +248,7 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity { deviceListAdapter.clear(); deviceListAdapter.notifyDataSetChanged(); - // Stops scanning after a pre-defined scan period. - handler.postDelayed(() -> { - if (scanning) { - stopLeDeviceScan(); - rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); // Reconnect current RL - } - }, SCAN_PERIOD_MILLIS); + handler.postDelayed(stopScanAfterTimeoutRunnable, SCAN_PERIOD_MILLIS); buttonStartScan.setEnabled(false); buttonStopScan.setVisibility(View.VISIBLE); @@ -267,6 +267,7 @@ public class RileyLinkBLEConfigActivity extends NoSplashAppCompatActivity { aapsLogger.debug(LTag.PUMPBTCOMM, "stopLeDeviceScan: Scanning Stop"); Toast.makeText(this, R.string.riley_link_ble_config_scan_finished, Toast.LENGTH_SHORT).show(); + handler.removeCallbacks(stopScanAfterTimeoutRunnable); } buttonStartScan.setEnabled(true);