Merge pull request #139 from smuething/more-daggerization

More daggerization
This commit is contained in:
bartsopers 2020-08-18 12:44:21 +02:00 committed by GitHub
commit 228441f54c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 70 additions and 81 deletions

View file

@ -26,6 +26,7 @@ import javax.inject.Singleton
CommandQueueModule::class,
ObjectivesModule::class,
WizardModule::class,
RileyLinkModule::class,
MedtronicModule::class,
OmnipodModule::class,
APSModule::class,

View file

@ -2,33 +2,12 @@ package info.nightscout.androidaps.dependencyInjection
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager
import info.nightscout.androidaps.plugins.pump.medtronic.comm.ui.MedtronicUITask
@Module
@Suppress("unused")
abstract class MedtronicModule {
@ContributesAndroidInjector abstract fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager
@ContributesAndroidInjector abstract fun medtronicCommunicationManagerProvider(): MedtronicCommunicationManager
@ContributesAndroidInjector abstract fun medtronicUITaskProvider(): MedtronicUITask
@ContributesAndroidInjector abstract fun serviceTaskProvider(): ServiceTask
@ContributesAndroidInjector abstract fun pumpTaskProvider(): PumpTask
@ContributesAndroidInjector abstract fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
@ContributesAndroidInjector abstract fun initializePumpManagerTaskProvider(): InitializePumpManagerTask
@ContributesAndroidInjector abstract fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask
@ContributesAndroidInjector abstract fun wakeAndTuneTaskProvider(): WakeAndTuneTask
@ContributesAndroidInjector abstract fun radioResponseProvider(): RadioResponse
@ContributesAndroidInjector abstract fun rileyLinkBLEProvider(): RileyLinkBLE
@ContributesAndroidInjector abstract fun rfSpyProvider(): RFSpy
@ContributesAndroidInjector abstract fun sendAndListenProvider(): SendAndListen
@ContributesAndroidInjector abstract fun setPreambleProvider(): SetPreamble
@ContributesAndroidInjector abstract fun radioPacketProvider(): RadioPacket
}

View file

@ -3,8 +3,6 @@ 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
@ -15,14 +13,9 @@ 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.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import javax.inject.Singleton
@Module
@Suppress("unused")
@ -52,9 +45,6 @@ abstract class OmnipodModule {
companion object {
@Provides
@Singleton
fun podStateManagerProvider(aapsLogger: AAPSLogger, sp: SP, omnipodPumpStatus: info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus,
rxBus: RxBusWrapper, resourceHelper: ResourceHelper, dateUtil: DateUtil): info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager =
info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper, dateUtil)
fun podStateManagerProvider(aapsPodStateManager: info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager) : info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager = aapsPodStateManager
}
}

View file

@ -0,0 +1,30 @@
package info.nightscout.androidaps.dependencyInjection
import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetPreamble
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioPacket
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.RadioResponse
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.*
@Module
@Suppress("unused")
abstract class RileyLinkModule {
@ContributesAndroidInjector abstract fun rileyLinkCommunicationManagerProvider(): RileyLinkCommunicationManager
@ContributesAndroidInjector abstract fun serviceTaskProvider(): ServiceTask
@ContributesAndroidInjector abstract fun pumpTaskProvider(): PumpTask
@ContributesAndroidInjector abstract fun discoverGattServicesTaskProvider(): DiscoverGattServicesTask
@ContributesAndroidInjector abstract fun initializePumpManagerTaskProvider(): InitializePumpManagerTask
@ContributesAndroidInjector abstract fun resetRileyLinkConfigurationTaskProvider(): ResetRileyLinkConfigurationTask
@ContributesAndroidInjector abstract fun wakeAndTuneTaskProvider(): WakeAndTuneTask
@ContributesAndroidInjector abstract fun radioResponseProvider(): RadioResponse
@ContributesAndroidInjector abstract fun rileyLinkBLEProvider(): RileyLinkBLE
@ContributesAndroidInjector abstract fun rfSpyProvider(): RFSpy
@ContributesAndroidInjector abstract fun sendAndListenProvider(): SendAndListen
@ContributesAndroidInjector abstract fun setPreambleProvider(): SetPreamble
@ContributesAndroidInjector abstract fun radioPacketProvider(): RadioPacket
}

View file

