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) {
switch (view.getId()) {
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() {
@Override
public void run() {
@ -97,6 +88,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
@Override
public void run() {
statusView.setText(ev.status);
statusView.setTextColor(Color.WHITE);
}
});
} else {
@ -111,6 +103,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
@Override
public void run() {
ComboPlugin plugin = ComboPlugin.getPlugin();
// status
if (plugin.getPump().lastCmdResult == null) {
statusView.setText("Initializing");
} else {
@ -118,24 +111,24 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
}
if (plugin.getPump().state.errorMsg != null) {
statusView.setTextColor(Color.RED);
} else if (plugin.getPump().state.suspended ) {
statusView.setTextColor(Color.YELLOW);
} else {
statusView.setTextColor(Color.WHITE);
}
// ???
if (plugin.isInitialized()) {
// TBR
PumpState ps = plugin.getPump().state;
if (ps != null) {
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
if (tbrActive) {
// tbrPercentageText.setText("" + ps.tbrPercent + "%");
// tbrDurationText.setText("" + ps.tbrRemainingDuration + " min");
// tbrRateText.setText("" + ps.tbrRate + " U/h");
String tbr = ps.tbrPercent + "% (" + ps.tbrRemainingDuration + " m remaining)";
tempBasalText.setText(tbr);
} else {
// tbrPercentageText.setText("Default basal rate running");
// tbrDurationText.setText("");
// tbrRateText.setText("");
tempBasalText.setText("");
}
// pumpErrorText.setText(ps.errorMsg != null ? ps.errorMsg : "");
// battery
if (ps.batteryState == PumpState.EMPTY) {
batteryView.setText("{fa-battery-empty}");
batteryView.setTextColor(Color.RED);
@ -146,29 +139,27 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
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;
// 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");
}
if (plugin.getPump().lastCmdResult != null) {
// last connection
CommandResult lastCmdResult = plugin.getPump().lastCmdResult;
lastConnectionView.setText(
"4 m ago (18:58)"
// new Date(lastCmdResult.completionTime).toLocaleString()
);
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));
if (!plugin.getPump().history.bolusHistory.isEmpty()) {
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) +
" (" + DecimalFormatter.to1Decimal(agoHours) + " " + MainApp.sResources.getString(R.string.hoursago) + ") " +
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");
TemporaryBasal temporaryBasal = new TemporaryBasal(System.currentTimeMillis());
temporaryBasal.percentRate = 420;
temporaryBasal.durationInMinutes = 20;
// temp basal
// TemporaryBasal temporaryBasal = new TemporaryBasal(System.currentTimeMillis());
// temporaryBasal.percentRate = 420;
// temporaryBasal.durationInMinutes = 20;
tempBasalText.setText(temporaryBasal.toStringFull());
tempBasalText.setText("420% 5/20' (18:45)");
// tempBasalText.setText(temporaryBasal.toStringFull());
// tempBasalText.setText("420% 5/20' (18:45)");
CommandResult lastCmdResult1 = plugin.getPump().lastCmdResult;
String lastCmd = lastCmdResult1.request;

View file

@ -287,7 +287,7 @@ public class ComboPlugin implements PluginBase, PumpInterface {
}
// 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
public double getBaseBasalRate() {
Profile profile = MainApp.getConfigBuilder().getProfile();

View file

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