Silly me, of course fragments (and everything else) are recreated by Android all the time.
This commit is contained in:
parent
29e7ea1966
commit
e9fa9b1788
2 changed files with 29 additions and 42 deletions
|
@ -53,16 +53,9 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
|
|||
lastCmdTime = (TextView) view.findViewById(R.id.combo_last_command_time);
|
||||
lastCmdResult = (TextView) view.findViewById(R.id.combo_last_command_result);
|
||||
|
||||
status.setText("Initializing");
|
||||
tbrPercentage.setText("");
|
||||
tbrDurationRemaining.setText("");
|
||||
tbrRate.setText("");
|
||||
lastCmd.setText("");
|
||||
lastCmdTime.setText("");
|
||||
lastCmdResult.setText("");
|
||||
|
||||
refresh.setOnClickListener(this);
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -87,12 +80,10 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
|
|||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.combo_refresh:
|
||||
status.setText("Refreshing");
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getPlugin().refreshDataFromPump("User request");
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
|
@ -107,25 +98,27 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
|
|||
@Override
|
||||
public void run() {
|
||||
status.setText(getPlugin().statusSummary);
|
||||
PumpState ps = getPlugin().pumpState;
|
||||
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
||||
if (tbrActive) {
|
||||
tbrPercentage.setText("" + ps.tbrPercent + "%");
|
||||
tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min");
|
||||
tbrRate.setText("" + ps.tbrRate + " U/h");
|
||||
} else {
|
||||
tbrPercentage.setText("Default basal rate running");
|
||||
tbrDurationRemaining.setText("");
|
||||
tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h");
|
||||
}
|
||||
if (getPlugin().lastCmd != null) {
|
||||
lastCmd.setText("" + getPlugin().lastCmd);
|
||||
lastCmdTime.setText(ps.timestamp.toLocaleString());
|
||||
lastCmdResult.setText(ps.errorMsg == null ? "Success" : ps.errorMsg);
|
||||
} else {
|
||||
lastCmd.setText("");
|
||||
lastCmdTime.setText("");
|
||||
lastCmdResult.setText("");
|
||||
if (getPlugin().isInitialized()) {
|
||||
PumpState ps = getPlugin().pumpState;
|
||||
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
|
||||
if (tbrActive) {
|
||||
tbrPercentage.setText("" + ps.tbrPercent + "%");
|
||||
tbrDurationRemaining.setText("" + ps.tbrRemainingDuration + " min");
|
||||
tbrRate.setText("" + ps.tbrRate + " U/h");
|
||||
} else {
|
||||
tbrPercentage.setText("Default basal rate running");
|
||||
tbrDurationRemaining.setText("");
|
||||
tbrRate.setText("" + getPlugin().getBaseBasalRate() + " U/h");
|
||||
}
|
||||
if (getPlugin().lastCmd != null) {
|
||||
lastCmd.setText("" + getPlugin().lastCmd);
|
||||
lastCmdTime.setText(ps.timestamp.toLocaleString());
|
||||
lastCmdResult.setText(ps.errorMsg == null ? "Success" : ps.errorMsg);
|
||||
} else {
|
||||
lastCmd.setText("");
|
||||
lastCmdTime.setText("");
|
||||
lastCmdResult.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -108,12 +108,6 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
ruffyScripter = new RuffyScripter(IRuffyService.Stub.asInterface(service));
|
||||
log.debug("ruffy serivce connected");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.debug("Querying pump for initial state");
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,9 +130,9 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
long lastAlarmTime = 0;
|
||||
while (true) {
|
||||
String errorMsg = pumpState.errorMsg;
|
||||
long now = System.currentTimeMillis();
|
||||
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
|
||||
if (errorMsg != null)
|
||||
if (errorMsg != null) {
|
||||
long now = System.currentTimeMillis();
|
||||
long fiveMinutesSinceLastAlarm = lastAlarmTime + (5 * 60 * 1000) + (15 * 1000);
|
||||
if (now > fiveMinutesSinceLastAlarm) {
|
||||
log.warn("Pump is in error state, raising alert: " + errorMsg);
|
||||
log.warn(" LastCmd: " + lastCmd);
|
||||
|
@ -159,8 +153,9 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
lastAlarmTime = now;
|
||||
} else {
|
||||
log.warn("Pump still in error state, but alarm raised recently, so not triggering again: " + errorMsg);
|
||||
}
|
||||
} else {
|
||||
log.debug("Pump state normal");
|
||||
log.trace("Pump state normal");
|
||||
}
|
||||
SystemClock.sleep(5 * 1000);
|
||||
}
|
||||
|
@ -257,9 +252,8 @@ public class ComboPlugin implements PluginBase, PumpInterface {
|
|||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
// TODO
|
||||
// hm, lastCmdDate > 0, like the DanaR does it?
|
||||
return true; // scripter does this as needed; ruffyScripter != null;
|
||||
// consider initialized when the pump's state was initially fetched
|
||||
return lastCmdTime.getTime() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue