Fix displaying connection problems in Combo tab.

This commit is contained in:
Johannes Mockenhaupt 2017-11-18 17:43:33 +01:00
parent deb566c1bd
commit 99db38a8e0
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 5 additions and 4 deletions

View file

@ -135,11 +135,12 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
// last connection
String minAgo = DateUtil.minAgo(plugin.getPump().lastSuccessfulCmdTime);
long min = (System.currentTimeMillis() - plugin.getPump().lastSuccessfulCmdTime) / 1000 / 60;
if (plugin.getPump().lastSuccessfulCmdTime + 60 * 1000 > System.currentTimeMillis()) {
lastConnectionView.setText(R.string.combo_pump_connected_now);
lastConnectionView.setTextColor(Color.WHITE);
} else if (plugin.getPump().lastSuccessfulCmdTime + 30 * 60 * 1000 < System.currentTimeMillis()) {
lastConnectionView.setText(getString(R.string.combo_no_pump_connection, minAgo));
lastConnectionView.setText(getString(R.string.combo_no_pump_connection, min));
lastConnectionView.setTextColor(Color.RED);
} else if (plugin.getPump().lastCmdTime > plugin.getPump().lastSuccessfulCmdTime) {
String lastFailed = minAgo + "\n" + getString(R.string.combo_connect_attempt_failed);

View file

@ -627,6 +627,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
* NO history, reservoir level fields are updated, this make be done separately if desired.
*/
private synchronized CommandResult runCommand(String activity, int retries, CommandExecution commandExecution) {
pump.lastCmdTime = System.currentTimeMillis();
CommandResult commandResult;
try {
if (activity != null) {
@ -659,11 +660,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
pump.lastCmdResult = commandResult;
pump.lastCmdTime = System.currentTimeMillis();
if (commandResult.success) {
pump.lastSuccessfulCmdTime = pump.lastCmdTime;
}
} finally {
if (activity != null) {
pump.activity = null;

View file

@ -768,7 +768,7 @@
<string name="combo_stats">Stats</string>
<string name="combo_pump_state_label">State</string>
<string name="combo_pump_activity">Activity</string>
<string name="combo_no_pump_connection">No successful connection for %s</string>
<string name="combo_no_pump_connection">No connection for %d min</string>
<string name="combo_connect_attempt_failed">Last connect attempt failed</string>
<string name="combo_last_connection_time">%s</string>
<string name="combo_tbr_remaining">%d%% (%d min remaining)</string>