From 02891a14fcb6ed0e306e700e2a5e54a44282c91f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 12 Nov 2019 00:01:58 +0100 Subject: [PATCH] use global units setting --- .../nightscout/androidaps/MainActivity.java | 22 ------ .../activities/HistoryBrowseActivity.java | 5 +- .../nightscout/androidaps/data/Profile.java | 58 +++++++-------- .../androidaps/data/ProfileStore.java | 38 ++++------ .../androidaps/data/QuickWizardEntry.java | 3 +- .../nightscout/androidaps/db/BgReading.java | 9 ++- .../androidaps/db/CareportalEvent.java | 2 +- .../androidaps/db/ExtendedBolus.java | 4 +- .../androidaps/db/TemporaryBasal.java | 4 +- .../interfaces/ProfileInterface.java | 1 - .../DetermineBasalAdapterAMAJS.java | 7 +- .../aps/openAPSAMA/OpenAPSAMAPlugin.java | 17 +++-- .../openAPSMA/DetermineBasalAdapterMAJS.java | 7 +- .../aps/openAPSMA/OpenAPSMAPlugin.java | 17 +++-- .../DetermineBasalAdapterSMBJS.java | 7 +- .../aps/openAPSSMB/OpenAPSSMBPlugin.java | 17 +++-- .../configBuilder/ProfileFunctions.java | 5 -- .../general/automation/elements/InputBg.java | 2 +- .../automation/elements/InputTempTarget.java | 2 +- .../automation/triggers/TriggerDelta.java | 2 +- .../Dialogs/NewNSTreatmentDialog.java | 70 +++++++++---------- .../plugins/general/nsclient/NSUpload.java | 13 +--- .../general/overview/OverviewFragment.java | 23 +++--- .../general/overview/OverviewPlugin.kt | 11 ++- .../overview/dialogs/CalibrationDialog.java | 2 +- .../overview/dialogs/NewCarbsDialog.java | 21 +++--- .../overview/dialogs/NewInsulinDialog.java | 20 +++--- .../general/overview/dialogs/WizardDialog.kt | 8 +-- .../general/overview/graphData/GraphData.java | 6 +- .../PersistentNotificationPlugin.java | 2 +- .../SmsCommunicatorPlugin.java | 2 +- .../tidepool/elements/ProfileElement.kt | 8 +-- .../general/wear/ActionStringHandler.java | 15 ++-- .../wearintegration/WatchUpdaterService.java | 6 +- .../xdripStatusline/StatuslinePlugin.java | 2 +- .../iob/iobCobCalculator/AutosensData.java | 2 +- .../iobCobCalculator/IobCobOref1Thread.java | 2 +- .../iob/iobCobCalculator/IobCobThread.java | 2 +- .../profile/local/LocalProfileFragment.kt | 1 - .../profile/local/LocalProfilePlugin.kt | 4 -- .../plugins/profile/ns/NSProfilePlugin.java | 5 -- .../pump/danaR/AbstractDanaRPlugin.java | 5 -- .../activities/DanaRHistoryActivity.java | 10 +-- .../danaR/activities/DanaRNSHistorySync.java | 2 +- .../plugins/pump/danaRS/DanaRSPlugin.java | 5 -- .../sensitivity/SensitivityAAPSPlugin.java | 4 +- .../sensitivity/SensitivityOref0Plugin.java | 6 +- .../sensitivity/SensitivityOref1Plugin.java | 6 +- .../SensitivityWeightedAveragePlugin.java | 4 +- .../plugins/source/BGSourceFragment.java | 12 +--- .../TreatmentsTempTargetFragment.java | 2 +- .../androidaps/utils/BolusWizard.kt | 12 ++-- .../androidaps/utils/XdripCalibrations.java | 2 +- app/src/main/res/values/strings.xml | 1 + 54 files changed, 222 insertions(+), 303 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index 64c2656086..698b74d1ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -249,8 +249,6 @@ public class MainActivity extends NoSplashAppCompatActivity { private void doMigrations() { - checkUpgradeToProfileTarget(); - // guarantee that the unreachable threshold is at least 30 and of type String // Added in 1.57 at 21.01.2018 int unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30); @@ -260,26 +258,6 @@ public class MainActivity extends NoSplashAppCompatActivity { } - private void checkUpgradeToProfileTarget() { // TODO: can be removed in the future - boolean oldKeyExists = SP.contains("openapsma_min_bg"); - if (oldKeyExists) { - Profile profile = ProfileFunctions.getInstance().getProfile(); - String oldRange = SP.getDouble("openapsma_min_bg", 0d) + " - " + SP.getDouble("openapsma_max_bg", 0d); - String newRange = ""; - if (profile != null) { - newRange = profile.getTargetLow() + " - " + profile.getTargetHigh(); - } - String message = "Target range is changed in current version.\n\nIt's not taken from preferences but from profile.\n\n!!! REVIEW YOUR SETTINGS !!!"; - message += "\n\nOld settings: " + oldRange; - message += "\nProfile settings: " + newRange; - OKDialog.show(this, "Target range change", message, () -> { - SP.remove("openapsma_min_bg"); - SP.remove("openapsma_max_bg"); - SP.remove("openapsma_target_bg"); - }); - } - } - @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java index 79f3fbf4d4..2397dda9ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java @@ -231,9 +231,8 @@ public class HistoryBrowseActivity extends NoSplashActivity { noProfile.setVisibility(View.GONE); } - final String units = profile.getUnits(); - final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); - final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); + final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(); + final double highLine = OverviewPlugin.INSTANCE.determineHighLine(); buttonDate.setText(DateUtil.dateAndTimeString(start)); buttonZoom.setText(String.valueOf(rangeToDisplay)); diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 6f18ba7af5..92d0fe5a8a 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -149,7 +149,7 @@ public class Profile { return units; } - public TimeZone getTimeZone() { + TimeZone getTimeZone() { return timeZone; } @@ -162,7 +162,7 @@ public class Profile { double multiplier = getMultiplier(array); LongSparseArray sparse = new LongSparseArray<>(); - for (Integer index = 0; index < array.length(); index++) { + for (int index = 0; index < array.length(); index++) { try { final JSONObject o = array.getJSONObject(index); long tas = 0; @@ -385,12 +385,12 @@ public class Profile { return retValue; } - public double getIsf() { - return getIsfTimeFromMidnight(secondsFromMidnight()); + public double getIsfMgdl() { + return toMgdl(getIsfTimeFromMidnight(secondsFromMidnight()), units); } - public double getIsf(long time) { - return getIsfTimeFromMidnight(secondsFromMidnight(time)); + public double getIsfMgdl(long time) { + return toMgdl(getIsfTimeFromMidnight(secondsFromMidnight(time)), units); } double getIsfTimeFromMidnight(int timeAsSeconds) { @@ -405,15 +405,15 @@ public class Profile { return getValuesList(isf_v, null, new DecimalFormat("0.0"), getUnits() + MainApp.gs(R.string.profile_per_unit)); } - public ProfileValue[] getIsfs() { + public ProfileValue[] getIsfsMgdl() { if (isf_v == null) isf_v = convertToSparseArray(ic); ProfileValue[] ret = new ProfileValue[isf_v.size()]; - for (Integer index = 0; index < isf_v.size(); index++) { - Integer tas = (int) isf_v.keyAt(index); + for (int index = 0; index < isf_v.size(); index++) { + int tas = (int) isf_v.keyAt(index); double value = isf_v.valueAt(index); - ret[index] = new ProfileValue(tas, value); + ret[index] = new ProfileValue(tas, toMgdl(value, units)); } return ret; } @@ -495,44 +495,44 @@ public class Profile { return ret; } - public double getTarget() { - return getTarget(secondsFromMidnight()); + public double getTargetMgdl() { + return getTargetMgdl(secondsFromMidnight()); } - protected double getTarget(int timeAsSeconds) { - return (getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2; + public double getTargetMgdl(int timeAsSeconds) { + return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); } - public double getTargetLow() { - return getTargetLowTimeFromMidnight(secondsFromMidnight()); + public double getTargetLowMgdl() { + return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units); } - public double getTargetLow(long time) { - return getTargetLowTimeFromMidnight(secondsFromMidnight(time)); + public double getTargetLowMgdl(long time) { + return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight(time)), units); } - public double getTargetLowTimeFromMidnight(int timeAsSeconds) { + double getTargetLowTimeFromMidnight(int timeAsSeconds) { if (targetLow_v == null) targetLow_v = convertToSparseArray(targetLow); return getValueToTime(targetLow_v, timeAsSeconds); } - public double getTargetHigh() { - return getTargetHighTimeFromMidnight(secondsFromMidnight()); + public double getTargetHighMgdl() { + return toMgdl(getTargetHighTimeFromMidnight(secondsFromMidnight()), units); } - public double getTargetHigh(long time) { - return getTargetHighTimeFromMidnight(secondsFromMidnight(time)); + public double getTargetHighMgdl(long time) { + return toMgdl(getTargetHighTimeFromMidnight(secondsFromMidnight(time)), units); } - public double getTargetHighTimeFromMidnight(int timeAsSeconds) { + double getTargetHighTimeFromMidnight(int timeAsSeconds) { if (targetHigh_v == null) targetHigh_v = convertToSparseArray(targetHigh); return getValueToTime(targetHigh_v, timeAsSeconds); } public class TargetValue { - public TargetValue(int timeAsSeconds, double low, double high) { + TargetValue(int timeAsSeconds, double low, double high) { this.timeAsSeconds = timeAsSeconds; this.low = low; this.high = high; @@ -559,17 +559,17 @@ public class Profile { return ret; } - public ProfileValue[] getSingleTargets() { + public ProfileValue[] getSingleTargetsMgdl() { if (targetLow_v == null) targetLow_v = convertToSparseArray(targetLow); if (targetHigh_v == null) targetHigh_v = convertToSparseArray(targetHigh); ProfileValue[] ret = new ProfileValue[targetLow_v.size()]; - for (Integer index = 0; index < targetLow_v.size(); index++) { - Integer tas = (int) targetLow_v.keyAt(index); + for (int index = 0; index < targetLow_v.size(); index++) { + int tas = (int) targetLow_v.keyAt(index); double target = (targetLow_v.valueAt(index) + targetHigh_v.valueAt(index)) / 2; - ret[index] = new ProfileValue(tas, target); + ret[index] = new ProfileValue(tas, toMgdl(target, units)); } return ret; } 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 a0b54ec0bb..85e27f0eef 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ProfileStore.java @@ -11,22 +11,19 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Iterator; -import info.nightscout.androidaps.Constants; - /** * Created by mike on 01.06.2017. */ public class ProfileStore { private static Logger log = LoggerFactory.getLogger(ProfileStore.class); - private JSONObject json = null; - private String units = Constants.MGDL; + private JSONObject json; - ArrayMap cachedObjects = new ArrayMap<>(); + private ArrayMap cachedObjects = new ArrayMap<>(); public ProfileStore(JSONObject json) { this.json = json; - getDefaultProfile(); // initialize units + getDefaultProfile(); } public JSONObject getData() { @@ -42,11 +39,11 @@ public class ProfileStore { if (store.has(defaultProfileName)) { profile = cachedObjects.get(defaultProfileName); if (profile == null) { - if (store.has("units")) - units = store.getString("units"); - profile = new Profile(store.getJSONObject(defaultProfileName), units); - units = profile.getUnits(); - cachedObjects.put(defaultProfileName, profile); + if (store.has("units")) { + String units = store.getString("units"); + profile = new Profile(store.getJSONObject(defaultProfileName), units); + cachedObjects.put(defaultProfileName, profile); + } } } } catch (JSONException e) { @@ -70,10 +67,6 @@ public class ProfileStore { return defaultProfileName; } - public String getUnits() { - return units; - } - @Nullable public Profile getSpecificProfile(String profileName) { Profile profile = null; @@ -82,11 +75,11 @@ public class ProfileStore { if (store.has(profileName)) { profile = cachedObjects.get(profileName); if (profile == null) { - if (store.has("units")) - units = store.getString("units"); - profile = new Profile(store.getJSONObject(profileName), units); - units = profile.getUnits(); - cachedObjects.put(profileName, profile); + if (store.has("units")) { + String units = store.getString("units"); + profile = new Profile(store.getJSONObject(profileName), units); + cachedObjects.put(profileName, profile); + } } } } catch (JSONException e) { @@ -96,7 +89,7 @@ public class ProfileStore { } public ArrayList getProfileList() { - ArrayList ret = new ArrayList(); + ArrayList ret = new ArrayList<>(); JSONObject store; try { @@ -110,9 +103,6 @@ public class ProfileStore { } catch (JSONException e) { log.error("Unhandled exception", e); } - return ret; } - - } diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java index 062f6ae391..af8451477d 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java @@ -11,6 +11,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; @@ -74,7 +75,7 @@ public class QuickWizardEntry { //BG double bg = 0; if (lastBG != null && useBG() == YES) { - bg = lastBG.valueToUnits(profile.getUnits()); + bg = lastBG.valueToUnits(ProfileFunctions.getSystemUnits()); } // COB 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 8b206e2c78..4224bf9c98 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -181,8 +181,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public double getY() { - String units = ProfileFunctions.getInstance().getProfileUnits(); - return valueToUnits(units); + return valueToUnits(ProfileFunctions.getSystemUnits()); } @Override @@ -215,9 +214,9 @@ public class BgReading implements DataPointWithLabelInterface { @Override public int getColor() { - String units = ProfileFunctions.getInstance().getProfileUnits(); - Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); - Double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); + String units = ProfileFunctions.getSystemUnits(); + Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(); + Double highLine = OverviewPlugin.INSTANCE.determineHighLine(); int color = MainApp.gc(R.color.inrange); if (isPrediction()) return getPredectionColor(); 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 40fadff684..47d25b27ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -167,7 +167,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { @Override public double getY() { - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); if (eventType.equals(MBG)) { double mbg = 0d; try { diff --git a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index 25d2c308c1..5c865a331c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -259,11 +259,11 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface { double sensitivityRatio = lastAutosensResult.ratio; double normalTarget = 100; - if (exercise_mode && isTempTarget && profile.getTarget() >= normalTarget + 5) { + if (exercise_mode && isTempTarget && profile.getTargetMgdl() >= normalTarget + 5) { // w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44 // e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6 double c = half_basal_exercise_target - normalTarget; - sensitivityRatio = c / (c + profile.getTarget() - normalTarget); + sensitivityRatio = c / (c + profile.getTargetMgdl() - normalTarget); } if (realDuration > 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index f2a10cf4a4..cf0eeab462 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -299,11 +299,11 @@ public class TemporaryBasal implements Interval, DbObjectBase { double sensitivityRatio = lastAutosensResult.ratio; double normalTarget = 100; - if (exercise_mode && isTempTarget && profile.getTarget() >= normalTarget + 5) { + if (exercise_mode && isTempTarget && profile.getTargetMgdl() >= normalTarget + 5) { // w/ target 100, temp target 110 = .89, 120 = 0.8, 140 = 0.67, 160 = .57, and 200 = .44 // e.g.: Sensitivity ratio set to 0.8 based on temp target of 120; Adjusting basal from 1.65 to 1.35; ISF from 58.9 to 73.6 double c = half_basal_exercise_target - normalTarget; - sensitivityRatio = c / (c + profile.getTarget() - normalTarget); + sensitivityRatio = c / (c + profile.getTargetMgdl() - normalTarget); } if (realDuration > 0) { 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 482278e437..5fb3b459b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/ProfileInterface.java @@ -10,6 +10,5 @@ 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/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java index 703dc4255b..9ea2d39567 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/DetermineBasalAdapterAMAJS.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; @@ -194,8 +195,6 @@ public class DetermineBasalAdapterAMAJS { double autosensDataRatio, boolean tempTargetSet) throws JSONException { - String units = profile.getUnits(); - mProfile = new JSONObject(); mProfile.put("max_iob", maxIob); mProfile.put("dia", Math.min(profile.getDia(), 3d)); @@ -206,7 +205,7 @@ public class DetermineBasalAdapterAMAJS { mProfile.put("max_bg", maxBg); mProfile.put("target_bg", targetBg); mProfile.put("carb_ratio", profile.getIc()); - mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units)); + mProfile.put("sens", profile.getIsfMgdl()); mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3)); mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d)); mProfile.put("skip_neutral_temps", true); @@ -220,7 +219,7 @@ public class DetermineBasalAdapterAMAJS { mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)); } - if (units.equals(Constants.MMOL)) { + if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) { mProfile.put("out_units", "mmol/L"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java index 65db6e440c..49881c5158 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSAMA/OpenAPSAMAPlugin.java @@ -107,6 +107,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { return; } + if (pump == null) { + RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); + if (L.isEnabled(L.APS)) + log.debug(MainApp.gs(R.string.nopumpselected)); + return; + } + if (!isEnabled(PluginType.APS)) { RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); if (L.isEnabled(L.APS)) @@ -121,12 +128,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { return; } - String units = profile.getUnits(); - double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value(); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = Profile.toMgdl(profile.getTarget(), units); + double minBg = profile.getTargetLowMgdl(); + double maxBg = profile.getTargetHighMgdl(); + double targetBg = profile.getTargetMgdl(); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); @@ -162,7 +167,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { return; if (!HardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) return; - if (!HardLimits.checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) + if (!HardLimits.checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF)) return; if (!HardLimits.checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal())) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java index 1ded34b7cb..dbc7782ab3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/DetermineBasalAdapterMAJS.java @@ -20,6 +20,7 @@ import javax.annotation.Nullable; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; @@ -160,8 +161,6 @@ public class DetermineBasalAdapterMAJS { GlucoseStatus glucoseStatus, MealData mealData) throws JSONException { - String units = profile.getUnits(); - mProfile = new JSONObject(); mProfile.put("max_iob", maxIob); mProfile.put("dia", Math.min(profile.getDia(), 3d)); @@ -172,11 +171,11 @@ public class DetermineBasalAdapterMAJS { mProfile.put("max_bg", maxBg); mProfile.put("target_bg", targetBg); mProfile.put("carb_ratio", profile.getIc()); - mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units)); + mProfile.put("sens", profile.getIsfMgdl()); mProfile.put("current_basal", basalRate); - if (units.equals(Constants.MMOL)) { + if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) { mProfile.put("out_units", "mmol/L"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java index 8cac8b87cc..0380156c74 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSMA/OpenAPSMAPlugin.java @@ -106,6 +106,13 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { return; } + if (pump == null) { + RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); + if (L.isEnabled(L.APS)) + log.debug(MainApp.gs(R.string.nopumpselected)); + return; + } + if (!isEnabled(PluginType.APS)) { RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); if (L.isEnabled(L.APS)) @@ -120,13 +127,11 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { return; } - String units = profile.getUnits(); - double maxBasal = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value(); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = Profile.toMgdl(profile.getTarget(), units); + double minBg = profile.getTargetLowMgdl(); + double maxBg = profile.getTargetHighMgdl(); + double targetBg = profile.getTargetMgdl(); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); @@ -160,7 +165,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { return; if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) + if (!checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF)) return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal())) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index b7b6d82e5e..76571176d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java @@ -23,6 +23,7 @@ import javax.annotation.Nullable; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; @@ -219,8 +220,6 @@ public class DetermineBasalAdapterSMBJS { boolean advancedFiltering ) throws JSONException { - String units = profile.getUnits(); - mProfile = new JSONObject(); mProfile.put("max_iob", maxIob); @@ -232,7 +231,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("max_bg", maxBg); mProfile.put("target_bg", targetBg); mProfile.put("carb_ratio", profile.getIc()); - mProfile.put("sens", Profile.toMgdl(profile.getIsf(), units)); + mProfile.put("sens", profile.getIsfMgdl()); mProfile.put("max_daily_safety_multiplier", SP.getInt(R.string.key_openapsama_max_daily_safety_multiplier, 3)); mProfile.put("current_basal_safety_multiplier", SP.getDouble(R.string.key_openapsama_current_basal_safety_multiplier, 4d)); @@ -273,7 +272,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("temptargetSet", tempTargetSet); mProfile.put("autosens_max", SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2"))); - if (units.equals(Constants.MMOL)) { + if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) { mProfile.put("out_units", "mmol/L"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java index c27a3f2059..426c04090b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/OpenAPSSMBPlugin.java @@ -111,6 +111,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr return; } + if (pump == null) { + RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); + if (L.isEnabled(L.APS)) + log.debug(MainApp.gs(R.string.nopumpselected)); + return; + } + if (!isEnabled(PluginType.APS)) { RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); if (L.isEnabled(L.APS)) @@ -125,16 +132,14 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr return; } - String units = profile.getUnits(); - Constraint inputConstraints = new Constraint<>(0d); // fake. only for collecting all results Constraint maxBasalConstraint = MainApp.getConstraintChecker().getMaxBasalAllowed(profile); inputConstraints.copyReasons(maxBasalConstraint); double maxBasal = maxBasalConstraint.value(); - double minBg = Profile.toMgdl(profile.getTargetLow(), units); - double maxBg = Profile.toMgdl(profile.getTargetHigh(), units); - double targetBg = Profile.toMgdl(profile.getTarget(), units); + double minBg = profile.getTargetLowMgdl(); + double maxBg = profile.getTargetHighMgdl(); + double targetBg = profile.getTargetMgdl(); minBg = Round.roundTo(minBg, 0.1d); maxBg = Round.roundTo(maxBg, 0.1d); @@ -168,7 +173,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr return; if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) return; - if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) + if (!checkOnlyHardLimits(profile.getIsfMgdl(), "sens", HardLimits.MINISF, HardLimits.MAXISF)) return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, HardLimits.maxBasal())) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java index 93767bc662..67079394c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ProfileFunctions.java @@ -120,11 +120,6 @@ public class ProfileFunctions { return SP.getString(R.string.key_units, Constants.MGDL); } - public String getProfileUnits() { - Profile profile = getProfile(); - return profile != null ? profile.getUnits() : Constants.MGDL; - } - @Nullable public Profile getProfile(long time) { TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java index 0809ed96d8..ff4781552a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java @@ -25,7 +25,7 @@ public class InputBg extends Element { public InputBg() { super(); - setUnits(ProfileFunctions.getInstance().getProfileUnits()); + setUnits(ProfileFunctions.getSystemUnits()); if (getUnits().equals(Constants.MMOL)) value = MMOL_MIN; else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java index 7e9207c0e1..e0fabcf0dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java @@ -37,7 +37,7 @@ public class InputTempTarget extends Element { public InputTempTarget() { super(); - setUnits(ProfileFunctions.getInstance().getProfileUnits()); + setUnits(ProfileFunctions.getSystemUnits()); if (getUnits().equals(Constants.MMOL)) value = 6; else diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java index a3939a60b7..6c741496e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java @@ -45,7 +45,7 @@ public class TriggerDelta extends Trigger { public TriggerDelta() { super(); - this.units = ProfileFunctions.getInstance().getProfileUnits(); + this.units = ProfileFunctions.getSystemUnits(); initializer(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java index 8818638201..1dc4a95268 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java @@ -71,7 +71,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick Profile profile; public ProfileStore profileStore; - String units = Constants.MGDL; TextView eventTypeText; LinearLayout layoutPercent; @@ -179,7 +178,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } } else { ArrayList profileList; - units = profile != null ? profile.getUnits() : Constants.MGDL; profileList = profileStore.getProfileList(); ArrayAdapter adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_centered, profileList); @@ -190,7 +188,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSpinner.setSelection(p); } } - final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); + final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, ProfileFunctions.getSystemUnits()); // temp target final List reasonList = Lists.newArrayList( @@ -205,8 +203,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { double defaultDuration; - double defaultTarget = 0; - if (profile != null && editTemptarget.getValue() == bg) { + double defaultTarget; + if (profile != null && editTemptarget.getValue().equals(bg)) { defaultTarget = bg; } else { //prevent changes on screen rotate @@ -214,7 +212,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } boolean erase = false; - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); DefaultValueHelper helper = new DefaultValueHelper(); if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) { defaultDuration = helper.determineEatingSoonTTDuration(); @@ -249,7 +247,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick }); // bg - bgUnitsView.setText(units); + bgUnitsView.setText(ProfileFunctions.getSystemUnits()); TextWatcher bgTextWatcher = new TextWatcher() { @@ -268,7 +266,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if (profile == null) { editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), bgTextWatcher); editTemptarget.setParams(Constants.MIN_TT_MGDL, Constants.MIN_TT_MGDL, Constants.MAX_TT_MGDL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok)); - } else if (units.equals(Constants.MMOL)) { + } else if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) { editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok), bgTextWatcher); editTemptarget.setParams(Constants.MIN_TT_MMOL, Constants.MIN_TT_MMOL, Constants.MAX_TT_MMOL, 0.1d, new DecimalFormat("0.0"), false, view.findViewById(R.id.ok)); } else { @@ -277,7 +275,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> { - Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); + Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, ProfileFunctions.getSystemUnits()); if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) { editBg.setValue(savedInstanceState.getDouble("editBg")); } else { @@ -286,16 +284,16 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick }); Integer maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value(); - editCarbs = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbsinput); + editCarbs = view.findViewById(R.id.careportal_newnstreatment_carbsinput); editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value(); - editInsulin = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_insulininput); + editInsulin = view.findViewById(R.id.careportal_newnstreatment_insulininput); editInsulin.setParams(0d, 0d, maxInsulin, 0.05d, new DecimalFormat("0.00"), false, view.findViewById(R.id.ok)); - editSplit = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_splitinput); + editSplit = view.findViewById(R.id.careportal_newnstreatment_splitinput); editSplit.setParams(100d, 0d, 100d, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok)); - editDuration = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_durationinput); + editDuration = view.findViewById(R.id.careportal_newnstreatment_durationinput); editDuration.setParams(0d, 0d, Constants.MAX_PROFILE_SWITCH_DURATION, 10d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); TextWatcher percentTextWatcher = new TextWatcher() { @@ -319,7 +317,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick Integer maxPercent = 200; if (profile != null) maxPercent = MainApp.getConstraintChecker().getMaxBasalPercentAllowed(profile).value(); - editPercent = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentinput); + editPercent = view.findViewById(R.id.careportal_newnstreatment_percentinput); editPercent.setParams(0d, -100d, (double) maxPercent, 5d, new DecimalFormat("0"), true, view.findViewById(R.id.ok), percentTextWatcher); TextWatcher absoluteTextWatcher = new TextWatcher() { @@ -343,16 +341,16 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick Double maxAbsolute = HardLimits.maxBasal(); if (profile != null) maxAbsolute = MainApp.getConstraintChecker().getMaxBasalAllowed(profile).value(); - editAbsolute = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_absoluteinput); + editAbsolute = view.findViewById(R.id.careportal_newnstreatment_absoluteinput); editAbsolute.setParams(0d, 0d, maxAbsolute, 0.05d, new DecimalFormat("0.00"), true, view.findViewById(R.id.ok), absoluteTextWatcher); - editCarbTime = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_carbtimeinput); + editCarbTime = view.findViewById(R.id.careportal_newnstreatment_carbtimeinput); editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); - editPercentage = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_percentage); + editPercentage = view.findViewById(R.id.careportal_newnstreatment_percentage); editPercentage.setParams(100d, (double) Constants.CPP_MIN_PERCENTAGE, (double) Constants.CPP_MAX_PERCENTAGE, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); - editTimeshift = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_timeshift); + editTimeshift = view.findViewById(R.id.careportal_newnstreatment_timeshift); editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok)); ProfileSwitch ps = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now()); @@ -369,21 +367,21 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick options.duration = false; } - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_eventtime_layout), options.date); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bg_layout), options.bg); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_bgsource_layout), options.bg); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_insulin_layout), options.insulin); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbs_layout), options.carbs); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_split_layout), options.split); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_duration_layout), options.duration); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_eventtime_layout), options.date); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_bg_layout), options.bg); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_bgsource_layout), options.bg); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_insulin_layout), options.insulin); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_carbs_layout), options.carbs); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_split_layout), options.split); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_duration_layout), options.duration); showOrHide(layoutPercent, options.percent); showOrHide(layoutAbsolute, options.absolute); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_carbtime_layout), options.prebolus); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP); - showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_carbtime_layout), options.prebolus); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_profile_layout), options.profile); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_percentage_layout), options.profile); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_timeshift_layout), options.profile); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP); + showOrHide(view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget); setCancelable(true); getDialog().setCanceledOnTouchOutside(false); @@ -457,7 +455,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick if ((data.size() > 0) && (data.get(0).date > millis - 7 * 60 * 1000L) && (data.get(0).date < millis + 7 * 60 * 1000L)) { - editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, units)); + editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, ProfileFunctions.getSystemUnits())); } } @@ -585,7 +583,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick data.put("preBolus", SafeParse.stringToDouble(editCarbTime.getText())); if (!notesEdit.getText().toString().equals("")) data.put("notes", notesEdit.getText().toString()); - data.put("units", units); + data.put("units", ProfileFunctions.getSystemUnits()); if (!enteredBy.equals("")) data.put("enteredBy", enteredBy); if (options.eventType == R.id.careportal_combobolus) { Double enteredInsulin = SafeParse.stringToDouble(editInsulin.getText()); @@ -611,7 +609,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick ret += MainApp.gs(R.string.treatments_wizard_bg_label); ret += ": "; ret += JsonHelper.safeGetObject(data, "glucose", ""); - ret += " " + units + "\n"; + ret += " " + ProfileFunctions.getSystemUnits() + "\n"; } if (data.has("glucoseType")) { ret += MainApp.gs(R.string.careportal_newnstreatment_glucosetype); @@ -734,8 +732,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick .reason(reason) .source(Source.USER); if (tempTarget.durationInMinutes != 0) { - tempTarget.low(Profile.toMgdl(targetBottom, units)) - .high(Profile.toMgdl(targetTop, units)); + tempTarget.low(Profile.toMgdl(targetBottom, ProfileFunctions.getSystemUnits())) + .high(Profile.toMgdl(targetTop, ProfileFunctions.getSystemUnits())); } else { tempTarget.low(0).high(0); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 881593b32a..170abed432 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -312,21 +312,14 @@ public class NSUpload { public static void uploadTempTarget(TempTarget tempTarget) { try { - Profile profile = ProfileFunctions.getInstance().getProfile(); - - if (profile == null) { - log.error("Profile is null. Skipping upload"); - return; - } - JSONObject data = new JSONObject(); data.put("eventType", CareportalEvent.TEMPORARYTARGET); data.put("duration", tempTarget.durationInMinutes); data.put("reason", tempTarget.reason); - data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits())); - data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, profile.getUnits())); + data.put("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits())); + data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits())); data.put("created_at", DateUtil.toISOString(tempTarget.date)); - data.put("units", profile.getUnits()); + data.put("units", ProfileFunctions.getSystemUnits()); data.put("enteredBy", MainApp.gs(R.string.app_name)); uploadCareportalEntryToNS(data); } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 5c2a7cac84..0ff8e0cfc8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -760,36 +760,36 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, pvd.show(manager, "ProfileViewDialog"); } else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) { DefaultValueHelper defHelper = new DefaultValueHelper(); - double target = defHelper.determineEatingSoonTT(profile.getUnits()); + double target = defHelper.determineEatingSoonTT(Constants.MGDL); TempTarget tempTarget = new TempTarget() .date(System.currentTimeMillis()) .duration(defHelper.determineEatingSoonTTDuration()) .reason(MainApp.gs(R.string.eatingsoon)) .source(Source.USER) - .low(Profile.toMgdl(target, profile.getUnits())) - .high(Profile.toMgdl(target, profile.getUnits())); + .low(target) + .high(target); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (item.getTitle().equals(MainApp.gs(R.string.activity))) { DefaultValueHelper defHelper = new DefaultValueHelper(); - double target = defHelper.determineActivityTT(profile.getUnits()); + double target = defHelper.determineActivityTT(Constants.MGDL); TempTarget tempTarget = new TempTarget() .date(now()) .duration(defHelper.determineActivityTTDuration()) .reason(MainApp.gs(R.string.activity)) .source(Source.USER) - .low(Profile.toMgdl(target, profile.getUnits())) - .high(Profile.toMgdl(target, profile.getUnits())); + .low(target) + .high(target); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) { DefaultValueHelper defHelper = new DefaultValueHelper(); - double target = defHelper.determineHypoTT(profile.getUnits()); + double target = defHelper.determineHypoTT(Constants.MGDL); TempTarget tempTarget = new TempTarget() .date(now()) .duration(defHelper.determineHypoTTDuration()) .reason(MainApp.gs(R.string.hypo)) .source(Source.USER) - .low(Profile.toMgdl(target, profile.getUnits())) - .high(Profile.toMgdl(target, profile.getUnits())); + .low(target) + .high(target); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (item.getTitle().equals(MainApp.gs(R.string.custom))) { NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); @@ -814,7 +814,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onClick(View v) { boolean xdrip = SourceXdripPlugin.getPlugin().isEnabled(PluginType.BGSOURCE); boolean dexcom = SourceDexcomPlugin.INSTANCE.isEnabled(PluginType.BGSOURCE); - String units = ProfileFunctions.getInstance().getProfileUnits(); FragmentManager manager = getFragmentManager(); // try to fix https://fabric.io/nightscout3/android/apps/info.nightscout.androidaps/issues/5aca7a1536c7b23527eb4be7?time=last-seven-days @@ -1041,7 +1040,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Profile profile = ProfileFunctions.getInstance().getProfile(); final String profileName = ProfileFunctions.getInstance().getProfileName(); - final String units = profile.getUnits(); + final String units = ProfileFunctions.getSystemUnits(); final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); @@ -1126,7 +1125,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else { tempTargetView.setTextColor(MainApp.gc(R.color.ribbonTextDefault)); tempTargetView.setBackgroundColor(MainApp.gc(R.color.ribbonDefault)); - tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLow(), profile.getTargetHigh(), units, units)); + tempTargetView.setText(Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), Constants.MGDL, units)); tempTargetView.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt index cece359f22..bcba0e335e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt @@ -65,19 +65,16 @@ object OverviewPlugin : PluginBase(PluginDescription() super.onStop() } - fun determineHighLine(units: String): Double { + @JvmOverloads + fun determineHighLine(units: String = ProfileFunctions.getSystemUnits()): Double { var highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(bgTargetHigh, units))!! if (highLineSetting < 1) highLineSetting = Profile.fromMgdlToUnits(180.0, units) return highLineSetting } - fun determineLowLine(): Double { - val profile = ProfileFunctions.getInstance().profile ?: return bgTargetLow - return determineLowLine(profile.units) - } - - fun determineLowLine(units: String): Double { + @JvmOverloads + fun determineLowLine(units: String = ProfileFunctions.getSystemUnits()): Double { var lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(bgTargetLow, units))!! if (lowLineSetting < 1) lowLineSetting = Profile.fromMgdlToUnits(76.0, units) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java index a82f94d2ff..4c5d5b5d80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CalibrationDialog.java @@ -60,7 +60,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis view.findViewById(R.id.ok).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this); - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units); bgNumber = (NumberPicker) view.findViewById(R.id.overview_calibration_bg); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java index 23352f3d5b..b6e9d25888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs; import android.os.Bundle; -import android.os.HandlerThread; import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; import android.text.Editable; @@ -316,7 +315,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C int carbs = editCarbs.getValue().intValue(); Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value(); - final String units = currentProfile.getUnits(); + final String units = ProfileFunctions.getSystemUnits(); DefaultValueHelper helper = new DefaultValueHelper(); int activityTTDuration = helper.determineActivityTTDuration(); @@ -332,20 +331,20 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C if (startActivityTTCheckbox.isChecked()) { String unitLabel = "mg/dl"; - if (currentProfile.getUnits().equals(Constants.MMOL)) { + if (units.equals(Constants.MMOL)) { unitLabel = "mmol/l"; } actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)"); } if (startEatingSoonTTCheckbox.isChecked()) { - if (currentProfile.getUnits().equals(Constants.MMOL)) { + if (units.equals(Constants.MMOL)) { actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)"); } else { actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)"); } } if (startHypoTTCheckbox.isChecked()) { - if (currentProfile.getUnits().equals(Constants.MMOL)) { + if (units.equals(Constants.MMOL)) { actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(hypoTT) + " mmol/l (" + hypoTTDuration + " min)"); } else { actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(hypoTT) + " mg/dl (" + hypoTTDuration + " min)"); @@ -398,8 +397,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C .duration(finalActivityTTDuration) .reason(MainApp.gs(R.string.activity)) .source(Source.USER) - .low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())); + .low(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits())) + .high(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits())); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (startEatingSoonTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget() @@ -407,8 +406,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C .duration(finalEatingSoonTTDuration) .reason(MainApp.gs(R.string.eatingsoon)) .source(Source.USER) - .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); + .low(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits())) + .high(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits())); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else if (startHypoTTCheckbox.isChecked()) { TempTarget tempTarget = new TempTarget() @@ -416,8 +415,8 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C .duration(finalHypoTTDuration) .reason(MainApp.gs(R.string.hypo)) .source(Source.USER) - .low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())); + .low(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits())) + .high(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits())); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java index d5d4308f63..b708296776 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewInsulinDialog.java @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.general.overview.dialogs; import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.os.HandlerThread; import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; import android.text.Editable; @@ -56,9 +55,9 @@ import static info.nightscout.androidaps.utils.DateUtil.now; public class NewInsulinDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class); - public static final double PLUS1_DEFAULT = 0.5d; - public static final double PLUS2_DEFAULT = 1d; - public static final double PLUS3_DEFAULT = 2d; + private static final double PLUS1_DEFAULT = 0.5d; + private static final double PLUS2_DEFAULT = 1d; + private static final double PLUS3_DEFAULT = 2d; private CheckBox startEatingSoonTTCheckbox; private CheckBox recordOnlyCheckbox; @@ -207,9 +206,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener okClicked = true; try { - Profile currentProfile = ProfileFunctions.getInstance().getProfile(); final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - if (currentProfile == null || pump == null) + if (pump == null) return; Double insulin = SafeParse.stringToDouble(editInsulin.getText()); @@ -228,11 +226,11 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration); eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration; - double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl); - eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl; + double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, ProfileFunctions.getSystemUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl); + eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : ProfileFunctions.getSystemUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl; if (startEatingSoonTTCheckbox.isChecked()) { - if (currentProfile.getUnits().equals(Constants.MMOL)) { + if (ProfileFunctions.getSystemUnits().equals(Constants.MMOL)) { actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)"); } else actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)"); @@ -272,8 +270,8 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener .duration(finalEatingSoonTTDuration) .reason(MainApp.gs(R.string.eatingsoon)) .source(Source.USER) - .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); + .low(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits())) + .high(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits())); TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt index efe800bef0..d0db643787 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/WizardDialog.kt @@ -222,7 +222,7 @@ class WizardDialog : DialogFragment() { } ?: return - val units = profile.units + val units = ProfileFunctions.getSystemUnits() treatments_wizard_bgunits.text = units if (units == Constants.MGDL) treatments_wizard_bg_input.setStep(1.0) @@ -302,7 +302,7 @@ class WizardDialog : DialogFragment() { treatment_wizard_notes.text.toString(), carbTime) wizard?.let { wizard -> - treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, specificProfile.units)).valueToUnitsToString(specificProfile.units), wizard.sens) + treatments_wizard_bg.text = String.format(MainApp.gs(R.string.format_bg_isf), BgReading().value(Profile.toMgdl(bg, ProfileFunctions.getSystemUnits())).valueToUnitsToString(ProfileFunctions.getSystemUnits()), wizard.sens) treatments_wizard_bginsulin.text = StringUtils.formatInsulin(wizard.insulinFromBG) treatments_wizard_carbs.text = String.format(MainApp.gs(R.string.format_carbs_ic), carbs.toDouble(), wizard.ic) @@ -320,8 +320,8 @@ class WizardDialog : DialogFragment() { // Trend if (treatments_wizard_bgtrendcheckbox.isChecked && wizard.glucoseStatus != null) { treatments_wizard_bgtrend.text = ((if (wizard.trend > 0) "+" else "") - + Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, specificProfile.units) - + " " + specificProfile.units) + + Profile.toUnitsString(wizard.trend * 3, wizard.trend * 3 / Constants.MMOLL_TO_MGDL, ProfileFunctions.getSystemUnits()) + + " " + ProfileFunctions.getSystemUnits()) } else { treatments_wizard_bgtrend.text = "" } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java index 6de3e2c335..a3dc3c4212 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/graphData/GraphData.java @@ -69,7 +69,7 @@ public class GraphData { private IobCobCalculatorPlugin iobCobCalculatorPlugin; public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) { - units = ProfileFunctions.getInstance().getProfileUnits(); + units = ProfileFunctions.getSystemUnits(); this.graph = graph; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; } @@ -264,9 +264,9 @@ public class GraphData { TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time); double value; if (tt == null) { - value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2; + value = Profile.fromMgdlToUnits((profile.getTargetLowMgdl(time) + profile.getTargetHighMgdl(time)) / 2, ProfileFunctions.getSystemUnits()); } else { - value = Profile.fromMgdlToUnits(tt.target(), profile.getUnits()); + value = Profile.fromMgdlToUnits(tt.target(), ProfileFunctions.getSystemUnits()); } if (lastTarget != value) { if (lastTarget != -1) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java index fdee040682..1cc2b1426a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/persistentNotification/PersistentNotificationPlugin.java @@ -181,7 +181,7 @@ public class PersistentNotificationPlugin extends PluginBase { line1 = MainApp.gs(R.string.loading); } else if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ProfileFunctions.getInstance().isProfileValid("Notification")) { String line1_aa; - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); BgReading lastBG = DatabaseHelper.lastBg(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java index 264d7c3e52..86feba8fd2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.java @@ -275,7 +275,7 @@ public class SmsCommunicatorPlugin extends PluginBase { String reply = ""; - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); if (actualBG != null) { reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/elements/ProfileElement.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/elements/ProfileElement.kt index 93009ea7e1..82ae37cebc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/elements/ProfileElement.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/tidepool/elements/ProfileElement.kt @@ -41,12 +41,12 @@ class ProfileElement private constructor(ps: ProfileSwitch) checkNotNull(profile) for (br in profile.basalValues) basalSchedules.Normal.add(BasalRate(br.timeAsSeconds * 1000, br.value)) - for (target in profile.singleTargets) - bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, Profile.toMgdl(target.value, profile.units))) + for (target in profile.singleTargetsMgdl) + bgTargets.Normal.add(Target(target.timeAsSeconds * 1000, target.value)) for (ic in profile.ics) carbRatios.Normal.add(Ratio(ic.timeAsSeconds * 1000, ic.value)) - for (isf in profile.isfs) - insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, Profile.toMgdl(isf.value, profile.units))) + for (isf in profile.isfsMgdl) + insulinSensitivities.Normal.add(Ratio(isf.timeAsSeconds * 1000, isf.value)) } inner class BasalProfile internal constructor( diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java index 1cf4dd7539..cae9817a55 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java @@ -131,12 +131,7 @@ public class ActionStringHandler { ///////////////////////////////////////////////////////// TEMPTARGET boolean isMGDL = Boolean.parseBoolean(act[1]); - Profile profile = ProfileFunctions.getInstance().getProfile(); - if (profile == null) { - sendError("No profile found!"); - return; - } - if (profile.getUnits().equals(Constants.MGDL) != isMGDL) { + if (ProfileFunctions.getSystemUnits().equals(Constants.MGDL) != isMGDL) { sendError("Different units used on watch and phone!"); return; } @@ -222,7 +217,7 @@ public class ActionStringHandler { DecimalFormat format = new DecimalFormat("0.00"); DecimalFormat formatInt = new DecimalFormat("0"); BolusWizard bolusWizard = new BolusWizard(profile, profileName, TreatmentsPlugin.getPlugin().getTempTargetFromHistory(), - carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(profile.getUnits()), + carbsAfterConstraints, cobInfo.displayCob, bgReading.valueToUnits(ProfileFunctions.getSystemUnits()), 0d, percentage, useBG, useCOB, useBolusIOB, useBasalIOB, false, useTT, useTrend); if (Math.abs(bolusWizard.getInsulinAfterConstraints() - bolusWizard.getCalculatedTotalInsulin()) >= 0.01) { @@ -534,14 +529,14 @@ public class ActionStringHandler { //Check for Temp-Target: TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); if (tempTarget != null) { - ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits()); + ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, ProfileFunctions.getSystemUnits()); ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd()); ret += "\n\n"; } ret += "DEFAULT RANGE: "; - ret += profile.getTargetLow() + " - " + profile.getTargetHigh(); - ret += " target: " + profile.getTarget(); + ret += Profile.fromMgdlToUnits(profile.getTargetLowMgdl(), ProfileFunctions.getSystemUnits()) + " - " + Profile.fromMgdlToUnits(profile.getTargetHighMgdl(), ProfileFunctions.getSystemUnits()); + ret += " target: " + Profile.fromMgdlToUnits(profile.getTargetMgdl(), ProfileFunctions.getSystemUnits()); return ret; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index 7eebdc8d8e..4f241cec6b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -303,7 +303,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) { - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); @@ -323,7 +323,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog highLine = OverviewPlugin.INSTANCE.getBgTargetHigh(); } - long sgvLevel = 0l; + long sgvLevel = 0L; if (lastBG.value > highLine) { sgvLevel = 1; } else if (lastBG.value < lowLine) { @@ -721,7 +721,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog //bgi - double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); + double bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.fromMgdlToUnits(profile.getIsfMgdl(), ProfileFunctions.getSystemUnits()); bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi); status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java index da61b83b98..b810624e87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/xdripStatusline/StatuslinePlugin.java @@ -206,7 +206,7 @@ public class StatuslinePlugin extends PluginBase { return status; } - double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); + double bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.fromMgdlToUnits(profile.getIsfMgdl(), ProfileFunctions.getSystemUnits()); status += " " + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to2Decimal(bgi); status += " " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "StatuslinePlugin").generateCOBString(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java index 4b47602f33..0c93e0266f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensData.java @@ -48,7 +48,7 @@ public class AutosensData implements DataPointWithLabelInterface { if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) { double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME); Profile profile = ProfileFunctions.getInstance().getProfile(t.date); - double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); + double sens = profile.getIsfMgdl(t.date); double ic = profile.getIc(t.date); min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; if (L.isEnabled(L.AUTOSENS)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 07d1b52947..57a1bba9ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -149,7 +149,7 @@ public class IobCobOref1Thread extends Thread { if (L.isEnabled(L.AUTOSENS)) log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")"); - double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits()); + double sens = profile.getIsfMgdl(bgTime); AutosensData autosensData = new AutosensData(); autosensData.time = bgTime; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index a8ecc2a06a..fba1555d4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -148,7 +148,7 @@ public class IobCobThread extends Thread { if (L.isEnabled(L.AUTOSENS)) log.debug("Processing calculation thread: " + from + " (" + i + "/" + bucketed_data.size() + ")"); - double sens = Profile.toMgdl(profile.getIsf(bgTime), profile.getUnits()); + double sens = profile.getIsfMgdl(bgTime); AutosensData autosensData = new AutosensData(); autosensData.time = bgTime; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index ddc33ca4fb..1b49e92863 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -17,7 +17,6 @@ import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.events.EventInitializationChanged import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog import info.nightscout.androidaps.plugins.insulin.InsulinOrefBasePlugin.MIN_DIA diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 859154ca6a..662752211e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -345,10 +345,6 @@ object LocalProfilePlugin : PluginBase(PluginDescription() return rawProfile } - override fun getUnits(): String { - return if (currentProfile().mgdl) Constants.MGDL else Constants.MMOL - } - override fun getProfileName(): String { return DecimalFormatter.to2Decimal(rawProfile?.defaultProfile?.percentageBasalSum() ?: 0.0) + "U " diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java index 38afe62bdf..41711b47bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/ns/NSProfilePlugin.java @@ -118,11 +118,6 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface { return profile; } - @Override - public String getUnits() { - return profile != null ? profile.getUnits() : Constants.MGDL; - } - @Override public String getProfileName() { return profile.getDefaultProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 1a40e449e5..d8b2873a50 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -444,11 +444,6 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte return DanaRPump.getInstance().createConvertedProfile(); } - @Override - public String getUnits() { - return DanaRPump.getInstance().getUnits(); - } - @Override public String getProfileName() { return DanaRPump.getInstance().createConvertedProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java index f20a74b024..ae25d781af 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRHistoryActivity.java @@ -41,7 +41,6 @@ import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.FabricPrivacy; -import info.nightscout.androidaps.utils.ToastUtils; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -49,8 +48,6 @@ public class DanaRHistoryActivity extends NoSplashActivity { private static Logger log = LoggerFactory.getLogger(L.PUMP); private CompositeDisposable disposable = new CompositeDisposable(); - static Profile profile = null; - Spinner historyTypeSpinner; TextView statusView; Button reloadButton; @@ -182,11 +179,6 @@ public class DanaRHistoryActivity extends NoSplashActivity { clearCardView(); } }); - profile = ProfileFunctions.getInstance().getProfile(); - if (profile == null) { - ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.noprofile)); - finish(); - } } public static class RecyclerViewAdapter extends RecyclerView.Adapter { @@ -252,7 +244,7 @@ public class DanaRHistoryActivity extends NoSplashActivity { holder.alarm.setVisibility(View.GONE); break; case RecordTypes.RECORD_TYPE_GLUCOSE: - holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profile.getUnits())); + holder.value.setText(Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, ProfileFunctions.getSystemUnits())); // rest is the same case RecordTypes.RECORD_TYPE_CARBO: case RecordTypes.RECORD_TYPE_BASALHOUR: diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java index dcb182a0d6..bf6f80af0b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/activities/DanaRNSHistorySync.java @@ -184,7 +184,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, ProfileFunctions.getInstance().getProfileUnits())); + nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, ProfileFunctions.getSystemUnits())); nsrec.put("glucoseType", "Finger"); nsrec.put("created_at", DateUtil.toISOString(record.recordDate)); nsrec.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 7b2668d45c..9b430496f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -275,11 +275,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte return DanaRPump.getInstance().createConvertedProfile(); } - @Override - public String getUnits() { - return DanaRPump.getInstance().getUnits(); - } - @Override public String getProfileName() { return DanaRPump.getInstance().createConvertedProfileName(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java index dfc4bed25d..8cfa903fb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityAAPSPlugin.java @@ -137,7 +137,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { Double[] deviations = new Double[deviationsArray.size()]; deviations = deviationsArray.toArray(deviations); - double sens = profile.getIsf(); + double sens = profile.getIsfMgdl(); String ratioLimit = ""; String sensResult = ""; @@ -148,7 +148,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { Arrays.sort(deviations); double percentile = IobCobCalculatorPlugin.percentile(deviations, 0.50); - double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + double basalOff = percentile * (60 / 5) / sens; double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); if (percentile < 0) { // sensitive diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java index cfcaf0eb22..6298724514 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java @@ -131,7 +131,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin { Double[] deviations = new Double[deviationsArray.size()]; deviations = deviationsArray.toArray(deviations); - double sens = profile.getIsf(); + double sens = profile.getIsfMgdl(); double ratio = 1; String ratioLimit = ""; @@ -154,10 +154,10 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin { double basalOff = 0; if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + basalOff = pSensitive * (60 / 5.0) / sens; sensResult = "Excess insulin sensitivity detected"; } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + basalOff = pResistant * (60 / 5.0) / sens; sensResult = "Excess insulin resistance detected"; } else { sensResult = "Sensitivity normal"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java index 5e0f5d3d85..131cafe89c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java @@ -146,7 +146,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { Double[] deviations = new Double[deviationsArray.size()]; deviations = deviationsArray.toArray(deviations); - double sens = profile.getIsf(); + double sens = profile.getIsfMgdl(); double ratio = 1; String ratioLimit = ""; @@ -174,10 +174,10 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { double basalOff = 0; if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + basalOff = pSensitive * (60 / 5.0) / sens; sensResult = "Excess insulin sensitivity detected"; } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + basalOff = pResistant * (60 / 5.0) / sens; sensResult = "Excess insulin resistance detected"; } else { sensResult = "Sensitivity normal"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java index 91b69162bb..5d0aac4d4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityWeightedAveragePlugin.java @@ -164,7 +164,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin return new AutosensResult(); } - double sens = profile.getIsf(); + double sens = profile.getIsfMgdl(); String ratioLimit = ""; String sensResult; @@ -173,7 +173,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin log.debug("Records: " + index + " " + pastSensitivity); double average = weightedsum / weights; - double basalOff = average * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + double basalOff = average * (60 / 5.0) / sens; double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); if (average < 0) { // sensitive diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java index 6023d70d12..1d72ed2e72 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.java @@ -16,12 +16,11 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.plugins.bus.RxBus; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.utils.DateUtil; @@ -38,8 +37,6 @@ public class BGSourceFragment extends Fragment { private CompositeDisposable disposable = new CompositeDisposable(); RecyclerView recyclerView; - String units = Constants.MGDL; - final long MILLS_TO_THE_PAST = T.hours(12).msecs(); @Override @@ -57,9 +54,6 @@ public class BGSourceFragment extends Fragment { RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)); recyclerView.setAdapter(adapter); - if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile().getDefaultProfile() != null) - units = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile().getDefaultProfile().getUnits(); - return view; } catch (Exception e) { FabricPrivacy.logException(e); @@ -109,7 +103,7 @@ public class BGSourceFragment extends Fragment { holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE); holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE); holder.date.setText(DateUtil.dateAndTimeString(bgReading.date)); - holder.value.setText(bgReading.valueToUnitsToString(units)); + holder.value.setText(bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits())); holder.direction.setText(bgReading.directionToSymbol()); holder.remove.setTag(bgReading); } @@ -147,7 +141,7 @@ public class BGSourceFragment extends Fragment { case R.id.bgsource_remove: AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(MainApp.gs(R.string.confirmation)); - builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(units)); + builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(ProfileFunctions.getSystemUnits())); builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { /* final String _id = bgReading._id; 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 ccd1b327c9..3ee36b87dd 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 @@ -69,7 +69,7 @@ public class TreatmentsTempTargetFragment extends Fragment implements View.OnCli @Override public void onBindViewHolder(TempTargetsViewHolder holder, int position) { - String units = ProfileFunctions.getInstance().getProfileUnits(); + String units = ProfileFunctions.getSystemUnits(); TempTarget tempTarget = tempTargetList.getReversed(position); holder.ph.setVisibility(tempTarget.source == Source.PUMP ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(tempTarget._id) ? View.VISIBLE : View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt index ef4cae3f83..89e0751e60 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/BolusWizard.kt @@ -117,12 +117,12 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, private fun doCalc() { // Insulin from BG - sens = profile.isf - targetBGLow = profile.targetLow - targetBGHigh = profile.targetHigh + sens = Profile.fromMgdlToUnits(profile.isfMgdl, ProfileFunctions.getSystemUnits()) + targetBGLow = Profile.fromMgdlToUnits(profile.targetLowMgdl, ProfileFunctions.getSystemUnits()) + targetBGHigh = Profile.fromMgdlToUnits(profile.targetHighMgdl, ProfileFunctions.getSystemUnits()) if (useTT && tempTarget != null) { - targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, profile.units) - targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, profile.units) + targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, ProfileFunctions.getSystemUnits()) + targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, ProfileFunctions.getSystemUnits()) } if (useBg && bg > 0) { bgDiff = when { @@ -138,7 +138,7 @@ class BolusWizard @JvmOverloads constructor(val profile: Profile, glucoseStatus?.let { if (useTrend) { trend = it.short_avgdelta - insulinFromTrend = Profile.fromMgdlToUnits(trend, profile.units) * 3 / sens + insulinFromTrend = Profile.fromMgdlToUnits(trend, ProfileFunctions.getSystemUnits()) * 3 / sens } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java index f7b8761823..404a082112 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.java @@ -46,7 +46,7 @@ public class XdripCalibrations { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putDouble("glucose_number", bg); - bundle.putString("units", ProfileFunctions.getInstance().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); + bundle.putString("units", ProfileFunctions.getSystemUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); bundle.putLong("timestamp", System.currentTimeMillis()); Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION); intent.putExtras(bundle); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5513d964f8..c7fd43356f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1619,5 +1619,6 @@ %1$dg On Off + No pump selected