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,9 +172,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
|
||||||
|
|
||||||
|
|
||||||
public void updateGUI() {
|
public void updateGUI() {
|
||||||
Activity fragmentActivity = getActivity();
|
runOnUiThread(() -> {
|
||||||
if (fragmentActivity != null)
|
|
||||||
fragmentActivity.runOnUiThread(() -> {
|
|
||||||
ComboPlugin plugin = ComboPlugin.getPlugin();
|
ComboPlugin plugin = ComboPlugin.getPlugin();
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
|
Loading…
Reference in a new issue