From 0a03798de939c476900184ac0b6179f13f2c9900 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Apr 2018 11:09:58 +0200 Subject: [PATCH] move treatments interface out of ConfigBuilder --- .../androidaps/data/QuickWizardEntry.java | 4 +- .../plugins/Actions/ActionsFragment.java | 12 +- .../Dialogs/NewNSTreatmentDialog.java | 14 +- .../ConfigBuilder/ConfigBuilderPlugin.java | 200 +----------------- .../ObjectivesPlugin.java | 3 +- .../IobCobCalculatorPlugin.java | 9 +- .../IobCobCalculator/IobCobThread.java | 11 +- .../DetermineBasalAdapterAMAJS.java | 13 +- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 9 +- .../OpenAPSMA/DetermineBasalAdapterMAJS.java | 4 +- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 17 +- .../DetermineBasalAdapterSMBJS.java | 9 +- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 9 +- .../Overview/Dialogs/NewCarbsDialog.java | 3 +- .../Overview/Dialogs/NewInsulinDialog.java | 4 +- .../Overview/Dialogs/NewTreatmentDialog.java | 3 +- .../Overview/Dialogs/WizardDialog.java | 21 +- .../plugins/Overview/OverviewFragment.java | 23 +- .../plugins/Overview/graphData/GraphData.java | 16 +- .../PersistentNotificationPlugin.java | 11 +- .../plugins/PumpCombo/ComboPlugin.java | 27 +-- .../PumpDanaR/AbstractDanaRPlugin.java | 15 +- .../plugins/PumpDanaR/DanaRFragment.java | 77 ++++--- .../plugins/PumpDanaR/DanaRPlugin.java | 20 +- .../comm/MsgStatusBolusExtended.java | 4 +- .../PumpDanaR/comm/MsgStatusTempBasal.java | 16 +- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 17 +- .../plugins/PumpDanaRS/DanaRSPlugin.java | 21 +- .../DanaRS_Packet_APS_History_Events.java | 19 +- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 11 +- .../PumpDanaRv2/comm/MsgHistoryEvents_v2.java | 19 +- .../plugins/PumpInsight/InsightPlugin.java | 29 +-- .../history/HistoryLogAdapter.java | 9 +- .../androidaps/plugins/PumpMDI/MDIPlugin.java | 3 +- .../PumpVirtual/VirtualPumpFragment.java | 7 +- .../PumpVirtual/VirtualPumpPlugin.java | 29 ++- .../SmsCommunicatorPlugin.java | 9 +- .../Treatments/TreatmentsFragment.java | 3 +- .../plugins/Treatments/TreatmentsPlugin.java | 36 +++- .../fragments/ProfileViewerDialog.java | 6 +- .../TreatmentsExtendedBolusesFragment.java | 8 +- .../TreatmentsTempTargetFragment.java | 13 +- .../TreatmentsTemporaryBasalsFragment.java | 12 +- .../plugins/Wear/ActionStringHandler.java | 19 +- .../wearintegration/WatchUpdaterService.java | 15 +- .../XDripStatusline/StatuslinePlugin.java | 4 +- .../queue/commands/CommandSetProfile.java | 4 +- .../info/nightscout/utils/BolusWizard.java | 4 +- .../nightscout/utils/BolusWizardTest.java | 8 +- 49 files changed, 367 insertions(+), 492 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java index b08926f119..4a94db0a44 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java @@ -7,7 +7,6 @@ import org.slf4j.LoggerFactory; import java.util.Date; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.TempTarget; @@ -16,6 +15,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; import info.nightscout.utils.SP; @@ -102,7 +102,7 @@ public class QuickWizardEntry { } // Basal IOB - TreatmentsInterface treatments = MainApp.getConfigBuilder(); + TreatmentsInterface treatments = TreatmentsPlugin.getPlugin(); treatments.updateTotalIOBTempBasals(); IobTotal basalIob = treatments.getLastCalculationTempBasals().round(); boolean basalIOB = false; 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 3ce9429ce4..e424943acb 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 @@ -10,7 +10,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; - import com.crashlytics.android.answers.CustomEvent; import com.squareup.otto.Subscribe; @@ -18,6 +17,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.HistoryBrowseActivity; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.TDDStatsActivity; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventExtendedBolusChange; @@ -33,7 +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.TDDStatsActivity; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.SingleClickButton; @@ -155,7 +155,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.GONE); } else { - ExtendedBolus activeExtendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (activeExtendedBolus != null) { extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.VISIBLE); @@ -171,7 +171,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL tempBasal.setVisibility(View.GONE); tempBasalCancel.setVisibility(View.GONE); } else { - final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { tempBasal.setVisibility(View.GONE); tempBasalCancel.setVisibility(View.VISIBLE); @@ -219,13 +219,13 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL newExtendedDialog.show(manager, "NewExtendedDialog"); break; case R.id.actions_extendedbolus_cancel: - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { ConfigBuilderPlugin.getCommandQueue().cancelExtended(null); FabricPrivacy.getInstance().logCustom(new CustomEvent("CancelExtended")); } break; case R.id.actions_canceltempbasal: - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, null); FabricPrivacy.getInstance().logCustom(new CustomEvent("CancelTemp")); } 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 55a037cd4b..61122fb0c2 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 @@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.Careportal.Dialogs; import android.app.Activity; import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; @@ -50,11 +49,8 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; -import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.queue.Callback; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.HardLimits; @@ -348,7 +344,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick editTimeshift = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_timeshift); editTimeshift.setParams(0d, (double) Constants.CPP_MIN_TIMESHIFT, (double) Constants.CPP_MAX_TIMESHIFT, 1d, new DecimalFormat("0"), false); - ProfileSwitch ps = MainApp.getConfigBuilder().getProfileSwitchFromHistory(DateUtil.now()); + ProfileSwitch ps = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now()); if (ps != null && ps.isCPP) { final int percentage = ps.percentage; final int timeshift = ps.timeshift; @@ -740,12 +736,12 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSwitch.isCPP = percentage != 100 || timeshift != 0; profileSwitch.timeshift = timeshift; profileSwitch.percentage = percentage; - MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch); + TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); } public static void doProfileSwitch(final int duration, final int percentage, final int timeshift) { - ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); + ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); if (profileSwitch != null) { profileSwitch = new ProfileSwitch(); profileSwitch.date = System.currentTimeMillis(); @@ -757,7 +753,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSwitch.isCPP = percentage != 100 || timeshift != 0; profileSwitch.timeshift = timeshift; profileSwitch.percentage = percentage; - MainApp.getConfigBuilder().addToHistoryProfileSwitch(profileSwitch); + TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch); FabricPrivacy.getInstance().logCustom(new CustomEvent("ProfileSwitch")); } else { log.error("No profile switch existing"); 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 c67562b5a1..c1c33f91b8 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 @@ -10,7 +10,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.List; import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; @@ -18,20 +17,13 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; -import info.nightscout.androidaps.data.Intervals; -import info.nightscout.androidaps.data.IobTotal; -import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.ProfileIntervals; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventAppInitialized; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventProfileSwitchChange; @@ -50,8 +42,6 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; -import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; -import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.queue.Callback; @@ -64,7 +54,7 @@ import info.nightscout.utils.ToastUtils; /** * Created by mike on 05.08.2016. */ -public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterface { +public class ConfigBuilderPlugin extends PluginBase { private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class); private static ConfigBuilderPlugin configBuilderPlugin; @@ -459,7 +449,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa log.debug("applyAPSRequest: " + request.toString()); long now = System.currentTimeMillis(); - TemporaryBasal activeTemp = getTempBasalFromHistory(now); + TemporaryBasal activeTemp = activeTreatments.getTempBasalFromHistory(now); if ((request.rate == 0 && request.duration == 0) || Math.abs(request.rate - pump.getBaseBasalRate()) < pump.getPumpDescription().basalStep) { if (activeTemp != null) { if (Config.logCongigBuilderActions) @@ -496,7 +486,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa return; } - long lastBolusTime = getLastBolusTime(); + long lastBolusTime = activeTreatments.getLastBolusTime(); if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) { log.debug("SMB requested but still in 3 min interval"); if (callback != null) { @@ -540,175 +530,6 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa getCommandQueue().bolus(detailedBolusInfo, callback); } - // ****** Treatments interface ***** - @Override - public void updateTotalIOBTreatments() { - activeTreatments.updateTotalIOBTreatments(); - } - - @Override - public void updateTotalIOBTempBasals() { - activeTreatments.updateTotalIOBTempBasals(); - } - - @Override - public IobTotal getLastCalculationTreatments() { - return activeTreatments.getLastCalculationTreatments(); - } - - @Override - public IobTotal getCalculationToTimeTreatments(long time) { - return activeTreatments.getCalculationToTimeTreatments(time); - } - - @Override - public IobTotal getLastCalculationTempBasals() { - return activeTreatments.getLastCalculationTempBasals(); - } - - @Override - public IobTotal getCalculationToTimeTempBasals(long time) { - return activeTreatments.getCalculationToTimeTempBasals(time); - } - - @Override - public MealData getMealData() { - return activeTreatments.getMealData(); - } - - @Override - public List getTreatmentsFromHistory() { - return activeTreatments.getTreatmentsFromHistory(); - } - - @Override - public List getTreatments5MinBackFromHistory(long time) { - return activeTreatments.getTreatments5MinBackFromHistory(time); - } - - @Override - public long getLastBolusTime() { - return activeTreatments.getLastBolusTime(); - } - - @Override - public boolean isInHistoryRealTempBasalInProgress() { - return activeTreatments.isInHistoryRealTempBasalInProgress(); - } - - @Override - @Nullable - public TemporaryBasal getRealTempBasalFromHistory(long time) { - return activeTreatments.getRealTempBasalFromHistory(time); - } - - @Override - public boolean isTempBasalInProgress() { - return activeTreatments != null && activeTreatments.isTempBasalInProgress(); - } - - @Override - @Nullable - public TemporaryBasal getTempBasalFromHistory(long time) { - return activeTreatments != null ? activeTreatments.getTempBasalFromHistory(time) : null; - } - - @Override - public Intervals getTemporaryBasalsFromHistory() { - return activeTreatments.getTemporaryBasalsFromHistory(); - } - - @Override - public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) { - boolean newRecordCreated = activeTreatments.addToHistoryTempBasal(tempBasal); - if (newRecordCreated) { - if (tempBasal.durationInMinutes == 0) - NSUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId); - else if (tempBasal.isAbsolute) - NSUpload.uploadTempBasalStartAbsolute(tempBasal, null); - else - NSUpload.uploadTempBasalStartPercent(tempBasal); - } - return newRecordCreated; - } - - @Override - public boolean isInHistoryExtendedBoluslInProgress() { - return activeTreatments.isInHistoryExtendedBoluslInProgress(); - } - - @Override - @Nullable - public ExtendedBolus getExtendedBolusFromHistory(long time) { - return activeTreatments.getExtendedBolusFromHistory(time); - } - - @Override - public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) { - boolean newRecordCreated = activeTreatments.addToHistoryExtendedBolus(extendedBolus); - if (newRecordCreated) { - if (extendedBolus.durationInMinutes == 0) { - if (activePump.isFakingTempsByExtendedBoluses()) - NSUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId); - else - NSUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId); - } else if (activePump.isFakingTempsByExtendedBoluses()) - NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin); - else - NSUpload.uploadExtendedBolus(extendedBolus); - } - return newRecordCreated; - } - - @Override - public Intervals getExtendedBolusesFromHistory() { - return activeTreatments.getExtendedBolusesFromHistory(); - } - - @Override - // return true if new record is created - public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo) { - boolean newRecordCreated = activeTreatments.addToHistoryTreatment(detailedBolusInfo); - if (newRecordCreated && detailedBolusInfo.isValid) - NSUpload.uploadBolusWizardRecord(detailedBolusInfo); - return newRecordCreated; - } - - @Override - @Nullable - public TempTarget getTempTargetFromHistory() { - return activeTreatments.getTempTargetFromHistory(System.currentTimeMillis()); - } - - @Override - @Nullable - public TempTarget getTempTargetFromHistory(long time) { - return activeTreatments.getTempTargetFromHistory(time); - } - - @Override - public Intervals getTempTargetsFromHistory() { - return activeTreatments.getTempTargetsFromHistory(); - } - - @Override - @Nullable - public ProfileSwitch getProfileSwitchFromHistory(long time) { - return activeTreatments.getProfileSwitchFromHistory(time); - } - - @Override - public ProfileIntervals getProfileSwitchesFromHistory() { - return activeTreatments.getProfileSwitchesFromHistory(); - } - - @Override - public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) { - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING)); - activeTreatments.addToHistoryProfileSwitch(profileSwitch); - NSUpload.uploadProfileSwitch(profileSwitch); - } - @Subscribe public void onProfileSwitch(EventProfileSwitchChange ignored) { getCommandQueue().setProfile(getProfile(), new Callback() { @@ -727,11 +548,6 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa }); } - @Override - public long oldestDataAvailable() { - return activeTreatments.oldestDataAvailable(); - } - public String getProfileName() { return getProfileName(System.currentTimeMillis()); } @@ -745,7 +561,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa } public String getProfileName(long time, boolean customized) { - ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); + ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); if (profileSwitch != null) { if (profileSwitch.profileJson != null) { return customized ? profileSwitch.getCustomizedName() : profileSwitch.profileName; @@ -782,7 +598,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa return null; //app not initialized } //log.debug("Profile for: " + new Date(time).toLocaleString() + " : " + getProfileName(time)); - ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); + ProfileSwitch profileSwitch = activeTreatments.getProfileSwitchFromHistory(time); if (profileSwitch != null) { if (profileSwitch.profileJson != null) { return profileSwitch.getProfileObject(); @@ -792,12 +608,12 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa return profile; } } - if (getProfileSwitchesFromHistory().size() > 0) { + if (activeTreatments.getProfileSwitchesFromHistory().size() > 0) { FabricPrivacy.getInstance().logCustom(new CustomEvent("CatchedError") .putCustomAttribute("buildversion", BuildConfig.BUILDVERSION) .putCustomAttribute("version", BuildConfig.VERSION) .putCustomAttribute("time", time) - .putCustomAttribute("getProfileSwitchesFromHistory", getProfileSwitchesFromHistory().toString()) + .putCustomAttribute("getProfileSwitchesFromHistory", activeTreatments.getProfileSwitchesFromHistory().toString()) ); } log.debug("getProfile at the end: returning null"); @@ -814,7 +630,7 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa } } }); - if (getActivePump().getPumpDescription().isExtendedBolusCapable && isInHistoryExtendedBoluslInProgress()) { + if (getActivePump().getPumpDescription().isExtendedBolusCapable && activeTreatments.isInHistoryExtendedBoluslInProgress()) { getCommandQueue().cancelExtended(new Callback() { @Override public void run() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 291b06372f..5a899bebe5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.SP; @@ -130,7 +131,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS)) apsEnabled = true; - boolean profileSwitchExists = MainApp.getConfigBuilder().getProfileSwitchFromHistory(DateUtil.now()) != null; + boolean profileSwitchExists = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now()) != null; return new RequirementResult(hasBGData && bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && apsEnabled && vpUploadNeeded && profileSwitchExists, MainApp.gs(R.string.objectives_bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS) 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 fe2b834d6a..06c7738df0 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 @@ -34,6 +34,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; /** @@ -286,7 +287,7 @@ public class IobCobCalculatorPlugin extends PluginBase { public long oldestDataAvailable() { long now = System.currentTimeMillis(); - long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); + long oldestDataAvailable = TreatmentsPlugin.getPlugin().oldestDataAvailable(); long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - 60 * 60 * 1000L * (24 + MainApp.getConfigBuilder().getProfile().getDia()))); log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); return getBGDataFrom; @@ -307,8 +308,8 @@ public class IobCobCalculatorPlugin extends PluginBase { } else { //log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString()); } - IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round(); - IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time).round(); if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) { // Add expected zere temp basal for next 240 mins IobTotal basalIobWithZeroTemp = basalIob.copy(); @@ -349,7 +350,7 @@ public class IobCobCalculatorPlugin extends PluginBase { if (retval == null) { retval = new BasalData(); Profile profile = MainApp.getConfigBuilder().getProfile(time); - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(time); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(time); retval.basal = profile.getBasal(time); if (tb != null) { retval.isTempBasalRunning = true; 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 5da63ad2f7..da7d0fbbbd 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 @@ -4,7 +4,6 @@ import android.content.Context; import android.os.PowerManager; import android.support.v4.util.LongSparseArray; -import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.CustomEvent; import org.slf4j.Logger; @@ -24,7 +23,7 @@ import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; -import info.nightscout.androidaps.queue.QueueThread; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.FabricPrivacy; @@ -33,7 +32,7 @@ import info.nightscout.utils.FabricPrivacy; */ public class IobCobThread extends Thread { - private static Logger log = LoggerFactory.getLogger(QueueThread.class); + private static Logger log = LoggerFactory.getLogger(IobCobThread.class); private final Event cause; private IobCobCalculatorPlugin iobCobCalculatorPlugin; @@ -145,8 +144,8 @@ public class IobCobThread extends Thread { double deviation = delta - bgi; double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; - double slopeFromMaxDeviation = 0; - double slopeFromMinDeviation = 999; + double slopeFromMaxDeviation = 0; + double slopeFromMinDeviation = 999; double maxDeviation = 0; double minDeviation = 999; @@ -188,7 +187,7 @@ public class IobCobThread extends Thread { } } - List recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBackFromHistory(bgTime); + List recentTreatments = TreatmentsPlugin.getPlugin().getTreatments5MinBackFromHistory(bgTime); for (int ir = 0; ir < recentTreatments.size(); ir++) { autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; autosensData.activeCarbsList.add(new AutosensData.CarbsInPast(recentTreatments.get(ir))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 0c92df635c..96e004d996 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugi import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.SP; public class DetermineBasalAdapterAMAJS { @@ -220,7 +221,7 @@ public class DetermineBasalAdapterAMAJS { } long now = System.currentTimeMillis(); - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); mCurrentTemp = new JSONObject(); mCurrentTemp.put("temp", "absolute"); @@ -228,7 +229,7 @@ public class DetermineBasalAdapterAMAJS { mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d); // as we have non default temps longer than 30 mintues - TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal tempBasal = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (tempBasal != null) { mCurrentTemp.put("minutesrunning", tempBasal.getRealDuration()); } @@ -255,14 +256,14 @@ public class DetermineBasalAdapterAMAJS { mAutosensData = new JSONObject(); mAutosensData.put("ratio", autosensDataRatio); } else { - mAutosensData = null; + mAutosensData = null; } } public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) { - if(jsonObject == null) return Undefined.instance; + if (jsonObject == null) return Undefined.instance; Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() { @Override @@ -274,8 +275,8 @@ public class DetermineBasalAdapterAMAJS { } public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) { - //Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() { - Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() { + //Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() { + Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() { @Override public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) { return objects[1]; 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 4f7edc7559..d9ffc67830 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 @@ -28,6 +28,7 @@ import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; @@ -139,7 +140,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { Profiler.log(log, "calculateIobArrayInDia()", startPart); startPart = new Date(); - MealData mealData = MainApp.getConfigBuilder().getMealData(); + MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); Profiler.log(log, "getMealData()", startPart); double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); @@ -149,7 +150,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { targetBg = HardLimits.verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); boolean isTempTarget = false; - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { isTempTarget = true; minBg = HardLimits.verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); @@ -193,12 +194,12 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke(); Profiler.log(log, "AMA calculation", start); // Fix bug determine basal - if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) + if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress()) determineBasalResultAMA.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { long now = System.currentTimeMillis(); - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultAMA.rate == 0 && determineBasalResultAMA.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultAMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index 1ffa682fc5..a56636385d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -18,13 +18,13 @@ import java.lang.reflect.InvocationTargetException; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.plugins.Loop.ScriptReader; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.SP; public class DetermineBasalAdapterMAJS { @@ -181,7 +181,7 @@ public class DetermineBasalAdapterMAJS { } long now = System.currentTimeMillis(); - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); mCurrentTemp = new JSONObject(); mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0); 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 c8372641b1..0d9895bad7 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 @@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; @@ -135,14 +136,14 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { maxBg = Round.roundTo(maxBg, 0.1d); Date start = new Date(); - MainApp.getConfigBuilder().updateTotalIOBTreatments(); - MainApp.getConfigBuilder().updateTotalIOBTempBasals(); - IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments(); - IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals(); + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals(); IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round(); - MealData mealData = MainApp.getConfigBuilder().getMealData(); + MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); Profiler.log(log, "MA data gathering", start); @@ -151,7 +152,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); maxBg = verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]); @@ -182,11 +183,11 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke(); // Fix bug determinef basal - if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) + if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress()) determineBasalResultMA.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java index 12c3122a76..89bf8431f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java @@ -27,10 +27,10 @@ import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.LoggerCallback; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; @@ -244,7 +244,8 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("maxCOB", SMBDefaults.maxCOB); mProfile.put("skip_neutral_temps", SMBDefaults.skip_neutral_temps); //TODO: align with max-absorption model in AMA sensitivity - mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact));; + mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + ; mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); @@ -266,7 +267,7 @@ public class DetermineBasalAdapterSMBJS { long now = System.currentTimeMillis(); - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); mCurrentTemp = new JSONObject(); mCurrentTemp.put("temp", "absolute"); @@ -274,7 +275,7 @@ public class DetermineBasalAdapterSMBJS { mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d); // as we have non default temps longer than 30 mintues - TemporaryBasal tempBasal = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal tempBasal = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (tempBasal != null) { mCurrentTemp.put("minutesrunning", tempBasal.getRealDuration()); } 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 8fe5f0a673..f30338d024 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 @@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.HardLimits; import info.nightscout.utils.NSUpload; @@ -146,7 +147,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { Profiler.log(log, "calculateIobArrayInDia()", startPart); startPart = new Date(); - MealData mealData = MainApp.getConfigBuilder().getMealData(); + MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); Profiler.log(log, "getMealData()", startPart); double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); @@ -156,7 +157,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]); boolean isTempTarget = false; - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(System.currentTimeMillis()); + TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis()); if (tempTarget != null) { isTempTarget = true; minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]); @@ -213,11 +214,11 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { Profiler.log(log, "SMB calculation", start); // TODO still needed with oref1? // Fix bug determine basal - if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !MainApp.getConfigBuilder().isTempBasalInProgress()) + if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress()) determineBasalResultSMB.tempBasalRequested = false; // limit requests on openloop mode if (!MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultSMB.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { 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 8c23c072cf..19119450df 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 @@ -45,6 +45,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.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -430,7 +431,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } }); } else { - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } } } 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 8b4d74ebba..ce19009cf8 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 @@ -29,7 +29,6 @@ import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DecimalFormat; import java.util.Calendar; import java.util.Date; import java.util.LinkedList; @@ -45,6 +44,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.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -301,7 +301,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, detailedBolusInfo.date = eventTime.getTime(); detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; detailedBolusInfo.insulin = finalInsulinAfterConstraints; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } else { DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index 72776b58e9..f21ccac0e2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -33,6 +33,7 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NumberPicker; @@ -185,7 +186,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene } }); } else { - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } FabricPrivacy.getInstance().logCustom(new CustomEvent("Bolus")); } 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 d48b2ccf34..f44e570774 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 @@ -58,6 +58,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; @@ -255,7 +256,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { saveCheckedStates(); - ttCheckbox.setEnabled(bgCheckbox.isChecked() && MainApp.getConfigBuilder().getTempTargetFromHistory() != null); + ttCheckbox.setEnabled(bgCheckbox.isChecked() && TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null); calculateInsulin(); } @@ -377,7 +378,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } }); } else { - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } FabricPrivacy.getInstance().logCustom(new CustomEvent("Wizard")); } @@ -426,13 +427,13 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } else { editBg.setValue(0d); } - ttCheckbox.setEnabled(MainApp.getConfigBuilder().getTempTargetFromHistory() != null); + ttCheckbox.setEnabled(TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null); // IOB calculation - MainApp.getConfigBuilder().updateTotalIOBTreatments(); - IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); - MainApp.getConfigBuilder().updateTotalIOBTempBasals(); - IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U"); basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); @@ -457,7 +458,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com Double c_correction = SafeParse.stringToDouble(editCorr.getText()); Double corrAfterConstraint = c_correction; if (c_correction > 0) - c_correction = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(c_correction)).value(); + c_correction = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(c_correction)).value(); if (c_correction - corrAfterConstraint != 0) { // c_correction != corrAfterConstraint doesn't work editCorr.setValue(0d); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), getString(R.string.bolusconstraintapplied)); @@ -471,14 +472,14 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com } c_bg = bgCheckbox.isChecked() ? c_bg : 0d; - TempTarget tempTarget = ttCheckbox.isChecked() ? MainApp.getConfigBuilder().getTempTargetFromHistory() : null; + TempTarget tempTarget = ttCheckbox.isChecked() ? TreatmentsPlugin.getPlugin().getTempTargetFromHistory() : null; // COB Double c_cob = 0d; if (cobCheckbox.isChecked()) { AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Wizard COB"); - if(autosensData != null) { + if (autosensData != null) { c_cob = autosensData.cob; } } 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 e08dd6ba0d..38498f5eaf 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 @@ -84,10 +84,10 @@ import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTreatmentChange; +import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; @@ -114,6 +114,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; @@ -188,7 +189,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Object updateSync = new Object(); - public enum CHARTTYPE {PRE, BAS, IOB, COB, DEV, SEN}; + public enum CHARTTYPE {PRE, BAS, IOB, COB, DEV, SEN} + + ; private static final ScheduledExecutorService worker = Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture scheduledUpdate = null; @@ -709,7 +712,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, void onClickQuickwizard() { final BgReading actualBg = DatabaseHelper.actualBg(); final Profile profile = MainApp.getConfigBuilder().getProfile(); - final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); + final TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && actualBg != null && profile != null) { @@ -1072,7 +1075,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // temp target - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); + TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); if (tempTarget != null) { tempTargetView.setTextColor(Color.BLACK); tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetBackground)); @@ -1121,7 +1124,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } } - final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); String basalText = ""; if (shorttextmode) { if (activeTemp != null) { @@ -1159,7 +1162,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, baseBasalView.setText(basalText); - final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + final ExtendedBolus extendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); String extendedBolusText = ""; if (extendedBolusView != null) { // must not exists in all layouts if (shorttextmode) { @@ -1265,10 +1268,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, timeAgoView.setText(DateUtil.minAgo(lastBG.date)); // iob - MainApp.getConfigBuilder().updateTotalIOBTreatments(); - MainApp.getConfigBuilder().updateTotalIOBTempBasals(); - final IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); - final IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + final IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); + final IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); if (shorttextmode) { String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"; 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 47e256f42d..7d1cd07b69 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 @@ -26,8 +26,8 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.BasalData; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.graphExtensions.AreaGraphSeries; @@ -242,7 +242,7 @@ public class GraphData { TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time); double value; if (tt == null) { - value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2; + value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2; } else { value = tt.target(); value = Profile.fromMgdlToUnits(value, profile.getUnits()); @@ -268,7 +268,7 @@ public class GraphData { public void addTreatments(long fromTime, long endTime) { List filteredTreatments = new ArrayList<>(); - List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); + List treatments = TreatmentsPlugin.getPlugin().getTreatmentsFromHistory(); for (int tx = 0; tx < treatments.size(); tx++) { Treatment t = treatments.get(tx); @@ -278,7 +278,7 @@ public class GraphData { } // ProfileSwitch - List profileSwitches = MainApp.getConfigBuilder().getProfileSwitchesFromHistory().getList(); + List profileSwitches = TreatmentsPlugin.getPlugin().getProfileSwitchesFromHistory().getList(); for (int tx = 0; tx < profileSwitches.size(); tx++) { DataPointWithLabelInterface t = profileSwitches.get(tx); @@ -288,7 +288,7 @@ public class GraphData { // Extended bolus if (!ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) { - List extendedBoluses = MainApp.getConfigBuilder().getExtendedBolusesFromHistory().getList(); + List extendedBoluses = TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory().getList(); for (int tx = 0; tx < extendedBoluses.size(); tx++) { DataPointWithLabelInterface t = extendedBoluses.get(tx); @@ -556,15 +556,15 @@ public class GraphData { public void performUpdate() { // clear old data graph.getSeries().clear(); - + // add precalculated series - for (Series s: series) { + for (Series s : series) { if (!s.isEmpty()) { s.onGraphViewAttached(graph); graph.getSeries().add(s); } } - + // draw it graph.onDataChanged(false, false); } 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 60c18d6018..5b940c0dbe 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 @@ -32,6 +32,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.Treatments.TreatmentsPlugin; import info.nightscout.utils.DecimalFormatter; /** @@ -94,16 +95,16 @@ public class PersistentNotificationPlugin extends PluginBase { } } - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { line1 += " " + activeTemp.toStringShort(); } //IOB - MainApp.getConfigBuilder().updateTotalIOBTreatments(); - MainApp.getConfigBuilder().updateTotalIOBTempBasals(); - IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); - IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" + ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " 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 d60279d648..43d855dab1 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 @@ -56,6 +56,7 @@ import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistoryRequest; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Tdd; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.CommandQueue; import info.nightscout.utils.DateUtil; @@ -462,7 +463,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return deliverBolus(detailedBolusInfo); } else { // no bolus required, carb only treatment - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.getInstance(); bolusingEvent.t = new Treatment(); @@ -651,7 +652,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = lastPumpBolus.amount; try { - boolean treatmentCreated = MainApp.getConfigBuilder().addToHistoryTreatment(dbi); + boolean treatmentCreated = TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi); if (!treatmentCreated) { log.error("Adding treatment record overrode an existing record: " + dbi); if (dbi.isSMB) { @@ -762,7 +763,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .duration(state.tbrRemainingDuration) .percent(state.tbrPercent) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempStart); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStart); MainApp.bus().post(new EventComboPumpUpdateGUI()); } @@ -788,7 +789,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint @Override public PumpEnactResult cancelTempBasal(boolean enforceNew) { log.debug("cancelTempBasal called"); - final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (enforceNew) { CommandResult stateResult = runCommand(MainApp.gs(R.string.combo_pump_action_refreshing), 2, ruffyScripter::readPumpState); if (!stateResult.success) { @@ -807,7 +808,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .date(cancelResult.state.timestamp) .duration(0) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); return new PumpEnactResult().isTempCancel(true).success(true).enacted(true); } else { return new PumpEnactResult().success(false).enacted(false); @@ -945,7 +946,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } } else { long now = System.currentTimeMillis(); - TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal aapsTbr = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (aapsTbr == null || aapsTbr.percentRate != 0) { log.debug("Creating 15m zero temp since pump is suspended"); TemporaryBasal newTempBasal = new TemporaryBasal() @@ -953,7 +954,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .percent(0) .duration(15) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal); } } @@ -1071,7 +1072,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint private void checkAndResolveTbrMismatch(PumpState state) { // compare with: info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgStatusTempBasal.updateTempBasalInDB() long now = System.currentTimeMillis(); - TemporaryBasal aapsTbr = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal aapsTbr = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (aapsTbr == null && state.tbrActive && state.tbrRemainingDuration > 2) { log.debug("Creating temp basal from pump TBR"); FabricPrivacy.getInstance().logCustom(new CustomEvent("ComboTbrMismatch") @@ -1083,7 +1084,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .percent(state.tbrPercent) .duration(state.tbrRemainingDuration) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal); } else if (aapsTbr != null && aapsTbr.getPlannedRemainingMinutes() > 2 && !state.tbrActive) { log.debug("Ending AAPS-TBR since pump has no TBR active"); FabricPrivacy.getInstance().logCustom(new CustomEvent("ComboTbrMismatch") @@ -1094,7 +1095,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .date(now) .duration(0) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); } else if (aapsTbr != null && state.tbrActive && (aapsTbr.percentRate != state.tbrPercent || Math.abs(aapsTbr.getPlannedRemainingMinutes() - state.tbrRemainingDuration) > 2)) { @@ -1107,14 +1108,14 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .date(now - 1000) .duration(0) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); TemporaryBasal newTempBasal = new TemporaryBasal() .date(now) .percent(state.tbrPercent) .duration(state.tbrRemainingDuration) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(newTempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal); } } @@ -1150,7 +1151,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; dbi.eventType = CareportalEvent.CORRECTIONBOLUS; - if (MainApp.getConfigBuilder().addToHistoryTreatment(dbi)) { + if (TreatmentsPlugin.getPlugin().addToHistoryTreatment(dbi)) { updated = true; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 07c4655de7..fc57e72e01 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -32,6 +32,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaR.services.AbstractDanaRExecutionService; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; @@ -172,7 +173,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; long now = System.currentTimeMillis(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; @@ -214,7 +215,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); PumpEnactResult result = new PumpEnactResult(); - ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { result.enacted = false; result.success = true; @@ -252,7 +253,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte @Override public PumpEnactResult cancelExtendedBolus() { PumpEnactResult result = new PumpEnactResult(); - ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (runningEB != null) { sExecutionService.extendedBolusStop(); result.enacted = true; @@ -326,13 +327,13 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", pump.lastBolusAmount); } - TemporaryBasal tb = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } - ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); @@ -434,11 +435,11 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte if (pump.lastBolusTime.getTime() != 0) { ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; } - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { ret += "Temp: " + activeTemp.toStringFull() + "\n"; } - ExtendedBolus activeExtendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (activeExtendedBolus != null) { ret += "Extended: " + activeExtendedBolus.toString() + "\n"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 92245a125b..7ef3d6a987 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -14,7 +14,6 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; - import com.squareup.otto.Subscribe; import org.slf4j.Logger; @@ -25,6 +24,7 @@ import butterknife.ButterKnife; import butterknife.OnClick; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.TDDStatsActivity; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; @@ -33,8 +33,8 @@ import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRHistoryActivity; -import info.nightscout.androidaps.TDDStatsActivity; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.events.EventQueueChanged; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -53,24 +53,41 @@ public class DanaRFragment extends SubscriberFragment { } }; - @BindView(R.id.danar_lastconnection) TextView lastConnectionView; - @BindView(R.id.danar_btconnection) TextView btConnectionView; - @BindView(R.id.danar_lastbolus) TextView lastBolusView; - @BindView(R.id.danar_dailyunits) TextView dailyUnitsView; - @BindView(R.id.danar_basabasalrate) TextView basaBasalRateView; - @BindView(R.id.danar_tempbasal) TextView tempBasalView; - @BindView(R.id.danar_extendedbolus) TextView extendedBolusView; - @BindView(R.id.danar_battery) TextView batteryView; - @BindView(R.id.danar_reservoir) TextView reservoirView; - @BindView(R.id.danar_iob) TextView iobView; - @BindView(R.id.danar_firmware) TextView firmwareView; - @BindView(R.id.danar_basalstep) TextView basalStepView; - @BindView(R.id.danar_bolusstep) TextView bolusStepView; - @BindView(R.id.danar_serialnumber) TextView serialNumberView; - @BindView(R.id.danar_queue) TextView queueView; + @BindView(R.id.danar_lastconnection) + TextView lastConnectionView; + @BindView(R.id.danar_btconnection) + TextView btConnectionView; + @BindView(R.id.danar_lastbolus) + TextView lastBolusView; + @BindView(R.id.danar_dailyunits) + TextView dailyUnitsView; + @BindView(R.id.danar_basabasalrate) + TextView basaBasalRateView; + @BindView(R.id.danar_tempbasal) + TextView tempBasalView; + @BindView(R.id.danar_extendedbolus) + TextView extendedBolusView; + @BindView(R.id.danar_battery) + TextView batteryView; + @BindView(R.id.danar_reservoir) + TextView reservoirView; + @BindView(R.id.danar_iob) + TextView iobView; + @BindView(R.id.danar_firmware) + TextView firmwareView; + @BindView(R.id.danar_basalstep) + TextView basalStepView; + @BindView(R.id.danar_bolusstep) + TextView bolusStepView; + @BindView(R.id.danar_serialnumber) + TextView serialNumberView; + @BindView(R.id.danar_queue) + TextView queueView; - @BindView(R.id.overview_pumpstatuslayout) LinearLayout pumpStatusLayout; - @BindView(R.id.overview_pumpstatus) TextView pumpStatusView; + @BindView(R.id.overview_pumpstatuslayout) + LinearLayout pumpStatusLayout; + @BindView(R.id.overview_pumpstatus) + TextView pumpStatusView; public DanaRFragment() { } @@ -104,21 +121,25 @@ public class DanaRFragment extends SubscriberFragment { return null; } - @OnClick(R.id.danar_history) void onHistoryClick() { + @OnClick(R.id.danar_history) + void onHistoryClick() { startActivity(new Intent(getContext(), DanaRHistoryActivity.class)); } - @OnClick(R.id.danar_viewprofile) void onViewProfileClick() { + @OnClick(R.id.danar_viewprofile) + void onViewProfileClick() { FragmentManager manager = getFragmentManager(); ProfileViewDialog profileViewDialog = new ProfileViewDialog(); profileViewDialog.show(manager, "ProfileViewDialog"); } - @OnClick(R.id.danar_stats) void onStatsClick() { + @OnClick(R.id.danar_stats) + void onStatsClick() { startActivity(new Intent(getContext(), TDDStatsActivity.class)); } - @OnClick(R.id.danar_btconnection) void onBtConnectionClick() { + @OnClick(R.id.danar_btconnection) + void onBtConnectionClick() { log.debug("Clicked connect to pump"); DanaRPump.getInstance().lastConnection = 0; ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null); @@ -201,20 +222,20 @@ public class DanaRFragment extends SubscriberFragment { basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h"); // DanaRPlugin, DanaRKoreanPlugin if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) { - if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); + if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) { + tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); } else { tempBasalView.setText(""); } } else { // v2 plugin - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { + tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); } else { tempBasalView.setText(""); } } - ExtendedBolus activeExtendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (activeExtendedBolus != null) { extendedBolusView.setText(activeExtendedBolus.toString()); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index f90d529987..369ab95292 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -25,6 +25,7 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -79,7 +80,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { Intent intent = new Intent(context, DanaRExecutionService.class); context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); MainApp.bus().register(this); - } + } @Override protected void onStop() { @@ -115,7 +116,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { boolean previousValue = useExtendedBoluses; useExtendedBoluses = SP.getBoolean("danar_useextended", false); - if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { sExecutionService.extendedBolusStop(); } } @@ -150,7 +151,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin { Treatment t = new Treatment(); t.isSMB = detailedBolusInfo.isSMB; boolean connectionOK = false; - if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); + if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) + connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); PumpEnactResult result = new PumpEnactResult(); result.success = connectionOK; result.bolusDelivered = t.insulin; @@ -160,7 +162,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.date = System.currentTimeMillis(); - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); return result; } else { PumpEnactResult result = new PumpEnactResult(); @@ -192,8 +194,8 @@ public class DanaRPlugin extends AbstractDanaRPlugin { final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses; long now = System.currentTimeMillis(); - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now); - ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); + ExtendedBolus activeExtended = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (doTempOff) { // If extended in progress @@ -328,9 +330,9 @@ public class DanaRPlugin extends AbstractDanaRPlugin { @Override public PumpEnactResult cancelTempBasal(boolean force) { - if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) + if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { return cancelExtendedBolus(); } PumpEnactResult result = new PumpEnactResult(); @@ -343,7 +345,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { public PumpEnactResult cancelRealTempBasal() { PumpEnactResult result = new PumpEnactResult(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (runningTB != null) { sExecutionService.tempBasalStop(); result.enacted = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java index c97340f44b..048cc35e6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java @@ -8,11 +8,11 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; public class MsgStatusBolusExtended extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgStatusBolusExtended.class); @@ -65,7 +65,7 @@ public class MsgStatusBolusExtended extends MessageBase { } public static void updateExtendedBolusInDB() { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); + TreatmentsInterface treatmentsInterface = TreatmentsPlugin.getPlugin(); DanaRPump pump = DanaRPump.getInstance(); long now = System.currentTimeMillis(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java index f47ad0d924..48e88897e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasal.java @@ -8,11 +8,10 @@ import org.slf4j.LoggerFactory; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; public class MsgStatusTempBasal extends MessageBase { private static Logger log = LoggerFactory.getLogger(MsgStatusTempBasal.class); @@ -59,29 +58,28 @@ public class MsgStatusTempBasal extends MessageBase { } public static void updateTempBasalInDB() { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRPump danaRPump = DanaRPump.getInstance(); long now = System.currentTimeMillis(); - if (treatmentsInterface.isInHistoryRealTempBasalInProgress()) { - TemporaryBasal tempBasal = treatmentsInterface.getRealTempBasalFromHistory(System.currentTimeMillis()); + if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) { + TemporaryBasal tempBasal = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()); if (danaRPump.isTempBasalInProgress) { if (tempBasal.percentRate != danaRPump.tempBasalPercent) { // Close current temp basal TemporaryBasal tempStop = new TemporaryBasal().date(danaRPump.tempBasalStart.getTime() - 1000).source(Source.USER); - treatmentsInterface.addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); // Create new TemporaryBasal newTempBasal = new TemporaryBasal() .date(danaRPump.tempBasalStart.getTime()) .percent(danaRPump.tempBasalPercent) .duration(danaRPump.tempBasalTotalSec / 60) .source(Source.USER); - treatmentsInterface.addToHistoryTempBasal(newTempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal); } } else { // Close current temp basal TemporaryBasal tempStop = new TemporaryBasal().date(now).source(Source.USER); - treatmentsInterface.addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); } } else { if (danaRPump.isTempBasalInProgress) { @@ -91,7 +89,7 @@ public class MsgStatusTempBasal extends MessageBase { .percent(danaRPump.tempBasalPercent) .duration(danaRPump.tempBasalTotalSec / 60) .source(Source.USER); - treatmentsInterface.addToHistoryTempBasal(newTempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 44a805fadf..e46e73fdcf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -26,8 +26,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; -import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -118,7 +117,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { boolean previousValue = useExtendedBoluses; useExtendedBoluses = SP.getBoolean("danar_useextended", false); - if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { sExecutionService.extendedBolusStop(); } } @@ -164,7 +163,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { log.debug("deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered); detailedBolusInfo.insulin = t.insulin; detailedBolusInfo.date = System.currentTimeMillis(); - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); return result; } else { PumpEnactResult result = new PumpEnactResult(); @@ -196,8 +195,8 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { final boolean doExtendedTemp = absoluteRate > getBaseBasalRate() && useExtendedBoluses; long now = System.currentTimeMillis(); - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now); - ExtendedBolus activeExtended = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); + ExtendedBolus activeExtended = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (doTempOff) { // If extended in progress @@ -332,9 +331,9 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { @Override public PumpEnactResult cancelTempBasal(boolean force) { - if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) + if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { return cancelExtendedBolus(); } PumpEnactResult result = new PumpEnactResult(); @@ -347,7 +346,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { public PumpEnactResult cancelRealTempBasal() { PumpEnactResult result = new PumpEnactResult(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (runningTB != null) { sExecutionService.tempBasalStop(); result.enacted = true; 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 af7ee06800..5a29c5e9f4 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 @@ -47,6 +47,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.Round; @@ -426,7 +427,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (doTempOff) { // If temp in progress - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); return cancelTempBasal(false); @@ -448,7 +449,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (percentRate > 500) // Special high temp 500/15min percentRate = 500; // Check if some temp is already in progress - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: currently running: " + activeTemp.toString()); @@ -502,7 +503,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; long now = System.currentTimeMillis(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; @@ -570,7 +571,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte int durationInHalfHours = Math.max(durationInMinutes / 30, 1); insulin = Round.roundTo(insulin, getPumpDescription().extendedBolusStep); PumpEnactResult result = new PumpEnactResult(); - ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (runningEB != null && Math.abs(runningEB.insulin - insulin) < getPumpDescription().extendedBolusStep) { result.enacted = false; result.success = true; @@ -607,7 +608,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte @Override public synchronized PumpEnactResult cancelTempBasal(boolean force) { PumpEnactResult result = new PumpEnactResult(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (runningTB != null) { danaRSService.tempBasalStop(); result.enacted = true; @@ -632,7 +633,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte @Override public synchronized PumpEnactResult cancelExtendedBolus() { PumpEnactResult result = new PumpEnactResult(); - ExtendedBolus runningEB = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus runningEB = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (runningEB != null) { danaRSService.extendedBolusStop(); result.enacted = true; @@ -672,13 +673,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte extended.put("LastBolus", pump.lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", pump.lastBolusAmount); } - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } - ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); @@ -722,11 +723,11 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (pump.lastBolusTime.getTime() != 0) { ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n"; } - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { ret += "Temp: " + activeTemp.toStringFull() + "\n"; } - ExtendedBolus activeExtendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (activeExtendedBolus != null) { ret += "Extended: " + activeExtendedBolus.toString() + "\n"; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java index 91d4abb1fe..a707c5e0cc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/comm/DanaRS_Packet_APS_History_Events.java @@ -18,6 +18,7 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { @@ -110,36 +111,36 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min"); temporaryBasal.percentRate = param1; temporaryBasal.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); status = "TEMPSTART " + DateUtil.timeString(datetime); break; case DanaRPump.TEMPSTOP: log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString()); - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); status = "TEMPSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.EXTENDEDSTART: log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); extendedBolus.insulin = param1 / 100d; extendedBolus.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "EXTENDEDSTART " + DateUtil.timeString(datetime); break; case DanaRPump.EXTENDEDSTOP: log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "EXTENDEDSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.BOLUS: detailedBolusInfo.insulin = param1 / 100d; - boolean newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); DetailedBolusInfoStorage.remove(detailedBolusInfo.date); status = "BOLUS " + DateUtil.timeString(datetime); break; case DanaRPump.DUALBOLUS: detailedBolusInfo.insulin = param1 / 100d; - newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); DetailedBolusInfoStorage.remove(detailedBolusInfo.date); status = "DUALBOLUS " + DateUtil.timeString(datetime); @@ -148,12 +149,12 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); extendedBolus.insulin = param1 / 100d; extendedBolus.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime); break; case DanaRPump.DUALEXTENDEDSTOP: log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.SUSPENDON: @@ -182,7 +183,7 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet { emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.pumpId = datetime.getTime(); - newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(emptyCarbsInfo); + newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); status = "CARBS " + DateUtil.timeString(datetime); break; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 74edcac728..07b0c4fbb6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -23,9 +23,8 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; -import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; -import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -216,7 +215,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (doTempOff) { // If temp in progress - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); return cancelTempBasal(false); @@ -238,7 +237,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (percentRate > 500) // Special high temp 500/15min percentRate = 500; // Check if some temp is already in progress - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { // Correct basal already set ? if (activeTemp.percentRate == percentRate) { @@ -290,7 +289,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; long now = System.currentTimeMillis(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(now); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now); if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; @@ -354,7 +353,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { @Override public PumpEnactResult cancelTempBasal(boolean force) { PumpEnactResult result = new PumpEnactResult(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal runningTB = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (runningTB != null) { sExecutionService.tempBasalStop(); result.enacted = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java index 7663bd9f9e..ac31d2df92 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgHistoryEvents_v2.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; public class MsgHistoryEvents_v2 extends MessageBase { @@ -84,36 +85,36 @@ public class MsgHistoryEvents_v2 extends MessageBase { log.debug("EVENT TEMPSTART (" + recordCode + ") " + datetime.toLocaleString() + " Ratio: " + param1 + "% Duration: " + param2 + "min"); temporaryBasal.percentRate = param1; temporaryBasal.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); status = "TEMPSTART " + DateUtil.timeString(datetime); break; case DanaRPump.TEMPSTOP: log.debug("EVENT TEMPSTOP (" + recordCode + ") " + datetime.toLocaleString()); - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); status = "TEMPSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.EXTENDEDSTART: log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); extendedBolus.insulin = param1 / 100d; extendedBolus.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "EXTENDEDSTART " + DateUtil.timeString(datetime); break; case DanaRPump.EXTENDEDSTOP: log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "EXTENDEDSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.BOLUS: detailedBolusInfo.insulin = param1 / 100d; - boolean newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); DetailedBolusInfoStorage.remove(detailedBolusInfo.date); status = "BOLUS " + DateUtil.timeString(datetime); break; case DanaRPump.DUALBOLUS: detailedBolusInfo.insulin = param1 / 100d; - newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + datetime.toLocaleString() + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min"); DetailedBolusInfoStorage.remove(detailedBolusInfo.date); status = "DUALBOLUS " + DateUtil.timeString(datetime); @@ -122,12 +123,12 @@ public class MsgHistoryEvents_v2 extends MessageBase { log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + datetime.toLocaleString() + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min"); extendedBolus.insulin = param1 / 100d; extendedBolus.durationInMinutes = param2; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime); break; case DanaRPump.DUALEXTENDEDSTOP: log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + datetime.toLocaleString() + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min"); - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime); break; case DanaRPump.SUSPENDON: @@ -156,7 +157,7 @@ public class MsgHistoryEvents_v2 extends MessageBase { emptyCarbsInfo.date = datetime.getTime(); emptyCarbsInfo.source = Source.PUMP; emptyCarbsInfo.pumpId = datetime.getTime(); - newRecord = MainApp.getConfigBuilder().addToHistoryTreatment(emptyCarbsInfo); + newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo); log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + datetime.toLocaleString() + " Carbs: " + param1 + "g"); status = "CARBS " + DateUtil.timeString(datetime); break; 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 25338db4a8..26ee1088a4 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 @@ -44,6 +44,7 @@ import info.nightscout.androidaps.plugins.PumpInsight.history.HistoryReceiver; import info.nightscout.androidaps.plugins.PumpInsight.history.LiveHistory; import info.nightscout.androidaps.plugins.PumpInsight.utils.Helpers; import info.nightscout.androidaps.plugins.PumpInsight.utils.StatusItem; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; @@ -426,7 +427,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai bolusingEvent.bolusId = bolusId; bolusingEvent.percent = 0; MainApp.bus().post(bolusingEvent); - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } else { log.debug("Failure to deliver treatment"); } @@ -530,7 +531,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai .percent(percent_amount) .duration(durationInMinutes) .source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); } if (Config.logPumpComm) @@ -579,7 +580,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai .percent(percent) .duration(durationInMinutes) .source(Source.USER); // TODO check this is correct - MainApp.getConfigBuilder().addToHistoryTempBasal(tempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); } updateGui(); @@ -615,9 +616,9 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai // TODO isn't conditional on one apparently being in progress only the history change final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER); - MainApp.getConfigBuilder().addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); } lastDataTime = new Date(); updateGui(); @@ -659,7 +660,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai extendedBolus.durationInMinutes = durationInMinutes; extendedBolus.source = Source.USER; extendedBolus.pumpId = getRecordUniqueID(ms.getResponseID()); - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); } if (Config.logPumpComm) @@ -688,10 +689,10 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai final Mstatus ms = async.busyWaitForCommandResult(cmd, BUSY_WAIT_TIME); - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis()); exStop.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(exStop); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(exStop); } if (Config.logPumpComm) @@ -741,13 +742,13 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai extended.put("ActiveProfile", MainApp.getConfigBuilder().getProfileName()); } catch (Exception e) { } - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } - ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); @@ -847,9 +848,9 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai } - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { try { - l.add(new StatusItem(gs(R.string.pump_tempbasal_label), MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull())); + l.add(new StatusItem(gs(R.string.pump_tempbasal_label), TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull())); } catch (NullPointerException e) { // } @@ -865,10 +866,10 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai } } - if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { try { - l.add(new StatusItem(gs(R.string.virtualpump_extendedbolus_label), MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()).toString())); + l.add(new StatusItem(gs(R.string.virtualpump_extendedbolus_label), TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()).toString())); } catch (NullPointerException e) { // } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java index 6fc0152eb8..689eb9e981 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/history/HistoryLogAdapter.java @@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; /** * Created by jamorham on 27/01/2018. @@ -26,7 +27,7 @@ class HistoryLogAdapter { TemporaryBasal temporaryBasal = new TemporaryBasal().date(eventDate.getTime()); - final TemporaryBasal temporaryBasalFromHistory = MainApp.getConfigBuilder().getTempBasalFromHistory(eventDate.getTime()); + final TemporaryBasal temporaryBasalFromHistory = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(eventDate.getTime()); if (temporaryBasalFromHistory == null) { log("Create new TBR: " + eventDate + " " + percent + " " + duration); @@ -54,7 +55,7 @@ class HistoryLogAdapter { .percent(percent) .duration(duration); - MainApp.getConfigBuilder().addToHistoryTempBasal(temporaryBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal); } void createExtendedBolusRecord(Date eventDate, double insulin, int durationInMinutes, long record_id) { @@ -68,7 +69,7 @@ class HistoryLogAdapter { extendedBolus.source = Source.PUMP; extendedBolus.pumpId = record_id; - MainApp.getConfigBuilder().addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); } void createStandardBolusRecord(Date eventDate, double insulin, long record_id) { @@ -82,6 +83,6 @@ class HistoryLogAdapter { detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.pumpId = record_id; detailedBolusInfo.insulin = insulin; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index 0e12428967..9c19a383ae 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; /** @@ -134,7 +135,7 @@ public class MDIPlugin extends PluginBase implements PumpInterface { result.bolusDelivered = detailedBolusInfo.insulin; result.carbsDelivered = detailedBolusInfo.carbs; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); return result; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java index f367e8917e..f5007ca121 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpFragment.java @@ -10,18 +10,17 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.FabricPrivacy; public class VirtualPumpFragment extends SubscriberFragment { @@ -84,13 +83,13 @@ public class VirtualPumpFragment extends SubscriberFragment { public void run() { VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getPlugin(); basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U"); - TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { tempBasalView.setText(activeTemp.toStringFull()); } else { tempBasalView.setText(""); } - ExtendedBolus activeExtendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis()); if (activeExtendedBolus != null) { extendedBolusView.setText(activeExtendedBolus.toString()); } else { 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 d0bd8ebd0b..0491ce0f74 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 @@ -24,11 +24,11 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; @@ -224,7 +224,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { log.debug("Delivering treatment insulin: " + detailedBolusInfo.insulin + "U carbs: " + detailedBolusInfo.carbs + "g " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); lastDataTime = new Date(); - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); return result; } @@ -235,7 +235,6 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile, boolean enforceNew) { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); TemporaryBasal tempBasal = new TemporaryBasal() .date(System.currentTimeMillis()) .absolute(absoluteRate) @@ -248,7 +247,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { result.absolute = absoluteRate; result.duration = durationInMinutes; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - treatmentsInterface.addToHistoryTempBasal(tempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); if (Config.logPumpComm) log.debug("Setting temp basal absolute: " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); @@ -258,9 +257,8 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { result = cancelTempBasal(false); if (!result.success) return result; @@ -277,7 +275,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { result.isTempCancel = false; result.duration = durationInMinutes; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - treatmentsInterface.addToHistoryTempBasal(tempBasal); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempBasal); if (Config.logPumpComm) log.debug("Settings temp basal percent: " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); @@ -287,7 +285,6 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = cancelExtendedBolus(); if (!result.success) return result; @@ -302,7 +299,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { result.isTempCancel = false; result.duration = durationInMinutes; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - treatmentsInterface.addToHistoryExtendedBolus(extendedBolus); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus); if (Config.logPumpComm) log.debug("Setting extended bolus: " + result); MainApp.bus().post(new EventVirtualPumpUpdateGui()); @@ -312,15 +309,14 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public PumpEnactResult cancelTempBasal(boolean force) { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); result.success = true; result.isTempCancel = true; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - if (treatmentsInterface.isTempBasalInProgress()) { + if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { result.enacted = true; TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER); - treatmentsInterface.addToHistoryTempBasal(tempStop); + TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop); //tempBasal = null; if (Config.logPumpComm) log.debug("Canceling temp basal: " + result); @@ -332,12 +328,11 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override public PumpEnactResult cancelExtendedBolus() { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); - if (treatmentsInterface.isInHistoryExtendedBoluslInProgress()) { + if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { ExtendedBolus exStop = new ExtendedBolus(System.currentTimeMillis()); exStop.source = Source.USER; - treatmentsInterface.addToHistoryExtendedBolus(exStop); + TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(exStop); } result.success = true; result.enacted = true; @@ -368,13 +363,13 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { extended.put("ActiveProfile", profileName); } catch (Exception e) { } - TemporaryBasal tb = MainApp.getConfigBuilder().getTempBasalFromHistory(now); + TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); if (tb != null) { extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile)); extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date)); extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes()); } - ExtendedBolus eb = MainApp.getConfigBuilder().getExtendedBolusFromHistory(now); + ExtendedBolus eb = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(now); if (eb != null) { extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate()); extended.put("ExtendedBolusStart", DateUtil.dateAndTimeString(eb.date)); 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 9162de1750..7f1555de5b 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 @@ -40,6 +40,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.FabricPrivacy; @@ -214,10 +215,10 @@ public class SmsCommunicatorPlugin extends PluginBase { if (glucoseStatus != null) reply += MainApp.sResources.getString(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; - MainApp.getConfigBuilder().updateTotalIOBTreatments(); - IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); - MainApp.getConfigBuilder().updateTotalIOBTempBasals(); - IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTreatments(); + IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments().round(); + TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals(); + IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().round(); reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" + MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index dc01656992..fe79f8555b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -8,7 +8,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; - import com.squareup.otto.Subscribe; import org.slf4j.Logger; @@ -125,7 +124,7 @@ public class TreatmentsFragment extends SubscriberFragment implements View.OnCli @Override protected void updateGUI() { if (ConfigBuilderPlugin.getActivePump().getPumpDescription().isExtendedBolusCapable - || MainApp.getConfigBuilder().getExtendedBolusesFromHistory().size() > 0) { + || TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory().size() > 0) { extendedBolusesTab.setVisibility(View.VISIBLE); } else { extendedBolusesTab.setVisibility(View.GONE); 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 e3a256983a..2a325bb50b 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 @@ -11,7 +11,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -40,6 +39,9 @@ import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; /** @@ -103,7 +105,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface } private static void initializeTempBasalData() { - double dia = Constants.defaultDIA; + double dia = Constants.defaultDIA; if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) dia = MainApp.getConfigBuilder().getProfile().getDia(); long fromMills = (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)); @@ -381,7 +383,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) { //log.debug("Adding new ExtentedBolus record" + extendedBolus.log()); - return MainApp.getDbHelper().createOrUpdate(extendedBolus); + boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(extendedBolus); + if (newRecordCreated) { + if (extendedBolus.durationInMinutes == 0) { + if (MainApp.getConfigBuilder().getActivePump().isFakingTempsByExtendedBoluses()) + NSUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId); + else + NSUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId); + } else if (MainApp.getConfigBuilder().getActivePump().isFakingTempsByExtendedBoluses()) + NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin); + else + NSUpload.uploadExtendedBolus(extendedBolus); + } + return newRecordCreated; } @Override @@ -401,9 +415,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) { //log.debug("Adding new TemporaryBasal record" + tempBasal.toString()); - return MainApp.getDbHelper().createOrUpdate(tempBasal); + boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(tempBasal); + if (newRecordCreated) { + if (tempBasal.durationInMinutes == 0) + NSUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId); + else if (tempBasal.isAbsolute) + NSUpload.uploadTempBasalStartAbsolute(tempBasal, null); + else + NSUpload.uploadTempBasalStartPercent(tempBasal); + } + return newRecordCreated; } + // return true if new record is created @Override public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo) { Treatment treatment = new Treatment(); @@ -429,6 +453,8 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface MainApp.getDbHelper().createOrUpdate(carbsTreatment); //log.debug("Adding new Treatment record" + carbsTreatment); } + if (newRecordCreated && detailedBolusInfo.isValid) + NSUpload.uploadBolusWizardRecord(detailedBolusInfo); return newRecordCreated; } @@ -503,7 +529,9 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) { //log.debug("Adding new TemporaryBasal record" + profileSwitch.log()); + MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING)); MainApp.getDbHelper().createOrUpdate(profileSwitch); + NSUpload.uploadProfileSwitch(profileSwitch); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index 3286f91a62..5f758c8a06 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -15,11 +15,11 @@ import org.slf4j.LoggerFactory; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.Unbinder; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.plugins.PumpDanaR.Dialogs.ProfileViewDialog; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -114,8 +114,8 @@ public class ProfileViewerDialog extends DialogFragment { private void setContent() { Profile profile = null; - ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time); - if(profileSwitch!=null && profileSwitch.profileJson != null){ + ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(time); + if (profileSwitch != null && profileSwitch.profileJson != null) { profile = profileSwitch.getProfileObject(); } if (profile != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java index 2bf7684c94..c8fc539d02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsExtendedBolusesFragment.java @@ -5,7 +5,6 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.Paint; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; @@ -24,6 +23,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; @@ -31,11 +31,11 @@ import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NSUpload; -import info.nightscout.androidaps.data.Intervals; public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { @@ -176,7 +176,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { llm = new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(llm); - RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getConfigBuilder().getExtendedBolusesFromHistory()); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory()); recyclerView.setAdapter(adapter); context = getContext(); @@ -202,7 +202,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment { activity.runOnUiThread(new Runnable() { @Override public void run() { - recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getConfigBuilder().getExtendedBolusesFromHistory()), false); + recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory()), false); } }); } 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 61b6c05199..d018efd97b 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 @@ -6,7 +6,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.graphics.Paint; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; @@ -23,15 +22,16 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.NSUpload; -import info.nightscout.androidaps.data.Intervals; import info.nightscout.utils.SP; /** @@ -85,15 +85,14 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements holder.reasonColon.setText(""); } if (tempTarget.isInProgress()) { - if(tempTarget == currentlyActiveTarget){ + if (tempTarget == currentlyActiveTarget) { // active as newest holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorInProgress)); } else { // other's that might become active again after the latest (overlapping) is over holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); } - } - else { + } else { holder.date.setTextColor(holder.reasonColon.getCurrentTextColor()); } holder.remove.setTag(tempTarget); @@ -176,7 +175,7 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements llm = new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(llm); - RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getConfigBuilder().getTempTargetsFromHistory()); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTempTargetsFromHistory()); recyclerView.setAdapter(adapter); refreshFromNS = (Button) view.findViewById(R.id.temptargetrange_refreshfromnightscout); @@ -225,7 +224,7 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements activity.runOnUiThread(new Runnable() { @Override public void run() { - recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getConfigBuilder().getTempTargetsFromHistory()), false); + recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTempTargetsFromHistory()), false); } }); } 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 9fb895c1c1..b9004e8dd5 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 @@ -5,7 +5,6 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.Paint; import android.os.Bundle; -import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.CardView; @@ -24,6 +23,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Intervals; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Source; @@ -32,11 +32,11 @@ import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NSUpload; -import info.nightscout.androidaps.data.Intervals; public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { @@ -204,7 +204,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { llm = new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(llm); - RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getConfigBuilder().getTemporaryBasalsFromHistory()); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTemporaryBasalsFromHistory()); recyclerView.setAdapter(adapter); tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob); @@ -232,9 +232,9 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment { activity.runOnUiThread(new Runnable() { @Override public void run() { - recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getConfigBuilder().getTemporaryBasalsFromHistory()), false); - if (MainApp.getConfigBuilder().getLastCalculationTempBasals() != null) { - String totalText = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getLastCalculationTempBasals().basaliob) + " U"; + recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTemporaryBasalsFromHistory()), false); + if (TreatmentsPlugin.getPlugin().getLastCalculationTempBasals() != null) { + String totalText = DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTempBasals().basaliob) + " U"; tempBasalTotalView.setText(totalText); } } 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 a6d35b4c0c..48969d3dce 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 @@ -6,11 +6,9 @@ import android.support.annotation.NonNull; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; -import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.List; @@ -42,6 +40,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; import info.nightscout.utils.DateUtil; @@ -245,7 +244,7 @@ public class ActionStringHandler { lastBolusWizard = bolusWizard; } else if ("opencpp".equals(act[0])) { - ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); + ProfileSwitch activeProfileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); if (activeProfileSwitch == null) { sendError("No active profile switch!"); return; @@ -257,7 +256,7 @@ public class ActionStringHandler { } } else if ("cppset".equals(act[0])) { - ProfileSwitch activeProfileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); + ProfileSwitch activeProfileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); if (activeProfileSwitch == null) { sendError("No active profile switch!"); return; @@ -271,7 +270,7 @@ public class ActionStringHandler { } else if ("tddstats".equals(act[0])) { Object activePump = MainApp.getConfigBuilder().getActivePump(); - if (activePump!= null) { + if (activePump != null) { // check if DB up to date List dummies = new LinkedList(); List historyList = getTDDList(dummies); @@ -326,7 +325,7 @@ public class ActionStringHandler { return "No profile loaded :("; } - if(historyList.isEmpty()){ + if (historyList.isEmpty()) { return "No history data!"; } @@ -336,7 +335,7 @@ public class ActionStringHandler { double refTDD = profile.baseBasalSum() * 2; PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); - if(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date()))){ + if (df.format(new Date(historyList.get(0).date)).equals(df.format(new Date()))) { double tdd = historyList.get(0).getTotal(); historyList.remove(0); message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100 * tdd / refTDD) + "%") + "\n"; @@ -394,7 +393,7 @@ public class ActionStringHandler { boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight; DateFormat df = new SimpleDateFormat("dd.MM."); - return (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date(System.currentTimeMillis() - (startsYesterday?1000 * 60 * 60 * 24:0)))))); + return (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date(System.currentTimeMillis() - (startsYesterday ? 1000 * 60 * 60 * 24 : 0)))))); } @NonNull @@ -480,7 +479,7 @@ public class ActionStringHandler { } //Check for Temp-Target: - TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); + TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); if (tempTarget != null) { ret += "Temp Target: " + Profile.toTargetRangeString(tempTarget.low, tempTarget.low, Constants.MGDL, profile.getUnits()); ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd()); @@ -663,7 +662,7 @@ public class ActionStringHandler { } }); } else { - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); } } 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 7acfc27a93..4f0ddaf0f3 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 @@ -46,6 +46,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugi import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.utils.DecimalFormatter; @@ -374,8 +375,8 @@ public class WatchUpdaterService extends WearableListenerService implements double beginBasalValue = profile.getBasal(beginBasalSegmentTime); double endBasalValue = beginBasalValue; - TemporaryBasal tb1 = MainApp.getConfigBuilder().getTempBasalFromHistory(runningTime); - TemporaryBasal tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(runningTime); + TemporaryBasal tb1 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(runningTime); + TemporaryBasal tb2 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(runningTime); double tb_before = beginBasalValue; double tb_amount = beginBasalValue; long tb_start = runningTime; @@ -404,7 +405,7 @@ public class WatchUpdaterService extends WearableListenerService implements } //temps - tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(runningTime); + tb2 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(runningTime); if (tb1 == null && tb2 == null) { //no temp stays no temp @@ -437,7 +438,7 @@ public class WatchUpdaterService extends WearableListenerService implements basals.add(basalMap(beginBasalSegmentTime, runningTime, beginBasalValue)); } if (tb1 != null) { - tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(now); //use "now" to express current situation + tb2 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); //use "now" to express current situation if (tb2 == null) { //express the cancelled temp by painting it down one minute early temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount)); @@ -453,7 +454,7 @@ public class WatchUpdaterService extends WearableListenerService implements } } } else { - tb2 = MainApp.getConfigBuilder().getTempBasalFromHistory(now); //use "now" to express current situation + tb2 = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(now); //use "now" to express current situation if (tb2 != null) { //onset at the end Profile profileTB = MainApp.getConfigBuilder().getProfile(runningTime); @@ -462,7 +463,7 @@ public class WatchUpdaterService extends WearableListenerService implements } } - List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); + List treatments = TreatmentsPlugin.getPlugin().getTreatmentsFromHistory(); for (Treatment treatment : treatments) { if (treatment.date > startTimeWindow) { boluses.add(treatmentMap(treatment.date, treatment.insulin, treatment.carbs, treatment.isSMB, treatment.isValid)); @@ -582,7 +583,7 @@ public class WatchUpdaterService extends WearableListenerService implements String iobSum, iobDetail, cobString, currentBasal, bgiString; iobSum = iobDetail = cobString = currentBasal = bgiString = ""; if (profile != null) { - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); + TreatmentsInterface treatmentsInterface = TreatmentsPlugin.getPlugin(); treatmentsInterface.updateTotalIOBTreatments(); IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); treatmentsInterface.updateTotalIOBTempBasals(); 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 78ef3f9e49..c3045bdb3d 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 @@ -9,7 +9,6 @@ import android.support.annotation.NonNull; import com.squareup.otto.Subscribe; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; @@ -27,6 +26,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DecimalFormatter; /** @@ -118,7 +118,7 @@ public class StatuslinePlugin extends PluginBase { } //Temp basal - TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); + TreatmentsInterface treatmentsInterface = TreatmentsPlugin.getPlugin(); TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis()); if (activeTemp != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java index 867d118428..96a11dacf5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java @@ -6,10 +6,10 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; -import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; /** @@ -32,7 +32,7 @@ public class CommandSetProfile extends Command { callback.result(r).run(); // Send SMS notification if ProfileSwitch is comming from NS - ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); + ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis()); if (r.enacted && profileSwitch.source == Source.NIGHTSCOUT) { SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class); if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginType.GENERAL)) { diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index ac710dc51f..3563a8a55d 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -1,12 +1,12 @@ package info.nightscout.utils; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; /** * Created by mike on 11.10.2016. @@ -93,7 +93,7 @@ public class BolusWizard { // Insulin from IOB // IOB calculation - TreatmentsInterface treatments = MainApp.getConfigBuilder(); + TreatmentsInterface treatments = TreatmentsPlugin.getPlugin(); treatments.updateTotalIOBTreatments(); IobTotal bolusIob = treatments.getLastCalculationTreatments().round(); treatments.updateTotalIOBTempBasals(); diff --git a/app/src/test/java/info/nightscout/utils/BolusWizardTest.java b/app/src/test/java/info/nightscout/utils/BolusWizardTest.java index 21872f47bc..4dfd87f870 100644 --- a/app/src/test/java/info/nightscout/utils/BolusWizardTest.java +++ b/app/src/test/java/info/nightscout/utils/BolusWizardTest.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin; +import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -23,7 +24,7 @@ import static org.mockito.Mockito.when; * Created by kuchjir on 12/12/2017. */ @RunWith(PowerMockRunner.class) -@PrepareForTest( { MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class }) +@PrepareForTest( { MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class }) public class BolusWizardTest { private static final double PUMP_BOLUS_STEP = 0.1; @@ -68,12 +69,13 @@ public class BolusWizardTest { PowerMockito.mockStatic(GlucoseStatus.class); when(GlucoseStatus.getGlucoseStatusData()).thenReturn(null); - ConfigBuilderPlugin treatment = mock(ConfigBuilderPlugin.class); + PowerMockito.mockStatic(TreatmentsPlugin.class); + TreatmentsPlugin treatment = mock(TreatmentsPlugin.class); IobTotal iobTotalZero = new IobTotal(System.currentTimeMillis()); when(treatment.getLastCalculationTreatments()).thenReturn(iobTotalZero); when(treatment.getLastCalculationTempBasals()).thenReturn(iobTotalZero); PowerMockito.mockStatic(MainApp.class); - when(MainApp.getConfigBuilder()).thenReturn(treatment); + when(TreatmentsPlugin.getPlugin()).thenReturn(treatment); PowerMockito.mockStatic(ConfigBuilderPlugin.class); PumpInterface pump = MDIPlugin.getPlugin();