wip ..
This commit is contained in:
parent
445392ee69
commit
5bd2911754
3 changed files with 27 additions and 11 deletions
|
@ -12,9 +12,13 @@ import android.widget.TextView;
|
|||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import de.jotomo.ruffy.spi.PumpState;
|
||||
import de.jotomo.ruffy.spi.history.Bolus;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -132,17 +136,17 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
}
|
||||
|
||||
// last connection
|
||||
String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulConnection);
|
||||
String time = DateUtil.timeString(plugin.getPump().lastSuccessfulConnection);
|
||||
String timeAgo = getString(R.string.combo_last_connection_time, minAgo, time);
|
||||
PrettyTime p = new PrettyTime();
|
||||
String timeAgo = StringUtils.capitalize(p.format(new Date(plugin.getPump().lastSuccessfulConnection)));
|
||||
if (plugin.getPump().lastSuccessfulConnection == 0) {
|
||||
lastConnectionView.setText(R.string.combo_pump_never_connected);
|
||||
lastConnectionView.setTextColor(Color.RED);
|
||||
} 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);
|
||||
} 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);
|
||||
} else {
|
||||
lastConnectionView.setText(timeAgo);
|
||||
|
@ -155,11 +159,12 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
||||
double bolusMinAgo = agoMsc / 60d / 1000d;
|
||||
double bolusHoursAgo = agoMsc / 60d / 60d / 1000d;
|
||||
lastBolusView.setText(getString(R.string.combo_last_bolus,
|
||||
bolus.amount,
|
||||
bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
|
||||
bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago),
|
||||
DateUtil.timeString(bolus.timestamp)));
|
||||
lastBolusView.setText(String.format("%.1f U (", bolus.amount) + p.format(new Date(bolus.timestamp)) + ")");
|
||||
// lastBolusView.setText(getString(R.string.combo_last_bolus,
|
||||
// bolus.amount,
|
||||
// bolusMinAgo < 60 ? bolusMinAgo : bolusHoursAgo,
|
||||
// bolusMinAgo < 60 ? getString(R.string.minago) : getString(R.string.hoursago),
|
||||
// DateUtil.timeString(bolus.timestamp)));
|
||||
} else {
|
||||
lastBolusView.setText("");
|
||||
}
|
||||
|
@ -171,9 +176,15 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
|||
long remaining = ps.tbrRemainingDuration - minSinceRead;
|
||||
if (remaining >= 0) {
|
||||
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);
|
||||
|
||||
|
||||
// TODO error ratio?
|
||||
// display last warning/error?
|
||||
// last comm error?
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -536,6 +536,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
PumpEnactResult pumpEnactResult = new PumpEnactResult();
|
||||
|
||||
final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
checkForTbrMismatch();
|
||||
|
||||
if (activeTemp == null || userRequested) {
|
||||
/* 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
|
||||
PumpState state = commandResult.state;
|
||||
if (!state.tbrActive && state.tbrPercent == percent
|
||||
&& (state.tbrRemainingDuration == durationInMinutes || state.tbrRemainingDuration == durationInMinutes - 1)) {
|
||||
|
||||
|
||||
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
|
||||
// implicit param 'pump'
|
||||
private void checkForTbrMismatch() {
|
||||
// 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;
|
||||
|
|
|
@ -28,6 +28,6 @@ class ComboPump {
|
|||
volatile BasalProfile basalProfile;
|
||||
@NonNull
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue