Combo Fragment misc.

This commit is contained in:
Johannes Mockenhaupt 2017-10-19 23:01:27 +02:00
parent 71eff7ec79
commit 3d6c8ee2a5
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 55 additions and 63 deletions

View file

@ -68,15 +68,6 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.combo_refresh: case R.id.combo_refresh:
/* Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
statusView.setText("Refreshing");
}
});
}*/
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -97,6 +88,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
@Override @Override
public void run() { public void run() {
statusView.setText(ev.status); statusView.setText(ev.status);
statusView.setTextColor(Color.WHITE);
} }
}); });
} else { } else {
@ -111,6 +103,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
@Override @Override
public void run() { public void run() {
ComboPlugin plugin = ComboPlugin.getPlugin(); ComboPlugin plugin = ComboPlugin.getPlugin();
// status
if (plugin.getPump().lastCmdResult == null) { if (plugin.getPump().lastCmdResult == null) {
statusView.setText("Initializing"); statusView.setText("Initializing");
} else { } else {
@ -118,57 +111,55 @@ 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 ) {
statusView.setTextColor(Color.YELLOW);
} else { } else {
statusView.setTextColor(Color.WHITE); statusView.setTextColor(Color.WHITE);
} }
// ???
if (plugin.isInitialized()) { if (plugin.isInitialized()) {
// TBR
PumpState ps = plugin.getPump().state; PumpState ps = plugin.getPump().state;
if (ps != null) { boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100; if (tbrActive) {
if (tbrActive) { String tbr = ps.tbrPercent + "% (" + ps.tbrRemainingDuration + " m remaining)";
// tbrPercentageText.setText("" + ps.tbrPercent + "%"); tempBasalText.setText(tbr);
// tbrDurationText.setText("" + ps.tbrRemainingDuration + " min"); } else {
// tbrRateText.setText("" + ps.tbrRate + " U/h"); tempBasalText.setText("");
} else {
// tbrPercentageText.setText("Default basal rate running");
// tbrDurationText.setText("");
// tbrRateText.setText("");
}
// pumpErrorText.setText(ps.errorMsg != null ? ps.errorMsg : "");
if (ps.batteryState == PumpState.EMPTY) {
batteryView.setText("{fa-battery-empty}");
batteryView.setTextColor(Color.RED);
} else if (ps.batteryState == PumpState.LOW) {
batteryView.setText("{fa-battery-quarter}");
batteryView.setTextColor(Color.YELLOW);
} else {
batteryView.setText("{fa-battery-full}");
batteryView.setTextColor(Color.WHITE);
}
switch (ps.insulinState) {
case 0:
reservoirView.setText("ok");
break;
case 1:
reservoirView.setText("low");
break;
case 2:
reservoirView.setText("empty");
break;
}
int reservoirLevel = plugin.getPump().history.reservoirLevel;
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
} }
if (plugin.getPump().lastCmdResult != null) { // battery
CommandResult lastCmdResult = plugin.getPump().lastCmdResult; if (ps.batteryState == PumpState.EMPTY) {
lastConnectionView.setText( batteryView.setText("{fa-battery-empty}");
"4 m ago (18:58)" batteryView.setTextColor(Color.RED);
// new Date(lastCmdResult.completionTime).toLocaleString() } else if (ps.batteryState == PumpState.LOW) {
); batteryView.setText("{fa-battery-quarter}");
batteryView.setTextColor(Color.YELLOW);
} else {
batteryView.setText("{fa-battery-full}");
batteryView.setTextColor(Color.WHITE);
} }
// reservoir
if (ps.insulinState == PumpState.LOW) {
reservoirView.setTextColor(Color.YELLOW);
} else if (ps.insulinState == PumpState.EMPTY) {
reservoirView.setTextColor(Color.RED);
} else {
reservoirView.setTextColor(Color.WHITE);
}
int reservoirLevel = plugin.getPump().history.reservoirLevel;
reservoirView.setText(reservoirLevel == -1 ? "" : "" + reservoirLevel + " U");
// last connection
CommandResult lastCmdResult = plugin.getPump().lastCmdResult;
if (lastCmdResult != null) {
String minAgo = DateUtil.minAgo(lastCmdResult.completionTime);
String time = DateUtil.timeString(lastCmdResult.completionTime);
lastConnectionView.setText("" + minAgo + " (" + time + ")");
}
// last bolus
plugin.getPump().history.bolusHistory.add(new Bolus(System.currentTimeMillis() - 7 * 60 * 1000, 12.8d)); plugin.getPump().history.bolusHistory.add(new Bolus(System.currentTimeMillis() - 7 * 60 * 1000, 12.8d));
if (!plugin.getPump().history.bolusHistory.isEmpty()) { if (!plugin.getPump().history.bolusHistory.isEmpty()) {
Bolus bolus = plugin.getPump().history.bolusHistory.get(0); Bolus bolus = plugin.getPump().history.bolusHistory.get(0);
@ -184,18 +175,20 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
lastBolusView.setText(DateUtil.timeString(bolus.timestamp) + lastBolusView.setText(DateUtil.timeString(bolus.timestamp) +
" (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " + " (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " +
DecimalFormatter.to2Decimal(bolus.amount) + " U"); DecimalFormatter.to2Decimal(bolus.amount) + " U");
lastBolusView.setText("12.80 U (15 m ago, 19:04)"); // (19:04)"); lastBolusView.setText("12.80 U (15.1 h ago, 19:04)"); // (19:04)");
} }
} }
// basal rate
basaBasalRateView.setText(DecimalFormatter.to2Decimal(plugin.getBaseBasalRate()) + " U/h"); basaBasalRateView.setText(DecimalFormatter.to2Decimal(plugin.getBaseBasalRate()) + " U/h");
TemporaryBasal temporaryBasal = new TemporaryBasal(System.currentTimeMillis()); // temp basal
temporaryBasal.percentRate = 420; // TemporaryBasal temporaryBasal = new TemporaryBasal(System.currentTimeMillis());
temporaryBasal.durationInMinutes = 20; // temporaryBasal.percentRate = 420;
// temporaryBasal.durationInMinutes = 20;
tempBasalText.setText(temporaryBasal.toStringFull()); // tempBasalText.setText(temporaryBasal.toStringFull());
tempBasalText.setText("420% 5/20' (18:45)"); // tempBasalText.setText("420% 5/20' (18:45)");
CommandResult lastCmdResult1 = plugin.getPump().lastCmdResult; CommandResult lastCmdResult1 = plugin.getPump().lastCmdResult;
String lastCmd = lastCmdResult1.request; String lastCmd = lastCmdResult1.request;

View file

@ -287,7 +287,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
} }
// TODO uses profile values for the time being // TODO uses profile values for the time being
// this get's called mulitple times a minute, must absolutely be cached // this get's called multiple times a minute, must absolutely be cached
@Override @Override
public double getBaseBasalRate() { public double getBaseBasalRate() {
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();

View file

@ -90,14 +90,13 @@
<com.joanzapata.iconify.widget.IconTextView <com.joanzapata.iconify.widget.IconTextView
android:id="@+id/combo_pumpstate_battery" android:id="@+id/combo_pumpstate_battery"
android:layout_weight="1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@android:color/white" android:layout_weight="1"
android:textSize="14sp"
android:paddingLeft="5dp"
android:gravity="start" android:gravity="start"
android:text="" /> android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="20dp" />
</LinearLayout> </LinearLayout>