Fix button state in Omnipod tab
This commit is contained in:
parent
8911bcd508
commit
78725ec013
3 changed files with 48 additions and 22 deletions
|
@ -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.communication.message.response.podinfo.PodInfoRecentPulseLog;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus;
|
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.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.manager.AapsOmnipodManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
|
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.RileyLinkOmnipodService;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodFragment;
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.OmnipodFragment;
|
||||||
|
@ -95,6 +96,8 @@ import io.reactivex.schedulers.Schedulers;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface, RileyLinkPumpDevice {
|
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 PodStateManager podStateManager;
|
||||||
private final RileyLinkServiceData rileyLinkServiceData;
|
private final RileyLinkServiceData rileyLinkServiceData;
|
||||||
private final ServiceTaskExecutor serviceTaskExecutor;
|
private final ServiceTaskExecutor serviceTaskExecutor;
|
||||||
|
@ -127,8 +130,8 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
private int timeChangeRetries;
|
private int timeChangeRetries;
|
||||||
private long nextPodCheck;
|
private long nextPodCheck;
|
||||||
private boolean sentIdToFirebase;
|
private boolean sentIdToFirebase;
|
||||||
private long lastConnectionTimeMillis;// 3 minutes
|
private long lastConnectionTimeMillis;
|
||||||
private static final long RILEY_LINK_CONNECT_TIMEOUT = 3 * 60 * 1000L;
|
private boolean podStateActionsAllowed = true;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OmnipodPumpPlugin(
|
public OmnipodPumpPlugin(
|
||||||
|
@ -398,6 +401,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
initializeAfterRileyLinkConnection();
|
initializeAfterRileyLinkConnection();
|
||||||
} else if (!omnipodStatusRequestList.isEmpty()) {
|
} else if (!omnipodStatusRequestList.isEmpty()) {
|
||||||
|
setAllowPodStateActions(false);
|
||||||
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
|
Iterator<OmnipodStatusRequestType> iterator = omnipodStatusRequestList.iterator();
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
@ -433,8 +437,10 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
aapsLogger.error(LTag.PUMP, "Unknown status request: " + statusRequest.name());
|
||||||
}
|
}
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
|
setAllowPodStateActions(true);
|
||||||
}
|
}
|
||||||
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
} else if (this.hasTimeDateOrTimeZoneChanged) {
|
||||||
|
setAllowPodStateActions(false);
|
||||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetTime, aapsOmnipodManager::setTime);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@ -455,6 +461,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
timeChangeRetries = 0;
|
timeChangeRetries = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setAllowPodStateActions(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,6 +542,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
// no bolus required, carb only treatment
|
// no bolus required, carb only treatment
|
||||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||||
|
|
||||||
|
// FIXME do we need this??
|
||||||
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE;
|
||||||
bolusingEvent.setT(new Treatment());
|
bolusingEvent.setT(new Treatment());
|
||||||
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
bolusingEvent.getT().isSMB = detailedBolusInfo.isSMB;
|
||||||
|
@ -767,6 +775,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
|
public void addPodStatusRequest(OmnipodStatusRequestType pumpStatusRequest) {
|
||||||
|
setAllowPodStateActions(false);
|
||||||
omnipodStatusRequestList.add(pumpStatusRequest);
|
omnipodStatusRequestList.add(pumpStatusRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -848,6 +857,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
protected PumpEnactResult deliverBolus(final DetailedBolusInfo detailedBolusInfo) {
|
||||||
|
setAllowPodStateActions(false);
|
||||||
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
PumpEnactResult result = executeCommand(OmnipodCommandType.SetBolus, () -> aapsOmnipodManager.bolus(detailedBolusInfo));
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
@ -856,6 +866,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
|
||||||
|
|
||||||
result.carbsDelivered(detailedBolusInfo.carbs);
|
result.carbsDelivered(detailedBolusInfo.carbs);
|
||||||
}
|
}
|
||||||
|
setAllowPodStateActions(true);
|
||||||
|
|
||||||
return result;
|
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));
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
|
@ -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.definition.OmnipodStatusRequestType
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProgressStatus
|
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.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.event.EventOmnipodPumpValuesChanged
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil
|
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.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
|
@ -101,11 +101,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
omnipod_refresh.setOnClickListener {
|
omnipod_refresh.setOnClickListener {
|
||||||
disablePodActionButtons()
|
disablePodActionButtons()
|
||||||
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodState);
|
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodState);
|
||||||
commandQueue.readStatus("Clicked Refresh", object : Callback() {
|
commandQueue.readStatus("Clicked Refresh", null)
|
||||||
override fun run() {
|
|
||||||
activity?.runOnUiThread { updatePodActionButtons() }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
omnipod_rileylink_stats.setOnClickListener {
|
omnipod_rileylink_stats.setOnClickListener {
|
||||||
|
@ -122,11 +118,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
} else {
|
} else {
|
||||||
disablePodActionButtons()
|
disablePodActionButtons()
|
||||||
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.AcknowledgeAlerts);
|
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.AcknowledgeAlerts);
|
||||||
commandQueue.readStatus("Clicked Alert Ack", object : Callback() {
|
commandQueue.readStatus("Clicked Alert Ack", null)
|
||||||
override fun run() {
|
|
||||||
activity?.runOnUiThread { updatePodActionButtons() }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,11 +128,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
} else {
|
} else {
|
||||||
disablePodActionButtons()
|
disablePodActionButtons()
|
||||||
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
|
omnipodPumpPlugin.addPodStatusRequest(OmnipodStatusRequestType.GetPodPulseLog);
|
||||||
commandQueue.readStatus("Clicked Refresh", object : Callback() {
|
commandQueue.readStatus("Clicked Refresh", null)
|
||||||
override fun run() {
|
|
||||||
activity?.runOnUiThread { updatePodActionButtons() }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,6 +150,12 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
updateOmipodStatus()
|
updateOmipodStatus()
|
||||||
updatePodActionButtons()
|
updatePodActionButtons()
|
||||||
}, { fabricPrivacy.logException(it) })
|
}, { fabricPrivacy.logException(it) })
|
||||||
|
disposables += rxBus
|
||||||
|
.toObservable(EventOmnipodPodStateActionsAllowedChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updatePodActionButtons()
|
||||||
|
}, { fabricPrivacy.logException(it) })
|
||||||
disposables += rxBus
|
disposables += rxBus
|
||||||
.toObservable(EventPreferenceChange::class.java)
|
.toObservable(EventPreferenceChange::class.java)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -355,13 +349,13 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRefreshStatusButton() {
|
private fun updateRefreshStatusButton() {
|
||||||
omnipod_refresh.isEnabled = rileyLinkServiceData.rileyLinkServiceState.isReady && podStateManager.isPodInitialized
|
omnipod_refresh.isEnabled = podStateManager.isPodInitialized && podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED)
|
||||||
&& podStateManager.podProgressStatus.isAtLeast(PodProgressStatus.PAIRING_COMPLETED) && !commandQueue.statusInQueue()
|
&& rileyLinkServiceData.rileyLinkServiceState.isReady && omnipodPumpPlugin.isPodStateActionsAllowed
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAcknowledgeAlertsButton() {
|
private fun updateAcknowledgeAlertsButton() {
|
||||||
if (podStateManager.isPodInitialized && podStateManager.hasActiveAlerts() && !podStateManager.isPodDead) {
|
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 {
|
} else {
|
||||||
omnipod_pod_active_alerts_ack.isEnabled = false
|
omnipod_pod_active_alerts_ack.isEnabled = false
|
||||||
}
|
}
|
||||||
|
@ -370,7 +364,7 @@ class OmnipodFragment : DaggerFragment() {
|
||||||
fun updatePulseLogButton() {
|
fun updatePulseLogButton() {
|
||||||
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
|
if (aapsOmnipodManager.isPodDebuggingOptionsEnabled) {
|
||||||
omnipod_pod_debug.visibility = View.VISIBLE
|
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 {
|
} else {
|
||||||
omnipod_pod_debug.visibility = View.GONE
|
omnipod_pod_debug.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue