Correctly load Pod state from Shared Preferences after startup

This commit is contained in:
Bart Sopers 2020-08-06 20:19:15 +02:00
parent eafb68d496
commit d446751d8a
2 changed files with 17 additions and 25 deletions

View file

@ -1,13 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.service;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.IBinder;
import com.google.gson.Gson;
import org.apache.commons.lang3.StringUtils;
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.RileyLinkTargetDevice;
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.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
@ -112,19 +107,11 @@ public class RileyLinkOmnipodService extends RileyLinkService {
private void initializeErosOmnipodManager() {
if (AapsOmnipodManager.getInstance() == null) {
PodSessionState podState = null;
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);
}
}
PodSessionState podState = omnipodUtil.loadSessionState();
OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
//omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
this.omnipodCommunicationManager = omnipodCommunicationService;
this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin);

View file

@ -101,7 +101,7 @@ public class OmnipodUtil {
if (currentCommand != null)
rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItem(currentCommand));
rxBus.send(new EventOmnipodDeviceStatusChange((OmnipodCommandType)null));
rxBus.send(new EventOmnipodDeviceStatusChange((OmnipodCommandType) null));
}
public static void displayNotConfiguredDialog(Context context) {
@ -233,18 +233,23 @@ public class OmnipodUtil {
}
public PodSessionState loadSessionState() {
String podState = sp.getString(OmnipodConst.Prefs.PodState, "");
PodSessionState podSessionState = null;
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + podState);
if (StringUtils.isNotEmpty(podState)) {
PodSessionState podSessionState = gsonInstance.fromJson(podState, PodSessionState.class);
String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, "");
if (StringUtils.isEmpty(storedPodState)) {
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: no PodSessionState present in SharedPreferences");
} else {
aapsLogger.info(LTag.PUMP, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState);
try {
podSessionState = gsonInstance.fromJson(storedPodState, PodSessionState.class);
podSessionState.injectDaggerClass(injector);
} catch (Exception ex) {
aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
}
}
setPodSessionState(podSessionState);
return podSessionState;
}
return null;
}
}