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.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 TextView stateView;
@ -50,6 +50,7 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
refresh = (Button) view.findViewById(R.id.combo_refresh);
refresh.setOnClickListener(this);
refresh.setOnLongClickListener(this);
updateGUI();
return view;
@ -59,16 +60,24 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis
public void onClick(View view) {
switch (view.getId()) {
case R.id.combo_refresh:
Thread thread = new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request"));
thread.start();
new Thread(() -> ComboPlugin.getPlugin().refreshDataFromPump("User request")).start();
break;
case R.id.combo_error_history:
// TODO show popup with pump errors and comm problems
// steal code from profile view, called on overview
// TODO v2 show popup with pump errors and comm problems steal code from profile view, called on overview
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
public void onStatusEvent(final EventComboPumpUpdateGUI ev) {
updateGUI();

View file

@ -716,7 +716,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
if (sync) {
// 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?
@ -798,13 +798,13 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (syncNeeded) {
runFullSync(request);
syncHistory(request);
}
return true;
}
private void runFullSync(final PumpHistoryRequest request) {
private void syncHistory(final PumpHistoryRequest request) {
CommandResult result = runCommand("Syncing pump history", 3, () -> ruffyScripter.readHistory(request));
if (!result.success) {
// TODO
@ -833,10 +833,24 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
// errors
// TODO
// tdd
// TODO v3
CommandResult refreshResult = runCommand("Refreshing", 3, ruffyScripter::readReservoirLevelAndLastBolus);
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
public PumpEnactResult cancelExtendedBolus() {
return OPERATION_NOT_SUPPORTED;

View file

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