From f28fca668f615fc697a16a7006cd70a08f5b648c Mon Sep 17 00:00:00 2001 From: Nico Schmitz Date: Wed, 13 Jun 2018 00:07:13 +0200 Subject: [PATCH] Integrate info fields from swissalpine/dev-work --- .../plugins/Overview/OverviewFragment.java | 84 +++++++++++++++++++ app/src/main/res/layout/overview_fragment.xml | 48 +++++++++++ 2 files changed, 132 insertions(+) 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 9dddaa4bb8..025bedc789 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 @@ -95,6 +95,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalcul import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; +import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewCarbsDialog; @@ -154,6 +155,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, TextView sage; TextView pbage; + TextView iageView; + TextView cageView; + TextView reservoirView; + TextView sageView; + TextView pbageView; + RecyclerView notificationsView; LinearLayoutManager llm; @@ -252,6 +259,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sage = (TextView) view.findViewById(R.id.careportal_sensorage); pbage = (TextView) view.findViewById(R.id.careportal_pbage); + iageView = (TextView) view.findViewById(R.id.overview_insulinage); + 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); + bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); @@ -1304,6 +1317,67 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, cobView.setText(cobText); } + CareportalEvent careportalEvent; + NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance(); + + 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); + if (careportalEvent != null) { + cageView.setTextColor(determineTextColor(careportalEvent, cageWarn, cageUrgent)); + cageView.setText("CAN"); //: " + careportalEvent.age()); + } else { + cageView.setText("n/a"); + } + } + + if (iageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE); + if (careportalEvent != null) { + iageView.setTextColor(determineTextColor(careportalEvent, iageWarn, iageUrgent)); + iageView.setText("INS"); //: + careportalEvent.age()); + } else { + iageView.setText("n/a"); + } + } + + if (reservoirView != null) { + if (pump.isInitialized() && pump.getReservoirLevel() < 50) { + reservoirView.setTextColor(MainApp.gc(R.color.low)); + } else { + reservoirView.setTextColor(MainApp.gc(R.color.colorLightGray)); + } + reservoirView.setText("RES"); + } + + if (sageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE); + if (careportalEvent != null) { + sageView.setTextColor(determineTextColor(careportalEvent, sageWarn, sageUrgent)); + sageView.setText("SEN"); // + careportalEvent.age()); + } else { + sageView.setText("n/a"); + } + } + + if (pbageView != null) { + careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.PUMPBATTERYCHANGE); + if (careportalEvent != null) { + pbageView.setTextColor(determineTextColor(careportalEvent, pbageWarn, pbageUrgent)); + pbageView.setText("BAT"); //careportalEvent.age()); + } else { + pbageView.setText("n/a"); + } + } + final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions; // pump status from ns if (pumpDeviceStatusView != null) { @@ -1466,4 +1540,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } + public static int determineTextColor(CareportalEvent careportalEvent, double warnThreshold, double urgentThreshold) { + if (careportalEvent.isOlderThan(urgentThreshold)) { + return MainApp.gc(R.color.low); + } else if (careportalEvent.isOlderThan(warnThreshold)) { + return MainApp.gc(R.color.high); + } else { + return MainApp.gc(R.color.colorLightGray); + } + } + } diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 8e37ae7675..79e3c518fe 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -183,6 +183,54 @@ + + + + + + + + + + + + + +