- refactor OmnipodUIComm to support Dagger injections

- added DeviceCommandExecutor interface
- added method to interface RileyLinkPumpDevice
This commit is contained in:
Andy Rozman 2020-05-07 22:41:24 +01:00
parent a915c279d4
commit bd39e246f3
9 changed files with 53 additions and 16 deletions

View file

@ -24,5 +24,4 @@ abstract class OmnipodModule {
@ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction
@ContributesAndroidInjector abstract fun podSessionState(): PodSessionState
}

View file

@ -0,0 +1,4 @@
package info.nightscout.androidaps.plugins.pump.common.defs;
public interface DeviceCommandExecutor {
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
public interface RileyLinkPumpDevice {
@ -16,4 +17,6 @@ public interface RileyLinkPumpDevice {
RileyLinkService getRileyLinkService();
DeviceCommandExecutor getDeviceCommandExecutor();
}

View file

@ -53,6 +53,7 @@ import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotifi
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -327,6 +328,11 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
return rileyLinkMedtronicService;
}
@Override
public DeviceCommandExecutor getDeviceCommandExecutor() {
return this.rileyLinkMedtronicService.getMedtronicUIComm(); // TODO fix this
}
@Override
public boolean isInitialized() {
if (displayConnectionMessages)

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.ui;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
@ -10,7 +11,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* Created by andy on 6/14/18.
*/
public class MedtronicUIComm {
public class MedtronicUIComm implements DeviceCommandExecutor {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;

View file

@ -49,6 +49,7 @@ import info.nightscout.androidaps.plugins.general.overview.notifications.Notific
import info.nightscout.androidaps.plugins.pump.common.PumpPluginAbstract;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -96,7 +97,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
private RileyLinkOmnipodService rileyLinkOmnipodService;
private OmnipodUtil omnipodUtil;
protected OmnipodPumpStatus omnipodPumpStatus = null;
protected OmnipodUIComm omnipodUIComm;
//protected OmnipodUIComm omnipodUIComm;
private CompositeDisposable disposable = new CompositeDisposable();
@ -432,6 +433,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return rileyLinkOmnipodService;
}
@Override
public OmnipodUIComm getDeviceCommandExecutor() {
return rileyLinkOmnipodService.getDeviceCommandExecutor();
}
private synchronized void clearBusyQueue() {
@ -505,7 +511,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
for (OmnipodStatusRequest omnipodStatusRequest : omnipodStatusRequestList) {
if (omnipodStatusRequest == OmnipodStatusRequest.GetPodPulseLog) {
OmnipodUITask omnipodUITask = omnipodUIComm.executeCommand(omnipodStatusRequest.getCommandType());
OmnipodUITask omnipodUITask = getDeviceCommandExecutor().executeCommand(omnipodStatusRequest.getCommandType());
PodInfoRecentPulseLog result = (PodInfoRecentPulseLog) omnipodUITask.returnDataObject;
@ -527,7 +533,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
}
} else {
omnipodUIComm.executeCommand(omnipodStatusRequest.getCommandType());
getDeviceCommandExecutor().executeCommand(omnipodStatusRequest.getCommandType());
}
removeList.add(omnipodStatusRequest);
}
@ -535,7 +541,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
omnipodStatusRequestList.removeAll(removeList);
} else if (this.hasTimeDateOrTimeZoneChanged) {
OmnipodUITask omnipodUITask = omnipodUIComm.executeCommand(OmnipodCommandType.SetTime);
OmnipodUITask omnipodUITask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetTime);
if (omnipodUITask.wasCommandSuccessful()) {
this.hasTimeDateOrTimeZoneChanged = false;
@ -724,7 +730,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
try {
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBolus,
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBolus,
detailedBolusInfo);
PumpEnactResult result = responseTask.getResult();
@ -757,7 +763,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(false);
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.CancelBolus);
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelBolus);
PumpEnactResult result = responseTask.getResult();
@ -826,7 +832,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
// }
// now start new TBR
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetTemporaryBasal,
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetTemporaryBasal,
absoluteRate, durationInMinutes);
PumpEnactResult result = responseTask.getResult();
@ -879,7 +885,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
return new PumpEnactResult(getInjector()).success(true).enacted(false);
}
OmnipodUITask responseTask2 = omnipodUIComm.executeCommand(OmnipodCommandType.CancelTemporaryBasal);
OmnipodUITask responseTask2 = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.CancelTemporaryBasal);
PumpEnactResult result = responseTask2.getResult();
@ -923,7 +929,7 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
setRefreshButtonEnabled(false);
OmnipodUITask responseTask = omnipodUIComm.executeCommand(OmnipodCommandType.SetBasalProfile,
OmnipodUITask responseTask = getDeviceCommandExecutor().executeCommand(OmnipodCommandType.SetBasalProfile,
profile);
PumpEnactResult result = responseTask.getResult();

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.DeviceCommandExecutor;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -10,7 +11,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/**
* Created by andy on 4.8.2019
*/
public class OmnipodUIComm {
public class OmnipodUIComm implements DeviceCommandExecutor {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;
@ -18,7 +19,6 @@ public class OmnipodUIComm {
private final OmnipodCommunicationManagerInterface omnipodCommunicationManager;
private final OmnipodUIPostprocessor omnipodUIPostprocessor;
public OmnipodUIComm(
HasAndroidInjector injector,
AAPSLogger aapsLogger,

View file

@ -5,18 +5,22 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import javax.inject.Inject;
import javax.inject.Singleton;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodPumpPluginInterface;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
/**
* Created by andy on 4.8.2019
*/
@Singleton
public class OmnipodUIPostprocessor {
@ -26,8 +30,8 @@ public class OmnipodUIPostprocessor {
private OmnipodPumpPluginInterface omnipodPumpPlugin;
private RxBusWrapper rxBus;
public OmnipodUIPostprocessor(OmnipodPumpPluginInterface plugin, OmnipodPumpStatus pumpStatus) {
@Inject
public OmnipodUIPostprocessor(OmnipodPumpPlugin plugin, OmnipodPumpStatus pumpStatus) {
this.pumpStatus = pumpStatus;
this.omnipodPumpPlugin = plugin;
this.rxBus = plugin.getRxBus();

View file

@ -23,12 +23,16 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIComm;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState;
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.PodSessionState;
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.ui.OmnipodUIComm;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@ -42,6 +46,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
@Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodUtil omnipodUtil;
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
private static RileyLinkOmnipodService instance;
@ -52,6 +57,7 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private boolean rileyLinkAddressChanged = false;
private boolean inPreInit = true;
OmnipodUIComm omnipodUIComm;
public RileyLinkOmnipodService() {
super();
@ -123,14 +129,22 @@ public class RileyLinkOmnipodService extends RileyLinkService {
//omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
this.omnipodCommunicationManager = omnipodCommunicationService;
this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin);
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUtil, omnipodUIPostprocessor, aapsOmnipodManager);
} else {
aapsOmnipodManager = AapsOmnipodManager.getInstance();
}
}
public OmnipodUIComm getDeviceCommandExecutor() {
return this.omnipodUIComm;
}
public void resetRileyLinkConfiguration() {
rfspy.resetRileyLinkConfiguration();
}