Inject AndroidInjector into RileyLinkCommunicationManager using dagger

This commit is contained in:
Steffen Müthing 2020-08-19 13:06:21 +02:00
parent 5d83e2a26b
commit 680f3f94d6
3 changed files with 9 additions and 14 deletions

View file

@ -11,7 +11,6 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
@ -73,9 +72,13 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
private boolean doWakeUpBeforeCommand = true; private boolean doWakeUpBeforeCommand = true;
// This empty constructor must be kept, otherwise dagger injection might break!
@Inject
public MedtronicCommunicationManager() {}
public MedtronicCommunicationManager(HasAndroidInjector injector) { @Inject
super(injector); public void onInit() {
// we can't do this in the constructor, as sp only gets injected after the constructor has returned
medtronicPumpStatus.previousConnection = sp.getLong( medtronicPumpStatus.previousConnection = sp.getLong(
RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L); RileyLinkConst.Prefs.LastGoodDeviceCommunicationTime, 0L);
} }

View file

@ -7,7 +7,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag; import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus; import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
@ -55,9 +54,9 @@ public class OmnipodCommunicationManager extends RileyLinkCommunicationManager {
@Inject OmnipodPumpStatus omnipodPumpStatus; @Inject OmnipodPumpStatus omnipodPumpStatus;
// This empty constructor must be kept, otherwise dagger injection might break!
@Inject @Inject
public OmnipodCommunicationManager(HasAndroidInjector injector) { public OmnipodCommunicationManager() {
super(injector);
} }
@Inject @Inject

View file

@ -36,12 +36,11 @@ public abstract class RileyLinkCommunicationManager {
@Inject protected RileyLinkServiceData rileyLinkServiceData; @Inject protected RileyLinkServiceData rileyLinkServiceData;
@Inject protected ServiceTaskExecutor serviceTaskExecutor; @Inject protected ServiceTaskExecutor serviceTaskExecutor;
@Inject protected RFSpy rfspy; @Inject protected RFSpy rfspy;
@Inject protected HasAndroidInjector injector;
private final int SCAN_TIMEOUT = 1500; private final int SCAN_TIMEOUT = 1500;
private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes private final int ALLOWED_PUMP_UNREACHABLE = 10 * 60 * 1000; // 10 minutes
public final HasAndroidInjector injector;
protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation protected int receiverDeviceAwakeForMinutes = 1; // override this in constructor of specific implementation
protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy)) protected String receiverDeviceID; // String representation of receiver device (ex. Pump (xxxxxx) or Pod (yyyyyy))
protected long lastGoodReceiverCommunicationTime = 0; protected long lastGoodReceiverCommunicationTime = 0;
@ -50,12 +49,6 @@ public abstract class RileyLinkCommunicationManager {
private int timeoutCount = 0; private int timeoutCount = 0;
public RileyLinkCommunicationManager(HasAndroidInjector injector) {
this.injector = injector;
this.injector.androidInjector().inject(this);
}
// All pump communications go through this function. // All pump communications go through this function.
protected RLMessage sendAndListen(RLMessage msg, int timeout_ms) protected RLMessage sendAndListen(RLMessage msg, int timeout_ms)
throws RileyLinkCommunicationException { throws RileyLinkCommunicationException {