Refresh entire pump state when long-pressing Combo tab's refresh button.

This commit is contained in:
Johannes Mockenhaupt 2017-11-03 14:23:47 +01:00
parent 604a9e664a
commit 49885afb39
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 38 additions and 8 deletions

View file

@ -22,7 +22,7 @@ import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI; import info.nightscout.androidaps.plugins.PumpCombo.events.EventComboPumpUpdateGUI;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
public class ComboFragment extends SubscriberFragment implements View.OnClickListener { public class ComboFragment extends SubscriberFragment implements View.OnClickListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(ComboFragment.class); private static Logger log = LoggerFactory.getLogger(ComboFragment.class);
private TextView stateView; private TextView stateView;
@ -50,6 +50,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
refresh = (Button) view.findViewById(R.id.combo_refresh); refresh = (Button) view.findViewById(R.id.combo_refresh);
refresh.setOnClickListener(this); refresh.setOnClickListener(this);
refresh.setOnLongClickListener(this);
updateGUI(); updateGUI();
return view; return view;
@ -59,16 +60,24 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
public void onClick(View view) { public void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.combo_refresh: case R.id.combo_refresh:
Thread thread = new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")); new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start();
thread.start();
break; break;
case R.id.combo_error_history: case R.id.combo_error_history:
// TODO show popup with pump errors and comm problems // TODO v2 show popup with pump errors and comm problems steal code from profile view, called on overview
// steal code from profile view, called on overview
break; break;
} }
} }
@Override
public boolean onLongClick(View view) {
switch (view.getId()) {
case R.id.combo_refresh:
new Thread(() -> ComboPlugin.getPlugin().forceSyncFullHistory()).start();
return true;
}
return false;
}
@Subscribe @Subscribe
public void onStatusEvent(final EventComboPumpUpdateGUI ev) { public void onStatusEvent(final EventComboPumpUpdateGUI ev) {
updateGUI(); updateGUI();

View file

@ -716,7 +716,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
} }
if (sync) { if (sync) {
// todo just return the PHR? // todo just return the PHR?
runFullSync(new PumpHistoryRequest().tbrHistory(System.currentTimeMillis() - 3 * 60 * 60 * 1000)); syncHistory(new PumpHistoryRequest().tbrHistory(System.currentTimeMillis() - 3 * 60 * 60 * 1000));
} }
// TODO request a loop run to (re)apply a TBR/SMB given this new information? or just wait till next iteration? // TODO request a loop run to (re)apply a TBR/SMB given this new information? or just wait till next iteration?
@ -798,13 +798,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (syncNeeded) { if (syncNeeded) {
runFullSync(request); syncHistory(request);
} }
return true; return true;
} }
private void runFullSync(final PumpHistoryRequest request) { private void syncHistory(final PumpHistoryRequest request) {
CommandResult result = runCommand("Syncing pump history", 3, () -> ruffyScripter.readHistory(request)); CommandResult result = runCommand("Syncing pump history", 3, () -> ruffyScripter.readHistory(request));
if (!result.success) { if (!result.success) {
// TODO // TODO
@ -833,10 +833,24 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// errors // errors
// TODO // TODO
// tdd
// TODO v3
CommandResult refreshResult = runCommand("Refreshing", 3, ruffyScripter::readReservoirLevelAndLastBolus); CommandResult refreshResult = runCommand("Refreshing", 3, ruffyScripter::readReservoirLevelAndLastBolus);
updateLocalData(refreshResult); updateLocalData(refreshResult);
} }
public void forceSyncFullHistory() {
syncHistory(new PumpHistoryRequest()
.bolusHistory(PumpHistoryRequest.FULL)
.tbrHistory(PumpHistoryRequest.FULL)
.errorHistory(PumpHistoryRequest.FULL)
.tddHistory(PumpHistoryRequest.FULL));
updateLocalData(runCommand(MainApp.sResources.getString(R.string.combo_pump_action_refreshing),
3, ruffyScripter::readPumpState));
}
@Override @Override
public PumpEnactResult cancelExtendedBolus() { public PumpEnactResult cancelExtendedBolus() {
return OPERATION_NOT_SUPPORTED; return OPERATION_NOT_SUPPORTED;

View file

@ -13,6 +13,7 @@ public class PumpHistoryRequest {
public long bolusHistory = SKIP; public long bolusHistory = SKIP;
public long tbrHistory = SKIP; public long tbrHistory = SKIP;
public long pumpErrorHistory = SKIP; public long pumpErrorHistory = SKIP;
public long tddHistory = SKIP;
public PumpHistoryRequest bolusHistory(long bolusHistory) { public PumpHistoryRequest bolusHistory(long bolusHistory) {
this.bolusHistory = bolusHistory; this.bolusHistory = bolusHistory;
@ -29,12 +30,18 @@ public class PumpHistoryRequest {
return this; return this;
} }
public PumpHistoryRequest tddHistory(long tddHistory) {
this.tddHistory = tddHistory;
return this;
}
@Override @Override
public String toString() { public String toString() {
return "PumpHistoryRequest{" + return "PumpHistoryRequest{" +
", bolusHistory=" + bolusHistory + ", bolusHistory=" + bolusHistory +
", tbrHistory=" + tbrHistory + ", tbrHistory=" + tbrHistory +
", pumpErrorHistory=" + pumpErrorHistory + ", pumpErrorHistory=" + pumpErrorHistory +
", tddHistory=" + tddHistory +
'}'; '}';
} }
} }