diff --git a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java index 466351076b..bcc778485b 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java @@ -10,6 +10,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Iterator; +import info.nightscout.androidaps.Constants; + /** * Created by mike on 01.06.2017. */ @@ -17,9 +19,11 @@ import java.util.Iterator; public class ProfileStore { private static Logger log = LoggerFactory.getLogger(ProfileStore.class); private JSONObject json = null; + private String units = Constants.MGDL; public ProfileStore(JSONObject json) { this.json = json; + getDefaultProfile(); // initialize units } public JSONObject getData() { @@ -33,10 +37,10 @@ public class ProfileStore { String defaultProfileName = json.getString("defaultProfile"); JSONObject store = json.getJSONObject("store"); if (store.has(defaultProfileName)) { - String units = null; if (store.has("units")) units = store.getString("units"); profile = new Profile(store.getJSONObject(defaultProfileName), units); + units = profile.getUnits(); } } catch (JSONException e) { e.printStackTrace(); @@ -59,6 +63,10 @@ public class ProfileStore { return defaultProfileName; } + public String getUnits() { + return units; + } + @Nullable public Profile getSpecificProfile(String profileName) { Profile profile = null; diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index fa5cd00c54..da129b41cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -158,7 +158,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public double getY() { - String units = MainApp.getConfigBuilder().getProfile().getUnits(); + String units = MainApp.getConfigBuilder().getProfileUnits(); return valueToUnits(units); } @@ -190,7 +190,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public int getColor() { - String units = MainApp.getConfigBuilder().getProfile().getUnits(); + String units = MainApp.getConfigBuilder().getProfileUnits(); Double lowLine = SP.getDouble("low_mark", 0d); Double highLine = SP.getDouble("high_mark", 0d); if (lowLine < 1) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index 17807443c3..aec38ea297 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -89,7 +89,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { } public String age() { - Map diff = computeDiff(date, new Date().getTime()); + Map diff = computeDiff(date, new Date().getTime()); return diff.get(TimeUnit.DAYS) + " " + MainApp.sResources.getString(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.sResources.getString(R.string.hours); } @@ -105,17 +105,17 @@ public class CareportalEvent implements DataPointWithLabelInterface { } //Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0} - public static Map computeDiff(long date1, long date2) { + public static Map computeDiff(long date1, long date2) { long diffInMillies = date2 - date1; List units = new ArrayList(EnumSet.allOf(TimeUnit.class)); Collections.reverse(units); - Map result = new LinkedHashMap(); + Map result = new LinkedHashMap(); long milliesRest = diffInMillies; - for ( TimeUnit unit : units ) { - long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS); + for (TimeUnit unit : units) { + long diff = unit.convert(milliesRest, TimeUnit.MILLISECONDS); long diffInMilliesForUnit = unit.toMillis(diff); milliesRest = milliesRest - diffInMilliesForUnit; - result.put(unit,diff); + result.put(unit, diff); } return result; } @@ -131,7 +131,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { @Override public double getY() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + String units = MainApp.getConfigBuilder().getProfileUnits(); if (eventType.equals(MBG)) { double mbg = 0d; try { @@ -140,13 +140,10 @@ public class CareportalEvent implements DataPointWithLabelInterface { } catch (JSONException e) { e.printStackTrace(); } - if (profile != null) - return profile.fromMgdlToUnits(mbg, profile.getUnits()); - return 0d; + return Profile.fromMgdlToUnits(mbg, units); } double glucose = 0d; - String units = Constants.MGDL; try { JSONObject object = new JSONObject(json); if (object.has("glucose")) { @@ -156,7 +153,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { } catch (JSONException e) { e.printStackTrace(); } - if (profile != null && glucose != 0d) { + if (glucose != 0d) { double mmol = 0d; double mgdl = 0; if (units.equals(Constants.MGDL)) { @@ -167,7 +164,7 @@ public class CareportalEvent implements DataPointWithLabelInterface { mmol = glucose; mgdl = glucose * Constants.MMOLL_TO_MGDL; } - return profile.toUnits(mgdl, mmol, profile.getUnits()); + return Profile.toUnits(mgdl, mmol, units); } return yValue; diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 832ddbca47..e98946c8da 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -204,6 +204,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } catch (SQLException e) { e.printStackTrace(); } + VirtualPumpPlugin.setFakingStatus(true); scheduleBgChange(); // trigger refresh scheduleTemporaryBasalChange(); scheduleTreatmentChange(); @@ -251,6 +252,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } catch (SQLException e) { e.printStackTrace(); } + VirtualPumpPlugin.setFakingStatus(false); scheduleTemporaryBasalChange(); } @@ -817,8 +819,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void createTemptargetFromJsonIfNotExists(JSONObject trJson) { try { - Profile profile = MainApp.getConfigBuilder().getProfile(); - String units = profile.getUnits(); + String units = MainApp.getConfigBuilder().getProfileUnits(); TempTarget tempTarget = new TempTarget(); tempTarget.date = trJson.getLong("mills"); tempTarget.durationInMinutes = trJson.getInt("duration"); @@ -1070,7 +1071,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBolus.durationInMinutes = trJson.getInt("duration"); extendedBolus.insulin = trJson.getDouble("originalExtendedAmount"); extendedBolus._id = trJson.getString("_id"); - VirtualPumpPlugin.fromNSAreCommingFakedExtendedBoluses = true; + if (!VirtualPumpPlugin.getFakingStatus()) { + VirtualPumpPlugin.setFakingStatus(true); + updateEarliestDataChange(0); + scheduleTemporaryBasalChange(); + } createOrUpdate(extendedBolus); } else if (trJson.has("isFakedTempBasal")) { // extended bolus end uploaded as temp basal end ExtendedBolus extendedBolus = new ExtendedBolus(); @@ -1080,7 +1085,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { extendedBolus.durationInMinutes = 0; extendedBolus.insulin = 0; extendedBolus._id = trJson.getString("_id"); - VirtualPumpPlugin.fromNSAreCommingFakedExtendedBoluses = true; + if (!VirtualPumpPlugin.getFakingStatus()) { + VirtualPumpPlugin.setFakingStatus(true); + updateEarliestDataChange(0); + scheduleTemporaryBasalChange(); + } createOrUpdate(extendedBolus); } else { TemporaryBasal tempBasal = new TemporaryBasal(); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java index 64fffa3e57..e3b368fe86 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java @@ -10,5 +10,6 @@ import info.nightscout.androidaps.data.ProfileStore; public interface ProfileInterface { @Nullable ProfileStore getProfile(); + String getUnits(); String getProfileName(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index dad922a5c5..635f689fb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -231,7 +231,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profile = MainApp.getConfigBuilder().getProfile(); profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); ArrayList profileList; - units = Constants.MGDL; units = profile.getUnits(); profileList = profileStore.getProfileList(); ArrayAdapter adapter = new ArrayAdapter(getContext(), diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 992fcc0244..c5d27a7e11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -1008,6 +1008,10 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return getProfile(new Date().getTime()); } + public String getProfileUnits() { + return activeProfile.getUnits(); + } + public Profile getProfile(long time) { //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 417322a6b4..4b7060e52f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -345,6 +345,7 @@ public class IobCobCalculatorPlugin implements PluginBase { return iobTotal; } + @Nullable private static Long findPreviousTimeFromBucketedData(long time) { if (bucketed_data == null) return null; @@ -413,6 +414,7 @@ public class IobCobCalculatorPlugin implements PluginBase { Profile profile = MainApp.getConfigBuilder().getProfile(); // predict IOB out to DIA plus 30m long time = new Date().getTime(); + time = roundUpTime(time); int len = (int) ((profile.getDia() * 60 + 30) / 5); IobTotal[] array = new IobTotal[len]; int pos = 0; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index c4316f0118..6e4038bc37 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -156,6 +156,7 @@ public class NSClientService extends Service { ev.isChanged(R.string.key_nsclientinternal_api_secret) || ev.isChanged(R.string.key_nsclientinternal_paused) ) { + latestDateInReceivedData = 0; destroy(); initialize(); } @@ -164,6 +165,7 @@ public class NSClientService extends Service { @Subscribe public void onStatusEvent(EventConfigBuilderChange ev) { if (nsEnabled != MainApp.getSpecificPlugin(NSClientInternalPlugin.class).isEnabled(PluginBase.GENERAL)) { + latestDateInReceivedData = 0; destroy(); initialize(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java index d1b25fff3a..aa1d51f4dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java @@ -60,14 +60,10 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis okButton = (Button) view.findViewById(R.id.overview_calibration_okbutton); okButton.setOnClickListener(this); - Profile profile = MainApp.getConfigBuilder().getProfile(); - Double bg = profile != null ? Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits()) : 0d; + String units = MainApp.getConfigBuilder().getProfileUnits(); + Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); - String units = Constants.MGDL; - if (profile != null) - units = profile.getUnits(); - - if (units.equals(Constants.MMOL)) + if (units.equals(Constants.MMOL)) bgText = new PlusMinusEditText(view, R.id.overview_calibration_bg, R.id.overview_calibration_bg_plus, R.id.overview_calibration_bg_minus, bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false); else bgText = new PlusMinusEditText(view, R.id.overview_calibration_bg, R.id.overview_calibration_bg_plus, R.id.overview_calibration_bg_minus, bg, 0d, 500d, 1d, new DecimalFormat("0"), false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 7ebdcc60f2..48550727c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -916,6 +916,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, PumpInterface pump = MainApp.getConfigBuilder(); Profile profile = MainApp.getConfigBuilder().getProfile(); + String units = profile.getUnits(); // open loop mode final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; @@ -958,13 +959,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); tempTargetView.setVisibility(View.VISIBLE); if (tempTarget.low == tempTarget.high) - tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits())); + tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, units), units)); else - tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + Profile.toUnitsString(tempTarget.high, Profile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits())); + tempTargetView.setText(Profile.toUnitsString(tempTarget.low, Profile.fromMgdlToUnits(tempTarget.low, units), units) + " - " + Profile.toUnitsString(tempTarget.high, Profile.fromMgdlToUnits(tempTarget.high, units), units)); } else { Double maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL; Double minBgDefault = Constants.MIN_BG_DEFAULT_MGDL; - if (!profile.getUnits().equals(Constants.MGDL)) { + if (!units.equals(Constants.MGDL)) { maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL; minBgDefault = Constants.MIN_BG_DEFAULT_MMOL; } @@ -1062,7 +1063,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(profile.getUnits()), 0d, true, true, false, false); + wizard.doCalc(profile, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U"; quickWizardButton.setText(text); if (wizard.calculatedTotalInsulin <= 0) @@ -1079,8 +1080,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, treatmentButton.setVisibility(View.GONE); } - String units = profile.getUnits(); - Double lowLine = SP.getDouble("low_mark", 0d); Double highLine = SP.getDouble("high_mark", 0d); if (lowLine < 1) { @@ -1097,7 +1096,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, color = MainApp.sResources.getColor(R.color.low); else if (lastBG.valueToUnits(units) > highLine) color = MainApp.sResources.getColor(R.color.high); - bgView.setText(lastBG.valueToUnitsToString(profile.getUnits())); + bgView.setText(lastBG.valueToUnitsToString(units)); arrowView.setText(lastBG.directionToSymbol()); bgView.setTextColor(color); arrowView.setTextColor(color); @@ -1156,7 +1155,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // ****** GRAPH ******* - //log.debug("updateGUI checkpoint 1"); + log.debug("updateGUI checkpoint 1"); // allign to hours Calendar calendar = Calendar.getInstance(); @@ -1287,7 +1286,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, absoluteBasalsLineSeries.setCustomPaint(absolutePaint); } - //log.debug("updateGUI checkpoint 2"); + log.debug("updateGUI checkpoint 2"); // **** IOB COB DEV graph **** class DeviationDataPoint extends DataPoint { @@ -1405,12 +1404,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else { iobGraph.setVisibility(View.GONE); } - //log.debug("updateGUI checkpoint 3"); + log.debug("updateGUI checkpoint 3"); // remove old data from graph bgGraph.getSecondScale().getSeries().clear(); bgGraph.getSeries().clear(); - //log.debug("updateGUI checkpoint 4"); + log.debug("updateGUI checkpoint 4"); // **** Area **** DoubleDataPoint[] areaDataPoints = new DoubleDataPoint[]{ @@ -1586,11 +1585,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public double getNearestBg(long date, List bgReadingsArray) { double bg = 0; - Profile profile = MainApp.getConfigBuilder().getProfile(); + String units = MainApp.getConfigBuilder().getProfileUnits(); for (int r = bgReadingsArray.size() - 1; r >= 0; r--) { BgReading reading = bgReadingsArray.get(r); if (reading.date > date) continue; - bg = Profile.fromMgdlToUnits(reading.value, profile.getUnits()); + bg = Profile.fromMgdlToUnits(reading.value, units); break; } return bg; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index 7e7f2ab7a2..1484eee396 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -118,17 +118,17 @@ public class PersistentNotificationPlugin implements PluginBase { String line1 = ctx.getString(R.string.noprofile); - Profile profile = MainApp.getConfigBuilder().getProfile(); + String units = MainApp.getConfigBuilder().getProfileUnits(); BgReading lastBG = DatabaseHelper.lastBg(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (profile != null && lastBG != null) { - line1 = lastBG.valueToUnitsToString(profile.getUnits()); + if (lastBG != null) { + line1 = lastBG.valueToUnitsToString(units); if (glucoseStatus != null) { - line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits()) - + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits()); + line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units); } else { line1 += " " + ctx.getString(R.string.old_data) + diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java index 40fbbf9eb3..4137b0263b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileCircadianPercentage/CircadianPercentageProfilePlugin.java @@ -213,6 +213,11 @@ public class CircadianPercentageProfilePlugin implements PluginBase, ProfileInte return convertedProfile; } + @Override + public String getUnits() { + return mgdl ? Constants.MGDL : Constants.MMOL; + } + @Override public String getProfileName() { performLimitCheck(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java index d1fab7cbcf..8aca0a8dbc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java @@ -240,6 +240,11 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { return convertedProfile; } + @Override + public String getUnits() { + return mgdl ? Constants.MGDL : Constants.MMOL; + } + @Override public String getProfileName() { return convertedProfileName; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index b310993584..68bd2c6a80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -153,6 +153,11 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { return profile; } + @Override + public String getUnits() { + return profile.getUnits(); + } + @Override public String getProfileName() { return profile.getDefaultProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java index de7c903df3..e02f4918c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java @@ -201,6 +201,11 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { return convertedProfile; } + @Override + public String getUnits() { + return mgdl ? Constants.MGDL : Constants.MMOL; + } + @Override public String getProfileName() { return "SimpleProfile"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 1188028492..0707cc842c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -798,6 +798,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C return pump.createConvertedProfile(); } + @Override + public String getUnits() { + return pump.getUnits(); + } + @Override public String getProfileName() { return pump.createConvertedProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java index af36e4059f..55fdc7ad04 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPump.java @@ -132,6 +132,10 @@ public class DanaRPump { public double maxBolus; public double maxBasal; + public String getUnits() { + return units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL; + } + public ProfileStore createConvertedProfile() { JSONObject json = new JSONObject(); JSONObject store = new JSONObject(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java index ef5dc16b43..0668a74c1d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java @@ -46,12 +46,6 @@ public class DanaRNSHistorySync { public void sync(int what) { try { - ConfigBuilderPlugin ConfigBuilderPlugin = MainApp.getConfigBuilder(); - Profile profile = MainApp.getConfigBuilder().getProfile(); - if (profile == null) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.noprofile)); - return; - } Calendar cal = Calendar.getInstance(); long records = historyRecords.size(); long processing = 0; @@ -179,7 +173,7 @@ public class DanaRNSHistorySync { log.debug("Syncing glucose record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate)); nsrec.put(DANARSIGNATURE, record.bytes); nsrec.put("eventType", "BG Check"); - nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, profile.getUnits())); + nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, MainApp.getConfigBuilder().getProfileUnits())); nsrec.put("glucoseType", "Finger"); nsrec.put("created_at", DateUtil.toISOString(record.recordDate)); nsrec.put("enteredBy", "openaps://" + MainApp.sResources.getString(R.string.app_name)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 6d72fe9684..8885056f5b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -802,6 +802,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf return pump.createConvertedProfile(); } + @Override + public String getUnits() { + return pump.getUnits(); + } + @Override public String getProfileName() { return pump.createConvertedProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index c79100ff81..4d332824aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -715,6 +715,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, return pump.createConvertedProfile(); } + @Override + public String getUnits() { + return pump.getUnits(); + } + @Override public String getProfileName() { return pump.createConvertedProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index b89e050fe5..cdf5ff0c7e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProg import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; +import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. @@ -45,12 +46,26 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { boolean fragmentEnabled = true; boolean fragmentVisible = true; - public static boolean fromNSAreCommingFakedExtendedBoluses = false; + private static boolean fromNSAreCommingFakedExtendedBoluses = false; PumpDescription pumpDescription = new PumpDescription(); + static void loadFakingStatus() { + fromNSAreCommingFakedExtendedBoluses = SP.getBoolean("fromNSAreCommingFakedExtendedBoluses", false); + } + + public static void setFakingStatus(boolean newStatus) { + fromNSAreCommingFakedExtendedBoluses = newStatus; + SP.putBoolean("fromNSAreCommingFakedExtendedBoluses", fromNSAreCommingFakedExtendedBoluses); + } + + public static boolean getFakingStatus() { + return fromNSAreCommingFakedExtendedBoluses; + } + static VirtualPumpPlugin instance = null; public static VirtualPumpPlugin getInstance() { + loadFakingStatus(); if (instance == null) instance = new VirtualPumpPlugin(); return instance; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 4e81aa49d9..280bb21912 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -238,8 +238,7 @@ public class SmsCommunicatorPlugin implements PluginBase { BgReading actualBG = DatabaseHelper.actualBg(); BgReading lastBG = DatabaseHelper.lastBg(); - Profile profile = MainApp.getConfigBuilder().getProfile(); - String units = profile.getUnits(); + String units = MainApp.getConfigBuilder().getProfileUnits(); if (actualBG != null) { reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java index 9b2603ef4f..7a74ca4a86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java @@ -62,16 +62,15 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli @Override public void onBindViewHolder(TempTargetsViewHolder holder, int position) { - Profile profile = MainApp.getConfigBuilder().getProfile(); - if (profile == null) return; + String units = MainApp.getConfigBuilder().getProfileUnits(); TempTarget tempTarget = tempTargetList.getReversed(position); holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ns.setVisibility(tempTarget._id != null ? View.VISIBLE : View.GONE); if (!tempTarget.isEndingEvent()) { holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTarget.originalEnd())); holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min"); - holder.low.setText(tempTarget.lowValueToUnitsToString(profile.getUnits())); - holder.high.setText(tempTarget.highValueToUnitsToString(profile.getUnits())); + holder.low.setText(tempTarget.lowValueToUnitsToString(units)); + holder.high.setText(tempTarget.highValueToUnitsToString(units)); holder.reason.setText(tempTarget.reason); } else { holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index d58742d32a..6fa3a54370 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -209,14 +209,13 @@ public class WatchUpdaterService extends WearableListenerService implements } private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) { - Profile profile = MainApp.getConfigBuilder().getProfile(); - if (profile == null) return null; + String units = MainApp.getConfigBuilder().getProfileUnits(); Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); //convert to mg/dl - if (!profile.getUnits().equals(Constants.MGDL)) { + if (!units.equals(Constants.MGDL)) { lowLine *= Constants.MMOLL_TO_MGDL; highLine *= Constants.MMOLL_TO_MGDL; @@ -239,7 +238,7 @@ public class WatchUpdaterService extends WearableListenerService implements DataMap dataMap = new DataMap(); int battery = getBatteryLevel(getApplicationContext()); - dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits())); + dataMap.putString("sgvString", lastBG.valueToUnitsToString(units)); dataMap.putDouble("timestamp", lastBG.date); if (glucoseStatus == null) { dataMap.putString("slopeArrow", ""); @@ -247,8 +246,8 @@ public class WatchUpdaterService extends WearableListenerService implements dataMap.putString("avgDelta", ""); } else { dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta)); - dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits())); - dataMap.putString("avgDelta", deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits())); + dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units)); + dataMap.putString("avgDelta", deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, units)); } dataMap.putString("battery", "" + battery); dataMap.putLong("sgvLevel", sgvLevel); diff --git a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java index 2bc60d3693..29de7d9ee3 100644 --- a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java +++ b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java @@ -44,12 +44,10 @@ public class XdripCalibrations { } public static boolean sendIntent(Double bg) { - final Profile profile = MainApp.getConfigBuilder().getProfile(); - Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putDouble("glucose_number", bg); - bundle.putString("units", profile.getUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); + bundle.putString("units", MainApp.getConfigBuilder().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); bundle.putLong("timestamp", new Date().getTime()); Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION); intent.putExtras(bundle);