From 4ec0ebfa74f6e4ce3bb9f742070822dbe792a0a2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 30 Jul 2018 14:21:11 +0200 Subject: [PATCH] move profile function from ConfigBuilder to extra class --- .../nightscout/androidaps/MainActivity.java | 3 +- .../info/nightscout/androidaps/MainApp.java | 1 - .../activities/HistoryBrowseActivity.java | 3 +- .../activities/TDDStatsActivity.java | 3 +- .../nightscout/androidaps/db/BgReading.java | 5 +- .../androidaps/db/CareportalEvent.java | 3 +- .../androidaps/db/DatabaseHelper.java | 3 +- .../androidaps/db/TemporaryBasal.java | 15 +- .../plugins/Actions/ActionsFragment.java | 3 +- .../Actions/dialogs/NewTempBasalDialog.java | 5 +- .../Dialogs/NewNSTreatmentDialog.java | 11 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 92 +----------- .../ConfigBuilder/ProfileFunctions.java | 142 ++++++++++++++++++ .../Insulin/InsulinOrefBasePlugin.java | 3 +- .../IobCobCalculator/AutosensData.java | 3 +- .../IobCobCalculatorPlugin.java | 5 +- .../IobCobCalculator/IobCobOref1Thread.java | 5 +- .../IobCobCalculator/IobCobThread.java | 5 +- .../androidaps/plugins/Loop/LoopPlugin.java | 5 +- .../plugins/NSClientInternal/NSUpload.java | 9 +- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 3 +- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 3 +- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 3 +- .../Overview/Dialogs/CalibrationDialog.java | 3 +- .../Overview/Dialogs/NewCarbsDialog.java | 3 +- .../Overview/Dialogs/NewInsulinDialog.java | 3 +- .../Overview/Dialogs/WizardDialog.java | 7 +- .../plugins/Overview/OverviewFragment.java | 17 ++- .../plugins/Overview/OverviewPlugin.java | 3 +- .../plugins/Overview/graphData/GraphData.java | 7 +- .../PersistentNotificationPlugin.java | 7 +- .../plugins/ProfileNS/NSProfileFragment.java | 3 +- .../plugins/PumpCombo/ComboPlugin.java | 3 +- .../activities/DanaRHistoryActivity.java | 3 +- .../activities/DanaRNSHistorySync.java | 3 +- .../services/DanaRExecutionService.java | 3 +- .../services/DanaRKoreanExecutionService.java | 3 +- .../plugins/PumpDanaRS/DanaRSPlugin.java | 3 +- .../PumpDanaRS/services/DanaRSService.java | 3 +- .../services/DanaRv2ExecutionService.java | 3 +- .../plugins/PumpInsight/InsightPlugin.java | 3 +- .../PumpVirtual/VirtualPumpPlugin.java | 3 +- .../Sensitivity/SensitivityAAPSPlugin.java | 3 +- .../Sensitivity/SensitivityOref0Plugin.java | 3 +- .../Sensitivity/SensitivityOref1Plugin.java | 3 +- .../SensitivityWeightedAveragePlugin.java | 3 +- .../SmsCommunicatorPlugin.java | 7 +- .../plugins/Treatments/TreatmentsPlugin.java | 19 +-- .../fragments/TreatmentsBolusFragment.java | 3 +- .../TreatmentsProfileSwitchFragment.java | 3 +- .../TreatmentsTempTargetFragment.java | 3 +- .../TreatmentsTemporaryBasalsFragment.java | 5 +- .../plugins/Wear/ActionStringHandler.java | 13 +- .../wearintegration/WatchUpdaterService.java | 17 ++- .../XDripStatusline/StatuslinePlugin.java | 3 +- .../androidaps/queue/CommandQueue.java | 3 +- .../receivers/KeepAliveReceiver.java | 3 +- .../androidaps/setupwizard/SWDefinition.java | 5 +- .../nightscout/utils/LocalAlertUtils.java | 3 +- .../nightscout/utils/XdripCalibrations.java | 3 +- 60 files changed, 313 insertions(+), 205 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index edb1bd7854..280c91bba5 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -49,6 +49,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Food.FoodPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; @@ -291,7 +292,7 @@ public class MainActivity extends AppCompatActivity { private void checkUpgradeToProfileTarget() { // TODO: can be removed in the future boolean oldKeyExists = SP.contains("openapsma_min_bg"); if (oldKeyExists) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); String oldRange = SP.getDouble("openapsma_min_bg", 0d) + " - " + SP.getDouble("openapsma_max_bg", 0d); String newRange = ""; if (profile != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 791f4f07df..e1cc242e7d 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -107,7 +107,6 @@ public class MainApp extends Application { @Override public void onCreate() { super.onCreate(); - if (L.isEnabled(L.CORE)) log.debug("onCreate"); sInstance = this; sResources = getResources(); 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 8d4b691116..0e4535a778 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.events.EventCustomCalculationFinished; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; @@ -229,7 +230,7 @@ public class HistoryBrowseActivity extends AppCompatActivity { return; final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { noProfile.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java index 34e5fa42ae..e18e2552eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/TDDStatsActivity.java @@ -40,6 +40,7 @@ import info.nightscout.androidaps.db.TDD; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; @@ -121,7 +122,7 @@ public class TDDStatsActivity extends Activity { TBB = SP.getString("TBB", "10.00"); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) { double cppTBB = profile.baseBasalSum(); TBB = decimalFormat.format(cppTBB); 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 5fb4093c21..aef7cefc94 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; @@ -168,7 +169,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public double getY() { - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); return valueToUnits(units); } @@ -202,7 +203,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public int getColor() { - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); Double lowLine = SP.getDouble("low_mark", 0d); Double highLine = SP.getDouble("high_mark", 0d); if (lowLine < 1) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index 6cda2ab4ce..2645d260e7 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSMbg; import info.nightscout.androidaps.plugins.Overview.OverviewFragment; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; @@ -153,7 +154,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval { @Override public double getY() { - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); if (eventType.equals(MBG)) { double mbg = 0d; try { diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 099c725036..5ef716bad9 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -42,6 +42,7 @@ import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; @@ -691,7 +692,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public void createTemptargetFromJsonIfNotExists(JSONObject trJson) { try { - String units = JsonHelper.safeGetString(trJson, "units", MainApp.getConfigBuilder().getProfileUnits()); + String units = JsonHelper.safeGetString(trJson, "units", ProfileFunctions.getInstance().getProfileUnits()); TempTarget tempTarget = new TempTarget() .date(trJson.getLong("mills")) .duration(trJson.getInt("duration")) 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 733027b188..71f734672b 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -93,7 +94,7 @@ public class TemporaryBasal implements Interval { } public TemporaryBasal(ExtendedBolus extendedBolus) { - double basal = MainApp.getConfigBuilder().getProfile(extendedBolus.date).getBasal(extendedBolus.date); + double basal = ProfileFunctions.getInstance().getProfile(extendedBolus.date).getBasal(extendedBolus.date); this.date = extendedBolus.date; this.isValid = extendedBolus.isValid; this.source = extendedBolus.source; @@ -318,7 +319,7 @@ public class TemporaryBasal implements Interval { public String toStringFull() { if(isFakeExtended){ - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Double currentBasalRate = profile.getBasal(); double rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); return getCalcuatedPercentageIfNeeded() + DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" + @@ -340,7 +341,7 @@ public class TemporaryBasal implements Interval { double rate = 0d; if (isFakeExtended) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Double currentBasalRate = profile.getBasal(); rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); } else if (isAbsolute){ @@ -348,7 +349,7 @@ public class TemporaryBasal implements Interval { } if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){ - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if(profile != null) { double basal = profile.getBasal(); if(basal != 0){ @@ -367,7 +368,7 @@ public class TemporaryBasal implements Interval { double rate = 0d; if (isFakeExtended) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Double currentBasalRate = profile.getBasal(); rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); } else if (isAbsolute){ @@ -375,7 +376,7 @@ public class TemporaryBasal implements Interval { } if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){ - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if(profile != null) { double basal = profile.getBasal(); if(basal != 0){ @@ -392,7 +393,7 @@ public class TemporaryBasal implements Interval { double rate = 0d; if (isFakeExtended) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Double currentBasalRate = profile.getBasal(); rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); } else if (isAbsolute){ diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 96d3bbc3d2..ea17a30218 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.SingleClickButton; @@ -131,7 +132,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL profileSwitch.setVisibility(View.GONE); } - if (MainApp.getConfigBuilder().getProfile() == null) { + if (ProfileFunctions.getInstance().getProfile() == null) { tempTarget.setVisibility(View.GONE); extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 7a03887cf6..32f1271d82 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.FabricPrivacy; @@ -70,7 +71,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi double tempPercentStep = pumpDescription.tempPercentStep; basalPercent.setParams(100d, 0d, maxTempPercent, tempPercentStep, new DecimalFormat("0"), true); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Double currentBasal = profile != null ? profile.getBasal() : 0d; basalAbsolute = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalabsoluteinput); basalAbsolute.setParams(currentBasal, 0d, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, new DecimalFormat("0.00"), true); @@ -118,7 +119,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi final boolean setAsPercent = percentRadio.isChecked(); int durationInMinutes = SafeParse.stringToInt(duration.getText()); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index 802a072002..b4ca897f8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -49,6 +49,7 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DefaultValueHelper; @@ -171,7 +172,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick view.findViewById(R.id.cancel).setOnClickListener(this); // profile - profile = MainApp.getConfigBuilder().getProfile(); + profile = ProfileFunctions.getInstance().getProfile(); profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); if (profileStore == null) { if (options.eventType == R.id.careportal_profileswitch) { @@ -186,7 +187,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSpinner.setAdapter(adapter); // set selected to actual profile for (int p = 0; p < profileList.size(); p++) { - if (profileList.get(p).equals(MainApp.getConfigBuilder().getProfileName(false))) + if (profileList.get(p).equals(ProfileFunctions.getInstance().getProfileName(false))) profileSpinner.setSelection(p); } } @@ -214,7 +215,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick } boolean erase = false; - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); DefaultValueHelper helper = new DefaultValueHelper(); if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) { defaultDuration = helper.determineEatingSoonTTDuration(); @@ -786,8 +787,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSwitch = new ProfileSwitch(); profileSwitch.date = System.currentTimeMillis(); profileSwitch.source = Source.USER; - profileSwitch.profileName = MainApp.getConfigBuilder().getProfileName(System.currentTimeMillis(), false); - profileSwitch.profileJson = MainApp.getConfigBuilder().getProfile().getData().toString(); + profileSwitch.profileName = ProfileFunctions.getInstance().getProfileName(System.currentTimeMillis(), false); + profileSwitch.profileJson = ProfileFunctions.getInstance().getProfile().getData().toString(); profileSwitch.profilePlugin = MainApp.getConfigBuilder().getActiveProfileInterface().getClass().getName(); profileSwitch.durationInMinutes = duration; profileSwitch.isCPP = percentage != 100 || timeshift != 0; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 3c582c0709..d0e7a38c23 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -530,97 +530,7 @@ public class ConfigBuilderPlugin extends PluginBase { getCommandQueue().bolus(detailedBolusInfo, callback); } - @Subscribe - public void onProfileSwitch(EventProfileSwitchChange ignored) { - getCommandQueue().setProfile(getProfile(), new Callback() { - @Override - public void run() { - if (!result.success) { - Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", result.comment); - i.putExtra("title", MainApp.gs(R.string.failedupdatebasalprofile)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); - } - MainApp.bus().post(new EventNewBasalProfile()); - } - }); - } - - public String getProfileName() { - return getProfileName(System.currentTimeMillis()); - } - - public String getProfileName(boolean customized) { - return getProfileName(System.currentTimeMillis(), customized); - } - - public String getProfileName(long time) { - return getProfileName(time, true); - } - - public String getProfileName(long time, boolean customized) { - ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); - if (profileSwitch != null) { - if (profileSwitch.profileJson != null) { - return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName; - } else { - ProfileStore profileStore = activeProfile.getProfile(); - if (profileStore != null) { - Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName); - if (profile != null) - return profileSwitch.profileName; - } - } - } - return MainApp.gs(R.string.noprofileselected); - } - - public boolean isProfileValid(String from) { - return getProfile() != null && getProfile().isValid(from); - } - - @Nullable - public Profile getProfile() { - return getProfile(System.currentTimeMillis()); - } - - public String getProfileUnits() { - Profile profile = getProfile(); - return profile != null ? profile.getUnits() : Constants.MGDL; - } - - @Nullable - public Profile getProfile(long time) { - if (activeTreatments == null) { - log.debug("getProfile activeTreatments == null: returning null"); - return null; //app not initialized - } - //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); - ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); - if (profileSwitch != null) { - if (profileSwitch.profileJson != null) { - return profileSwitch.getProfileObject(); - } else if (activeProfile.getProfile() != null) { - Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName); - if (profile != null) - return profile; - } - } - if (activeTreatments.getProfileSwitchesFromHistory().size() > 0) { - FabricPrivacy.getInstance().logCustom(new CustomEvent("CatchedError") - .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) - .putCustomAttribute("version", BuildConfig.VERSION) - .putCustomAttribute("time", time) - .putCustomAttribute("getProfileSwitchesFromHistory", activeTreatments.getProfileSwitchesFromHistory().toString()) - ); - } - log.debug("getProfile at the end: returning null"); - return null; - } - - public void disconnectPump(int durationInMinutes, Profile profile) { + public void disconnectPump(int durationInMinutes, Profile profile) { LoopPlugin.getPlugin().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L); getCommandQueue().tempBasalPercent(0, durationInMinutes, true, profile, new Callback() { @Override 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 new file mode 100644 index 0000000000..8cddbbc5a3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ProfileFunctions.java @@ -0,0 +1,142 @@ +package info.nightscout.androidaps.plugins.ConfigBuilder; + +import android.content.Intent; +import android.support.annotation.Nullable; + +import com.crashlytics.android.answers.CustomEvent; +import com.squareup.otto.Subscribe; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.BuildConfig; +import info.nightscout.androidaps.Constants; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.androidaps.db.ProfileSwitch; +import info.nightscout.androidaps.events.EventNewBasalProfile; +import info.nightscout.androidaps.events.EventProfileSwitchChange; +import info.nightscout.androidaps.interfaces.ProfileInterface; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.queue.Callback; +import info.nightscout.utils.FabricPrivacy; + +public class ProfileFunctions { + private static Logger log = LoggerFactory.getLogger(L.PROFILE); + + private static ProfileFunctions profileFunctions = null; + + public static ProfileFunctions getInstance() { + if (profileFunctions == null) + profileFunctions = new ProfileFunctions(); + return profileFunctions; + } + + static { + ProfileFunctions.getInstance(); // register to bus at start + } + + ProfileFunctions() { + MainApp.bus().register(this); + } + + @Subscribe + public void onProfileSwitch(EventProfileSwitchChange ignored) { + if (L.isEnabled(L.PROFILE)) + log.debug("onProfileSwitch"); + MainApp.getConfigBuilder().getCommandQueue().setProfile(getProfile(), new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.gs(R.string.failedupdatebasalprofile)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } + MainApp.bus().post(new EventNewBasalProfile()); + } + }); + } + + public String getProfileName() { + return getProfileName(System.currentTimeMillis()); + } + + public String getProfileName(boolean customized) { + return getProfileName(System.currentTimeMillis(), customized); + } + + public String getProfileName(long time) { + return getProfileName(time, true); + } + + public String getProfileName(long time, boolean customized) { + TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin(); + ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface(); + + ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); + if (profileSwitch != null) { + if (profileSwitch.profileJson != null) { + return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName; + } else { + ProfileStore profileStore = activeProfile.getProfile(); + if (profileStore != null) { + Profile profile = profileStore.getSpecificProfile(profileSwitch.profileName); + if (profile != null) + return profileSwitch.profileName; + } + } + } + return MainApp.gs(R.string.noprofileselected); + } + + public boolean isProfileValid(String from) { + return getProfile() != null && getProfile().isValid(from); + } + + @Nullable + public Profile getProfile() { + return getProfile(System.currentTimeMillis()); + } + + public String getProfileUnits() { + Profile profile = getProfile(); + return profile != null ? profile.getUnits() : Constants.MGDL; + } + + @Nullable + public Profile getProfile(long time) { + TreatmentsInterface activeTreatments = TreatmentsPlugin.getPlugin(); + ProfileInterface activeProfile = MainApp.getConfigBuilder().getActiveProfileInterface(); + + //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); + ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); + if (profileSwitch != null) { + if (profileSwitch.profileJson != null) { + return profileSwitch.getProfileObject(); + } else if (activeProfile.getProfile() != null) { + Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName); + if (profile != null) + return profile; + } + } + if (activeTreatments.getProfileSwitchesFromHistory().size() > 0) { + FabricPrivacy.getInstance().logCustom(new CustomEvent("CatchedError") + .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) + .putCustomAttribute("version", BuildConfig.VERSION) + .putCustomAttribute("time", time) + .putCustomAttribute("getProfileSwitchesFromHistory", activeTreatments.getProfileSwitchesFromHistory().toString()) + ); + } + log.debug("getProfile at the end: returning null"); + return null; + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java index 5d4d1187ac..a2d80efd68 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java @@ -5,6 +5,7 @@ import com.squareup.otto.Bus; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; @@ -61,7 +62,7 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli } public double getUserDefinedDia() { - return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : MIN_DIA; + return ProfileFunctions.getInstance().getProfile() != null ? ProfileFunctions.getInstance().getProfile().getDia() : MIN_DIA; } public Iob iobCalcForTreatment(Treatment treatment, long time) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 499984e3dc..60a5851011 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -13,6 +13,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; @@ -45,7 +46,7 @@ public class AutosensData implements DataPointWithLabelInterface { remaining = t.carbs; 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 = MainApp.getConfigBuilder().getProfile(t.date); + Profile profile = ProfileFunctions.getInstance().getProfile(t.date); double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); double ic = profile.getIc(t.date); min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 824a0eda9b..07feacadff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.Sensitivity.SensitivityOref1Plugin; @@ -302,7 +303,7 @@ public class IobCobCalculatorPlugin extends PluginBase { } public long calculateDetectionStart(long from, boolean limitDataToOldestAvailable) { - Profile profile = MainApp.getConfigBuilder().getProfile(from); + Profile profile = ProfileFunctions.getInstance().getProfile(from); double dia = Constants.defaultDIA; if (profile != null) dia = profile.getDia(); @@ -599,7 +600,7 @@ public class IobCobCalculatorPlugin extends PluginBase { } if (MainApp.getConfigBuilder() == null) return; // app still initializing - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return; // app still initializing dia = profile.getDia(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java index 30d087d71c..3dbd518c24 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobOref1Thread.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; @@ -79,7 +80,7 @@ public class IobCobOref1Thread extends Thread { log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from); return; // app still initializing } - if (!MainApp.getConfigBuilder().isProfileValid("IobCobThread")) { + if (!ProfileFunctions.getInstance().isProfileValid("IobCobThread")) { if (L.isEnabled(L.AUTOSENS)) log.debug("Aborting calculation thread (No profile): " + from); return; // app still initializing @@ -129,7 +130,7 @@ public class IobCobOref1Thread extends Thread { continue; } - Profile profile = MainApp.getConfigBuilder().getProfile(bgTime); + Profile profile = ProfileFunctions.getInstance().getProfile(bgTime); if (profile == null) { if (L.isEnabled(L.AUTOSENS)) log.debug("Aborting calculation thread (no profile): " + from); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index 251e5f7b90..5ec09301c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventIobCalculationProgress; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; @@ -78,7 +79,7 @@ public class IobCobThread extends Thread { log.debug("Aborting calculation thread (ConfigBuilder not ready): " + from); return; // app still initializing } - if (!MainApp.getConfigBuilder().isProfileValid("IobCobThread")) { + if (!ProfileFunctions.getInstance().isProfileValid("IobCobThread")) { if (L.isEnabled(L.AUTOSENS)) log.debug("Aborting calculation thread (No profile): " + from); return; // app still initializing @@ -128,7 +129,7 @@ public class IobCobThread extends Thread { continue; } - Profile profile = MainApp.getConfigBuilder().getProfile(bgTime); + Profile profile = ProfileFunctions.getInstance().getProfile(bgTime); if (profile == null) { if (L.isEnabled(L.AUTOSENS)) log.debug("Aborting calculation thread (no profile): " + from); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 4200317cef..91ef310eaa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui; @@ -271,9 +272,9 @@ public class LoopPlugin extends PluginBase { if (!isEnabled(PluginType.LOOP)) return; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); - if (!MainApp.getConfigBuilder().isProfileValid("Loop")) { + if (!ProfileFunctions.getInstance().isProfileValid("Loop")) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.noprofileselected)); MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java index a3094a4646..e1f9535caa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSUpload.java @@ -24,6 +24,7 @@ import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; @@ -83,7 +84,7 @@ public class NSUpload { if (useAbsolute) { TemporaryBasal t = temporaryBasal.clone(); t.isAbsolute = true; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) { t.absoluteRate = profile.getBasal(temporaryBasal.date) * temporaryBasal.percentRate / 100d; uploadTempBasalStartAbsolute(t, null); @@ -195,8 +196,8 @@ public class NSUpload { } public static void uploadDeviceStatus() { - Profile profile = MainApp.getConfigBuilder().getProfile(); - String profileName = MainApp.getConfigBuilder().getProfileName(); + Profile profile = ProfileFunctions.getInstance().getProfile(); + String profileName = ProfileFunctions.getInstance().getProfileName(); if (profile == null || profileName == null) { log.error("Profile is null. Skipping upload"); @@ -303,7 +304,7 @@ public class NSUpload { public static void uploadTempTarget(TempTarget tempTarget) { try { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { log.error("Profile is null. Skipping upload"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 1c6bf3e39d..cb651a2ae9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -21,6 +21,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -97,7 +98,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext())); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (profile == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index ce350011cd..5b57810632 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -21,6 +21,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; @@ -96,7 +97,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext())); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (profile == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index 64daaed9c1..5f6b13c416 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -100,7 +101,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext())); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = ConfigBuilderPlugin.getActivePump(); if (profile == null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java index f0ccdd9809..f1f62c0bc4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SafeParse; @@ -63,7 +64,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 = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); 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/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java index cd03cb7b6a..40450adf77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java @@ -21,6 +21,7 @@ import android.widget.RadioButton; import com.google.common.base.Joiner; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -309,7 +310,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C } okClicked = true; try { - final Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + final Profile currentProfile = ProfileFunctions.getInstance().getProfile(); if (currentProfile == null) { return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java index 2889c8266b..1fad80af8f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java @@ -40,6 +40,7 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; @@ -208,7 +209,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener okClicked = true; try { - Profile currentProfile = MainApp.getConfigBuilder().getProfile(); + Profile currentProfile = ProfileFunctions.getInstance().getProfile(); if (currentProfile == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 0ad53d99a4..7985418ada 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -56,6 +56,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; @@ -325,7 +326,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com return; } okClicked = true; - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null && (calculatedTotalInsulin > 0d || calculatedCarbs > 0d)) { String confirmMessage = MainApp.gs(R.string.entertreatmentquestion); @@ -432,7 +433,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } private void initDialog() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface() != null ? MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() : null; if (profile == null || profileStore == null) { @@ -483,7 +484,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com String selectedAlternativeProfile = profileSpinner.getSelectedItem().toString(); Profile specificProfile; if (selectedAlternativeProfile.equals(MainApp.gs(R.string.active))) - specificProfile = MainApp.getConfigBuilder().getProfile(); + specificProfile = ProfileFunctions.getInstance().getProfile(); else specificProfile = profileStore.getSpecificProfile(selectedAlternativeProfile); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 91dbb29042..ac98eee730 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -85,6 +85,7 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; @@ -453,7 +454,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (v == apsModeView) { final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - if (loopPlugin == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) + if (!ProfileFunctions.getInstance().isProfileValid("ContexMenuCreation")) return; menu.setHeaderTitle(MainApp.gs(R.string.loop)); if (loopPlugin.isEnabled(PluginType.LOOP)) { @@ -496,7 +497,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, @Override public boolean onContextItemSelected(MenuItem item) { - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return true; final LoopPlugin loopPlugin = LoopPlugin.getPlugin(); @@ -637,7 +638,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, public void onClick(View v) { boolean xdrip = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginType.BGSOURCE); boolean g5 = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginType.BGSOURCE); - String units = MainApp.getConfigBuilder().getProfileUnits(); + 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 @@ -725,7 +726,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } private void onClickAcceptTemp() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); Context context = getContext(); if (context == null) return; @@ -767,7 +768,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, void onClickQuickwizard() { final BgReading actualBg = DatabaseHelper.actualBg(); - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); final TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); @@ -1048,7 +1049,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, pumpStatusLayout.setVisibility(View.GONE); loopStatusLayout.setVisibility(View.GONE); - if (!MainApp.getConfigBuilder().isProfileValid("Overview")) { + if (!ProfileFunctions.getInstance().isProfileValid("Overview")) { pumpStatusView.setText(R.string.noprofileset); pumpStatusLayout.setVisibility(View.VISIBLE); return; @@ -1061,7 +1062,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); final String units = profile.getUnits(); final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); @@ -1245,7 +1246,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, extendedBolusView.setVisibility(View.VISIBLE); } - activeProfileView.setText(MainApp.getConfigBuilder().getProfileName()); + activeProfileView.setText(ProfileFunctions.getInstance().getProfileName()); activeProfileView.setBackgroundColor(Color.GRAY); // QuickWizard button diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index dfd6b9970c..b184201908 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; @@ -92,7 +93,7 @@ public class OverviewPlugin extends PluginBase { } public double determineLowLine() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { return bgTargetLow; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index 72fbbff5a5..30ed626b89 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.BasalData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -63,7 +64,7 @@ public class GraphData { private IobCobCalculatorPlugin iobCobCalculatorPlugin; public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) { - units = MainApp.getConfigBuilder().getProfileUnits(); + units = ProfileFunctions.getInstance().getProfileUnits(); this.graph = graph; this.iobCobCalculatorPlugin = iobCobCalculatorPlugin; } @@ -144,7 +145,7 @@ public class GraphData { double lastBaseBasal = 0; double lastTempBasal = 0; for (long time = fromTime; time < toTime; time += 60 * 1000L) { - Profile profile = MainApp.getConfigBuilder().getProfile(time); + Profile profile = ProfileFunctions.getInstance().getProfile(time); if (profile == null) continue; BasalData basalData = iobCobCalculatorPlugin.getBasalData(profile, time); double baseBasalValue = basalData.basal; @@ -348,7 +349,7 @@ public class GraphData { Scale iobScale = new Scale(); for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { - Profile profile = MainApp.getConfigBuilder().getProfile(time); + Profile profile = ProfileFunctions.getInstance().getProfile(time); double iob = 0d; if (profile != null) iob = iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time, profile).iob; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index f6a9494a20..f87643fcf8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -37,6 +37,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DecimalFormatter; @@ -108,9 +109,9 @@ public class PersistentNotificationPlugin extends PluginBase { String line1 = ""; - if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || !MainApp.getConfigBuilder().isProfileValid("Notificiation")) + if (MainApp.getConfigBuilder().getActiveProfileInterface() == null || !ProfileFunctions.getInstance().isProfileValid("Notificiation")) return null; - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); BgReading lastBG = DatabaseHelper.lastBg(); @@ -147,7 +148,7 @@ public class PersistentNotificationPlugin extends PluginBase { String line3 = DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h"; - line3 += " - " + MainApp.getConfigBuilder().getProfileName(); + line3 += " - " + ProfileFunctions.getInstance().getProfileName(); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, CHANNEL_ID); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java index b0f0700fe2..e3aeca0c45 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; import info.nightscout.utils.DecimalFormatter; @@ -92,7 +93,7 @@ public class NSProfileFragment extends SubscriberFragment { profileSpinner.setAdapter(adapter); // set selected to actual profile for (int p = 0; p < profileList.size(); p++) { - if (profileList.get(p).equals(MainApp.getConfigBuilder().getProfileName())) + if (profileList.get(p).equals(ProfileFunctions.getInstance().getProfileName())) profileSpinner.setSelection(p); } noProfile.setVisibility(View.GONE); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 7116056657..ff866702b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -43,6 +43,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -1338,7 +1339,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint JSONObject extendedJson = new JSONObject(); extendedJson.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); - extendedJson.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); + extendedJson.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); PumpState ps = pump.state; if (ps.tbrActive) { extendedJson.put("TempBasalAbsoluteRate", ps.basalRate); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java index 444a11b5c4..6398c41a09 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; @@ -197,7 +198,7 @@ public class DanaRHistoryActivity extends Activity { clearCardView(); } }); - profile = MainApp.getConfigBuilder().getProfile(); + profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.noprofile)); finish(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java index 36bad4f6fa..eab9e8bc6e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRNSHistorySync.java @@ -14,6 +14,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; import info.nightscout.utils.DateUtil; @@ -182,7 +183,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, MainApp.getConfigBuilder().getProfileUnits())); + nsrec.put("glucose", Profile.fromMgdlToUnits(record.recordValue, ProfileFunctions.getInstance().getProfileUnits())); 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/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 0f1dc5dbf9..446913b1b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -167,7 +168,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { long now = System.currentTimeMillis(); mDanaRPump.lastConnection = now; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index e54dd7be83..4be6cee2c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -23,6 +23,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; @@ -171,7 +172,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { long now = System.currentTimeMillis(); mDanaRPump.lastConnection = now; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index ae314f77a7..f83702d7c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -41,6 +41,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; @@ -745,7 +746,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } extended.put("BaseBasalRate", getBaseBasalRate()); try { - extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); + extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); } catch (Exception e) { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index 23618f2b18..932c9c747e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -142,7 +143,7 @@ public class DanaRSService extends Service { danaRPump.lastConnection = System.currentTimeMillis(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 4065d1624d..1e1147c849 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -192,7 +193,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mDanaRPump.lastConnection = System.currentTimeMillis(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); if (profile != null && Math.abs(mDanaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) { MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index 661ed0b0a5..2f9d5d21dd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; @@ -671,7 +672,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai status.put("timestamp", DateUtil.toISOString(connector.getLastContactTime())); extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION); try { - extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); + extended.put("ActiveProfile", ProfileFunctions.getInstance().getProfileName()); } catch (Exception e) { } TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 7aae82b8f8..a72c1313d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; @@ -191,7 +192,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public double getBaseBasalRate() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) return profile.getBasal(); else 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 350769ec24..993a51edf8 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 @@ -17,6 +17,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -59,7 +60,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin { if (age.equals(MainApp.gs(R.string.key_child))) defaultHours = 4; int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { log.error("No profile"); 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 2ddf402763..de0e9c9c0c 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 @@ -17,6 +17,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -54,7 +55,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin { int hoursForDetection = 24; long now = System.currentTimeMillis(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { log.error("No profile"); 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 fe56899fea..06656617c5 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 @@ -17,6 +17,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -53,7 +54,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { // dependency, this should be avoided LongSparseArray autosensDataTable = iobCobCalculatorPlugin.getAutosensDataTable(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { log.error("No profile"); 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 82c3d04d91..95b027a86c 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 @@ -15,6 +15,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; @@ -71,7 +72,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin } - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { if (L.isEnabled(L.AUTOSENS)) log.debug("No profile available"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index b372ca7cb8..dd663ec1be 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -21,6 +21,7 @@ import java.util.List; 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.services.Intents; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.GlucoseStatus; @@ -207,7 +208,7 @@ public class SmsCommunicatorPlugin extends PluginBase { BgReading actualBG = DatabaseHelper.actualBg(); BgReading lastBG = DatabaseHelper.lastBg(); - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); if (actualBG != null) { reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "; @@ -378,7 +379,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } } else { tempBasal = SafeParse.stringToDouble(splited[1]); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { reply = MainApp.gs(R.string.noprofile); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); @@ -471,7 +472,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed && tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) { tempBasalWaitingForConfirmation.processed = true; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30, true, profile, new Callback() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 5c952b58f1..6e99f28c12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; @@ -113,8 +114,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (L.isEnabled(L.DATATREATMENTS)) log.debug("initializeTreatmentData"); double dia = Constants.defaultDIA; - if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) - dia = MainApp.getConfigBuilder().getProfile().getDia(); + if (MainApp.getConfigBuilder() != null && ProfileFunctions.getInstance().getProfile() != null) + dia = ProfileFunctions.getInstance().getProfile().getDia(); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); synchronized (treatments) { treatments.clear(); @@ -126,8 +127,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (L.isEnabled(L.DATATREATMENTS)) log.debug("initializeTempBasalData"); double dia = Constants.defaultDIA; - if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) - dia = MainApp.getConfigBuilder().getProfile().getDia(); + if (MainApp.getConfigBuilder() != null && ProfileFunctions.getInstance().getProfile() != null) + dia = ProfileFunctions.getInstance().getProfile().getDia(); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); synchronized (tempBasals) { @@ -140,8 +141,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (L.isEnabled(L.DATATREATMENTS)) log.debug("initializeExtendedBolusData"); double dia = Constants.defaultDIA; - if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) - dia = MainApp.getConfigBuilder().getProfile().getDia(); + if (MainApp.getConfigBuilder() != null && ProfileFunctions.getInstance().getProfile() != null) + dia = ProfileFunctions.getInstance().getProfile().getDia(); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); synchronized (extendedBoluses) { @@ -176,7 +177,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface public IobTotal getCalculationToTimeTreatments(long time) { IobTotal total = new IobTotal(time); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return total; @@ -224,7 +225,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface public MealData getMealData() { MealData result = new MealData(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return result; long now = System.currentTimeMillis(); @@ -410,7 +411,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public void updateTotalIOBTempBasals() { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile != null) lastTempBasalsCalculation = getCalculationToTimeTempBasals(DateUtil.now(), profile); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java index aa6204cbe2..c9b744e86d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java @@ -24,6 +24,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.Profile; @@ -69,7 +70,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View. @Override public void onBindViewHolder(TreatmentsViewHolder holder, int position) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return; Treatment t = treatments.get(position); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java index 903a075dca..2449dff52e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsProfileSwitchFragment.java @@ -24,6 +24,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.ProfileSwitch; @@ -64,7 +65,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen @Override public void onBindViewHolder(ProfileSwitchViewHolder holder, int position) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return; ProfileSwitch profileSwitch = profileSwitchList.get(position); holder.ph.setVisibility(profileSwitch.source == Source.PUMP ? View.VISIBLE : View.GONE); 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 96b559d89d..d60dfc9e4c 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 @@ -21,6 +21,7 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.db.Source; @@ -65,7 +66,7 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements @Override public void onBindViewHolder(TempTargetsViewHolder holder, int position) { - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); 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/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java index 9b61eba2ae..3185bd81ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTemporaryBasalsFragment.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; @@ -84,7 +85,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { } holder.duration.setText(DecimalFormatter.to0Decimal(tempBasal.durationInMinutes, " min")); if (tempBasal.isAbsolute) { - Profile profile = MainApp.getConfigBuilder().getProfile(tempBasal.date); + Profile profile = ProfileFunctions.getInstance().getProfile(tempBasal.date); if (profile != null) { holder.absolute.setText(DecimalFormatter.to0Decimal(tempBasal.tempBasalConvertedToAbsolute(tempBasal.date, profile), " U/h")); holder.percent.setText(""); @@ -99,7 +100,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { holder.realDuration.setText(DecimalFormatter.to0Decimal(tempBasal.getRealDuration(), " min")); long now = DateUtil.now(); IobTotal iob = new IobTotal(now); - Profile profile = MainApp.getConfigBuilder().getProfile(now); + Profile profile = ProfileFunctions.getInstance().getProfile(now); if (profile != null) iob = tempBasal.iobCalc(now, profile); holder.iob.setText(DecimalFormatter.to2Decimal(iob.basaliob, " U")); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java index fc4728c53c..84e32ca087 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/ActionStringHandler.java @@ -32,6 +32,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; @@ -134,7 +135,7 @@ public class ActionStringHandler { ///////////////////////////////////////////////////////// TEMPTARGET boolean isMGDL = Boolean.parseBoolean(act[1]); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { sendError("No profile found!"); return; @@ -203,7 +204,7 @@ public class ActionStringHandler { boolean useTrend = SP.getBoolean(R.string.key_wearwizard_trend, false); int percentage = Integer.parseInt(act[2]); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { sendError("No profile found!"); return; @@ -363,7 +364,7 @@ public class ActionStringHandler { private static String generateTDDMessage(List historyList, List dummies) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { return "No profile loaded :("; @@ -517,7 +518,7 @@ public class ActionStringHandler { if (!Config.APS) { return "Targets only apply in APS mode!"; } - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { return "No profile set :("; } @@ -541,7 +542,7 @@ public class ActionStringHandler { if (!Config.APS) { return "Only apply in APS mode!"; } - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { return "No profile set :("; } @@ -651,7 +652,7 @@ public class ActionStringHandler { if (timeshift < 0 || timeshift > 23) { msg += String.format(MainApp.gs(R.string.valueoutofrange), "Profile-Timeshift") + "\n"; } - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { msg += MainApp.gs(R.string.notloadedplugins) + "\n"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index b5d30ad071..ce9b0e0f2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -37,6 +37,7 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Treatments.Treatment; @@ -223,7 +224,7 @@ public class WatchUpdaterService extends WearableListenerService implements } private DataMap dataMapSingleBG(BgReading lastBG, GlucoseStatus glucoseStatus) { - String units = MainApp.getConfigBuilder().getProfileUnits(); + String units = ProfileFunctions.getInstance().getProfileUnits(); Double lowLine = SafeParse.stringToDouble(mPrefs.getString("low_mark", "0")); Double highLine = SafeParse.stringToDouble(mPrefs.getString("high_mark", "0")); @@ -363,7 +364,7 @@ public class WatchUpdaterService extends WearableListenerService implements ArrayList predictions = new ArrayList<>(); - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) { return; @@ -383,7 +384,7 @@ public class WatchUpdaterService extends WearableListenerService implements if (tb1 != null) { tb_before = beginBasalValue; - Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime); + Profile profileTB = ProfileFunctions.getInstance().getProfile(runningTime); if (profileTB != null) { tb_amount = tb1.tempBasalConvertedToAbsolute(runningTime, profileTB); tb_start = runningTime; @@ -392,7 +393,7 @@ public class WatchUpdaterService extends WearableListenerService implements for (; runningTime < now; runningTime += 5 * 60 * 1000) { - Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime); + Profile profileTB = ProfileFunctions.getInstance().getProfile(runningTime); //basal rate endBasalValue = profile.getBasal(runningTime); if (endBasalValue != beginBasalValue) { @@ -444,7 +445,7 @@ public class WatchUpdaterService extends WearableListenerService implements temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount)); } else { //express currently running temp by painting it a bit into the future - Profile profileNow = MainApp.getConfigBuilder().getProfile(now); + Profile profileNow = ProfileFunctions.getInstance().getProfile(now); double currentAmount = tb2.tempBasalConvertedToAbsolute(now, profileNow); if (currentAmount != tb_amount) { temps.add(tempDatamap(tb_start, tb_before, now, tb_amount, tb_amount)); @@ -457,7 +458,7 @@ public class WatchUpdaterService extends WearableListenerService implements tb2 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); //use "now" to express current situation if (tb2 != null) { //onset at the end - Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime); + Profile profileTB = ProfileFunctions.getInstance().getProfile(runningTime); double currentAmount = tb2.tempBasalConvertedToAbsolute(runningTime, profileTB); temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount)); } @@ -580,7 +581,7 @@ public class WatchUpdaterService extends WearableListenerService implements private void sendStatus() { if (googleApiClient.isConnected()) { - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); String status = MainApp.gs(R.string.noprofile); String iobSum, iobDetail, cobString, currentBasal, bgiString; iobSum = iobDetail = cobString = currentBasal = bgiString = ""; @@ -699,7 +700,7 @@ public class WatchUpdaterService extends WearableListenerService implements String basalStringResult; - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return ""; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index d5ac60a626..bc879bc2a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -93,7 +94,7 @@ public class StatuslinePlugin extends PluginBase { private void sendStatus() { String status = ""; // sent once on disable - Profile profile = MainApp.getConfigBuilder().getProfile(); + Profile profile = ProfileFunctions.getInstance().getProfile(); if (isEnabled(PluginType.GENERAL) && profile != null) { status = buildStatusString(profile); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index 4df1e65c2c..f98f86d8fb 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperActivity; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; @@ -502,7 +503,7 @@ public class CommandQueue { public boolean isThisProfileSet(Profile profile) { PumpInterface activePump = ConfigBuilderPlugin.getActivePump(); - Profile current = MainApp.getConfigBuilder().getProfile(); + Profile current = ProfileFunctions.getInstance().getProfile(); if (activePump != null && current != null) { boolean result = activePump.isThisProfileSet(profile); if (!result) { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index d574b08f40..2a6ab73106 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -7,6 +7,7 @@ import android.content.Context; import android.content.Intent; import android.os.PowerManager; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.utils.FabricPrivacy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +55,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { private void checkPump() { final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (pump != null && profile != null) { Date lastConnection = pump.lastDataTime(); boolean isStatusOutdated = lastConnection.getTime() + STATUS_UPDATE_FREQUENCY < System.currentTimeMillis(); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index acd967f24a..433c3927db 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -306,8 +307,8 @@ public class SWDefinition { newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.show(getActivity().getSupportFragmentManager(), "NewNSTreatmentDialog"); })) - .validator(() -> MainApp.getConfigBuilder().getProfile() != null) - .visibility(() -> MainApp.getConfigBuilder().getProfile() == null) + .validator(() -> ProfileFunctions.getInstance().getProfile() != null) + .visibility(() -> ProfileFunctions.getInstance().getProfile() == null) ) .add(new SWScreen(R.string.configbuilder_pump) .skippable(false) diff --git a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java index 9fabe03ec2..e41d1dd914 100644 --- a/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/utils/LocalAlertUtils.java @@ -13,6 +13,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; @@ -80,7 +81,7 @@ public class LocalAlertUtils { //TODO: persist the actual time the pump is read and simplify the whole logic when to alarm final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); - final Profile profile = MainApp.getConfigBuilder().getProfile(); + final Profile profile = ProfileFunctions.getInstance().getProfile(); if (pump != null && profile != null) { Date lastConnection = pump.lastDataTime(); long earliestAlarmTime = lastConnection.getTime() + pumpUnreachableThreshold(); diff --git a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java index 8ac6433676..18c066b1da 100644 --- a/app/src/main/java/info/nightscout/utils/XdripCalibrations.java +++ b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java @@ -15,6 +15,7 @@ import java.util.List; 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.services.Intents; /** @@ -45,7 +46,7 @@ public class XdripCalibrations { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putDouble("glucose_number", bg); - bundle.putString("units", MainApp.getConfigBuilder().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); + bundle.putString("units", ProfileFunctions.getInstance().getProfileUnits().equals(Constants.MGDL) ? "mgdl" : "mmol"); bundle.putLong("timestamp", System.currentTimeMillis()); Intent intent = new Intent(Intents.ACTION_REMOTE_CALIBRATION); intent.putExtras(bundle);