ComboFragment: disable buttons when running.
This commit is contained in:
parent
d08958e43f
commit
ecd16c26b8
1 changed files with 167 additions and 119 deletions
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
|
||||||
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
import info.nightscout.androidaps.queue.events.EventQueueChanged;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
||||||
|
@ -71,11 +72,24 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runOnUiThread(Runnable action) {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.combo_refresh_button:
|
case R.id.combo_refresh_button:
|
||||||
ConfigBuilderPlugin.getCommandQueue().readStatus("User request", null);
|
refreshButton.setEnabled(false);
|
||||||
|
ConfigBuilderPlugin.getCommandQueue().readStatus("User request", new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runOnUiThread(() -> refreshButton.setEnabled(true));
|
||||||
|
}
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case R.id.combo_alerts_button:
|
case R.id.combo_alerts_button:
|
||||||
ComboAlertHistoryDialog ehd = new ComboAlertHistoryDialog();
|
ComboAlertHistoryDialog ehd = new ComboAlertHistoryDialog();
|
||||||
|
@ -87,24 +101,60 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
break;
|
break;
|
||||||
case R.id.combo_full_history_button:
|
case R.id.combo_full_history_button:
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(R.string.combo_warning);
|
|
||||||
builder.setMessage(R.string.combo_read_full_history_info);
|
builder.setMessage(R.string.combo_read_full_history_info);
|
||||||
builder.show();
|
builder.show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO clean up when when queuing
|
||||||
@Override
|
@Override
|
||||||
public boolean onLongClick(View view) {
|
public boolean onLongClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.combo_alerts_button:
|
case R.id.combo_alerts_button:
|
||||||
new Thread(() -> ComboPlugin.getPlugin().readAlertData()).start();
|
alertsButton.setEnabled(false);
|
||||||
|
tddsButton.setEnabled(false);
|
||||||
|
fullHistoryButton.setEnabled(false);
|
||||||
|
new Thread(() -> ComboPlugin.getPlugin().readAlertData(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
alertsButton.setEnabled(true);
|
||||||
|
tddsButton.setEnabled(true);
|
||||||
|
fullHistoryButton.setEnabled(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})).start();
|
||||||
return true;
|
return true;
|
||||||
case R.id.combo_tdds_button:
|
case R.id.combo_tdds_button:
|
||||||
new Thread(() -> ComboPlugin.getPlugin().readTddData()).start();
|
alertsButton.setEnabled(false);
|
||||||
|
tddsButton.setEnabled(false);
|
||||||
|
fullHistoryButton.setEnabled(false);
|
||||||
|
new Thread(() -> ComboPlugin.getPlugin().readTddData(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
alertsButton.setEnabled(true);
|
||||||
|
tddsButton.setEnabled(true);
|
||||||
|
fullHistoryButton.setEnabled(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})).start();
|
||||||
return true;
|
return true;
|
||||||
case R.id.combo_full_history_button:
|
case R.id.combo_full_history_button:
|
||||||
new Thread(() -> ComboPlugin.getPlugin().readAllPumpData()).start();
|
alertsButton.setEnabled(false);
|
||||||
|
tddsButton.setEnabled(false);
|
||||||
|
fullHistoryButton.setEnabled(false);
|
||||||
|
new Thread(() -> ComboPlugin.getPlugin().readAllPumpData(new Callback() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
runOnUiThread(() -> {
|
||||||
|
alertsButton.setEnabled(true);
|
||||||
|
tddsButton.setEnabled(true);
|
||||||
|
fullHistoryButton.setEnabled(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})).start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,123 +172,121 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
|
|
||||||
|
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
Activity fragmentActivity = getActivity();
|
runOnUiThread(() -> {
|
||||||
if (fragmentActivity != null)
|
ComboPlugin plugin = ComboPlugin.getPlugin();
|
||||||
fragmentActivity.runOnUiThread(() -> {
|
|
||||||
ComboPlugin plugin = ComboPlugin.getPlugin();
|
|
||||||
|
|
||||||
// state
|
// state
|
||||||
stateView.setText(plugin.getStateSummary());
|
stateView.setText(plugin.getStateSummary());
|
||||||
PumpState ps = plugin.getPump().state;
|
PumpState ps = plugin.getPump().state;
|
||||||
if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY
|
if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY
|
||||||
|| ps.activeAlert != null && ps.activeAlert.errorCode != null) {
|
|| ps.activeAlert != null && ps.activeAlert.errorCode != null) {
|
||||||
stateView.setTextColor(Color.RED);
|
stateView.setTextColor(Color.RED);
|
||||||
stateView.setTypeface(null, Typeface.BOLD);
|
stateView.setTypeface(null, Typeface.BOLD);
|
||||||
} else if (plugin.getPump().state.suspended
|
} else if (plugin.getPump().state.suspended
|
||||||
|| ps.activeAlert != null && ps.activeAlert.warningCode != null) {
|
|| ps.activeAlert != null && ps.activeAlert.warningCode != null) {
|
||||||
stateView.setTextColor(Color.YELLOW);
|
stateView.setTextColor(Color.YELLOW);
|
||||||
stateView.setTypeface(null, Typeface.BOLD);
|
stateView.setTypeface(null, Typeface.BOLD);
|
||||||
|
} else {
|
||||||
|
stateView.setTextColor(Color.WHITE);
|
||||||
|
stateView.setTypeface(null, Typeface.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// activity
|
||||||
|
String activity = plugin.getPump().activity;
|
||||||
|
activityView.setText(activity != null ? activity : "");
|
||||||
|
|
||||||
|
if (plugin.isInitialized()) {
|
||||||
|
refreshButton.setVisibility(View.VISIBLE);
|
||||||
|
alertsButton.setVisibility(View.VISIBLE);
|
||||||
|
tddsButton.setVisibility(View.VISIBLE);
|
||||||
|
fullHistoryButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
// battery
|
||||||
|
batteryView.setTextSize(20);
|
||||||
|
if (ps.batteryState == PumpState.EMPTY) {
|
||||||
|
batteryView.setText("{fa-battery-empty}");
|
||||||
|
batteryView.setTextColor(Color.RED);
|
||||||
|
} else if (ps.batteryState == PumpState.LOW) {
|
||||||
|
batteryView.setText("{fa-battery-quarter}");
|
||||||
|
batteryView.setTextColor(Color.YELLOW);
|
||||||
} else {
|
} else {
|
||||||
stateView.setTextColor(Color.WHITE);
|
batteryView.setText("{fa-battery-full}");
|
||||||
stateView.setTypeface(null, Typeface.NORMAL);
|
batteryView.setTextColor(Color.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// activity
|
// reservoir
|
||||||
String activity = plugin.getPump().activity;
|
int reservoirLevel = plugin.getPump().reservoirLevel;
|
||||||
activityView.setText(activity != null ? activity : "");
|
if (reservoirLevel != -1) {
|
||||||
|
reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label));
|
||||||
if (plugin.isInitialized()) {
|
} else if (ps.insulinState == PumpState.LOW) {
|
||||||
refreshButton.setVisibility(View.VISIBLE);
|
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low));
|
||||||
alertsButton.setVisibility(View.VISIBLE);
|
} else if (ps.insulinState == PumpState.EMPTY) {
|
||||||
tddsButton.setVisibility(View.VISIBLE);
|
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty));
|
||||||
fullHistoryButton.setVisibility(View.VISIBLE);
|
} else {
|
||||||
|
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal));
|
||||||
// battery
|
|
||||||
batteryView.setTextSize(20);
|
|
||||||
if (ps.batteryState == PumpState.EMPTY) {
|
|
||||||
batteryView.setText("{fa-battery-empty}");
|
|
||||||
batteryView.setTextColor(Color.RED);
|
|
||||||
} else if (ps.batteryState == PumpState.LOW) {
|
|
||||||
batteryView.setText("{fa-battery-quarter}");
|
|
||||||
batteryView.setTextColor(Color.YELLOW);
|
|
||||||
} else {
|
|
||||||
batteryView.setText("{fa-battery-full}");
|
|
||||||
batteryView.setTextColor(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reservoir
|
|
||||||
int reservoirLevel = plugin.getPump().reservoirLevel;
|
|
||||||
if (reservoirLevel != -1) {
|
|
||||||
reservoirView.setText(reservoirLevel + " " + MainApp.sResources.getString(R.string.treatments_wizard_unit_label));
|
|
||||||
} else if (ps.insulinState == PumpState.LOW) {
|
|
||||||
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_low));
|
|
||||||
} else if (ps.insulinState == PumpState.EMPTY) {
|
|
||||||
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_empty));
|
|
||||||
} else {
|
|
||||||
reservoirView.setText(MainApp.gs(R.string.combo_reservoir_normal));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ps.insulinState == PumpState.UNKNOWN) {
|
|
||||||
reservoirView.setTextColor(Color.WHITE);
|
|
||||||
reservoirView.setTypeface(null, Typeface.NORMAL);
|
|
||||||
} else if (ps.insulinState == PumpState.LOW) {
|
|
||||||
reservoirView.setTextColor(Color.YELLOW);
|
|
||||||
reservoirView.setTypeface(null, Typeface.BOLD);
|
|
||||||
} else if (ps.insulinState == PumpState.EMPTY) {
|
|
||||||
reservoirView.setTextColor(Color.RED);
|
|
||||||
reservoirView.setTypeface(null, Typeface.BOLD);
|
|
||||||
} else {
|
|
||||||
reservoirView.setTextColor(Color.WHITE);
|
|
||||||
reservoirView.setTypeface(null, Typeface.NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(MainApp.gs(R.string.combo_no_pump_connection, min));
|
|
||||||
lastConnectionView.setTextColor(Color.RED);
|
|
||||||
} else {
|
|
||||||
lastConnectionView.setText(minAgo);
|
|
||||||
lastConnectionView.setTextColor(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// last bolus
|
|
||||||
Bolus bolus = plugin.getPump().lastBolus;
|
|
||||||
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
|
|
||||||
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
|
||||||
double bolusMinAgo = agoMsc / 60d / 1000d;
|
|
||||||
String unit = MainApp.gs(R.string.treatments_wizard_unit_label);
|
|
||||||
String ago;
|
|
||||||
if ((agoMsc < 60 * 1000)) {
|
|
||||||
ago = MainApp.gs(R.string.combo_pump_connected_now);
|
|
||||||
} else if (bolusMinAgo < 60) {
|
|
||||||
ago = DateUtil.minAgo(bolus.timestamp);
|
|
||||||
} else {
|
|
||||||
ago = DateUtil.hourAgo(bolus.timestamp);
|
|
||||||
}
|
|
||||||
lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago));
|
|
||||||
} else {
|
|
||||||
lastBolusView.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// base basal rate
|
|
||||||
baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
|
|
||||||
|
|
||||||
// TBR
|
|
||||||
String tbrStr = "";
|
|
||||||
if (ps.tbrPercent != -1 && ps.tbrPercent != 100) {
|
|
||||||
long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60;
|
|
||||||
long remaining = ps.tbrRemainingDuration - minSinceRead;
|
|
||||||
if (remaining >= 0) {
|
|
||||||
tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tempBasalText.setText(tbrStr);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
if (ps.insulinState == PumpState.UNKNOWN) {
|
||||||
|
reservoirView.setTextColor(Color.WHITE);
|
||||||
|
reservoirView.setTypeface(null, Typeface.NORMAL);
|
||||||
|
} else if (ps.insulinState == PumpState.LOW) {
|
||||||
|
reservoirView.setTextColor(Color.YELLOW);
|
||||||
|
reservoirView.setTypeface(null, Typeface.BOLD);
|
||||||
|
} else if (ps.insulinState == PumpState.EMPTY) {
|
||||||
|
reservoirView.setTextColor(Color.RED);
|
||||||
|
reservoirView.setTypeface(null, Typeface.BOLD);
|
||||||
|
} else {
|
||||||
|
reservoirView.setTextColor(Color.WHITE);
|
||||||
|
reservoirView.setTypeface(null, Typeface.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(MainApp.gs(R.string.combo_no_pump_connection, min));
|
||||||
|
lastConnectionView.setTextColor(Color.RED);
|
||||||
|
} else {
|
||||||
|
lastConnectionView.setText(minAgo);
|
||||||
|
lastConnectionView.setTextColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// last bolus
|
||||||
|
Bolus bolus = plugin.getPump().lastBolus;
|
||||||
|
if (bolus != null && bolus.timestamp + 6 * 60 * 60 * 1000 >= System.currentTimeMillis()) {
|
||||||
|
long agoMsc = System.currentTimeMillis() - bolus.timestamp;
|
||||||
|
double bolusMinAgo = agoMsc / 60d / 1000d;
|
||||||
|
String unit = MainApp.gs(R.string.treatments_wizard_unit_label);
|
||||||
|
String ago;
|
||||||
|
if ((agoMsc < 60 * 1000)) {
|
||||||
|
ago = MainApp.gs(R.string.combo_pump_connected_now);
|
||||||
|
} else if (bolusMinAgo < 60) {
|
||||||
|
ago = DateUtil.minAgo(bolus.timestamp);
|
||||||
|
} else {
|
||||||
|
ago = DateUtil.hourAgo(bolus.timestamp);
|
||||||
|
}
|
||||||
|
lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus.amount, unit, ago));
|
||||||
|
} else {
|
||||||
|
lastBolusView.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// base basal rate
|
||||||
|
baseBasalRate.setText(MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate()));
|
||||||
|
|
||||||
|
// TBR
|
||||||
|
String tbrStr = "";
|
||||||
|
if (ps.tbrPercent != -1 && ps.tbrPercent != 100) {
|
||||||
|
long minSinceRead = (System.currentTimeMillis() - plugin.getPump().state.timestamp) / 1000 / 60;
|
||||||
|
long remaining = ps.tbrRemainingDuration - minSinceRead;
|
||||||
|
if (remaining >= 0) {
|
||||||
|
tbrStr = MainApp.gs(R.string.combo_tbr_remaining, ps.tbrPercent, remaining);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tempBasalText.setText(tbrStr);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue