Bring back last bolus to combo fragment.

(cherry picked from commit 108349e)
This commit is contained in:
Johannes Mockenhaupt 2018-01-20 20:13:08 +01:00
parent 5de588b540
commit e3abe04545
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
5 changed files with 35 additions and 3 deletions

View file

@ -15,6 +15,7 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import de.jotomo.ruffy.spi.PumpState; import de.jotomo.ruffy.spi.PumpState;
import de.jotomo.ruffy.spi.history.Bolus;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
@ -29,6 +30,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
private TextView batteryView; private TextView batteryView;
private TextView reservoirView; private TextView reservoirView;
private TextView lastConnectionView; private TextView lastConnectionView;
private TextView lastBolusView;
private TextView baseBasalRate; private TextView baseBasalRate;
private TextView tempBasalText; private TextView tempBasalText;
private Button refreshButton; private Button refreshButton;
@ -45,6 +47,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
activityView = (TextView) view.findViewById(R.id.combo_activity); activityView = (TextView) view.findViewById(R.id.combo_activity);
batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery); batteryView = (TextView) view.findViewById(R.id.combo_pumpstate_battery);
reservoirView = (TextView) view.findViewById(R.id.combo_insulinstate); 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); lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
baseBasalRate = (TextView) view.findViewById(R.id.combo_base_basal_rate); baseBasalRate = (TextView) view.findViewById(R.id.combo_base_basal_rate);
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal); 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); 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 // base basal rate
baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));

View file

@ -413,6 +413,11 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (result.reservoirLevel != PumpState.UNKNOWN) { if (result.reservoirLevel != PumpState.UNKNOWN) {
pump.reservoirLevel = result.reservoirLevel; 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) { if (result.state.menu != null) {
pump.state = result.state; pump.state = result.state;
} }

View file

@ -1,12 +1,14 @@
package info.nightscout.androidaps.plugins.PumpCombo; package info.nightscout.androidaps.plugins.PumpCombo;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import de.jotomo.ruffy.spi.BasalProfile; import de.jotomo.ruffy.spi.BasalProfile;
import de.jotomo.ruffy.spi.PumpState; 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.PumpAlert;
import de.jotomo.ruffy.spi.history.Tdd; import de.jotomo.ruffy.spi.history.Tdd;
@ -20,6 +22,8 @@ class ComboPump {
volatile int reservoirLevel = -1; volatile int reservoirLevel = -1;
@NonNull @NonNull
volatile BasalProfile basalProfile = new BasalProfile(); 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 // Alert and TDD histories are not stored in DB, but are read on demand and just cached here
List<PumpAlert> errorHistory = new ArrayList<>(0); List<PumpAlert> errorHistory = new ArrayList<>(0);

View file

@ -236,7 +236,6 @@
</LinearLayout> </LinearLayout>
<!-- reading last bolus from pump triggers pump bug
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"
@ -281,7 +280,6 @@
android:textSize="14sp" /> android:textSize="14sp" />
</LinearLayout> </LinearLayout>
-->
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -479,7 +479,7 @@ public class RuffyScripter implements RuffyCommands {
} }
/** /**
* This reads the state of the, which is whatever is currently displayed on the display, * This reads the state of the pump, which is whatever is currently displayed on the display,
* no actions are performed. * no actions are performed.
*/ */
public PumpState readPumpStateInternal() { public PumpState readPumpStateInternal() {