From f0a96866af8fcd4acc6a59f43177f46359210222 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 23 Dec 2020 22:27:27 +0100 Subject: [PATCH 01/22] NumberPicker better check for allowed range --- .../androidaps/utils/ui/NumberPicker.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.java b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.java index 0c77607cb8..02dfe36f81 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.java +++ b/core/src/main/java/info/nightscout/androidaps/utils/ui/NumberPicker.java @@ -132,12 +132,10 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, setTextWatcher(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - } @Override @@ -153,11 +151,10 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, } }); - editText.setOnFocusChangeListener(new OnFocusChangeListener() { - @Override public void onFocusChange(View v, boolean hasFocus) { - focused = hasFocus; - updateEditText(); - } + editText.setOnFocusChangeListener((v, hasFocus) -> { + focused = hasFocus; + if (!focused) getValue(); // check min/max + updateEditText(); }); } @@ -204,12 +201,12 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, editText.addTextChangedListener(textWatcher); } - public void setParams(Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formater, boolean allowZero, Button okButton) { + public void setParams(Double initValue, Double minValue, Double maxValue, Double step, NumberFormat formatter, boolean allowZero, Button okButton) { this.value = initValue; this.minValue = minValue; this.maxValue = maxValue; this.step = step; - this.formatter = formater; + this.formatter = formatter; this.allowZero = allowZero; callValueChangedListener(); this.okButton = okButton; @@ -234,6 +231,14 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener, } public Double getValue() { + if (value > maxValue) { + value = maxValue; + ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit)); + } + if (value < minValue) { + value = minValue; + ToastUtils.showToastInUiThread(getContext(), getContext().getString(R.string.youareonallowedlimit)); + } return value; } From 953783e325e7e08062ba65710e0f5272ed23aa54 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 23 Dec 2020 22:28:09 +0100 Subject: [PATCH 02/22] CPP_MAX_PERCENTAGE = 250 --- core/src/main/java/info/nightscout/androidaps/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/Constants.java b/core/src/main/java/info/nightscout/androidaps/Constants.java index 474addaa38..355b560ee8 100644 --- a/core/src/main/java/info/nightscout/androidaps/Constants.java +++ b/core/src/main/java/info/nightscout/androidaps/Constants.java @@ -30,7 +30,7 @@ public class Constants { // Circadian Percentage Profile public static final int CPP_MIN_PERCENTAGE = 30; - public static final int CPP_MAX_PERCENTAGE = 200; + public static final int CPP_MAX_PERCENTAGE = 250; public static final int CPP_MIN_TIMESHIFT = -6; public static final int CPP_MAX_TIMESHIFT = 23; From 422c78d30fb6da46b37ef1b236ff3530b8d799ce Mon Sep 17 00:00:00 2001 From: Philoul Date: Wed, 23 Dec 2020 22:42:21 +0100 Subject: [PATCH 03/22] Minor Layout improvements (if long label used) --- app/src/main/res/layout/dialog_carbs.xml | 15 ++++++++------ .../main/res/layout/dialog_profileswitch.xml | 20 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index e5c5af48aa..cd37c4795d 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -83,9 +83,10 @@ @@ -116,9 +117,10 @@ @@ -149,9 +151,10 @@ diff --git a/app/src/main/res/layout/dialog_profileswitch.xml b/app/src/main/res/layout/dialog_profileswitch.xml index 66e308d2ad..45a13d2f1e 100644 --- a/app/src/main/res/layout/dialog_profileswitch.xml +++ b/app/src/main/res/layout/dialog_profileswitch.xml @@ -81,9 +81,10 @@ @@ -115,9 +116,10 @@ @@ -148,9 +150,10 @@ @@ -181,9 +184,10 @@ From 554b14e9ef7efd94c9a73f65e4075d3f49852b3c Mon Sep 17 00:00:00 2001 From: Philoul Date: Thu, 24 Dec 2020 11:06:50 +0100 Subject: [PATCH 04/22] Increase height of Compact Tab and Profile/TT row --- .../java/info/nightscout/androidaps/MainActivity.kt | 6 +++++- .../res/layout/overview_loop_pumpstatus_layout.xml | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index 951638d9ae..71ead679db 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -225,7 +225,11 @@ class MainActivity : NoSplashAppCompatActivity() { if (sp.getBoolean(R.string.key_short_tabtitles, false)) { tabs_normal.visibility = View.GONE tabs_compact.visibility = View.VISIBLE - toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, resources.getDimension(R.dimen.compact_height).toInt()) + val typedValue = TypedValue() + if (theme.resolveAttribute(R.attr.actionBarSize, typedValue, true)) { + toolbar.layoutParams = LinearLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT, + TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics)) + } TabLayoutMediator(tabs_compact, main_pager) { tab, position -> tab.text = (main_pager.adapter as TabPageAdapter).getPluginAt(position).nameShort }.attach() diff --git a/app/src/main/res/layout/overview_loop_pumpstatus_layout.xml b/app/src/main/res/layout/overview_loop_pumpstatus_layout.xml index 98c0d0bd62..d52d6007b9 100644 --- a/app/src/main/res/layout/overview_loop_pumpstatus_layout.xml +++ b/app/src/main/res/layout/overview_loop_pumpstatus_layout.xml @@ -19,8 +19,8 @@ android:layout_marginEnd="5dp" android:layout_weight="1" android:gravity="center_vertical|center_horizontal" - android:paddingTop="3dp" - android:paddingBottom="3dp" + android:paddingTop="6dp" + android:paddingBottom="6dp" android:text="Profile" android:textAppearance="?android:attr/textAppearanceSmall" /> @@ -31,8 +31,8 @@ android:layout_gravity="end" android:layout_weight="1" android:gravity="center_vertical|center_horizontal" - android:paddingTop="3dp" - android:paddingBottom="3dp" + android:paddingTop="6dp" + android:paddingBottom="6dp" android:text="TempTarget" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/mdtp_white" /> @@ -53,8 +53,8 @@ android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:gravity="center_vertical|center_horizontal" - android:paddingTop="3dp" - android:paddingBottom="3dp" + android:paddingTop="6dp" + android:paddingBottom="6dp" android:text="@string/initializing" android:textAppearance="?android:attr/textAppearanceSmall" /> From 1e3ea8f74fc8f625b3d99c430e12fc142a8238bb Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Thu, 24 Dec 2020 22:25:25 +0100 Subject: [PATCH 05/22] Show connected RileyLink name --- .../pump/common/hw/rileylink/ble/RFSpy.java | 11 ++++++++ .../RileyLinkStatusGeneralFragment.java | 16 ++++++++--- .../service/RileyLinkBroadcastReceiver.java | 10 +++++-- .../service/RileyLinkServiceData.java | 1 + .../res/layout/rileylink_status_general.xml | 28 +++++++++++++++++++ rileylink/src/main/res/values/strings.xml | 1 + 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index 6e502e6c36..4df1a22389 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -112,6 +112,17 @@ public class RFSpy { reader.newDataIsAvailable(); } + public String getBleDeviceName() { + BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(UUID.fromString(GattAttributes.SERVICE_GAP), UUID.fromString(GattAttributes.CHARA_GAP_NAME)); + if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { + String value = new String(result.value); + aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", value); + return value; + } else { + aapsLogger.error(LTag.PUMPBTCOMM, "getBleDeviceName failed with code: " + result.resultCode); + return null; + } + } public Integer getBatteryLevel() { BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index 576e04e436..3c0a156c76 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -6,6 +6,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import org.apache.commons.lang3.StringUtils; import org.joda.time.LocalDateTime; import java.util.Locale; @@ -31,6 +32,8 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper; public class RileyLinkStatusGeneralFragment extends DaggerFragment implements RefreshableInterface { + private static final String PLACEHOLDER = "-"; + @Inject ActivePluginProvider activePlugin; @Inject ResourceHelper resourceHelper; @Inject AAPSLogger aapsLogger; @@ -39,6 +42,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re TextView connectionStatus; TextView configuredAddress; + TextView connectedRileyLinkName; TextView connectedDevice; TextView connectionError; TextView deviceType; @@ -65,6 +69,7 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status); this.configuredAddress = getActivity().findViewById(R.id.rls_t1_configured_address); + this.connectedRileyLinkName = getActivity().findViewById(R.id.rls_t1_connected_riley_link_name); this.connectedDevice = getActivity().findViewById(R.id.rls_t1_connected_device); this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error); this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type); @@ -75,10 +80,11 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact); this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version); + // BS: FIXME Remove if (!first) { // 7-14 - int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // + int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv14, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12, R.id.rls_t1_tv13}; for (int id : ids) { @@ -100,14 +106,16 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); + // BS FIXME rileyLinkServiceData is injected so I suppose it cannot be null? if (rileyLinkServiceData != null) { - this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); + this.configuredAddress.setText(StringUtils.isEmpty(rileyLinkServiceData.rileylinkAddress) ? PLACEHOLDER : rileyLinkServiceData.rileylinkAddress); + this.connectedRileyLinkName.setText(StringUtils.isEmpty(rileyLinkServiceData.rileyLinkName) ? PLACEHOLDER : rileyLinkServiceData.rileyLinkName); this.connectionError.setText(rileyLinkServiceData.rileyLinkError == null ? // - "-" + PLACEHOLDER : resourceHelper.gs(rileyLinkServiceData.rileyLinkError.getResourceId(targetDevice))); if (firmwareVersion == null) { - this.firmwareVersion.setText("BLE113: -\nCC110: -"); + this.firmwareVersion.setText("BLE113: " + PLACEHOLDER + "\nCC110: " + PLACEHOLDER); } else { this.firmwareVersion.setText("BLE113: " + rileyLinkServiceData.versionBLE113 + "\nCC110: " + rileyLinkServiceData.versionCC110); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index b240f8bc0b..387e2922c8 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -84,7 +84,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { } private RileyLinkService getServiceInstance() { - RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice)activePlugin.getActivePump(); + RileyLinkPumpDevice pumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); return pumpDevice.getRileyLinkService(); } @@ -139,10 +139,10 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { } else { rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled); } + rileyLinkServiceData.rileyLinkName = null; return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { - aapsLogger.warn(LTag.PUMPBTCOMM, "RileyLinkConst.Intents.RileyLinkReady"); // sendIPCNotification(RT2Const.IPC.MSG_note_WakingPump); @@ -153,7 +153,9 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { String bleVersion = rileyLinkService.rfspy.getBLEVersionCached(); RileyLinkFirmwareVersion rlVersion = rileyLinkServiceData.firmwareVersion; -// if (isLoggingEnabled()) + rileyLinkServiceData.rileyLinkName = rileyLinkService.rfspy.getBleDeviceName(); + aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", rileyLinkServiceData.rileyLinkName); + aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): " + bleVersion); rileyLinkService.rileyLinkServiceData.versionBLE113 = bleVersion; @@ -168,6 +170,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) { String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); + rileyLinkServiceData.rileyLinkName = null; if (RileylinkBLEAddress.equals("")) { aapsLogger.error("No Rileylink BLE Address saved in app"); } else { @@ -180,6 +183,7 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) { rileyLinkService.disconnectRileyLink(); + rileyLinkServiceData.rileyLinkName = null; return true; } else { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java index 6307c7ad87..10eb06373c 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkServiceData.java @@ -35,6 +35,7 @@ public class RileyLinkServiceData { public RileyLinkFirmwareVersion firmwareVersion; // here we have "compatibility level" version public RileyLinkTargetFrequency rileyLinkTargetFrequency; public String rileylinkAddress; + public String rileyLinkName; long lastTuneUpTime = 0L; public Double lastGoodFrequency; diff --git a/rileylink/src/main/res/layout/rileylink_status_general.xml b/rileylink/src/main/res/layout/rileylink_status_general.xml index dfa5f94d82..ac72198024 100644 --- a/rileylink/src/main/res/layout/rileylink_status_general.xml +++ b/rileylink/src/main/res/layout/rileylink_status_general.xml @@ -56,6 +56,34 @@ android:textAlignment="center" /> + + + + + + + pref_medtronic_encoding %1$.1f %2$s (%3$s) + Connected RileyLink name %1$d day From f596348d85aaf8acace5e255737b1b41efca4534 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Fri, 25 Dec 2020 02:05:37 +0100 Subject: [PATCH 06/22] Workarounds for some bugs in RL scanning UI --- .../service/RileyLinkMedtronicService.java | 10 ++--- .../service/RileyLinkOmnipodService.java | 10 ++--- .../dialog/RileyLinkBLEScanActivity.java | 32 ++++++++++++---- .../common/hw/rileylink/ble/RileyLinkBLE.java | 7 +++- .../dialog/RileyLinkStatusActivity.java | 37 ------------------- .../service/RileyLinkBroadcastReceiver.java | 4 -- .../rileylink/service/RileyLinkService.java | 7 +++- 7 files changed, 46 insertions(+), 61 deletions(-) diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java index 0744545ccc..1b400b7bde 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java @@ -180,7 +180,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { } - public boolean verifyConfiguration() { + public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) { try { String regexSN = "[0-9]{6}"; String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; @@ -316,7 +316,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { //boolean bolusDebug = bolusDebugEnabled != null && bolusDebugEnabled.equals(resourceHelper.gs(R.string.common_on)); //MedtronicHistoryData.doubleBolusDebug = bolusDebug; - reconfigureService(); + reconfigureService(forceRileyLinkAddressRenewal); return true; @@ -327,7 +327,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { } } - private boolean reconfigureService() { + private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) { if (!inPreInit) { @@ -336,7 +336,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { serialChanged = false; } - if (rileyLinkAddressChanged) { + if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) { rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); rileyLinkAddressChanged = false; } @@ -380,6 +380,6 @@ public class RileyLinkMedtronicService extends RileyLinkService { public boolean setNotInPreInit() { this.inPreInit = false; - return reconfigureService(); + return reconfigureService(false); } } diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/service/RileyLinkOmnipodService.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/service/RileyLinkOmnipodService.java index 8928e5b1f1..b92d26f017 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/service/RileyLinkOmnipodService.java +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/rileylink/service/RileyLinkOmnipodService.java @@ -109,7 +109,7 @@ public class RileyLinkOmnipodService extends RileyLinkService { } @Override - public boolean verifyConfiguration() { + public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) { try { errorDescription = null; @@ -133,7 +133,7 @@ public class RileyLinkOmnipodService extends RileyLinkService { rileyLinkServiceData.rileyLinkTargetFrequency = RileyLinkTargetFrequency.Omnipod; - reconfigureService(); + reconfigureService(forceRileyLinkAddressRenewal); return true; @@ -144,9 +144,9 @@ public class RileyLinkOmnipodService extends RileyLinkService { } } - private boolean reconfigureService() { + private boolean reconfigureService(boolean forceRileyLinkAddressRenewal) { if (!inPreInit) { - if (rileyLinkAddressChanged) { + if (rileyLinkAddressChanged || forceRileyLinkAddressRenewal) { rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); rileyLinkAddressChanged = false; } @@ -158,6 +158,6 @@ public class RileyLinkOmnipodService extends RileyLinkService { public boolean setNotInPreInit() { this.inPreInit = false; - return reconfigureService(); + return reconfigureService(false); } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index 3c298574f9..00fdefea36 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -79,6 +79,8 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { private String actionTitleStart, actionTitleStop; private MenuItem menuItem; + private boolean rlDisconnected; + @Override public void onCreate(Bundle savedInstanceState) { @@ -106,7 +108,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress); RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump(); - rileyLinkPump.getRileyLinkService().verifyConfiguration(); // force reloading of address + rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address rileyLinkPump.triggerPumpConfigurationChangedEvent(); finish(); @@ -115,10 +117,12 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { toolbarBTScan = findViewById(R.id.rileylink_toolbarBTScan); toolbarBTScan.setTitle(R.string.rileylink_scanner_title); setSupportActionBar(toolbarBTScan); - - prepareForScanning(); } + @Override protected void onResume() { + super.onResume(); + prepareForScanning(); + } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -138,6 +142,10 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getTitle().equals(actionTitleStart)) { + // disable currently selected RL, so that we can discover it + rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this); + rlDisconnected = true; + scanLeDevice(true); return true; } else if (item.getTitle().equals(actionTitleStop)) { @@ -148,8 +156,21 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { } } + @Override public void onBackPressed() { + super.onBackPressed(); + if (rlDisconnected) { + // Reconnect RL if it was disconnected for the scan + rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this); + } + } - public void prepareForScanning() { + @Override protected void onDestroy() { + super.onDestroy(); + mScanning = false; + mLEScanner.stopScan(mScanCallback2); + } + + private void prepareForScanning() { boolean checkOK = blePrecheck.prerequisitesCheck(this); if (checkOK) { @@ -158,9 +179,6 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { filters = Collections.singletonList(new ScanFilter.Builder().setServiceUuid( ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build()); } - - // disable currently selected RL, so that we can discover it - rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnect, this); } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java index 8d7f1e44b4..5a26b80dd8 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.java @@ -151,8 +151,8 @@ public class RileyLinkBLE { } else if ((newState == BluetoothProfile.STATE_CONNECTING) || // (newState == BluetoothProfile.STATE_DISCONNECTING)) { - aapsLogger.debug(LTag.PUMPBTCOMM,"We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : - "Disconnecting"); + aapsLogger.debug(LTag.PUMPBTCOMM, "We are in {} state.", status == BluetoothProfile.STATE_CONNECTING ? "Connecting" : + "Disconnecting"); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkDisconnected, context); if (manualDisconnect) @@ -392,6 +392,9 @@ public class RileyLinkBLE { if (gattDebugEnabled) { aapsLogger.debug(LTag.PUMPBTCOMM, "Gatt Connected."); } + + rileyLinkServiceData.rileylinkAddress = bluetoothConnectionGatt.getDevice().getAddress(); + rileyLinkServiceData.rileyLinkName = bluetoothConnectionGatt.getDevice().getName(); } } diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java index 7bcc9a93ac..c4e06f8ab1 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java @@ -16,7 +16,6 @@ import java.util.List; import javax.inject.Inject; - import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; import info.nightscout.androidaps.plugins.pump.common.R; import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; @@ -66,50 +65,14 @@ public class RileyLinkStatusActivity extends NoSplashAppCompatActivity { RefreshableInterface selectableInterface = (RefreshableInterface) mSectionsPagerAdapter .getItem(tabLayout.getSelectedTabPosition()); selectableInterface.refreshData(); - - // refreshData(tabLayout.getSelectedTabPosition()); - - // Toast.makeText(getApplicationContext(), "Test pos: " + tabLayout.getSelectedTabPosition(), - // Toast.LENGTH_LONG); }); this.connectionStatus = findViewById(R.id.rls_t1_connection_status); this.configuredAddress = findViewById(R.id.rls_t1_configured_address); this.connectedDevice = findViewById(R.id.rls_t1_connected_device); this.connectionError = findViewById(R.id.rls_t1_connection_error); - - // // 7-12 - // int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // - // R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12}; - // - // for (int id : ids) { - // - // TextView tv = (TextView) findViewById(id); - // tv.setText(tv.getText() + ":"); - // } - - // refreshData(0); - // refreshData(1); - } - - public void refreshData(int position) { - if (position == 0) { - // FIXME i18n - this.connectionStatus.setText(rileyLinkServiceData.rileyLinkServiceState.name()); - this.configuredAddress.setText(rileyLinkServiceData.rileylinkAddress); - // FIXME - this.connectedDevice.setText("???"); - // FIXME i18n - this.connectionError.setText(rileyLinkServiceData.rileyLinkError.name()); - } else { - - } - - } - - public void setupViewPager(ViewPager pager) { mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index 387e2922c8..3a80dff4fd 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -139,7 +139,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { } else { rileyLinkServiceData.setServiceState(RileyLinkServiceState.BluetoothError, RileyLinkError.BluetoothDisabled); } - rileyLinkServiceData.rileyLinkName = null; return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkReady)) { @@ -170,7 +169,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkNewAddressSet)) { String RileylinkBLEAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, ""); - rileyLinkServiceData.rileyLinkName = null; if (RileylinkBLEAddress.equals("")) { aapsLogger.error("No Rileylink BLE Address saved in app"); } else { @@ -183,8 +181,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { return true; } else if (action.equals(RileyLinkConst.Intents.RileyLinkDisconnect)) { rileyLinkService.disconnectRileyLink(); - rileyLinkServiceData.rileyLinkName = null; - return true; } else { return false; diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java index b039e49c59..7b4e11fd35 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkService.java @@ -230,6 +230,7 @@ public abstract class RileyLinkService extends DaggerService { if (rileyLinkBLE.isConnected()) { rileyLinkBLE.disconnect(); rileyLinkServiceData.rileylinkAddress = null; + rileyLinkServiceData.rileyLinkName = null; } rileyLinkServiceData.setRileyLinkServiceState(RileyLinkServiceState.BluetoothReady); @@ -260,5 +261,9 @@ public abstract class RileyLinkService extends DaggerService { return null; } - public abstract boolean verifyConfiguration(); + public boolean verifyConfiguration() { + return verifyConfiguration(false); + } + + public abstract boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal); } From 33297ae4cf7c7a0bdac5bdfa7abbfd7788db4d75 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Fri, 25 Dec 2020 02:17:43 +0100 Subject: [PATCH 07/22] Remove redundant code and improve comment --- .../pump/common/dialog/RileyLinkBLEScanActivity.java | 2 +- .../plugins/pump/common/hw/rileylink/ble/RFSpy.java | 12 ------------ .../service/RileyLinkBroadcastReceiver.java | 3 --- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index 00fdefea36..364e0e19c3 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -108,7 +108,7 @@ public class RileyLinkBLEScanActivity extends NoSplashAppCompatActivity { sp.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress); RileyLinkPumpDevice rileyLinkPump = (RileyLinkPumpDevice) activePlugin.getActivePump(); - rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address + rileyLinkPump.getRileyLinkService().verifyConfiguration(true); // force reloading of address to assure that the RL gets reconnected (even if the address didn't change) rileyLinkPump.triggerPumpConfigurationChangedEvent(); finish(); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java index 4df1a22389..bf06acad02 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RFSpy.java @@ -112,18 +112,6 @@ public class RFSpy { reader.newDataIsAvailable(); } - public String getBleDeviceName() { - BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(UUID.fromString(GattAttributes.SERVICE_GAP), UUID.fromString(GattAttributes.CHARA_GAP_NAME)); - if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { - String value = new String(result.value); - aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", value); - return value; - } else { - aapsLogger.error(LTag.PUMPBTCOMM, "getBleDeviceName failed with code: " + result.resultCode); - return null; - } - } - public Integer getBatteryLevel() { BLECommOperationResult result = rileyLinkBle.readCharacteristic_blocking(batteryServiceUUID, batteryLevelUUID); if (result.resultCode == BLECommOperationResult.RESULT_SUCCESS) { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java index 3a80dff4fd..dbe2731e89 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/RileyLinkBroadcastReceiver.java @@ -152,9 +152,6 @@ public class RileyLinkBroadcastReceiver extends DaggerBroadcastReceiver { String bleVersion = rileyLinkService.rfspy.getBLEVersionCached(); RileyLinkFirmwareVersion rlVersion = rileyLinkServiceData.firmwareVersion; - rileyLinkServiceData.rileyLinkName = rileyLinkService.rfspy.getBleDeviceName(); - aapsLogger.debug(LTag.PUMPBTCOMM, "BLE device name: {}", rileyLinkServiceData.rileyLinkName); - aapsLogger.debug(LTag.PUMPBTCOMM, "RfSpy version (BLE113): " + bleVersion); rileyLinkService.rileyLinkServiceData.versionBLE113 = bleVersion; From 03c59d6e19d3e5d9cbc610bff868101b1dd53613 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 25 Dec 2020 12:06:54 +0100 Subject: [PATCH 08/22] SMS: report pump unreachable --- .../androidaps/dialogs/WizardDialog.kt | 6 +-- .../DetermineBasalAdapterSMBJS.java | 6 +-- .../general/maintenance/ImportExportPrefs.kt | 2 +- .../androidaps/receivers/KeepAliveReceiver.kt | 2 +- .../androidaps/utils/LocalAlertUtils.kt | 47 ++++++++++--------- app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/pref_smscommunicator.xml | 6 +++ .../AbstractDanaRExecutionService.java | 2 +- .../omnipod/ui/OmnipodOverviewFragment.kt | 2 +- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt index 17ed64b96f..45eebec6f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/WizardDialog.kt @@ -146,7 +146,7 @@ class WizardDialog : DaggerDialogFragment() { treatments_wizard_bgtrendcheckbox.setOnCheckedChangeListener(::onCheckedChanged) treatments_wizard_sbcheckbox.setOnCheckedChangeListener(::onCheckedChanged) - val showCalc = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_calculation_visible), false) + val showCalc = sp.getBoolean(R.string.key_wizard_calculation_visible, false) treatments_wizard_delimiter.visibility = showCalc.toVisibility() treatments_wizard_resulttable.visibility = showCalc.toVisibility() treatments_wizard_calculationcheckbox.isChecked = showCalc @@ -211,8 +211,8 @@ class WizardDialog : DaggerDialogFragment() { } private fun loadCheckedStates() { - treatments_wizard_bgtrendcheckbox.isChecked = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_include_trend_bg), false) - treatments_wizard_cobcheckbox.isChecked = sp.getBoolean(resourceHelper.gs(R.string.key_wizard_include_cob), false) + treatments_wizard_bgtrendcheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_trend_bg, false) + treatments_wizard_cobcheckbox.isChecked = sp.getBoolean(R.string.key_wizard_include_cob, false) } private fun initDialog() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index 1013434c95..a94581ca94 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java @@ -267,8 +267,8 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("low_temptarget_lowers_sensitivity", false); - mProfile.put("sensitivity_raises_target", sp.getBoolean(resourceHelper.gs(R.string.key_sensitivity_raises_target),SMBDefaults.sensitivity_raises_target)); - mProfile.put("resistance_lowers_target", sp.getBoolean(resourceHelper.gs(R.string.key_resistance_lowers_target),SMBDefaults.resistance_lowers_target)); + mProfile.put("sensitivity_raises_target", sp.getBoolean(R.string.key_sensitivity_raises_target,SMBDefaults.sensitivity_raises_target)); + mProfile.put("resistance_lowers_target", sp.getBoolean(R.string.key_resistance_lowers_target,SMBDefaults.resistance_lowers_target)); mProfile.put("adv_target_adjustments", SMBDefaults.adv_target_adjustments); mProfile.put("exercise_mode", SMBDefaults.exercise_mode); mProfile.put("half_basal_exercise_target", SMBDefaults.half_basal_exercise_target); @@ -284,7 +284,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("enableUAM", uamAllowed); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); - boolean smbEnabled = sp.getBoolean(resourceHelper.gs(R.string.key_use_smb), false); + boolean smbEnabled = sp.getBoolean(R.string.key_use_smb, false); mProfile.put("SMBInterval", sp.getInt(R.string.key_smbinterval, SMBDefaults.SMBInterval)); mProfile.put("enableSMB_with_COB", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_COB, false)); mProfile.put("enableSMB_with_temptarget", smbEnabled && sp.getBoolean(R.string.key_enableSMB_with_temptarget, false)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt index 6617200ec8..f8c71218b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/ImportExportPrefs.kt @@ -123,7 +123,7 @@ class ImportExportPrefs @Inject constructor( } private fun prefsEncryptionIsDisabled() = - buildHelper.isEngineeringMode() && !sp.getBoolean(resourceHelper.gs(R.string.key_maintenance_encrypt_exported_prefs), true) + buildHelper.isEngineeringMode() && !sp.getBoolean(R.string.key_maintenance_encrypt_exported_prefs, true) private fun askForMasterPass(activity: FragmentActivity, @StringRes canceledMsg: Int, then: ((password: String) -> Unit)) { passwordCheck.queryPassword(activity, R.string.master_password, R.string.key_master_password, { password -> diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt index bd532dc462..d97ab4f7a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.kt @@ -77,7 +77,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() { aapsLogger.debug(LTag.CORE, "KeepAlive scheduled") SystemClock.sleep(5000) // wait for app initialization localAlertUtils.shortenSnoozeInterval() - localAlertUtils.presnoozeAlarms() + localAlertUtils.preSnoozeAlarms() val am = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager val i = Intent(context, KeepAliveReceiver::class.java) val pi = PendingIntent.getBroadcast(context, 0, i, 0) diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt index bf5b5504e8..76589d3b7a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.kt @@ -5,19 +5,21 @@ import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.db.BgReading import info.nightscout.androidaps.interfaces.ActivePluginProvider +import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import info.nightscout.androidaps.plugins.bus.RxBusWrapper -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.nsclient.NSUpload import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification import info.nightscout.androidaps.plugins.general.overview.notifications.Notification +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject import javax.inject.Singleton +import kotlin.math.min /** * Created by adrian on 17/12/17. @@ -31,48 +33,49 @@ class LocalAlertUtils @Inject constructor( private val activePlugin: ActivePluginProvider, private val profileFunction: ProfileFunction, private val iobCobCalculatorPlugin: IobCobCalculatorPlugin, + private val smsCommunicatorPlugin: SmsCommunicatorPlugin, private val config: Config, private val nsUpload: NSUpload, private val dateUtil: DateUtil ) { - fun missedReadingsThreshold(): Long { - return T.mins(sp.getInt(resourceHelper.gs(R.string.key_missed_bg_readings_threshold_minutes), Constants.DEFAULT_MISSED_BG_READINGS_THRESHOLD_MINUTES).toLong()).msecs() + private fun missedReadingsThreshold(): Long { + return T.mins(sp.getInt(R.string.key_missed_bg_readings_threshold_minutes, Constants.DEFAULT_MISSED_BG_READINGS_THRESHOLD_MINUTES).toLong()).msecs() } - fun pumpUnreachableThreshold(): Long { - return T.mins(sp.getInt(resourceHelper.gs(R.string.key_pump_unreachable_threshold_minutes), Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES).toLong()).msecs() + private fun pumpUnreachableThreshold(): Long { + return T.mins(sp.getInt(R.string.key_pump_unreachable_threshold_minutes, Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES).toLong()).msecs() } fun checkPumpUnreachableAlarm(lastConnection: Long, isStatusOutdated: Boolean, isDisconnected: Boolean) { val alarmTimeoutExpired = isAlarmTimeoutExpired(lastConnection, pumpUnreachableThreshold()) val nextAlarmOccurrenceReached = sp.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis() - if (config.APS && sp.getBoolean(resourceHelper.gs(R.string.key_enable_pump_unreachable_alert), true) - && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { - aapsLogger.debug(LTag.CORE, "Generating pump unreachable alarm. lastConnection: " + dateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated) - val n = Notification(Notification.PUMP_UNREACHABLE, resourceHelper.gs(R.string.pump_unreachable), Notification.URGENT) - n.soundId = R.raw.alarm - sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()) - rxBus.send(EventNewNotification(n)) - if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { - nsUpload.uploadError(n.text) + if (config.APS && isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !isDisconnected) { + if (sp.getBoolean(R.string.key_enable_pump_unreachable_alert, true)) { + aapsLogger.debug(LTag.CORE, "Generating pump unreachable alarm. lastConnection: " + dateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated) + sp.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()) + rxBus.send(EventNewNotification(Notification(Notification.PUMP_UNREACHABLE, resourceHelper.gs(R.string.pump_unreachable), Notification.URGENT).also { it.soundId - R.raw.alarm })) + if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) + nsUpload.uploadError(resourceHelper.gs(R.string.pump_unreachable)) } + if (sp.getBoolean(R.string.key_smscommunicator_report_pump_ureachable, true)) + smsCommunicatorPlugin.sendNotificationToAllNumbers(resourceHelper.gs(R.string.pump_unreachable)) } if (!isStatusOutdated && !alarmTimeoutExpired) rxBus.send(EventDismissNotification(Notification.PUMP_UNREACHABLE)) } private fun isAlarmTimeoutExpired(lastConnection: Long, unreachableThreshold: Long): Boolean { - if (activePlugin.activePump.pumpDescription.hasCustomUnreachableAlertCheck) { - return activePlugin.activePump.isUnreachableAlertTimeoutExceeded(unreachableThreshold) + return if (activePlugin.activePump.pumpDescription.hasCustomUnreachableAlertCheck) { + activePlugin.activePump.isUnreachableAlertTimeoutExceeded(unreachableThreshold) } else { - return lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis() + lastConnection + pumpUnreachableThreshold() < System.currentTimeMillis() } } - /*Presnoozes the alarms with 5 minutes if no snooze exists. + /*Pre-snoozes the alarms with 5 minutes if no snooze exists. * Call only at startup! */ - fun presnoozeAlarms() { + fun preSnoozeAlarms() { if (sp.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) { sp.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000) } @@ -83,10 +86,10 @@ class LocalAlertUtils @Inject constructor( fun shortenSnoozeInterval() { //shortens alarm times in case of setting changes or future data var nextMissedReadingsAlarm = sp.getLong("nextMissedReadingsAlarm", 0L) - nextMissedReadingsAlarm = Math.min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm) + nextMissedReadingsAlarm = min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm) sp.putLong("nextMissedReadingsAlarm", nextMissedReadingsAlarm) var nextPumpDisconnectedAlarm = sp.getLong("nextPumpDisconnectedAlarm", 0L) - nextPumpDisconnectedAlarm = Math.min(System.currentTimeMillis() + pumpUnreachableThreshold(), nextPumpDisconnectedAlarm) + nextPumpDisconnectedAlarm = min(System.currentTimeMillis() + pumpUnreachableThreshold(), nextPumpDisconnectedAlarm) sp.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm) } @@ -104,7 +107,7 @@ class LocalAlertUtils @Inject constructor( fun checkStaleBGAlert() { val bgReading: BgReading? = iobCobCalculatorPlugin.lastBg() - if (sp.getBoolean(resourceHelper.gs(R.string.key_enable_missed_bg_readings_alert), false) + if (sp.getBoolean(R.string.key_enable_missed_bg_readings_alert, false) && bgReading != null && bgReading.date + missedReadingsThreshold() < System.currentTimeMillis() && sp.getLong("nextMissedReadingsAlarm", 0L) < System.currentTimeMillis()) { val n = Notification(Notification.BG_READINGS_MISSED, resourceHelper.gs(R.string.missed_bg_readings), Notification.URGENT) n.soundId = R.raw.alarm diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b95cad27a2..ac2b63ce4a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1415,5 +1415,8 @@ Unable to create local profile. Profile is invalid. Don\'t kill my app? Alarm + smscommunicator_report_pump_ureachable + Send SMS if unreachable pump event is triggered + Report pump ureachable diff --git a/app/src/main/res/xml/pref_smscommunicator.xml b/app/src/main/res/xml/pref_smscommunicator.xml index 564b540789..91e83a7084 100644 --- a/app/src/main/res/xml/pref_smscommunicator.xml +++ b/app/src/main/res/xml/pref_smscommunicator.xml @@ -49,6 +49,12 @@ + + \ No newline at end of file diff --git a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java index d5b17e7800..bb02e4e136 100644 --- a/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java +++ b/danar/src/main/java/info/nightscout/androidaps/danar/services/AbstractDanaRExecutionService.java @@ -184,7 +184,7 @@ public abstract class AbstractDanaRExecutionService extends DaggerService { } protected void getBTSocketForSelectedPump() { - mDevName = sp.getString(resourceHelper.gs(R.string.key_danar_bt_name), ""); + mDevName = sp.getString(R.string.key_danar_bt_name, ""); BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter != null) { diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt index 6a0dcce2ab..fbfeae4b8b 100644 --- a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt +++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/ui/OmnipodOverviewFragment.kt @@ -596,7 +596,7 @@ class OmnipodOverviewFragment : DaggerFragment() { // FIXME ideally we should just have access to LocalAlertUtils here private fun getPumpUnreachableTimeout(): Duration { - return Duration.standardMinutes(sp.getInt(resourceHelper.gs(R.string.key_pump_unreachable_threshold_minutes), Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES).toLong()) + return Duration.standardMinutes(sp.getInt(R.string.key_pump_unreachable_threshold_minutes, Constants.DEFAULT_PUMP_UNREACHABLE_THRESHOLD_MINUTES).toLong()) } inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() { From bc04f8137fcc3a7350600db62f53e2b7e1957ff2 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Fri, 25 Dec 2020 12:57:28 +0100 Subject: [PATCH 09/22] Code cleanup in RileyLinkStatusGeneralFragment --- .../RileyLinkStatusGeneralFragment.java | 49 +++++-------------- .../res/layout/rileylink_status_general.xml | 16 +----- rileylink/src/main/res/values/strings.xml | 22 +++++---- 3 files changed, 27 insertions(+), 60 deletions(-) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java index 3c0a156c76..309530cfa9 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java @@ -40,29 +40,24 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re @Inject RileyLinkServiceData rileyLinkServiceData; @Inject DateUtil dateUtil; - TextView connectionStatus; - TextView configuredAddress; - TextView connectedRileyLinkName; - TextView connectedDevice; - TextView connectionError; - TextView deviceType; - TextView deviceModel; - TextView serialNumber; - TextView pumpFrequency; - TextView lastUsedFrequency; - TextView lastDeviceContact; - TextView firmwareVersion; - - boolean first = false; + private TextView connectionStatus; + private TextView configuredAddress; + private TextView connectedRileyLinkName; + private TextView connectedDevice; + private TextView connectionError; + private TextView deviceType; + private TextView deviceModel; + private TextView serialNumber; + private TextView pumpFrequency; + private TextView lastUsedFrequency; + private TextView lastDeviceContact; + private TextView firmwareVersion; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.rileylink_status_general, container, false); - - return rootView; + return inflater.inflate(R.layout.rileylink_status_general, container, false); } - @Override public void onStart() { super.onStart(); @@ -80,28 +75,10 @@ public class RileyLinkStatusGeneralFragment extends DaggerFragment implements Re this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact); this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version); - // BS: FIXME Remove - if (!first) { - - // 7-14 - int[] ids = {R.id.rls_t1_tv02, R.id.rls_t1_tv14, R.id.rls_t1_tv03, R.id.rls_t1_tv04, R.id.rls_t1_tv05, R.id.rls_t1_tv07, // - R.id.rls_t1_tv08, R.id.rls_t1_tv09, R.id.rls_t1_tv10, R.id.rls_t1_tv11, R.id.rls_t1_tv12, R.id.rls_t1_tv13}; - - for (int id : ids) { - - TextView tv = getActivity().findViewById(id); - tv.setText(tv.getText() + ":"); - } - - first = true; - } - refreshData(); } - public void refreshData() { - RileyLinkTargetDevice targetDevice = rileyLinkServiceData.targetDevice; this.connectionStatus.setText(resourceHelper.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); diff --git a/rileylink/src/main/res/layout/rileylink_status_general.xml b/rileylink/src/main/res/layout/rileylink_status_general.xml index ac72198024..406740a419 100644 --- a/rileylink/src/main/res/layout/rileylink_status_general.xml +++ b/rileylink/src/main/res/layout/rileylink_status_general.xml @@ -37,7 +37,6 @@ android:orientation="horizontal"> + android:text="@string/rileylink_pump_serial_number" /> + android:text="@string/rileylink_pump_frequency" /> Pump Status RileyLink Settings RileyLink - Configured Address - Connected Device - Connection Status - Connection Error + Configured Address: + Connected Device: + Connection Status: + Connection Error: Device - Device Type - Device Model - Last used frequency - Last device contact - Firmware + Device Type: + Device Model: + Last Used Frequency: + Last Device Contact: + Firmware Version: + Connected RileyLink Name: + Pump Serial Number: + Pump Frequency: @@ -64,7 +67,6 @@ pref_medtronic_encoding %1$.1f %2$s (%3$s) - Connected RileyLink name %1$d day From 3c32583d8c21b5726000a0a454c04b3c0a31c36d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 25 Dec 2020 14:42:39 +0100 Subject: [PATCH 10/22] ProfileHelper layout buttons fix --- app/src/main/res/layout/activity_profilehelper.xml | 12 ++++++------ app/src/main/res/values/styles.xml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/layout/activity_profilehelper.xml b/app/src/main/res/layout/activity_profilehelper.xml index 310a4c566d..da47a6c88c 100644 --- a/app/src/main/res/layout/activity_profilehelper.xml +++ b/app/src/main/res/layout/activity_profilehelper.xml @@ -12,9 +12,9 @@ android:layout_height="wrap_content" android:orientation="vertical"> -