Add (back) last bolus to ComboFragment.
This commit is contained in:
parent
4517736122
commit
8b8a135804
|
@ -4,7 +4,6 @@ package info.nightscout.androidaps.plugins.PumpCombo;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -16,14 +15,11 @@ import com.squareup.otto.Subscribe;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
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.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.db.TemporaryBasal;
|
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
@ -36,6 +32,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 tempBasalText;
|
private TextView tempBasalText;
|
||||||
|
|
||||||
private Button refresh;
|
private Button refresh;
|
||||||
|
@ -49,6 +46,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
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);
|
||||||
lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
|
lastConnectionView = (TextView) view.findViewById(R.id.combo_lastconnection);
|
||||||
|
lastBolusView = (TextView) view.findViewById(R.id.combo_last_bolus);
|
||||||
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
|
tempBasalText = (TextView) view.findViewById(R.id.combo_temp_basal);
|
||||||
|
|
||||||
refresh = (Button) view.findViewById(R.id.combo_refresh);
|
refresh = (Button) view.findViewById(R.id.combo_refresh);
|
||||||
|
@ -111,7 +109,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
}
|
}
|
||||||
if (plugin.getPump().state.errorMsg != null) {
|
if (plugin.getPump().state.errorMsg != null) {
|
||||||
statusView.setTextColor(Color.RED);
|
statusView.setTextColor(Color.RED);
|
||||||
} else if (plugin.getPump().state.suspended ) {
|
} else if (plugin.getPump().state.suspended) {
|
||||||
statusView.setTextColor(Color.YELLOW);
|
statusView.setTextColor(Color.YELLOW);
|
||||||
} else {
|
} else {
|
||||||
statusView.setTextColor(Color.WHITE);
|
statusView.setTextColor(Color.WHITE);
|
||||||
|
@ -140,7 +138,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
} else {
|
} else {
|
||||||
reservoirView.setTextColor(Color.WHITE);
|
reservoirView.setTextColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
int reservoirLevel = plugin.getPump().history.reservoirLevel;
|
int reservoirLevel = plugin.getPump().reservoirLevel;
|
||||||
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
|
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
|
||||||
|
|
||||||
// last connection
|
// last connection
|
||||||
|
@ -148,6 +146,19 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
String time = DateUtil.timeString(lastCmdResult.completionTime);
|
String time = DateUtil.timeString(lastCmdResult.completionTime);
|
||||||
lastConnectionView.setText("" + minAgo + " (" + time + ")");
|
lastConnectionView.setText("" + minAgo + " (" + time + ")");
|
||||||
|
|
||||||
|
// last bolus
|
||||||
|
plugin.getPump().history.bolusHistory.add(new Bolus(System.currentTimeMillis() - 7 * 60 * 1000, 12.8d));
|
||||||
|
Bolus bolus = plugin.getPump().lastBolus;
|
||||||
|
if (bolus == null || bolus.timestamp + 6 * 60 * 60 * 1000 < System.currentTimeMillis()) {
|
||||||
|
lastBolusView.setText("");
|
||||||
|
} else {
|
||||||
|
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
||||||
|
double agoHours = agoMsc / 60d / 60d / 1000d;
|
||||||
|
lastBolusView.setText(DecimalFormatter.to2Decimal(bolus.amount) + " U " +
|
||||||
|
"(" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ", "
|
||||||
|
+ DateUtil.timeString(bolus.timestamp) + ") ");
|
||||||
|
}
|
||||||
|
|
||||||
// TBR
|
// TBR
|
||||||
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
||||||
if (tbrActive) {
|
if (tbrActive) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import de.jotomo.ruffy.spi.BolusProgressReporter;
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.RuffyCommands;
|
import de.jotomo.ruffy.spi.RuffyCommands;
|
||||||
|
import de.jotomo.ruffy.spi.history.Bolus;
|
||||||
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
|
import de.jotomo.ruffy.spi.history.PumpHistoryRequest;
|
||||||
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
|
import de.jotomo.ruffyscripter.RuffyCommandsV1Impl;
|
||||||
import info.nightscout.androidaps.BuildConfig;
|
import info.nightscout.androidaps.BuildConfig;
|
||||||
|
@ -562,11 +563,18 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
// TODO handle running into WARNING_OR_ERROR ... or scripter? purge it
|
// TODO handle running into WARNING_OR_ERROR ... or scripter? purge it
|
||||||
CommandResult commandResult = commandExecution.execute();
|
CommandResult commandResult = commandExecution.execute();
|
||||||
pump.lastCmdResult = commandResult;
|
pump.lastCmdResult = commandResult;
|
||||||
pump.lastCmdResult.completionTime = System.currentTimeMillis(); // todo
|
|
||||||
pump.state = commandResult.state;
|
pump.state = commandResult.state;
|
||||||
// TOOD
|
// TOOD
|
||||||
if (commandResult.history != null)
|
if (commandResult.history != null) {
|
||||||
|
if (commandResult.history.reservoirLevel != -1) {
|
||||||
|
pump.reservoirLevel = commandResult.history.reservoirLevel;
|
||||||
|
}
|
||||||
pump.history = commandResult.history;
|
pump.history = commandResult.history;
|
||||||
|
if (pump.history.bolusHistory.size() > 0) {
|
||||||
|
pump.lastBolus = pump.history.bolusHistory.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
MainApp.bus().post(new EventComboPumpUpdateGUI());
|
||||||
return commandResult;
|
return commandResult;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ package info.nightscout.androidaps.plugins.PumpCombo;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.PumpState;
|
import de.jotomo.ruffy.spi.PumpState;
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
|
import de.jotomo.ruffy.spi.history.Bolus;
|
||||||
import de.jotomo.ruffy.spi.history.PumpHistory;
|
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||||
|
|
||||||
class ComboPump {
|
class ComboPump {
|
||||||
|
@ -16,4 +16,7 @@ class ComboPump {
|
||||||
volatile PumpState state = new PumpState();
|
volatile PumpState state = new PumpState();
|
||||||
@NonNull
|
@NonNull
|
||||||
volatile PumpHistory history = new PumpHistory();
|
volatile PumpHistory history = new PumpHistory();
|
||||||
|
@Nullable
|
||||||
|
volatile Bolus lastBolus;
|
||||||
|
volatile int reservoirLevel = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,6 +190,51 @@
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1.5"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/pump_lastbolus_label"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/combo_last_bolus"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="start"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="2dip"
|
android:layout_height="2dip"
|
||||||
|
|
|
@ -11,6 +11,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import de.jotomo.ruffy.spi.history.Bolus;
|
||||||
|
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||||
import de.jotomo.ruffyscripter.RuffyScripter;
|
import de.jotomo.ruffyscripter.RuffyScripter;
|
||||||
import de.jotomo.ruffy.spi.BolusProgressReporter;
|
import de.jotomo.ruffy.spi.BolusProgressReporter;
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
|
@ -199,9 +201,11 @@ public class BolusCommand extends BaseCommand {
|
||||||
+ "did not return the main menu successfully.");
|
+ "did not return the main menu successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArrayList<Bolus> boluses = new ArrayList<>();
|
||||||
|
boluses.add(new Bolus(System.currentTimeMillis(), bolus));
|
||||||
return new CommandResult().success(true).enacted(true)
|
return new CommandResult().success(true).enacted(true)
|
||||||
.message(String.format(Locale.US, "Delivered %02.1f U", bolus));
|
.message(String.format(Locale.US, "Delivered %02.1f U", bolus))
|
||||||
|
.history(new PumpHistory().bolusHistory(boluses));
|
||||||
} catch (CommandException e) {
|
} catch (CommandException e) {
|
||||||
return e.toCommandResult();
|
return e.toCommandResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuDate;
|
||||||
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
import org.monkey.d.ruffy.ruffy.driver.display.menu.MenuTime;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.jotomo.ruffy.spi.CommandResult;
|
import de.jotomo.ruffy.spi.CommandResult;
|
||||||
|
@ -36,25 +37,33 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
scripter.pressCheckKey();
|
scripter.pressCheckKey();
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
|
scripter.verifyMenuIsDisplayed(MenuType.BOLUS_DATA);
|
||||||
if (request.bolusHistory != PumpHistoryRequest.SKIP) {
|
if (request.bolusHistory != PumpHistoryRequest.SKIP) {
|
||||||
// Could also be extended, multiwave:
|
if (request.bolusHistory == PumpHistoryRequest.LAST) {
|
||||||
BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE);
|
// Could also be extended, multiwave:
|
||||||
if (!bolusType.equals(BolusType.NORMAL)) {
|
BolusType bolusType = (BolusType) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS_TYPE);
|
||||||
throw new CommandException().success(false).enacted(false).message("Unsupported bolus type encountered: " + bolusType);
|
if (!bolusType.equals(BolusType.NORMAL)) {
|
||||||
}
|
throw new CommandException().success(false).enacted(false).message("Unsupported bolus type encountered: " + bolusType);
|
||||||
Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS);
|
}
|
||||||
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
|
Double bolus = (Double) scripter.getCurrentMenu().getAttribute(MenuAttribute.BOLUS);
|
||||||
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
|
MenuDate date = (MenuDate) scripter.getCurrentMenu().getAttribute(MenuAttribute.DATE);
|
||||||
|
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
|
||||||
|
// TODO handle year changes; if current month == 1 and record date == 12, use $YEAR-1
|
||||||
|
int currentMonth = new Date().getMonth() + 1;
|
||||||
|
int currentYear = new Date().getYear() + 1900;
|
||||||
|
if (currentMonth == 1 && date.getMonth() == 12) {
|
||||||
|
currentYear -= 1;
|
||||||
|
}
|
||||||
|
long recordDate = new Date(currentYear - 1900, date.getMonth() - 1, date.getDay(), time.getHour(), time.getMinute()).getTime();
|
||||||
|
history.bolusHistory.add(new Bolus(recordDate, bolus));
|
||||||
|
|
||||||
history.bolusHistory.add(new Bolus(0, bolus));
|
// int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
|
||||||
|
// int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
|
||||||
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
|
|
||||||
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
read displayed date, bolus, add to history
|
read displayed date, bolus, add to history
|
||||||
while data > last known, press up to go through history
|
while data > last known, press up to go through history
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
scripter.pressMenuKey();
|
scripter.pressMenuKey();
|
||||||
scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA);
|
scripter.verifyMenuIsDisplayed(MenuType.ERROR_DATA);
|
||||||
|
@ -81,6 +90,7 @@ public class ReadHistoryCommand extends BaseCommand {
|
||||||
// TODO start or end time?
|
// TODO start or end time?
|
||||||
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
|
MenuTime time = (MenuTime) scripter.getCurrentMenu().getAttribute(MenuAttribute.TIME);
|
||||||
}
|
}
|
||||||
|
scripter.pressBackKey();
|
||||||
scripter.returnToRootMenu();
|
scripter.returnToRootMenu();
|
||||||
}
|
}
|
||||||
scripter.verifyRootMenuIsDisplayed();
|
scripter.verifyRootMenuIsDisplayed();
|
||||||
|
|
|
@ -20,6 +20,14 @@ public class MenuDate {
|
||||||
month = Integer.parseInt(p[1]);
|
month = Integer.parseInt(p[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDay() {
|
||||||
|
return day;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMonth() {
|
||||||
|
return month;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return day+"."+ String.format("%02d",month)+".";
|
return day+"."+ String.format("%02d",month)+".";
|
||||||
|
|
Loading…
Reference in a new issue