ComboFragment: colours and text for last connection.
This commit is contained in:
parent
6a01ca1d4d
commit
e09d337c02
|
@ -15,6 +15,8 @@ import com.squareup.otto.Subscribe;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.jotomo.ruffy.spi.CommandResult;
|
||||
import de.jotomo.ruffy.spi.PumpState;
|
||||
import de.jotomo.ruffy.spi.history.Bolus;
|
||||
|
@ -141,19 +143,32 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
if (lastCmdResult != null) {
|
||||
String minAgo = DateUtil.minAgo(lastCmdResult.completionTime);
|
||||
String time = DateUtil.timeString(lastCmdResult.completionTime);
|
||||
lastConnectionView.setText("" + minAgo + " (" + time + ")");
|
||||
if (plugin.getPump().lastSuccessfulConnection < System.currentTimeMillis() + 30 * 60 * 1000) {
|
||||
lastConnectionView.setText(
|
||||
"No successful connection" +
|
||||
"\nwithin the last " + minAgo + " min");
|
||||
lastConnectionView.setTextColor(Color.RED);
|
||||
}
|
||||
if (plugin.getPump().lastConnectionAttempt > plugin.getPump().lastSuccessfulConnection) {
|
||||
lastConnectionView.setText("" + minAgo + " (" + time + ")" +
|
||||
"\nLast connect attempt failed");
|
||||
lastConnectionView.setTextColor(Color.YELLOW);
|
||||
} else {
|
||||
lastConnectionView.setText("" + minAgo + " (" + time + ")");
|
||||
lastConnectionView.setTextColor(Color.WHITE);
|
||||
}
|
||||
|
||||
// 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 {
|
||||
List<Bolus> history = plugin.getPump().history.bolusHistory;
|
||||
if (!history.isEmpty() && history.get(0).timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
|
||||
Bolus bolus = history.get(0);
|
||||
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) + ") ");
|
||||
} else {
|
||||
lastBolusView.setText("");
|
||||
}
|
||||
|
||||
// TBR
|
||||
|
|
|
@ -662,6 +662,12 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
MainApp.bus().post(new EventComboPumpUpdateGUI(status));
|
||||
CommandResult commandResult = commandExecution.execute();
|
||||
|
||||
if (commandResult.success) {
|
||||
pump.lastSuccessfulConnection = System.currentTimeMillis();
|
||||
} else {
|
||||
pump.lastConnectionAttempt = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// TODO hm... automatically confirm messages and return them and handle them here proper?
|
||||
// with an option to corfirm all messages, non-critical (letting occlusion alert ring on phone and pump)
|
||||
// or let all alarms ring and don't try to control the pump in any way
|
||||
|
|
|
@ -10,6 +10,9 @@ import de.jotomo.ruffy.spi.history.Bolus;
|
|||
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||
|
||||
class ComboPump {
|
||||
public long lastSuccessfulConnection;
|
||||
public long lastConnectionAttempt;
|
||||
|
||||
@Nullable
|
||||
volatile CommandResult lastCmdResult;
|
||||
@NonNull
|
||||
|
|
Loading…
Reference in a new issue