This commit is contained in:
Johannes Mockenhaupt 2017-11-07 09:36:21 +01:00
parent 445392ee69
commit 5bd2911754
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 27 additions and 11 deletions

View file

@ -12,9 +12,13 @@ import android.widget.TextView;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import org.apache.commons.lang3.StringUtils;
import org.ocpsoft.prettytime.PrettyTime;
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.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.R; import info.nightscout.androidaps.R;
@ -132,17 +136,17 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
} }
// last connection // last connection
String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulConnection); PrettyTime p = new PrettyTime();
String time = DateUtil.timeString(plugin.getPump().lastSuccessfulConnection); String timeAgo = StringUtils.capitalize(p.format(new Date(plugin.getPump().lastSuccessfulConnection)));
String timeAgo = getString(R.string.combo_last_connection_time, minAgo, time);
if (plugin.getPump().lastSuccessfulConnection == 0) { if (plugin.getPump().lastSuccessfulConnection == 0) {
lastConnectionView.setText(R.string.combo_pump_never_connected); lastConnectionView.setText(R.string.combo_pump_never_connected);
lastConnectionView.setTextColor(Color.RED); lastConnectionView.setTextColor(Color.RED);
} else if (plugin.getPump().lastSuccessfulConnection < System.currentTimeMillis() - 30 * 60 * 1000) { } else if (plugin.getPump().lastSuccessfulConnection < System.currentTimeMillis() - 30 * 60 * 1000) {
lastConnectionView.setText(getString(R.string.combo_no_pump_connection, minAgo)); // lastConnectionView.setText(getString(R.string.combo_no_pump_connection, minAgo));
lastConnectionView.setTextColor(Color.RED); lastConnectionView.setTextColor(Color.RED);
} else if (plugin.getPump().lastConnectionAttempt > plugin.getPump().lastSuccessfulConnection) { } else if (plugin.getPump().lastConnectionAttempt > plugin.getPump().lastSuccessfulConnection) {
lastConnectionView.setText(timeAgo + "\n" + getString(R.string.combo_connect_attempt_failed)); String lastFailed = timeAgo + "\n" + getString(R.string.combo_connect_attempt_failed);
lastConnectionView.setText(lastFailed);
lastConnectionView.setTextColor(Color.YELLOW); lastConnectionView.setTextColor(Color.YELLOW);
} else { } else {
lastConnectionView.setText(timeAgo); lastConnectionView.setText(timeAgo);
@ -155,11 +159,12 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
long agoMsc = System.currentTimeMillis() - bolus.timestamp; long agoMsc = System.currentTimeMillis() - bolus.timestamp;
double bolusMinAgo = agoMsc / 60d / 1000d; double bolusMinAgo = agoMsc / 60d / 1000d;
double bolusHoursAgo = agoMsc / 60d / 60d / 1000d; double bolusHoursAgo = agoMsc / 60d / 60d / 1000d;
lastBolusView.setText(getString(R.string.combo_last_bolus, lastBolusView.setText(String.format("%.1f U (", bolus.amount) + p.format(new Date(bolus.timestamp)) + ")");
bolus.amount, // lastBolusView.setText(getString(R.string.combo_last_bolus,
bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo, // bolus.amount,
bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago), // bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
DateUtil.timeString(bolus.timestamp))); // bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago),
// DateUtil.timeString(bolus.timestamp)));
} else { } else {
lastBolusView.setText(""); lastBolusView.setText("");
} }
@ -171,9 +176,15 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
long remaining = ps.tbrRemainingDuration - minSinceRead; long remaining = ps.tbrRemainingDuration - minSinceRead;
if (remaining >= 0) { if (remaining >= 0) {
tbrStr = getString(R.string.combo_tbr_remaining, ps.tbrPercent, remaining); tbrStr = getString(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
tbrStr = ps.tbrPercent + "% (" + p.formatDuration(new Date(System.currentTimeMillis() + remaining * 60 * 1000)) + " remaining)";
} }
} }
tempBasalText.setText(tbrStr); tempBasalText.setText(tbrStr);
// TODO error ratio?
// display last warning/error?
// last comm error?
} }
}); });
} }

View file

@ -536,6 +536,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
PumpEnactResult pumpEnactResult = new PumpEnactResult(); PumpEnactResult pumpEnactResult = new PumpEnactResult();
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
checkForTbrMismatch();
if (activeTemp == null || userRequested) { if (activeTemp == null || userRequested) {
/* v1 compatibility to sync DB to pump if they diverged (activeTemp == null) */ /* v1 compatibility to sync DB to pump if they diverged (activeTemp == null) */
@ -575,6 +576,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
// TODO properly check pumpstate to confirm cancellation // TODO properly check pumpstate to confirm cancellation
PumpState state = commandResult.state;
if (!state.tbrActive && state.tbrPercent == percent
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
if (tempBasal != null) { if (tempBasal != null) {
@ -668,6 +672,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
// TODO rename to checkState or so and also check time (& date) of pump // TODO rename to checkState or so and also check time (& date) of pump
// implicit param 'pump'
private void checkForTbrMismatch() { private void checkForTbrMismatch() {
// detectTbrMismatch(): 'quick' check with no overhead on the pump side // detectTbrMismatch(): 'quick' check with no overhead on the pump side
// TODO check if this works with pump suspend, esp. around pump suspend there'll be syncing to do; // TODO check if this works with pump suspend, esp. around pump suspend there'll be syncing to do;

View file

@ -28,6 +28,6 @@ class ComboPump {
volatile BasalProfile basalProfile; volatile BasalProfile basalProfile;
@NonNull @NonNull
volatile PumpHistory history = new PumpHistory(); volatile PumpHistory history = new PumpHistory();
/** Time the active TBR was set (if any) */ /** Time the active TBR was set (if any). Needed to calculate remaining time in fragment */
long tbrSetTime; long tbrSetTime;
} }