diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index ee023e23cc..e1b5bdd92f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -15,6 +15,7 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; import de.jotomo.ruffy.spi.PumpState; +import de.jotomo.ruffy.spi.history.Bolus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; @@ -29,6 +30,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis private TextView batteryView; private TextView reservoirView; private TextView lastConnectionView; + private TextView lastBolusView; private TextView baseBasalRate; private TextView tempBasalText; private Button refreshButton; @@ -45,6 +47,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis activityView = (TextView) view.findViewById(R.id.combo_activity); batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery); reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate); + lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus); lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection); baseBasalRate = (TextView) view.findViewById(R.id.combo_base_basal_rate); tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal); @@ -192,6 +195,28 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis lastConnectionView.setTextColor(Color.WHITE); } + // last bolus + Bolus bolus = plugin.getPump().lastBolus; + if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) { + long agoMsc = System.currentTimeMillis() - bolus.timestamp; + double bolusMinAgo = agoMsc / 60d / 1000d; + double bolusHoursAgo = agoMsc / 60d / 60d / 1000d; + // TODO i18n + if ((agoMsc < 60 * 1000)) { + lastBolusView.setText(String.format("%.1f U (now)", bolus.amount)); + } else if (bolusMinAgo < 60) { + lastBolusView.setText(String.format("%.1f U (%d min ago)", bolus.amount, (int) bolusMinAgo)); +// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, +// getString(R.string.minago, bolusMinAgo), DateUtil.timeString(bolus.timestamp))); + } else { + lastBolusView.setText(String.format("%.1f U (%.1f h ago)", bolus.amount, bolusHoursAgo)); +// lastBolusView.setText(getString(R.string.combo_last_bolus, bolus.amount, +// String.format("%.1f", bolusHoursAgo) + getString(R.string.hoursago), DateUtil.timeString(bolus.timestamp))); + } + } else { + lastBolusView.setText(""); + } + // base basal rate baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); 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 3f5075b007..812aa1d753 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 @@ -413,6 +413,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (result.reservoirLevel != PumpState.UNKNOWN) { pump.reservoirLevel = result.reservoirLevel; } + if (result.lastBolus != null) { + pump.lastBolus = result.lastBolus; + } else if (result.history != null && !result.history.bolusHistory.isEmpty()) { + pump.lastBolus = result.history.bolusHistory.get(0); + } if (result.state.menu != null) { pump.state = result.state; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java index 0455fa3ada..3aa4137b8b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPump.java @@ -1,12 +1,14 @@ package info.nightscout.androidaps.plugins.PumpCombo; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.util.ArrayList; import java.util.List; import de.jotomo.ruffy.spi.BasalProfile; import de.jotomo.ruffy.spi.PumpState; +import de.jotomo.ruffy.spi.history.Bolus; import de.jotomo.ruffy.spi.history.PumpAlert; import de.jotomo.ruffy.spi.history.Tdd; @@ -20,6 +22,8 @@ class ComboPump { volatile int reservoirLevel = -1; @NonNull volatile BasalProfile basalProfile = new BasalProfile(); + @Nullable + volatile Bolus lastBolus; // Alert and TDD histories are not stored in DB, but are read on demand and just cached here List errorHistory = new ArrayList<>(0); diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index 54e3e2f3d1..29d8659d53 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -236,7 +236,6 @@ -