@ -40,6 +40,7 @@ public class RileyLinkMedtronicService extends RileyLinkService {
@Inject MedtronicUtil medtronicUtil;
@Inject MedtronicUIPostprocessor medtronicUIPostprocessor;
@Inject MedtronicPumpStatus medtronicPumpStatus;
@Inject RFSpy rfSpy;
private MedtronicUIComm medtronicUIComm;
private MedtronicCommunicationManager medtronicCommunicationManager;
@ -99,8 +100,6 @@ public class RileyLinkMedtronicService extends RileyLinkService {
// get most recently used RileyLink address
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkBLE = new RileyLinkBLE(injector, this); // or this
rfspy = new RFSpy(injector, rileyLinkBLE);
rfspy.startReader();
// init rileyLinkCommunicationManager

View file

@ -62,6 +62,11 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
@Inject
public OmnipodCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
super(injector, rfspy);
}
@Inject
public void onInit() {
// this cannot be done in the constructor, as sp is not populated at that time
omnipodPumpStatus.previousConnection = sp.getLong(
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
}

View file

@ -47,6 +47,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
@Inject lateinit var podStateManager: PodStateManager
@Inject lateinit var injector: HasAndroidInjector
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
@Inject lateinit var aapsOmnipodManager: AapsOmnipodManager
private var initPodChanged = false
@ -141,7 +142,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
fun resetPodAction() {
OKDialog.showConfirmation(this,
resourceHelper.gs(R.string.omnipod_cmd_reset_pod_desc), Thread {
AapsOmnipodManager.getInstance().resetPodStatus()
aapsOmnipodManager.resetPodStatus()
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> {
@Inject ProfileFunction profileFunction;
@Inject AapsOmnipodManager aapsOmnipodManager;
private InitActionFragment initActionFragment;
public InitPodTask(HasAndroidInjector injector, InitActionFragment initActionFragment) {
@ -34,19 +35,19 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType,
initActionFragment,
null
);
} else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType,
initActionFragment,
profileFunction.getProfile()
);
} else if (initActionFragment.podInitActionType == PodInitActionType.DeactivatePodWizardStep) {
initActionFragment.callResult = AapsOmnipodManager.getInstance().deactivatePod(initActionFragment);
initActionFragment.callResult = aapsOmnipodManager.deactivatePod(initActionFragment);
}
return "OK";

View file

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

View file

@ -14,8 +14,6 @@ import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
@ -45,11 +43,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
@Inject PodStateManager podStateManager;
@Inject DatabaseHelperInterface databaseHelper;
private static RileyLinkOmnipodService instance;
private OmnipodCommunicationManager omnipodCommunicationManager;
private AapsOmnipodManager aapsOmnipodManager;
@Inject AapsOmnipodManager aapsOmnipodManager;
@Inject OmnipodCommunicationManager omnipodCommunicationManager;
private IBinder mBinder = new LocalBinder();
private boolean rileyLinkAddressChanged = false;
@ -59,11 +54,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
public RileyLinkOmnipodService() {
super();
instance = this;
}
public static RileyLinkOmnipodService getInstance() {
return instance;
}
@Override
@ -94,8 +84,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
// get most recently used RileyLink address
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
rileyLinkBLE = new RileyLinkBLE(injector, this); // or this
rfspy = new RFSpy(injector, rileyLinkBLE);
rfspy.startReader();
initializeErosOmnipodManager();
@ -105,18 +93,8 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
private void initializeErosOmnipodManager() {
AapsOmnipodManager instance = AapsOmnipodManager.getInstance();
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);
if (omnipodUIComm == null) {
omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager, rileyLinkUtil);
} else {
aapsOmnipodManager = instance;
}
rxBus.send(new EventOmnipodPumpValuesChanged());
}

View file

@ -53,7 +53,6 @@ public abstract class RileyLinkCommunicationManager {
public RileyLinkCommunicationManager(HasAndroidInjector injector, RFSpy rfspy) {
this.injector = injector;
injector.androidInjector().inject(this);
this.rfspy = rfspy;
}

View file

@ -5,6 +5,7 @@ import android.os.SystemClock;
import java.util.UUID;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
@ -40,6 +41,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by geoff on 5/26/16.
*/
@Singleton
public class RFSpy {
@Inject AAPSLogger aapsLogger;
@ -64,10 +66,14 @@ public class RFSpy {
private Double currentFrequencyMHz;
@Inject
public RFSpy(HasAndroidInjector injector, RileyLinkBLE rileyLinkBle) {
injector.androidInjector().inject(this);
this.injector = injector;
this.rileyLinkBle = rileyLinkBle;
}
@Inject
public void onInit() {
aapsLogger.debug("RileyLinkServiceData:" + rileyLinkServiceData);
reader = new RFSpyReader(aapsLogger, rileyLinkBle);
}

View file

@ -18,8 +18,8 @@ import java.util.UUID;
import java.util.concurrent.Semaphore;
import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
* Created by geoff on 5/26/16.
* Added: State handling, configuration of RF for different configuration ranges, connection handling
*/
@Singleton
public class RileyLinkBLE {
@Inject AAPSLogger aapsLogger;
@ -58,13 +59,11 @@ public class RileyLinkBLE {
private Runnable radioResponseCountNotified;
private boolean mIsConnected = false;
public RileyLinkBLE(HasAndroidInjector injector, final Context context) {
injector.androidInjector().inject(this);
@Inject
public RileyLinkBLE(final Context context) {
this.context = context;
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter);
bluetoothGattCallback = new BluetoothGattCallback() {
@Override
@ -257,6 +256,11 @@ public class RileyLinkBLE {
};
}
@Inject
public void onInit() {
aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter);
}
private boolean isAnyRileyLinkServiceFound(BluetoothGattService service) {

View file

@ -45,10 +45,10 @@ public abstract class RileyLinkService extends DaggerService {
@Inject protected ResourceHelper resourceHelper;
@Inject protected RileyLinkServiceData rileyLinkServiceData;
@Inject protected ActivePluginProvider activePlugin;
@Inject protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management
@Inject protected RFSpy rfspy; // interface for RL xxx Mhz radio.
@NotNull protected RileyLinkBLE rileyLinkBLE; // android-bluetooth management, must be set in initRileyLinkServiceData
protected BluetoothAdapter bluetoothAdapter;
protected RFSpy rfspy; // interface for RL xxx Mhz radio.
protected RileyLinkBroadcastReceiver mBroadcastReceiver;
protected RileyLinkBluetoothStateReceiver bluetoothStateReceiver;