Correctly load Pod state from Shared Preferences after startup
This commit is contained in:
parent
eafb68d496
commit
d446751d8a
|
@ -1,13 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.service;
|
package info.nightscout.androidaps.plugins.pump.omnipod.service;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
@ -23,8 +20,6 @@ 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.RileyLinkServiceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
|
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.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.medtronic.defs.PumpDeviceState;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
|
||||||
|
@ -112,19 +107,11 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
||||||
|
|
||||||
private void initializeErosOmnipodManager() {
|
private void initializeErosOmnipodManager() {
|
||||||
if (AapsOmnipodManager.getInstance() == null) {
|
if (AapsOmnipodManager.getInstance() == null) {
|
||||||
PodSessionState podState = null;
|
PodSessionState podState = omnipodUtil.loadSessionState();
|
||||||
if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) {
|
|
||||||
try {
|
|
||||||
omnipodUtil.loadSessionState();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
|
OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
|
||||||
//omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
|
//omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
|
||||||
this.omnipodCommunicationManager = omnipodCommunicationService;
|
this.omnipodCommunicationManager = omnipodCommunicationService;
|
||||||
|
|
||||||
|
|
||||||
this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
|
this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
|
||||||
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin);
|
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class OmnipodUtil {
|
||||||
if (currentCommand != null)
|
if (currentCommand != null)
|
||||||
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand));
|
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand));
|
||||||
|
|
||||||
rxBus.send(new EventOmnipodDeviceStatusChange((OmnipodCommandType)null));
|
rxBus.send(new EventOmnipodDeviceStatusChange((OmnipodCommandType) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void displayNotConfiguredDialog(Context context) {
|
public static void displayNotConfiguredDialog(Context context) {
|
||||||
|
@ -233,18 +233,23 @@ public class OmnipodUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PodSessionState loadSessionState() {
|
public PodSessionState loadSessionState() {
|
||||||
String podState = sp.getString(OmnipodConst.Prefs.PodState, "");
|
PodSessionState podSessionState = null;
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + podState);
|
String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, "");
|
||||||
|
if (StringUtils.isEmpty(storedPodState)) {
|
||||||
if (StringUtils.isNotEmpty(podState)) {
|
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: no PodSessionState present in SharedPreferences");
|
||||||
PodSessionState podSessionState = gsonInstance.fromJson(podState, PodSessionState.class);
|
} else {
|
||||||
|
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState);
|
||||||
|
try {
|
||||||
|
podSessionState = gsonInstance.fromJson(storedPodState, PodSessionState.class);
|
||||||
podSessionState.injectDaggerClass(injector);
|
podSessionState.injectDaggerClass(injector);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setPodSessionState(podSessionState);
|
setPodSessionState(podSessionState);
|
||||||
|
|
||||||
return podSessionState;
|
return podSessionState;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue