Daggerize AapsOmnipodManager

This commit is contained in:
Steffen Müthing 2020-08-17 00:24:33 +02:00
parent 0fef4128ef
commit 8f7ba93c47
4 changed files with 14 additions and 34 deletions

View file

@ -47,6 +47,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
@Inject lateinit var podStateManager: PodStateManager @Inject lateinit var podStateManager: PodStateManager
@Inject lateinit var injector: HasAndroidInjector @Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData @Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@Inject lateinit var aapsOmnipodManager: AapsOmnipodManager
private var initPodChanged = false private var initPodChanged = false
@ -141,7 +142,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
fun resetPodAction() { fun resetPodAction() {
OKDialog.showConfirmation(this, OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.omnipod_cmd_reset_pod_desc), Thread { resourceHelper.gs(R.string.omnipod_cmd_reset_pod_desc), Thread {
AapsOmnipodManager.getInstance().resetPodStatus() aapsOmnipodManager.resetPodStatus()
refreshButtons() refreshButtons()
}) })
} }

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodMa
public class InitPodTask extends AsyncTask<Void, Void, String> { public class InitPodTask extends AsyncTask<Void, Void, String> {
@Inject ProfileFunction profileFunction; @Inject ProfileFunction profileFunction;
@Inject AapsOmnipodManager aapsOmnipodManager;
private InitActionFragment initActionFragment; private InitActionFragment initActionFragment;
public InitPodTask(HasAndroidInjector injector, InitActionFragment initActionFragment) { public InitPodTask(HasAndroidInjector injector, InitActionFragment initActionFragment) {
@ -34,19 +35,19 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod( initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType, initActionFragment.podInitActionType,
initActionFragment, initActionFragment,
null null
); );
} else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { } else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod( initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType, initActionFragment.podInitActionType,
initActionFragment, initActionFragment,
profileFunction.getProfile() profileFunction.getProfile()
); );
} else if (initActionFragment.podInitActionType == PodInitActionType.DeactivatePodWizardStep) { } else if (initActionFragment.podInitActionType == PodInitActionType.DeactivatePodWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().deactivatePod(initActionFragment); initActionFragment.callResult = aapsOmnipodManager.deactivatePod(initActionFragment);
} }
return "OK"; return "OK";

View file

@ -10,6 +10,9 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector; import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.activities.ErrorHelperActivity; import info.nightscout.androidaps.activities.ErrorHelperActivity;
import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -73,7 +76,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP; import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
// TODO make singleton @Singleton
public class AapsOmnipodManager implements IOmnipodManager { public class AapsOmnipodManager implements IOmnipodManager {
private final PodStateManager podStateManager; private final PodStateManager podStateManager;
@ -87,15 +90,9 @@ public class AapsOmnipodManager implements IOmnipodManager {
private final Context context; private final Context context;
private final OmnipodManager delegate; private final OmnipodManager delegate;
//TODO: remove and use injection
private static AapsOmnipodManager instance;
private DatabaseHelperInterface databaseHelper; private DatabaseHelperInterface databaseHelper;
public static AapsOmnipodManager getInstance() { @Inject
return instance;
}
public AapsOmnipodManager(OmnipodCommunicationManager communicationService, public AapsOmnipodManager(OmnipodCommunicationManager communicationService,
PodStateManager podStateManager, PodStateManager podStateManager,
OmnipodPumpStatus pumpStatus, OmnipodPumpStatus pumpStatus,
@ -123,7 +120,6 @@ public class AapsOmnipodManager implements IOmnipodManager {
this.databaseHelper = databaseHelper; this.databaseHelper = databaseHelper;
delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager); delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
instance = this;
} }
public PodStateManager getPodStateManager() { public PodStateManager getPodStateManager() {

View file

@ -43,11 +43,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor; @Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager; @Inject PodStateManager podStateManager;
@Inject DatabaseHelperInterface databaseHelper; @Inject DatabaseHelperInterface databaseHelper;
@Inject AapsOmnipodManager aapsOmnipodManager;
private static RileyLinkOmnipodService instance; @Inject OmnipodCommunicationManager omnipodCommunicationManager;
private OmnipodCommunicationManager omnipodCommunicationManager;
private AapsOmnipodManager aapsOmnipodManager;
private IBinder mBinder = new LocalBinder(); private IBinder mBinder = new LocalBinder();
private boolean rileyLinkAddressChanged = false; private boolean rileyLinkAddressChanged = false;
@ -57,11 +54,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public RileyLinkOmnipodService() { public RileyLinkOmnipodService() {
super(); super();
instance = this;
}
public static RileyLinkOmnipodService getInstance() {
return instance;
} }
@Override @Override
@ -101,18 +93,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
} }
private void initializeErosOmnipodManager() { private void initializeErosOmnipodManager() {
AapsOmnipodManager instance = AapsOmnipodManager.getInstance(); if (omnipodUIComm == null) {
if (instance == null) {
OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
this.omnipodCommunicationManager = omnipodCommunicationService;
aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podStateManager, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this, databaseHelper);
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager, rileyLinkUtil); omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager, rileyLinkUtil);
} else {
aapsOmnipodManager = instance;
} }
rxBus.send(new EventOmnipodPumpValuesChanged()); rxBus.send(new EventOmnipodPumpValuesChanged());
} }