Fix button state in Omnipod tab

This commit is contained in:
Bart Sopers 2020-08-23 23:40:22 +02:00
parent 8911bcd508
commit 78725ec013
3 changed files with 48 additions and 22 deletions

View file

@ -74,6 +74,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorage
import info.nightscout.androidaps.plugins.pump.omnipod.driver.communication.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodFragment;
@ -95,6 +96,8 @@ import io.reactivex.schedulers.Schedulers;
*/
@Singleton
public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, RileyLinkPumpDevice {
private static final long RILEY_LINK_CONNECT_TIMEOUT = 3 * 60 * 1000L; // 3 minutes
private final PodStateManager podStateManager;
private final RileyLinkServiceData rileyLinkServiceData;
private final ServiceTaskExecutor serviceTaskExecutor;
@ -127,8 +130,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
private int timeChangeRetries;
private long nextPodCheck;
private boolean sentIdToFirebase;
private long lastConnectionTimeMillis;// 3 minutes
private static final long RILEY_LINK_CONNECT_TIMEOUT = 3 * 60 * 1000L;
private long lastConnectionTimeMillis;
private boolean podStateActionsAllowed = true;
@Inject
public OmnipodPumpPlugin(
@ -398,6 +401,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
if (firstRun) {
initializeAfterRileyLinkConnection();
} else if (!omnipodStatusRequestList.isEmpty()) {
setAllowPodStateActions(false);
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
while (iterator.hasNext()) {
@ -433,8 +437,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
}
iterator.remove();
setAllowPodStateActions(true);
}
} else if (this.hasTimeDateOrTimeZoneChanged) {
setAllowPodStateActions(false);
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
if (result.success) {
@ -455,6 +461,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
timeChangeRetries = 0;
}
}
setAllowPodStateActions(true);
}
}
@ -535,6 +542,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
// no bolus required, carb only treatment
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
// FIXME do we need this??
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
bolusingEvent.setT(new Treatment());
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
@ -767,6 +775,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
}
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
setAllowPodStateActions(false);
omnipodStatusRequestList.add(pumpStatusRequest);
}
@ -848,6 +857,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
@NonNull
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
setAllowPodStateActions(false);
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
if (result.success) {
@ -856,6 +866,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
result.carbsDelivered(detailedBolusInfo.carbs);
}
setAllowPodStateActions(true);
return result;
}
@ -887,4 +898,17 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
return new PumpEnactResult(getInjector()).success(false).enacted(false).comment(getResourceHelper().gs(resourceId));
}
private void setAllowPodStateActions(boolean allowed) {
if (podStateActionsAllowed != allowed) {
podStateActionsAllowed = allowed;
rxBus.send(new EventOmnipodPodStateActionsAllowedChanged());
}
}
// Allow usage of buttons in Omnipod tab that read or modify the Pod state:
// Refresh Status, Acknowledge Alerts and Get Pulse Log
public boolean isPodStateActionsAllowed() {
return podStateActionsAllowed;
}
}

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.plugins.pump.omnipod.event
import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
class EventOmnipodPodStateActionsAllowedChanged : Event()

View file

@ -23,10 +23,10 @@ import info.nightscout.androidaps.plugins.pump.omnipod.R
import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStatusRequestType
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPodStateActionsAllowedChanged
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.T
@ -101,11 +101,7 @@ class OmnipodFragment : DaggerFragment() {
omnipod_refresh.setOnClickListener {
disablePodActionButtons()
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodState);
commandQueue.readStatus("Clicked Refresh", object : Callback() {
override fun run() {
activity?.runOnUiThread { updatePodActionButtons() }
}
})
commandQueue.readStatus("Clicked Refresh", null)
}
omnipod_rileylink_stats.setOnClickListener {
@ -122,11 +118,7 @@ class OmnipodFragment : DaggerFragment() {
} else {
disablePodActionButtons()
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.AcknowledgeAlerts);
commandQueue.readStatus("Clicked Alert Ack", object : Callback() {
override fun run() {
activity?.runOnUiThread { updatePodActionButtons() }
}
})
commandQueue.readStatus("Clicked Alert Ack", null)
}
}
@ -136,11 +128,7 @@ class OmnipodFragment : DaggerFragment() {
} else {
disablePodActionButtons()
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
commandQueue.readStatus("Clicked Refresh", object : Callback() {
override fun run() {
activity?.runOnUiThread { updatePodActionButtons() }
}
})
commandQueue.readStatus("Clicked Refresh", null)
}
}
}
@ -162,6 +150,12 @@ class OmnipodFragment : DaggerFragment() {
updateOmipodStatus()
updatePodActionButtons()
}, { fabricPrivacy.logException(it) })
disposables += rxBus
.toObservable(EventOmnipodPodStateActionsAllowedChanged::class.java)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
updatePodActionButtons()
}, { fabricPrivacy.logException(it) })
disposables += rxBus
.toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
@ -355,13 +349,13 @@ class OmnipodFragment : DaggerFragment() {
}
private fun updateRefreshStatusButton() {
omnipod_refresh.isEnabled = rileyLinkServiceData.rileyLinkServiceState.isReady && podStateManager.isPodInitialized
&& podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED) && !commandQueue.statusInQueue()
omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
&& rileyLinkServiceData.rileyLinkServiceState.isReady && omnipodPumpPlugin.isPodStateActionsAllowed
}
private fun updateAcknowledgeAlertsButton() {
if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts() && !podStateManager.isPodDead) {
omnipod_pod_active_alerts_ack.isEnabled = rileyLinkServiceData.rileyLinkServiceState.isReady && !commandQueue.statusInQueue()
omnipod_pod_active_alerts_ack.isEnabled = omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady
} else {
omnipod_pod_active_alerts_ack.isEnabled = false
}
@ -370,7 +364,7 @@ class OmnipodFragment : DaggerFragment() {
fun updatePulseLogButton() {
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
omnipod_pod_debug.visibility = View.VISIBLE
omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && rileyLinkServiceData.rileyLinkServiceState.isReady && !commandQueue.statusInQueue()
omnipod_pod_debug.isEnabled = podStateManager.isPodActivationCompleted && omnipodPumpPlugin.isPodStateActionsAllowed && rileyLinkServiceData.rileyLinkServiceState.isReady
} else {
omnipod_pod_debug.visibility = View.GONE
}