Turn RFSpy and RileyLinkBLE into Dagger singletons

This commit is contained in:
Steffen Müthing 2020-08-17 00:21:56 +02:00
parent 3646ef083e
commit e432346fc5
6 changed files with 18 additions and 13 deletions

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

@ -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;
@ -94,8 +92,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();

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,6 +18,7 @@ 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;
@ -40,6 +41,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 +60,11 @@ public class RileyLinkBLE {
private Runnable radioResponseCountNotified;
private boolean mIsConnected = false;
@Inject
public RileyLinkBLE(HasAndroidInjector injector, final Context context) {
injector.androidInjector().inject(this);
this.context = context;
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
aapsLogger.debug(LTag.PUMPBTCOMM, "BT Adapter: " + this.bluetoothAdapter);
bluetoothGattCallback = new BluetoothGattCallback() {
@Override
@ -257,6 +257,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;