diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java index ed24669ce4..d8a6be8200 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCommon/dialog/RileyLinkBLEScanActivity.java @@ -128,7 +128,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { } }); - startScanBLE(); + prepareForScanning(); } @@ -150,16 +150,19 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.rileylink_miScan: + case R.id.rileylink_miScan: { + // FIXME scanLeDevice(true); return true; + } + default: return super.onOptionsItemSelected(item); } } - public void startScanBLE() { + public void prepareForScanning() { // https://developer.android.com/training/permissions/requesting.html // http://developer.radiusnetworks.com/2015/09/29/is-your-beacon-app-ready-for-android-6.html if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { @@ -194,10 +197,11 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid( ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); - scanLeDevice(true); + // scanLeDevice(true); } } + // disable currently selected RL, so that we can discover it RileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect); } @@ -224,13 +228,9 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { Log.d(TAG, scanRecord.toString()); - runOnUiThread(new Runnable() { - - @Override - public void run() { - if (addDevice(scanRecord)) - mLeDeviceListAdapter.notifyDataSetChanged(); - } + runOnUiThread(() -> { + if (addDevice(scanRecord)) + mLeDeviceListAdapter.notifyDataSetChanged(); }); } @@ -238,22 +238,18 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { @Override public void onBatchScanResults(final List results) { - runOnUiThread(new Runnable() { + runOnUiThread(() -> { - @Override - public void run() { + boolean added = false; - boolean added = false; + for (ScanResult result : results) { - for (ScanResult result : results) { - - if (addDevice(result)) - added = true; - } - - if (added) - mLeDeviceListAdapter.notifyDataSetChanged(); + if (addDevice(result)) + added = true; } + + if (added) + mLeDeviceListAdapter.notifyDataSetChanged(); }); } @@ -293,7 +289,6 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { private String getDeviceDebug(BluetoothDevice device) { - return "BluetoothDevice [name=" + device.getName() + ", address=" + device.getAddress() + // ", type=" + device.getType(); // + ", alias=" + device.getAlias(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java index 02c71946aa..bd86b4a744 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMedtronic/MedtronicFragment.java @@ -252,80 +252,85 @@ public class MedtronicFragment extends SubscriberFragment { pumpStatus.rileyLinkError = (RileyLinkError)checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError()); - if (pumpStatus.rileyLinkError != null) { - int resourceId = pumpStatus.rileyLinkError.getResourceId(getTargetDevice()); - errorsView.setText(getTranslation(resourceId)); - } else - errorsView.setText("-"); + if (errorsView != null) { + if (pumpStatus.rileyLinkError != null) { + int resourceId = pumpStatus.rileyLinkError.getResourceId(getTargetDevice()); + errorsView.setText(getTranslation(resourceId)); + } else + errorsView.setText("-"); + } pumpStatus.pumpDeviceState = (PumpDeviceState)checkStatusSet(pumpStatus.pumpDeviceState, MedtronicUtil.getPumpDeviceState()); - if (pumpStatus.pumpDeviceState != null) { - // TODO Pump State + if (pumpStatusIconView != null) { - switch (pumpStatus.pumpDeviceState) { - case Sleeping: - pumpStatusIconView.setText("{fa-bed} "); // + pumpStatus.pumpDeviceState.name()); - break; + if (pumpStatus.pumpDeviceState != null) { + // TODO Pump State - case NeverContacted: - case WakingUp: - case PumpUnreachable: - case ErrorWhenCommunicating: - case TimeoutWhenCommunicating: - case InvalidConfiguration: - pumpStatusIconView.setText(" " + getTranslation(pumpStatus.pumpDeviceState.getResourceId())); - break; + switch (pumpStatus.pumpDeviceState) { + case Sleeping: + pumpStatusIconView.setText("{fa-bed} "); // + pumpStatus.pumpDeviceState.name()); + break; - // FIXME - case Active: { - MedtronicCommandType cmd = MedtronicUtil.getCurrentCommand(); + case NeverContacted: + case WakingUp: + case PumpUnreachable: + case ErrorWhenCommunicating: + case TimeoutWhenCommunicating: + case InvalidConfiguration: + pumpStatusIconView.setText(" " + getTranslation(pumpStatus.pumpDeviceState.getResourceId())); + break; - LOG.debug("Command: " + cmd); + // FIXME + case Active: { + MedtronicCommandType cmd = MedtronicUtil.getCurrentCommand(); - if (cmd == null) - pumpStatusIconView.setText(" " + MainApp.gs(pumpStatus.pumpDeviceState.getResourceId())); - else { - Integer resourceId = cmd.getResourceId(); + LOG.debug("Command: " + cmd); - if (cmd == MedtronicCommandType.GetHistoryData) { + if (cmd == null) + pumpStatusIconView.setText(" " + MainApp.gs(pumpStatus.pumpDeviceState.getResourceId())); + else { + Integer resourceId = cmd.getResourceId(); + + if (cmd == MedtronicCommandType.GetHistoryData) { + + if (MedtronicUtil.frameNumber == null) { + pumpStatusIconView.setText(MainApp.gs( + R.string.medtronic_cmd_desc_get_history_request, MedtronicUtil.pageNumber)); + } else { + pumpStatusIconView.setText(MainApp.gs(resourceId, MedtronicUtil.pageNumber, + MedtronicUtil.frameNumber)); + } - if (MedtronicUtil.frameNumber == null) { - pumpStatusIconView.setText(MainApp.gs(R.string.medtronic_cmd_desc_get_history_request, - MedtronicUtil.pageNumber)); } else { - pumpStatusIconView.setText(MainApp.gs(resourceId, MedtronicUtil.pageNumber, - MedtronicUtil.frameNumber)); + if (resourceId == null) { + pumpStatusIconView.setText(" " + cmd.name()); + } else { + pumpStatusIconView.setText(" " + getTranslation(resourceId)); + } } - } else { - if (resourceId == null) { - pumpStatusIconView.setText(" " + cmd.name()); - } else { - pumpStatusIconView.setText(" " + getTranslation(resourceId)); - } } } + break; + // // FIXME + // + // pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name()); + // break; + // + // // FIXME + // + // pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name()); + // break; + default: + LOG.warn("Unknown pump state: " + pumpStatus.pumpDeviceState); } - break; - - // // FIXME - // - // pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name()); - // break; - // - // // FIXME - // - // pumpStatusIconView.setText(" " + pumpStatus.pumpDeviceState.name()); - // break; - default: - LOG.warn("Unknown pump state: " + pumpStatus.pumpDeviceState); + } else { + pumpStatusIconView.setText("{fa-bed} "); } - } else { - pumpStatusIconView.setText("{fa-bed} "); } if (queueView != null) { diff --git a/app/src/main/res/menu/menu_rileylink_ble_scan.xml b/app/src/main/res/menu/menu_rileylink_ble_scan.xml index aea8fbaa96..65e8422435 100644 --- a/app/src/main/res/menu/menu_rileylink_ble_scan.xml +++ b/app/src/main/res/menu/menu_rileylink_ble_scan.xml @@ -5,7 +5,6 @@ \ No newline at end of file