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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -141,19 +143,32 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
if (lastCmdResult != null) {
|
if (lastCmdResult != null) {
|
||||||
String minAgo = DateUtil.minAgo(lastCmdResult.completionTime);
|
String minAgo = DateUtil.minAgo(lastCmdResult.completionTime);
|
||||||
String time = DateUtil.timeString(lastCmdResult.completionTime);
|
String time = DateUtil.timeString(lastCmdResult.completionTime);
|
||||||
|
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.setText("" + minAgo + " (" + time + ")");
|
||||||
|
lastConnectionView.setTextColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
// last bolus
|
// last bolus
|
||||||
plugin.getPump().history.bolusHistory.add(new Bolus(System.currentTimeMillis() - 7 * 60 * 1000, 12.8d));
|
List<Bolus> history = plugin.getPump().history.bolusHistory;
|
||||||
Bolus bolus = plugin.getPump().lastBolus;
|
if (!history.isEmpty() && history.get(0).timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
|
||||||
if (bolus == null || bolus.timestamp + 6 * 60 * 60 * 1000 < System.currentTimeMillis()) {
|
Bolus bolus = history.get(0);
|
||||||
lastBolusView.setText("");
|
|
||||||
} else {
|
|
||||||
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
||||||
double agoHours = agoMsc / 60d / 60d / 1000d;
|
double agoHours = agoMsc / 60d / 60d / 1000d;
|
||||||
lastBolusView.setText(DecimalFormatter.to2Decimal(bolus.amount) + " U " +
|
lastBolusView.setText(DecimalFormatter.to2Decimal(bolus.amount) + " U " +
|
||||||
"(" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ", "
|
"(" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ", "
|
||||||
+ DateUtil.timeString(bolus.timestamp) + ") ");
|
+ DateUtil.timeString(bolus.timestamp) + ") ");
|
||||||
|
} else {
|
||||||
|
lastBolusView.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TBR
|
// TBR
|
||||||
|
|
|
@ -662,6 +662,12 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
||||||
MainApp.bus().post(new EventComboPumpUpdateGUI(status));
|
MainApp.bus().post(new EventComboPumpUpdateGUI(status));
|
||||||
CommandResult commandResult = commandExecution.execute();
|
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?
|
// 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)
|
// 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
|
// 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;
|
import de.jotomo.ruffy.spi.history.PumpHistory;
|
||||||
|
|
||||||
class ComboPump {
|
class ComboPump {
|
||||||
|
public long lastSuccessfulConnection;
|
||||||
|
public long lastConnectionAttempt;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
volatile CommandResult lastCmdResult;
|
volatile CommandResult lastCmdResult;
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
Loading…
Reference in a new issue