From 1604b533277a3b3702d3ca06bd094ea992270c5c Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Thu, 14 Jun 2018 20:49:58 +0200 Subject: [PATCH] Fix bugs, refactor code and add preferences --- .../androidaps/db/CareportalEvent.java | 4 +- .../plugins/Overview/OverviewFragment.java | 90 +++++++++++-------- .../plugins/PumpCombo/ComboPlugin.java | 2 +- app/src/main/res/layout/overview_fragment.xml | 3 +- app/src/main/res/values-de/strings.xml | 8 +- app/src/main/res/values/strings.xml | 18 ++-- app/src/main/res/xml/pref_overview.xml | 46 +++++++--- 7 files changed, 110 insertions(+), 61 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index 72ff1ddab0..a963158f2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -86,8 +86,8 @@ public class CareportalEvent implements DataPointWithLabelInterface { return System.currentTimeMillis() - date; } - public long getHoursFromStart() { - return (System.currentTimeMillis() - date) / (60 * 60 * 1000); + public double getHoursFromStart() { + return (System.currentTimeMillis() - date) / (60 * 60 * 1000.0); } public String age() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index eedf854860..02053c0b9c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Overview; import android.annotation.SuppressLint; import android.app.Activity; import android.app.NotificationManager; +import android.arch.core.util.Function; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; @@ -159,7 +160,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, TextView cageView; TextView reservoirView; TextView sageView; - TextView pbageView; + TextView batteryView; + LinearLayout statuslightsLayout; RecyclerView notificationsView; LinearLayoutManager llm; @@ -263,7 +265,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, cageView = (TextView) view.findViewById(R.id.overview_canulaage); reservoirView = (TextView) view.findViewById(R.id.overview_reservoirlevel); sageView = (TextView) view.findViewById(R.id.overview_sensorage); - pbageView = (TextView) view.findViewById(R.id.overview_pbage); + batteryView = (TextView) view.findViewById(R.id.overview_batterylevel); + statuslightsLayout = (LinearLayout) view.findViewById(R.id.overview_statuslights); bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); @@ -1321,44 +1324,54 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, cobView.setText(cobText); } - CareportalEvent careportalEvent; - NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + if (statuslightsLayout != null) { + if (SP.getBoolean(R.string.key_show_statuslights, false)) { + CareportalEvent careportalEvent; + NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 96); + double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 72); + double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72); + double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48); + double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166); + double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164); + //double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360); + //double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240); + double batUrgent = SP.getDouble(R.string.key_statuslights_bat_critical, 5.0); + double batWarn = SP.getDouble(R.string.key_statuslights_bat_warning, 25.0); + double resUrgent = SP.getDouble(R.string.key_statuslights_res_critical, 10.0); + double resWarn = SP.getDouble(R.string.key_statuslights_res_warning, 80.0); - double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 120); - double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 96); - double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 48); - double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 24); - double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 504); - double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 336); - double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 672); - double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 504); + if (cageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); + double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyRibbonView(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE, true); + } - if (cageView != null) { - careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE); - double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; - applyRibbonView(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE); - } + if (iageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); + double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyRibbonView(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE, true); + } - if (iageView != null) { - careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); - double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; - applyRibbonView(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE); - } + if (reservoirView != null) { + double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1; + applyRibbonView(reservoirView, "RES", reservoirLevel, resWarn, resUrgent, -1, false); + } - if (reservoirView != null) { - double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1; - applyRibbonView(reservoirView, "RES", reservoirLevel, 80, 10, -1); - } + if (sageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); + double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; + applyRibbonView(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE, true); + } - if (sageView != null) { - careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); - double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE; - applyRibbonView(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE); - } - - if (pbageView != null) { - double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1; - applyRibbonView(pbageView, "BAT", batteryLevel, 25, 5, -1); + if (batteryView != null) { + double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1; + applyRibbonView(batteryView, "BAT", batteryLevel, batWarn, batUrgent, -1, false); + } + statuslightsLayout.setVisibility(View.VISIBLE); + } else { + statuslightsLayout.setVisibility(View.GONE); + } } final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions; @@ -1523,13 +1536,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } - public static void applyRibbonView(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid) { + public static void applyRibbonView(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) { + Function check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold; if (value != invalid) { view.setText(text); - if (value <= urgentThreshold) { + if (check.apply(urgentThreshold)) { view.setTextColor(MainApp.gc(R.color.ribbonTextCritical)); view.setBackgroundColor(MainApp.gc(R.color.ribbonBgCritical)); - } else if (value <= warnThreshold) { + } else if (check.apply(warnThreshold)) { view.setTextColor(MainApp.gc(R.color.ribbonTextWarning)); view.setBackgroundColor(MainApp.gc(R.color.ribbonBgWarning)); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index b11b0c4694..d4aa0d7da8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -432,7 +432,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint public int getBatteryLevel() { switch (pump.state.batteryState) { case PumpState.EMPTY: - return 0; + return 5; case PumpState.LOW: return 25; default: diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 5aae13e1f7..3dfe816f46 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -184,6 +184,7 @@ TBR Pumpen-Speicher Aktiviere die SuperBolus-Funktion im Wizard. Nicht aktivieren, wenn du nicht weißt, welche Auswirkungen dieser Bolus hat! ES KANN ZU EINER ÜBERDOSIERUNG AN INSULIN KOMMEN! - Zeige Reservoir-Füllstand in Übersicht - Zeigt den Füllstand des Reservoirs in der Übersicht an. + Zeige Status-Ampeln in der Übersicht + Aktiviert die Statusanzeige für CAGE, IAGE, SAGE, Reservoir- und Batteriestand auf dem Startbildschirm. + Reservoirfüllstand Warnung [IE] + Reservoirfüllstand Alarm [IE] + Batterieladung Warnung [%] + Batterieladung Alarm [%] Status des Bolus wird ermittelt PAIRING Bolus-Abgabe gestartet diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f478801797..4abf52f6d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -607,13 +607,17 @@ key_usersuperbolus Enable superbolus in wizard Enable superbolus functionality in wizard. Do not enable until you learn what it really does. IT MAY CAUSE INSULIN OVERDOSE IF USED BLINDLY! - key_show_reservoirview - Show reservoir level in overview - Show the reservoir level on the overview page. - key_reservoirview_levelwarning - Level warning - key_reservoirview_levelcritical - Level critical + key_show_statuslights + Show status lights on home screen + Enable status lights for cage, iage, sage, reservoir and battery level on home screen. + key_statuslights_res_warning + Threshold warning reservoir level [U] + key_statuslights_res_critical + Threshold critical reservoir level [U] + key_statuslights_bat_warning + Threshold warning battery level [%] + key_statuslights_bat_critical + Threshold critical battery level [%] IOB COB Firmware diff --git a/app/src/main/res/xml/pref_overview.xml b/app/src/main/res/xml/pref_overview.xml index b235a97f1e..daf1605fb5 100644 --- a/app/src/main/res/xml/pref_overview.xml +++ b/app/src/main/res/xml/pref_overview.xml @@ -145,36 +145,62 @@ + android:key="@string/key_show_statuslights" + android:summary="@string/show_statuslights_summary" + android:title="@string/show_statuslights" /> + + + +