Daggerize AapsPodStateManager

This commit is contained in:
Bart Sopers 2020-08-09 16:41:16 +02:00
parent da2c2110da
commit 1787afda98
11 changed files with 113 additions and 132 deletions

View file

@ -1,7 +1,11 @@
package info.nightscout.androidaps.dependencyInjection
import dagger.Module
import dagger.Provides
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodHistoryActivity
@ -11,8 +15,13 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.In
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.InitPodRefreshAction
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.RemoveActionFragment
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUITask
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Singleton
@Module
@Suppress("unused")
@ -31,13 +40,20 @@ abstract class OmnipodModule {
// Service
@ContributesAndroidInjector
abstract fun omnipodCommunicationManagerProvider(): OmnipodCommunicationManager
@ContributesAndroidInjector abstract fun aapsOmnipodManagerProvider(): AapsOmnipodManager
// Data
@ContributesAndroidInjector abstract fun omnipodUITaskProvider(): OmnipodUITask
@ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction
@ContributesAndroidInjector abstract fun podStateManager(): PodStateManager
@ContributesAndroidInjector abstract fun initPodTask(): InitPodTask
@ContributesAndroidInjector abstract fun omnipodPumpPlugin(): OmnipodPumpPlugin
@ContributesAndroidInjector abstract fun initAapsPodStateManager(): AapsPodStateManager
companion object {
@Provides
@Singleton
fun podStateManagerProvider(aapsLogger: AAPSLogger, sp: SP, omnipodPumpStatus: OmnipodPumpStatus,
rxBus: RxBusWrapper, resourceHelper: ResourceHelper): PodStateManager =
AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper)
}
}

View file

