Skip to content
Snippets Groups Projects
Commit 4e151e3e authored by Volker Richert's avatar Volker Richert
Browse files

create a copy of lastPumpStatus

parent b9fedb0c
No related branches found
No related tags found
No related merge requests found
...@@ -745,19 +745,18 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -745,19 +745,18 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
// Get the most recently written CGM record for the active pump. // Get the most recently written CGM record for the active pump.
PumpStatusEvent pumpStatusData = null; PumpStatusEvent pumpStatusData = null;
PumpInfo pump = getActivePump(); // ignoring activePump atm
//PumpInfo pump = getActivePump();
if (pump != null && pump.isValid() && pump.getPumpHistory().size() > 0) { if (dataStore.getLastPumpStatus().getEventDate().getTime() > 0) {
pumpStatusData = pump.getPumpHistory().last(); pumpStatusData = dataStore.getLastPumpStatus();
} }
// FIXME - grab the last item from the activePump's getPumpHistory
updateChart(mRealm.where(PumpStatusEvent.class) updateChart(mRealm.where(PumpStatusEvent.class)
.greaterThan("eventDate", new Date(System.currentTimeMillis() - 1000*60*60*24)) .greaterThan("eventDate", new Date(System.currentTimeMillis() - 1000*60*60*24))
.findAllSorted("eventDate", Sort.ASCENDING)); .findAllSorted("eventDate", Sort.ASCENDING));
if (pumpStatusData != null) { if (pumpStatusData != null) {
String sgvString; String sgvString;
if (configurationStore.isMmolxl()) { if (configurationStore.isMmolxl()) {
float fBgValue = (float) pumpStatusData.getSgv(); float fBgValue = (float) pumpStatusData.getSgv();
......
...@@ -111,7 +111,6 @@ public class MedtronicCnlIntentService extends IntentService { ...@@ -111,7 +111,6 @@ public class MedtronicCnlIntentService extends IntentService {
short pumpBatteryLevel = dataStore.getLastPumpStatus().getBatteryPercentage(); short pumpBatteryLevel = dataStore.getLastPumpStatus().getBatteryPercentage();
if (timeLastGoodSGV != 0) { if (timeLastGoodSGV != 0) {
timePollExpected = timeLastGoodSGV + POLL_PERIOD_MS + POLL_GRACE_PERIOD_MS + (POLL_PERIOD_MS * ((timePollStarted - 1000L - (timeLastGoodSGV + POLL_GRACE_PERIOD_MS)) / POLL_PERIOD_MS)); timePollExpected = timeLastGoodSGV + POLL_PERIOD_MS + POLL_GRACE_PERIOD_MS + (POLL_PERIOD_MS * ((timePollStarted - 1000L - (timeLastGoodSGV + POLL_GRACE_PERIOD_MS)) / POLL_PERIOD_MS));
} }
......
package info.nightscout.android.utils; package info.nightscout.android.utils;
import com.bugfender.sdk.a.a.k.a;
import java.util.Date; import java.util.Date;
import info.nightscout.android.model.medtronicNg.PumpStatusEvent; import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
import io.realm.Realm;
/** /**
* Created by volker on 30.03.2017. * Created by volker on 30.03.2017.
...@@ -11,13 +14,16 @@ import info.nightscout.android.model.medtronicNg.PumpStatusEvent; ...@@ -11,13 +14,16 @@ import info.nightscout.android.model.medtronicNg.PumpStatusEvent;
public class DataStore { public class DataStore {
private static DataStore instance; private static DataStore instance;
private final Realm mRealm;
private PumpStatusEvent lastPumpStatus; private PumpStatusEvent lastPumpStatus;
private int uplooaderBatteryLevel = 0; private int uplooaderBatteryLevel = 0;
private int unavailableSGVCount = 0; private int unavailableSGVCount = 0;
private long activePumpMac = 0; private long activePumpMac = 0;
private DataStore() {} private DataStore() {
mRealm = Realm.getDefaultInstance();
}
public static DataStore getInstance() { public static DataStore getInstance() {
if (DataStore.instance == null) { if (DataStore.instance == null) {
...@@ -27,7 +33,8 @@ public class DataStore { ...@@ -27,7 +33,8 @@ public class DataStore {
PumpStatusEvent dummyStatus = new PumpStatusEvent(); PumpStatusEvent dummyStatus = new PumpStatusEvent();
dummyStatus.setEventDate(new Date(0)); dummyStatus.setEventDate(new Date(0));
instance.setLastPumpStatus(dummyStatus); // bypass setter to avoid dealing with a real Realm object
instance.lastPumpStatus = dummyStatus;
} }
return instance; return instance;
...@@ -38,7 +45,7 @@ public class DataStore { ...@@ -38,7 +45,7 @@ public class DataStore {
} }
public void setLastPumpStatus(PumpStatusEvent lastPumpStatus) { public void setLastPumpStatus(PumpStatusEvent lastPumpStatus) {
this.lastPumpStatus = lastPumpStatus; this.lastPumpStatus = mRealm.copyFromRealm(lastPumpStatus);;
} }
public int getUplooaderBatteryLevel() { public int getUplooaderBatteryLevel() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment