From 980a997f79a879c924db4fa104610674fc24829d Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 5 Oct 2021 00:05:00 +0200 Subject: [PATCH] Add lastConnection ago and last bolus (Standard only) in fragment --- .../pump/insight/LocalInsightFragment.java | 27 ++++++++++++++++++- .../pump/insight/LocalInsightPlugin.java | 4 +++ insight/src/main/res/values/strings.xml | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java index bf89837dda..4a16e1aee0 100644 --- a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java +++ b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightFragment.java @@ -178,6 +178,7 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick getTDDItems(statusItems); getBaseBasalRateItem(statusItems); getTBRItem(statusItems); + getLastBolusItem(statusItems); getBolusItems(statusItems); for (int i = 0; i < statusItems.size(); i++) { statusItemContainer.addView(statusItems.get(i)); @@ -239,7 +240,16 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick default: long lastConnection = localInsightPlugin.getConnectionService().getLastConnected(); if (lastConnection == 0) return; - statusItems.add(getStatusItem(resourceHelper.gs(R.string.last_connected), dateUtil.timeString(lastConnection))); + long agoMsc = System.currentTimeMillis() - lastConnection; + double lastConnectionMinAgo = agoMsc / 60d / 1000d; + String ago; + if (lastConnectionMinAgo < 60) { + ago = dateUtil.minAgo(resourceHelper, lastConnection); + } else { + ago = dateUtil.hourAgo(lastConnection, resourceHelper); + } + statusItems.add(getStatusItem(resourceHelper.gs(R.string.last_connected), + dateUtil.timeString(lastConnection) + " (" + ago + ")")); } } @@ -306,6 +316,21 @@ public class LocalInsightFragment extends DaggerFragment implements View.OnClick resourceHelper.gs(R.string.tbr_formatter, activeTBR.getPercentage(), activeTBR.getInitialDuration() - activeTBR.getRemainingDuration(), activeTBR.getInitialDuration()))); } + private void getLastBolusItem(List statusItems) { + if (localInsightPlugin.lastBolusAmount == 0 || localInsightPlugin.lastBolusTimestamp == 0) return; + long agoMsc = System.currentTimeMillis() - localInsightPlugin.lastBolusTimestamp; + double bolusMinAgo = agoMsc / 60d / 1000d; + String unit = resourceHelper.gs(R.string.insulin_unit_shortname); + String ago; + if (bolusMinAgo < 60) { + ago = dateUtil.minAgo(resourceHelper, localInsightPlugin.lastBolusTimestamp); + } else { + ago = dateUtil.hourAgo(localInsightPlugin.lastBolusTimestamp, resourceHelper); + } + statusItems.add(getStatusItem(resourceHelper.gs(R.string.insight_last_bolus), + resourceHelper.gs(R.string.insight_last_bolus_formater, localInsightPlugin.lastBolusAmount, unit, ago))); + } + private void getBolusItems(List statusItems) { if (localInsightPlugin.getActiveBoluses() == null) return; for (ActiveBolus activeBolus : localInsightPlugin.getActiveBoluses()) { diff --git a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index ead54ec5e3..c93a7e895f 100644 --- a/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/insight/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -190,6 +190,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai private List activeBoluses; private boolean statusLoaded; private TBROverNotificationBlock tbrOverNotificationBlock; + public double lastBolusAmount = 0; + public long lastBolusTimestamp = 0L; @Inject public LocalInsightPlugin( @@ -1439,6 +1441,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai bolusID.getId(), PumpType.ACCU_CHEK_INSIGHT, serial); + lastBolusTimestamp = bolusID.getTimestamp(); + lastBolusAmount = event.getImmediateAmount(); } if (event.getBolusType() == BolusType.EXTENDED || event.getBolusType() == BolusType.MULTIWAVE) { if (event.getDuration() > 0 && profileFunction.getProfile(bolusID.getTimestamp()) != null) diff --git a/insight/src/main/res/values/strings.xml b/insight/src/main/res/values/strings.xml index dd12e644a3..ba021a8b99 100644 --- a/insight/src/main/res/values/strings.xml +++ b/insight/src/main/res/values/strings.xml @@ -21,6 +21,8 @@ %1$d%% for %2$d / %3$d min Multiwave bolus %1$.2f / %2$.2f U for %3$d min + Last Bolus + %1$.1f %2$s (%3$s) Searching for devices… Pairing completed Do the codes displayed on this device and on your pump match?