@ -23,6 +23,7 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyL
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodStatusRequest
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus
@ -60,6 +61,7 @@ class OmnipodFragment : DaggerFragment() {
@Inject lateinit var omnipodPumpPlugin: OmnipodPumpPlugin
@Inject lateinit var warnColors: WarnColors
@Inject lateinit var omnipodPumpStatus: OmnipodPumpStatus
@Inject lateinit var podStateManager: PodStateManager
@Inject lateinit var sp: SP
@Inject lateinit var omnipodUtil: OmnipodUtil
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@ -264,27 +266,27 @@ class OmnipodFragment : DaggerFragment() {
omnipodPumpStatus.podAvailable = false
omnipodPumpStatus.podNumber == null
} else if (driverState == OmnipodDriverState.Initalized_PodInitializing) {
omnipod_pod_address.text = omnipodPumpStatus.podStateManager.address.toString()
omnipod_pod_address.text = podStateManager.address.toString()
omnipod_pod_lot.text = "-"
omnipod_pod_tid.text = "-"
omnipod_pod_fw_version.text = "-"
omnipod_pod_expiry.text = "-"
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_initalizing) + " (" + omnipodPumpStatus.podStateManager.getSetupProgress().name + ")"
omnipod_pod_status.text = resourceHelper.gs(R.string.omnipod_pod_status_initalizing) + " (" + podStateManager.getSetupProgress().name + ")"
omnipodPumpStatus.podAvailable = false
omnipodPumpStatus.podNumber == omnipodPumpStatus.podStateManager.address.toString()
omnipodPumpStatus.podNumber == podStateManager.address.toString()
} else {
omnipodPumpStatus.podLotNumber = "" + omnipodPumpStatus.podStateManager.lot
omnipodPumpStatus.podLotNumber = "" + podStateManager.lot
omnipodPumpStatus.podAvailable = true
omnipod_pod_address.text = omnipodPumpStatus.podStateManager.address.toString()
omnipod_pod_lot.text = if (omnipodPumpStatus.podStateManager.lot == null) "" else omnipodPumpStatus.podStateManager.lot.toString()
omnipod_pod_tid.text = if (omnipodPumpStatus.podStateManager.tid == null) "" else omnipodPumpStatus.podStateManager.tid.toString()
if (omnipodPumpStatus.podStateManager.pmVersion == null || omnipodPumpStatus.podStateManager.piVersion == null) {
omnipod_pod_address.text = podStateManager.address.toString()
omnipod_pod_lot.text = if (podStateManager.lot == null) "" else podStateManager.lot.toString()
omnipod_pod_tid.text = if (podStateManager.tid == null) "" else podStateManager.tid.toString()
if (podStateManager.pmVersion == null || podStateManager.piVersion == null) {
omnipod_pod_fw_version.text = ""
} else {
omnipod_pod_fw_version.text = omnipodPumpStatus.podStateManager.pmVersion.toString() + " / " + omnipodPumpStatus.podStateManager.piVersion.toString()
omnipod_pod_fw_version.text = podStateManager.pmVersion.toString() + " / " + podStateManager.piVersion.toString()
}
omnipod_pod_expiry.text = omnipodPumpStatus.podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = omnipodPumpStatus.podStateManager.address.toString()
omnipod_pod_expiry.text = podStateManager.expiryDateAsString
omnipodPumpStatus.podNumber = podStateManager.address.toString()
var podDeviceState = omnipodPumpStatus.podDeviceState
@ -327,13 +329,13 @@ class OmnipodFragment : DaggerFragment() {
}
}
if (omnipodPumpStatus.podStateManager.isSetupCompleted) {
if (omnipodPumpStatus.podStateManager.lastDeliveryStatus != null) {
stateText += " (last delivery status: " + omnipodPumpStatus.podStateManager.lastDeliveryStatus.name + ")"
if (podStateManager.isSetupCompleted) {
if (podStateManager.lastDeliveryStatus != null) {
stateText += " (last delivery status: " + podStateManager.lastDeliveryStatus.name + ")"
}
} else {
if (omnipodPumpStatus.podStateManager.isPaired) {
stateText += " (setup progress: " + omnipodPumpStatus.podStateManager.setupProgress.name + ")"
if (podStateManager.isPaired) {
stateText += " (setup progress: " + podStateManager.setupProgress.name + ")"
}
}

View file

@ -90,6 +90,7 @@ import io.reactivex.schedulers.Schedulers;
public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPumpPluginInterface, RileyLinkPumpDevice {
// TODO Dagger (maybe done)
@Inject protected PodStateManager podStateManager;
private static OmnipodPumpPlugin plugin = null;
private RileyLinkServiceData rileyLinkServiceData;
private ServiceTaskExecutor serviceTaskExecutor;
@ -149,6 +150,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
PumpType.Insulet_Omnipod,
injector, resourceHelper, aapsLogger, commandQueue, rxBus, activePlugin, sp, context, fabricPrivacy
);
injector.androidInjector().inject(this);
this.rileyLinkServiceData = rileyLinkServiceData;
this.serviceTaskExecutor = serviceTaskExecutor;
@ -197,6 +199,10 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
if (isOmnipodEros) {
// We can't do this in PodStateManager itself, because JodaTimeAndroid.init() hasn't been called yet
// When PodStateManager is created, which causes an IllegalArgumentException for DateTimeZones not being recognized
podStateManager.loadPodState();
serviceConnection = new ServiceConnection() {
@Override
@ -486,8 +492,8 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
@Override
public boolean isSuspended() {
return (omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod) ||
(omnipodUtil.getPodStateManager().hasState() && omnipodUtil.getPodStateManager().isSuspended());
return omnipodUtil.getDriverState() == OmnipodDriverState.Initalized_NoPod ||
!podStateManager.isSetupCompleted() || podStateManager.isSuspended();
// return (pumpStatusLocal != null && !pumpStatusLocal.podAvailable) ||
// (omnipodUtil.getPodStateManager().hasState() && OmnipodUtil.getPodStateManager().isSuspended());
@ -613,8 +619,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private void initializePump(boolean realInit) {
aapsLogger.info(LTag.PUMP, getLogPrefix() + "initializePump - start");
// TODO ccc
@ -622,7 +626,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(false);
PodStateManager podStateManager = omnipodUtil.getPodStateManager();
if (podStateManager.isPaired()) {
aapsLogger.debug(LTag.PUMP, "PodStateManager (saved): " + podStateManager);

View file

@ -6,6 +6,8 @@ import com.google.gson.JsonDeserializer;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializer;
import net.danlew.android.joda.JodaTimeAndroid;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.model.FullInitPodWizardModel
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.model.RemovePodWizardModel
@ -42,6 +43,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
@Inject lateinit var fabricPrivacy: FabricPrivacy
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var omnipodUtil: OmnipodUtil
@Inject lateinit var podStateManager: PodStateManager
@Inject lateinit var injector: HasAndroidInjector
private var initPodChanged = false
@ -98,7 +100,6 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
wizardPagerContext.clearContext()
wizardPagerContext.pagerSettings = pagerSettings
val podStateManager = omnipodUtil.getPodStateManager()
val isFullInit = !podStateManager.isPaired || podStateManager.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED)
if (isFullInit) {
wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext)
@ -150,11 +151,11 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
}
fun refreshButtons() {
initpod_init_pod.isEnabled = !omnipodUtil.podStateManager.isPaired() ||
omnipodUtil.getPodStateManager().getSetupProgress().isBefore(SetupProgress.COMPLETED)
initpod_init_pod.isEnabled = !podStateManager.isPaired() ||
podStateManager.getSetupProgress().isBefore(SetupProgress.COMPLETED)
initpod_remove_pod.isEnabled = omnipodUtil.podStateManager.hasState() && omnipodUtil.podStateManager.isPaired
initpod_reset_pod.isEnabled = omnipodUtil.podStateManager.hasState()
initpod_remove_pod.isEnabled = podStateManager.hasState() && podStateManager.isPaired
initpod_reset_pod.isEnabled = podStateManager.hasState()
if (omnipodUtil.getDriverState() == OmnipodDriverState.NotInitalized) {
// if rileylink is not running we disable all operations

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState;
@ -33,6 +34,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
private PodActionType actionType;
@Inject OmnipodUtil omnipodUtil;
@Inject PodStateManager podStateManager;
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@ -58,7 +60,7 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
@Override
public void execute() {
if (actionType == PodActionType.InitPod) {
if (omnipodUtil.getPodStateManager().getSetupProgress().isBefore(SetupProgress.COMPLETED)) {
if (podStateManager.getSetupProgress().isBefore(SetupProgress.COMPLETED)) {
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodInitializing);
} else {
omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached);

View file

@ -30,6 +30,7 @@ public class PodInfoFragment extends DaggerFragment {
private static final String ARG_KEY = "key";
@Inject OmnipodUtil omnipodUtil;
@Inject PodStateManager podStateManager;
private PageFragmentCallbacks mCallbacks;
private String mKey;
@ -84,9 +85,6 @@ public class PodInfoFragment extends DaggerFragment {
}
private boolean createDataOfPod() {
PodStateManager podStateManager = omnipodUtil.getPodStateManager();
if (podStateManager == null)
return false;
@ -96,7 +94,7 @@ public class PodInfoFragment extends DaggerFragment {
if (podStateManager.getLot() != null) {
mCurrentReviewItems.add(new ReviewItem("LOT", "" + podStateManager.getLot(), "35"));
}
if(podStateManager.getTid() != null) {
if (podStateManager.getTid() != null) {
mCurrentReviewItems.add(new ReviewItem("TID", "" + podStateManager.getLot(), "36"));
}
if (podStateManager.getPiVersion() != null) {

View file

@ -16,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLin
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
@ -46,7 +45,6 @@ public class OmnipodPumpStatus extends PumpStatus {
public Double tempBasalAmount = 0.0d;
public Integer tempBasalLength;
public long tempBasalPumpId;
public PodStateManager podStateManager;
public PumpType pumpType;
public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
@ -141,7 +139,6 @@ public class OmnipodPumpStatus extends PumpStatus {
", tempBasalEnd=" + tempBasalEnd +
", tempBasalAmount=" + tempBasalAmount +
", tempBasalLength=" + tempBasalLength +
", podStateManager=" + podStateManager +
", regexMac='" + regexMac + '\'' +
", podNumber='" + podNumber + '\'' +
", podDeviceState=" + podDeviceState +

View file

@ -9,6 +9,9 @@ import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.Event;
import info.nightscout.androidaps.events.EventRefreshOverview;
@ -21,24 +24,23 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@Singleton
public class AapsPodStateManager extends PodStateManager {
private final AAPSLogger aapsLogger;
private final SP sp;
private final OmnipodUtil omnipodUtil;
private final OmnipodPumpStatus omnipodPumpStatus;
private final RxBusWrapper rxBus;
private final ResourceHelper resourceHelper;
public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, OmnipodUtil omnipodUtil,
OmnipodPumpStatus omnipodPumpStatus, RxBusWrapper rxBus,
ResourceHelper resourceHelper) {
@Inject
public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, OmnipodPumpStatus omnipodPumpStatus,
RxBusWrapper rxBus, ResourceHelper resourceHelper) {
super(aapsLogger);
if (aapsLogger == null) {
@ -47,9 +49,6 @@ public class AapsPodStateManager extends PodStateManager {
if (sp == null) {
throw new IllegalArgumentException("sp can not be null");
}
if (omnipodUtil == null) {
throw new IllegalArgumentException("omnipodUtil can not be null");
}
if (omnipodPumpStatus == null) {
throw new IllegalArgumentException("omnipodPumpStatus can not be null");
}
@ -62,7 +61,6 @@ public class AapsPodStateManager extends PodStateManager {
this.aapsLogger = aapsLogger;
this.sp = sp;
this.omnipodUtil = omnipodUtil;
this.omnipodPumpStatus = omnipodPumpStatus;
this.rxBus = rxBus;
this.resourceHelper = resourceHelper;
@ -80,58 +78,56 @@ public class AapsPodStateManager extends PodStateManager {
@Override
protected void notifyPodStateChanged() {
if (omnipodPumpStatus != null) {
if (!hasState()) {
omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false;
omnipodPumpStatus.lastBolusTime = null;
omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0;
omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
sendEvent(new EventOmnipodPumpValuesChanged());
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} else {
// Update active alerts
if (hasActiveAlerts()) {
List<String> alerts = getTranslatedActiveAlerts();
String alertsText = TextUtils.join("\n", alerts);
if (!hasState()) {
omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false;
omnipodPumpStatus.lastBolusTime = null;
omnipodPumpStatus.lastBolusAmount = null;
omnipodPumpStatus.reservoirRemainingUnits = 0.0;
omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
sendEvent(new EventOmnipodPumpValuesChanged());
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
} else {
// Update active alerts
if (hasActiveAlerts()) {
List<String> alerts = getTranslatedActiveAlerts();
String alertsText = TextUtils.join("\n", alerts);
if (!omnipodPumpStatus.ackAlertsAvailable || !alertsText.equals(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsAvailable = true;
omnipodPumpStatus.ackAlertsText = TextUtils.join("\n", alerts);
if (!omnipodPumpStatus.ackAlertsAvailable || !alertsText.equals(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsAvailable = true;
omnipodPumpStatus.ackAlertsText = TextUtils.join("\n", alerts);
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
} else {
if (omnipodPumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
} else {
if (omnipodPumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(omnipodPumpStatus.ackAlertsText)) {
omnipodPumpStatus.ackAlertsText = null;
omnipodPumpStatus.ackAlertsAvailable = false;
sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
}
}
Date lastBolusStartTime = getLastBolusStartTime() == null ? null : getLastBolusStartTime().toDate();
Double lastBolusAmount = getLastBolusAmount();
Date lastBolusStartTime = getLastBolusStartTime() == null ? null : getLastBolusStartTime().toDate();
Double lastBolusAmount = getLastBolusAmount();
// Update other info: last bolus, units remaining, suspended
if (Objects.equals(lastBolusStartTime, omnipodPumpStatus.lastBolusTime) //
|| !Objects.equals(lastBolusAmount, omnipodPumpStatus.lastBolusAmount) //
|| !isReservoirStatusUpToDate(omnipodPumpStatus, getReservoirLevel())
|| isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
omnipodPumpStatus.pumpStatusType = isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running;
sendEvent(new EventOmnipodPumpValuesChanged());
// Update other info: last bolus, units remaining, suspended
if (Objects.equals(lastBolusStartTime, omnipodPumpStatus.lastBolusTime) //
|| !Objects.equals(lastBolusAmount, omnipodPumpStatus.lastBolusAmount) //
|| !isReservoirStatusUpToDate(omnipodPumpStatus, getReservoirLevel())
|| isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
omnipodPumpStatus.pumpStatusType = isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running;
sendEvent(new EventOmnipodPumpValuesChanged());
if (isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
}
if (isSuspended() != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
sendEvent(new EventRefreshOverview("Omnipod Pump", false));
}
}
}
omnipodUtil.notifyDeviceStatusChanged();
rxBus.send(new EventOmnipodDeviceStatusChange(this));
}
private List<String> getTranslatedActiveAlerts() {

View file

@ -7,6 +7,8 @@ import android.os.IBinder;
import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime;
import javax.inject.Inject;
import info.nightscout.androidaps.R;
@ -26,9 +28,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunication
import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -43,6 +45,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodUtil omnipodUtil;
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager;
private static RileyLinkOmnipodService instance;
@ -60,12 +63,10 @@ public class RileyLinkOmnipodService extends RileyLinkService {
instance = this;
}
public static RileyLinkOmnipodService getInstance() {
return instance;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
aapsLogger.warn(LTag.PUMPCOMM, "onConfigurationChanged");
@ -109,12 +110,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private void initializeErosOmnipodManager() {
AapsOmnipodManager instance = AapsOmnipodManager.getInstance();
if (instance == null) {
PodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodUtil, omnipodPumpStatus, rxBus, resourceHelper);
podStateManager.loadPodState();
omnipodUtil.setPodStateManager(podStateManager);
OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
//omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
this.omnipodCommunicationManager = omnipodCommunicationService;
aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus,
@ -123,10 +119,9 @@ public class RileyLinkOmnipodService extends RileyLinkService {
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUtil, omnipodUIPostprocessor, aapsOmnipodManager);
} else {
omnipodUtil.setPodStateManager(instance.getPodStateManager());
aapsOmnipodManager = instance;
}
omnipodUtil.notifyDeviceStatusChanged();
rxBus.send(new EventOmnipodDeviceStatusChange(podStateManager));
}

View file

@ -52,13 +52,13 @@ public class OmnipodUtil {
private OmnipodPodType omnipodPodType;
private OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
@Inject
public OmnipodUtil(
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil,
OmnipodPumpStatus omnipodPumpStatus,
PodStateManager podStateManager,
SP sp,
ActivePluginProvider activePlugins
) {
@ -70,22 +70,18 @@ public class OmnipodUtil {
this.activePlugins = activePlugins;
}
public boolean isLowLevelDebug() {
return lowLevelDebug;
}
public void setLowLevelDebug(boolean lowLevelDebug) {
this.lowLevelDebug = lowLevelDebug;
}
public OmnipodCommandType getCurrentCommand() {
return currentCommand;
}
public void setCurrentCommand(OmnipodCommandType currentCommand) {
this.currentCommand = currentCommand;
@ -100,12 +96,10 @@ public class OmnipodUtil {
MainApp.gs(R.string.omnipod_error_operation_not_possible_no_configuration), (Runnable) null);
}
public OmnipodDriverState getDriverState() {
return driverState;
}
public void setDriverState(OmnipodDriverState state) {
if (driverState == state)
return;
@ -123,7 +117,6 @@ public class OmnipodUtil {
// }
}
private Gson createGson() {
GsonBuilder gsonBuilder = new GsonBuilder()
.registerTypeAdapter(DateTime.class, (JsonSerializer<DateTime>) (dateTime, typeOfSrc, context) ->
@ -138,16 +131,8 @@ public class OmnipodUtil {
return gsonBuilder.create();
}
public void setPodStateManager(PodStateManager podStateManager) {
if (podStateManager == null) {
throw new IllegalArgumentException("Pod state manager can not be null");
}
omnipodPumpStatus.podStateManager = podStateManager;
notifyDeviceStatusChanged();
}
public void notifyDeviceStatusChanged() {
rxBus.send(new EventOmnipodDeviceStatusChange(omnipodPumpStatus.podStateManager));
}
@ -155,41 +140,26 @@ public class OmnipodUtil {
omnipodPumpStatus.podDeviceState = podDeviceState;
}
public void setOmnipodPodType(OmnipodPodType omnipodPodType) {
this.omnipodPodType = omnipodPodType;
}
public OmnipodPodType getOmnipodPodType() {
return this.omnipodPodType;
}
public PodDeviceState getPodDeviceState() {
return omnipodPumpStatus.podDeviceState;
}
public PodStateManager getPodStateManager() {
if (omnipodPumpStatus.podStateManager == null) {
aapsLogger.error("OmnipodUtil.getPodStateManager was called, but podStateManager is null");
throw new IllegalStateException("Pod state manager is null");
}
return omnipodPumpStatus.podStateManager;
}
public boolean isOmnipodEros() {
return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod;
}
public boolean isOmnipodDash() {
return this.activePlugins.getActivePump().model() == PumpType.Insulet_Omnipod_Dash;
}
public void setPumpType(PumpType pumpType_) {
omnipodPumpStatus.pumpType = pumpType_;
}
@ -198,7 +168,6 @@ public class OmnipodUtil {
return omnipodPumpStatus.pumpType;
}
public Gson getGsonInstance() {
return this.gsonInstance;
}