Make accessing pump/cmd state in Fragment safer.

This commit is contained in:
Johannes Mockenhaupt 2017-07-20 18:28:57 +02:00
parent cb8a22582a
commit 46b1dff334
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -109,9 +109,7 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
statusText.setText(getPlugin().statusSummary);
if (getPlugin().isInitialized()) {
PumpState ps = getPlugin().pumpState;
if (ps == null) {
return;
}
if (ps != null) {
boolean tbrActive = ps.tbrPercent != -1 && ps.tbrPercent != 100;
if (tbrActive) {
tbrPercentageText.setText("" + ps.tbrPercent + "%");
@ -123,19 +121,21 @@ public class ComboFragment extends Fragment implements View.OnClickListener {
tbrRateText.setText("" + getPlugin().getBaseBasalRate() + " U/h");
}
pumpErrorText.setText(ps.errorMsg != null ? ps.errorMsg : "");
if (getPlugin().lastCmd != null) {
lastCmdText.setText("" + getPlugin().lastCmd);
lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString());
CommandResult lastCmdResult = getPlugin().lastCmdResult;
if (lastCmdResult != null) {
String message = lastCmdResult.message;
lastCmdResultText.setText(message != null ? message : "");
} else {
lastCmdResultText.setText("");
}
Command lastCmd = getPlugin().lastCmd;
if (lastCmd != null) {
lastCmdText.setText(lastCmd.toString());
lastCmdTimeText.setText(getPlugin().lastCmdTime.toLocaleString());
} else {
ComboFragment.this.lastCmdText.setText("");
lastCmdText.setText("");
lastCmdTimeText.setText("");
}
CommandResult lastCmdResult = getPlugin().lastCmdResult;
if (lastCmdResult != null && lastCmdResult.message != null) {
lastCmdResultText.setText(lastCmdResult.message);
} else {
lastCmdResultText.setText("");
}
}