diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index 3c9460e889..b74eb0c405 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -114,71 +114,6 @@ public class TempBasal { return result; } -/* - public IobTotal old_iobCalc(long time) { - IobTotal result = new IobTotal(time); - NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); - InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin(); - - if (profile == null) - return result; - - Double basalRate = profile.getBasal(NSProfile.secondsFromMidnight(time)); - - if (basalRate == null) - return result; - - int realDuration = getDurationToTime(time); - - if (realDuration > 0) { - Double netBasalRate = 0d; - Double tempBolusSize = 0.05; - - if (isExtended) { - netBasalRate = this.absolute; - } else { - if (this.isAbsolute) { - netBasalRate = this.absolute - basalRate; - } else { - netBasalRate = (this.percent - 100) / 100d * basalRate; - } - } - - result.netRatio = netBasalRate; - Double netBasalAmount = Math.round(netBasalRate * realDuration * 10 / 6) / 100d; - result.netInsulin = netBasalAmount; - if (netBasalAmount < 0.1) { - tempBolusSize = 0.01; - } - if (netBasalRate < 0) { - tempBolusSize = -tempBolusSize; - } - Long tempBolusCount = Math.round(netBasalAmount / tempBolusSize); - if (tempBolusCount > 0) { - Long tempBolusSpacing = realDuration / tempBolusCount; - for (Long j = 0L; j < tempBolusCount; j++) { - Treatment tempBolusPart = new Treatment(insulinInterface); - tempBolusPart.insulin = tempBolusSize; - Long date = this.timeStart.getTime() + j * tempBolusSpacing * 60 * 1000; - tempBolusPart.created_at = new Date(date); - - Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia()); - result.basaliob += aIOB.iobContrib; - result.activity += aIOB.activityContrib; - Double dia_ago = time - profile.getDia() * 60 * 60 * 1000; - if (date > dia_ago && date <= time) { - result.netbasalinsulin += tempBolusPart.insulin; - if (tempBolusPart.insulin > 0) { - result.hightempinsulin += tempBolusPart.insulin; - } - } - } - } - } - return result; - } -*/ - // Determine end of basal public long getTimeEnd() { long tempBasalTimePlannedEnd = getPlannedTimeEnd(); @@ -203,7 +138,7 @@ public class TempBasal { return Math.round(msecs / 60f / 1000); } - public int getDurationToTime(long time) { + private int getDurationToTime(long time) { long endTime = Math.min(time, getTimeEnd()); long msecs = endTime - timeStart.getTime(); return Math.round(msecs / 60f / 1000); @@ -220,33 +155,31 @@ public class TempBasal { } public boolean isInProgress() { - return isInProgress(new Date()); + return isInProgress(new Date().getTime()); } public double tempBasalConvertedToAbsolute(Date time) { if (isExtended) { - NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); - double absval = profile.getBasal(NSProfile.secondsFromMidnight(time)) + absolute; - return absval; + NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); + return profile.getBasal(NSProfile.secondsFromMidnight(time)) + absolute; } else { if (isAbsolute) return absolute; else { - NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); - double absval = profile.getBasal(NSProfile.secondsFromMidnight(time)) * percent / 100; - return absval; + NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); + return profile.getBasal(NSProfile.secondsFromMidnight(time)) * percent / 100; } } } - public boolean isInProgress(Date time) { - if (timeStart.getTime() > time.getTime()) return false; // in the future + public boolean isInProgress(long time) { + if (timeStart.getTime() > time) return false; // in the future if (timeEnd == null) { // open end - if (timeStart.getTime() < time.getTime() && getPlannedTimeEnd() > time.getTime()) + if (timeStart.getTime() < time && getPlannedTimeEnd() > time) return true; // in interval return false; } // closed end - if (timeStart.getTime() < time.getTime() && timeEnd.getTime() > time.getTime()) + if (timeStart.getTime() < time && timeEnd.getTime() > time) return true; // in interval return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index a6134907a0..2e4bcc0a34 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -19,9 +19,6 @@ public interface PumpInterface { boolean isSuspended(); boolean isBusy(); - boolean isTempBasalInProgress(); - boolean isExtendedBoluslInProgress(); - // Upload to pump new basal profile int SUCCESS = 0; int FAILED = 1; @@ -35,9 +32,6 @@ public interface PumpInterface { double getBaseBasalRate(); // base basal rate, not temp basal double getTempBasalAbsoluteRate(); double getTempBasalRemainingMinutes(); - TempBasal getTempBasal(Date time); - TempBasal getTempBasal(); - TempBasal getExtendedBolus(); PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context); void stopBolusDelivering(); diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java index 0eca9595f6..322941179c 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/TreatmentsInterface.java @@ -26,8 +26,11 @@ public interface TreatmentsInterface { List getTreatments(); List getTreatments5MinBack(long time); - TempBasal getTempBasal (Date time); - TempBasal getExtendedBolus (Date time); + boolean isTempBasalInProgress(); + boolean isExtendedBoluslInProgress(); + + TempBasal getTempBasal (long time); + TempBasal getExtendedBolus (long time); long oldestDataAvaialable(); 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 a4043acba2..4cd1015cfb 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 @@ -16,11 +16,14 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Date; +import java.util.List; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; +import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.db.Treatment; @@ -58,7 +61,7 @@ import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. */ -public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface { +public class ConfigBuilderPlugin implements PluginBase, PumpInterface, ConstraintsInterface, TreatmentsInterface { private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class); static BgSourceInterface activeBgSource; @@ -201,10 +204,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return activeProfile; } - public static TreatmentsInterface getActiveTreatments() { - return activeTreatments; - } - public static InsulinInterface getActiveInsulin() { return activeInsulin; } @@ -222,7 +221,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain log.debug(p.getName() + ":" + (p.isEnabled(1) ? " GENERAL" : "") + (p.isEnabled(2) ? " TREATMENT" : "") + - (p.isEnabled(3) ? " TEMPBASAL" : "") + (p.isEnabled(4) ? " PROFILE" : "") + (p.isEnabled(5) ? " APS" : "") + (p.isEnabled(6) ? " PUMP" : "") + @@ -362,20 +360,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain else return false; } - @Override - public boolean isTempBasalInProgress() { - if (activePump != null) - return activePump.isTempBasalInProgress(); - else return false; - } - - @Override - public boolean isExtendedBoluslInProgress() { - if (activePump != null) - return activePump.isExtendedBoluslInProgress(); - else return false; - } - @Override public int setNewBasalProfile(NSProfile profile) { // Compare with pump limits @@ -444,30 +428,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain return 0d; } - @Override - public TempBasal getTempBasal(Date time) { - if (activePump != null) - return activePump.getTempBasal(time); - else - return null; - } - - @Override - public TempBasal getTempBasal() { - if (activePump != null) - return activePump.getTempBasal(); - else - return null; - } - - @Override - public TempBasal getExtendedBolus() { - if (activePump != null) - return activePump.getExtendedBolus(); - else - return null; - } - public PumpEnactResult deliverTreatmentFromBolusWizard(InsulinInterface insulinType, Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { mWakeLock.acquire(); PumpEnactResult result; @@ -719,7 +679,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.05) { result = new PumpEnactResult(); result.absolute = getTempBasalAbsoluteRate(); - result.duration = activePump.getTempBasal().getPlannedRemainingMinutes(); + result.duration = getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); result.enacted = false; result.comment = "Temp basal set correctly"; result.success = true; @@ -1187,4 +1147,74 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } } + // 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 getTreatments() { + return activeTreatments.getTreatments(); + } + + @Override + public List getTreatments5MinBack(long time) { + return activeTreatments.getTreatments5MinBack(time); + } + + @Override + public boolean isTempBasalInProgress() { + return activeTreatments.isTempBasalInProgress(); + } + + @Override + public boolean isExtendedBoluslInProgress() { + return activeTreatments.isExtendedBoluslInProgress(); + } + + @Override + public TempBasal getTempBasal(long time) { + return activeTreatments.getTempBasal(time); + } + + @Override + public TempBasal getExtendedBolus(long time) { + return activeTreatments.getExtendedBolus(time); + } + + @Override + public long oldestDataAvaialable() { + return activeTreatments.oldestDataAvaialable(); + } } 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 4b862650e1..4576744fee 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 @@ -238,12 +238,6 @@ public class IobCobCalculatorPlugin implements PluginBase { return; } - if (ConfigBuilderPlugin.getActiveTreatments() == null) { - log.debug("calculateSensitivityData: No treatments plugin"); - return; - } - - TreatmentsInterface treatmentsInterface = ConfigBuilderPlugin.getActiveTreatments(); if (bucketed_data == null || bucketed_data.size() < 3) { log.debug("calculateSensitivityData: No bucketed data available"); return; @@ -286,7 +280,7 @@ public class IobCobCalculatorPlugin implements PluginBase { double bgi = -iob.activity * sens * 5; double deviation = delta - bgi; - List recentTreatments = treatmentsInterface.getTreatments5MinBack(bgTime); + List recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBack(bgTime); for (int ir = 0; ir < recentTreatments.size(); ir++) { autosensData.carbsFromBolus += recentTreatments.get(ir).carbs; } @@ -338,8 +332,8 @@ public class IobCobCalculatorPlugin implements PluginBase { } else { //log.debug(">>> Cache miss " + new Date(time).toLocaleString()); } - IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTreatments(time).round(); - IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTempBasals(time).round(); + IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round(); + IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round(); /* if (basalIob.basaliob > 0) { log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob ); 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 4ce3cd61b5..2518dcffbe 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 @@ -11,6 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.util.Date; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; @@ -231,7 +232,7 @@ public class DetermineBasalAdapterAMAJS { mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate()); // as we have non default temps longer than 30 mintues - TempBasal tempBasal = pump.getTempBasal(); + TempBasal tempBasal = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if(tempBasal != null){ mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration()); } 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 fc0355fdab..7a379b5ab2 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 @@ -191,7 +191,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { Profiler.log(log, "calculateIobArrayInDia()", startPart); startPart = new Date(); - MealData mealData = MainApp.getConfigBuilder().getActiveTreatments().getMealData(); + MealData mealData = MainApp.getConfigBuilder().getMealData(); Profiler.log(log, "getMealData()", startPart); maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); @@ -222,7 +222,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return; if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return; - long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTreatments().oldestDataAvaialable(); + long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvaialable(); long getBGDataFrom = Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))); log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString()); 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 44bced35d7..9dd41bc304 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 @@ -186,15 +186,14 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { maxBg = Round.roundTo(maxBg, 0.1d); Date start = new Date(); - TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments(); - treatments.updateTotalIOBTreatments(); - treatments.updateTotalIOBTempBasals(); - IobTotal bolusIob = treatments.getLastCalculationTreatments(); - IobTotal basalIob = treatments.getLastCalculationTempBasals(); + MainApp.getConfigBuilder().updateTotalIOBTreatments(); + MainApp.getConfigBuilder().updateTotalIOBTempBasals(); + IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments(); + IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals(); IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round(); - MealData mealData = treatments.getMealData(); + MealData mealData = MainApp.getConfigBuilder().getMealData(); maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob); Profiler.log(log, "MA data gathering", start); 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 aa51b14fca..f8186c4c97 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 @@ -62,7 +62,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; -public class WizardDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener, Spinner.OnItemSelectedListener { +public class WizardDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener, Spinner.OnItemSelectedListener { private static Logger log = LoggerFactory.getLogger(WizardDialog.class); Button wizardDialogDeliverButton; @@ -123,7 +123,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co this.context = context; } - @Override + @Override public void onResume() { super.onResume(); if (getDialog() != null) @@ -211,8 +211,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co bgTrend = (TextView) view.findViewById(R.id.treatments_wizard_bgtrend); bgTrendInsulin = (TextView) view.findViewById(R.id.treatments_wizard_bgtrendinsulin); cobLayout = (LinearLayout) view.findViewById(R.id.treatments_wizard_cob_layout); - cob = (TextView) view.findViewById(R.id.treatments_wizard_cob);; - cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin);; + cob = (TextView) view.findViewById(R.id.treatments_wizard_cob); + ; + cobInsulin = (TextView) view.findViewById(R.id.treatments_wizard_cobinsulin); + ; bgCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bgcheckbox); bolusIobCheckbox = (CheckBox) view.findViewById(R.id.treatments_wizard_bolusiobcheckbox); @@ -409,14 +411,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co } // IOB calculation - TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments(); - treatments.updateTotalIOBTreatments(); - IobTotal bolusIob = treatments.getLastCalculationTreatments(); - IobTotal basalIob = new IobTotal(new Date().getTime()); - if (treatments != null) { - treatments.updateTotalIOBTempBasals(); - basalIob = treatments.getLastCalculationTempBasals().round(); - } + MainApp.getConfigBuilder().updateTotalIOBTreatments(); + IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); + MainApp.getConfigBuilder().updateTotalIOBTempBasals(); + IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U"); basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); 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 d5f6bbb607..2a148fd30e 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 @@ -483,7 +483,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, break; case R.id.overview_canceltempbutton: final PumpInterface pump = MainApp.getConfigBuilder(); - if (pump.isTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { sHandler.post(new Runnable() { @Override public void run() { @@ -891,8 +891,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, calibrationButton.setVisibility(View.GONE); } - TempBasal activeTemp = pump.getTempBasal(); - if (pump.isTempBasalInProgress()) { + TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { cancelTempButton.setVisibility(View.VISIBLE); cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); runningTempView.setVisibility(View.VISIBLE); @@ -1006,10 +1006,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin)); // iob - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); - IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); - IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); + MainApp.getConfigBuilder().updateTotalIOBTreatments(); + MainApp.getConfigBuilder().updateTotalIOBTempBasals(); + IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); + IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " @@ -1077,7 +1077,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, double lastBaseBasal = 0; double lastTempBasal = 0; for (long time = fromTime; time < now; time += 5 * 60 * 1000L) { - TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time)); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(time); double baseBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))); double baseLineValue = baseBasalValue; double tempBasalValue = 0; @@ -1366,7 +1366,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // Treatments - List treatments = MainApp.getConfigBuilder().getActiveTreatments().getTreatments(); + List treatments = MainApp.getConfigBuilder().getTreatments(); List filteredTreatments = new ArrayList(); for (int tx = 0; tx < treatments.size(); tx++) { 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 ec3c258bbb..3a9dd4d1d7 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 @@ -138,16 +138,16 @@ public class PersistentNotificationPlugin implements PluginBase{ PumpInterface pump = MainApp.getConfigBuilder(); - if (pump.isTempBasalInProgress()) { - TempBasal activeTemp = pump.getTempBasal(); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); line1 += " " + activeTemp.toStringShort(); } //IOB - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); - IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); - IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); + MainApp.getConfigBuilder().updateTotalIOBTreatments(); + MainApp.getConfigBuilder().updateTotalIOBTempBasals(); + IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); + IobTotal basalIob = MainApp.getConfigBuilder().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/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index 4aed68baec..22fc43287d 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 @@ -219,13 +219,13 @@ public class DanaRFragment extends Fragment { dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); - if (getPlugin().isRealTempBasalInProgress()) { - tempBasalView.setText(getPlugin().getRealTempBasal().toString()); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } - if (getPlugin().isExtendedBoluslInProgress()) { - extendedBolusView.setText(getPlugin().getExtendedBolus().toString()); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString()); } else { extendedBolusView.setText(""); } 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 56d24c756c..863daee656 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 @@ -139,7 +139,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT; - if (useExtendedBoluses != previousValue && isExtendedBoluslInProgress()) { + if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { sExecutionService.extendedBolusStop(); } } @@ -240,22 +240,6 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf } // Pump interface - @Override - public boolean isTempBasalInProgress() { - if (getRealTempBasal() != null) return true; - if (getExtendedBolus() != null && useExtendedBoluses) return true; - return false; - } - - public boolean isRealTempBasalInProgress() { - return getRealTempBasal() != null; //TODO: crosscheck here - } - - @Override - public boolean isExtendedBoluslInProgress() { - return getExtendedBolus() != null; //TODO: crosscheck here - } - @Override public int setNewBasalProfile(NSProfile profile) { if (sExecutionService == null) { @@ -321,7 +305,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public double getTempBasalAbsoluteRate() { - TempBasal tb = getRealTempBasal(); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { if (tb.isAbsolute) { return tb.absolute; @@ -331,7 +315,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf return tempRate; } } - TempBasal eb = getExtendedBolus(); + TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()); if (eb != null && useExtendedBoluses) { return getBaseBasalRate() + eb.absolute; } @@ -340,39 +324,21 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public double getTempBasalRemainingMinutes() { - if (isRealTempBasalInProgress()) - return getRealTempBasal().getPlannedRemainingMinutes(); - if (isExtendedBoluslInProgress() && useExtendedBoluses) - return getExtendedBolus().getPlannedRemainingMinutes(); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) + return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) + return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes(); return 0; } - @Override - public TempBasal getTempBasal() { - if (isRealTempBasalInProgress()) - return getRealTempBasal(); - if (isExtendedBoluslInProgress() && useExtendedBoluses) - return getExtendedBolus(); - return null; - } - - public TempBasal getTempBasal(Date time) { - TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time); + public TempBasal getTempBasal(long time) { + TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time); if (temp != null) return temp; if (useExtendedBoluses) - return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time); + return MainApp.getConfigBuilder().getExtendedBolus(time); return null; } - public TempBasal getRealTempBasal() { - return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date()); - } - - @Override - public TempBasal getExtendedBolus() { - return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date()); - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); @@ -429,13 +395,13 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (doTempOff) { // If extended in progress - if (isExtendedBoluslInProgress() && useExtendedBoluses) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); return cancelExtendedBolus(); } // If temp in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); return cancelRealTempBasal(); @@ -458,7 +424,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf percentRate = 200; } // If extended in progress - if (isExtendedBoluslInProgress() && useExtendedBoluses) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); result = cancelExtendedBolus(); @@ -468,9 +434,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf } } // Check if some temp is already in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { // Correct basal already set ? - if (getRealTempBasal().percent == percentRate) { + if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; result.absolute = getTempBasalAbsoluteRate(); @@ -499,7 +465,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf } if (doExtendedTemp) { // Check if some temp is already in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); result = cancelRealTempBasal(); @@ -520,12 +486,12 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf // What is current rate of extended bolusing in u/h? if (Config.logPumpActions) { - log.debug("setTempBasalAbsolute: Extended bolus in progress: " + isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); + log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h"); } // Compare with extended rate in progress - if (isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { // correct extended already set result.success = true; result.absolute = getDanaRPump().extendedBolusAbsoluteRate; @@ -650,9 +616,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public PumpEnactResult cancelTempBasal() { - if (isRealTempBasalInProgress()) + if (MainApp.getConfigBuilder().isTempBasalInProgress()) return cancelRealTempBasal(); - if (isExtendedBoluslInProgress()) + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) return cancelExtendedBolus(); PumpEnactResult result = new PumpEnactResult(); result.success = true; @@ -740,7 +706,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf extended.put("PumpIOB", getDanaRPump().iob); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - TempBasal tb = getTempBasal(); + TempBasal tb = getTempBasal(new Date().getTime()); if (tb != null) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); @@ -867,11 +833,11 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (getDanaRPump().lastBolusTime.getTime() != 0) { ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; } - if (isRealTempBasalInProgress()) { - ret += "Temp: " + getRealTempBasal().toString() + "\n"; + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n"; } - if (isExtendedBoluslInProgress()) { - ret += "Extended: " + getExtendedBolus().toString() + "\n"; + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n"; } if (!veryShort){ ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; 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 691811efc3..645b0d2292 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 @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -63,14 +64,14 @@ public class MsgStatusBolusExtended extends MessageBase { } public static void updateExtendedBolusInDB() { - DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRPump pump = DanaRPump.getInstance(); Date now = new Date(); try { - if (danaRPlugin.isExtendedBoluslInProgress()) { - TempBasal extendedBolus = danaRPlugin.getExtendedBolus(); + if (treatmentsInterface.isExtendedBoluslInProgress()) { + TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime()); if (pump.isExtendedInProgress) { if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) { // Close current extended 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 1db0ea29ee..96cca6dd5e 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 @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -54,14 +55,14 @@ public class MsgStatusTempBasal extends MessageBase { } public static void updateTempBasalInDB() { - DanaRPlugin DanaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRPump danaRPump = DanaRPump.getInstance(); Date now = new Date(); try { - if (DanaRPlugin.isRealTempBasalInProgress()) { - TempBasal tempBasal = DanaRPlugin.getRealTempBasal(); + if (treatmentsInterface.isTempBasalInProgress()) { + TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime()); if (danaRPump.isTempBasalInProgress) { if (tempBasal.percent != danaRPump.tempBasalPercent) { // Close current temp basal diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java index bafe3f63ff..2c90a6e4a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanFragment.java @@ -217,13 +217,13 @@ public class DanaRKoreanFragment extends Fragment { dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h"); - if (danaRKoreanPlugin.isRealTempBasalInProgress()) { - tempBasalView.setText(danaRKoreanPlugin.getRealTempBasal().toString()); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } - if (danaRKoreanPlugin.isExtendedBoluslInProgress()) { - extendedBolusView.setText(danaRKoreanPlugin.getExtendedBolus().toString()); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString()); } else { extendedBolusView.setText(""); } 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 795e0fbaaf..0f2b4972d6 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 @@ -141,7 +141,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints pumpDescription.highTempBasalStyle = useExtendedBoluses ? PumpDescription.EXTENDED : PumpDescription.PERCENT; - if (useExtendedBoluses != previousValue && isExtendedBoluslInProgress()) { + if (useExtendedBoluses != previousValue && MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { sExecutionService.extendedBolusStop(); } } @@ -242,22 +242,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints } // Pump interface - @Override public boolean isTempBasalInProgress() { - if (getRealTempBasal() != null) return true; - if (getExtendedBolus() != null && useExtendedBoluses) return true; + if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()) != null) return true; + if (MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()) != null && useExtendedBoluses) return true; return false; } - public boolean isRealTempBasalInProgress() { - return getRealTempBasal() != null; //TODO: crosscheck here - } - - @Override - public boolean isExtendedBoluslInProgress() { - return getExtendedBolus() != null; //TODO: crosscheck here - } - @Override public int setNewBasalProfile(NSProfile profile) { if (sExecutionService == null) { @@ -322,7 +312,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints @Override public double getTempBasalAbsoluteRate() { - TempBasal tb = getRealTempBasal(); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { if (tb.isAbsolute) { return tb.absolute; @@ -332,7 +322,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints return tempRate; } } - TempBasal eb = getExtendedBolus(); + TempBasal eb = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()); if (eb != null && useExtendedBoluses) { return getBaseBasalRate() + eb.absolute; } @@ -341,39 +331,21 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints @Override public double getTempBasalRemainingMinutes() { - if (isRealTempBasalInProgress()) - return getRealTempBasal().getPlannedRemainingMinutes(); - if (isExtendedBoluslInProgress() && useExtendedBoluses) - return getExtendedBolus().getPlannedRemainingMinutes(); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) + return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) + return MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).getPlannedRemainingMinutes(); return 0; } - @Override - public TempBasal getTempBasal() { - if (isRealTempBasalInProgress()) - return getRealTempBasal(); - if (isExtendedBoluslInProgress() && useExtendedBoluses) - return getExtendedBolus(); - return null; - } - - public TempBasal getTempBasal(Date time) { - TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time); + public TempBasal getTempBasal(long time) { + TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time); if (temp != null) return temp; if (useExtendedBoluses) - return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time); + return MainApp.getConfigBuilder().getExtendedBolus(time); return null; } - public TempBasal getRealTempBasal() { - return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date()); - } - - @Override - public TempBasal getExtendedBolus() { - return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date()); - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); @@ -430,13 +402,13 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints if (doTempOff) { // If extended in progress - if (isExtendedBoluslInProgress() && useExtendedBoluses) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping extended bolus (doTempOff)"); return cancelExtendedBolus(); } // If temp in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); return cancelRealTempBasal(); @@ -459,7 +431,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints percentRate = 200; } // If extended in progress - if (isExtendedBoluslInProgress() && useExtendedBoluses) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && useExtendedBoluses) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping extended bolus (doLowTemp || doHighTemp)"); result = cancelExtendedBolus(); @@ -469,9 +441,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints } } // Check if some temp is already in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { // Correct basal already set ? - if (getRealTempBasal().percent == percentRate) { + if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; result.absolute = getTempBasalAbsoluteRate(); @@ -500,7 +472,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints } if (doExtendedTemp) { // Check if some temp is already in progress - if (isRealTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doExtendedTemp)"); result = cancelRealTempBasal(); @@ -521,12 +493,12 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints // What is current rate of extended bolusing in u/h? if (Config.logPumpActions) { - log.debug("setTempBasalAbsolute: Extended bolus in progress: " + isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); + log.debug("setTempBasalAbsolute: Extended bolus in progress: " + MainApp.getConfigBuilder().isExtendedBoluslInProgress() + " rate: " + getDanaRPump().extendedBolusAbsoluteRate + "U/h duration remaining: " + getDanaRPump().extendedBolusRemainingMinutes + "min"); log.debug("setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h"); } // Compare with extended rate in progress - if (isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress() && Math.abs(getDanaRPump().extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) { // correct extended already set result.success = true; result.absolute = getDanaRPump().extendedBolusAbsoluteRate; @@ -651,9 +623,9 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints @Override public PumpEnactResult cancelTempBasal() { - if (isRealTempBasalInProgress()) + if (MainApp.getConfigBuilder().isTempBasalInProgress()) return cancelRealTempBasal(); - if (isExtendedBoluslInProgress()) + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) return cancelExtendedBolus(); PumpEnactResult result = new PumpEnactResult(); result.success = true; @@ -741,7 +713,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints extended.put("PumpIOB", getDanaRPump().iob); // extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); // extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - TempBasal tb = getTempBasal(); + TempBasal tb = getTempBasal(new Date().getTime()); if (tb != null) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); @@ -868,11 +840,11 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints // if (getDanaRPump().lastBolusTime.getTime() != 0) { // ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; // } - if (isRealTempBasalInProgress()) { - ret += "Temp: " + getRealTempBasal().toString() + "\n"; + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n"; } - if (isExtendedBoluslInProgress()) { - ret += "Extended: " + getExtendedBolus().toString() + "\n"; + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n"; } if (!veryShort){ ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBolusExtended.java index f5879b76a8..a17bff1872 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBolusExtended.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusBolusExtended.java @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump; @@ -66,13 +67,14 @@ public class MsgStatusBolusExtended extends MessageBase { public static void updateExtendedBolusInDB() { DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump(); Date now = new Date(); try { - if (DanaRKoreanPlugin.isExtendedBoluslInProgress()) { - TempBasal extendedBolus = DanaRKoreanPlugin.getExtendedBolus(); + if (treatmentsInterface.isExtendedBoluslInProgress()) { + TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime()); if (danaRKoreanPump.isExtendedInProgress) { if (extendedBolus.absolute != danaRKoreanPump.extendedBolusAbsoluteRate) { // Close current extended diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusTempBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusTempBasal.java index 6ba599f33b..c3892f9354 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusTempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgStatusTempBasal.java @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPump; @@ -55,13 +56,14 @@ public class MsgStatusTempBasal extends MessageBase { public static void updateTempBasalInDB() { DanaRKoreanPlugin DanaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRKoreanPump danaRKoreanPump = DanaRKoreanPlugin.getDanaRPump(); Date now = new Date(); try { - if (DanaRKoreanPlugin.isRealTempBasalInProgress()) { - TempBasal tempBasal = DanaRKoreanPlugin.getRealTempBasal(); + if (treatmentsInterface.isTempBasalInProgress()) { + TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime()); if (danaRKoreanPump.isTempBasalInProgress) { if (tempBasal.percent != danaRKoreanPump.tempBasalPercent) { // Close current temp basal diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java index ddf7371f4b..146c5e4a16 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Fragment.java @@ -220,13 +220,13 @@ public class DanaRv2Fragment extends Fragment { dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U"); SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d); basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h"); - if (getPlugin().isTempBasalInProgress()) { - tempBasalView.setText(getPlugin().getTempBasal().toString()); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } - if (getPlugin().isExtendedBoluslInProgress()) { - extendedBolusView.setText(getPlugin().getExtendedBolus().toString()); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString()); } else { extendedBolusView.setText(""); } 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 246a9c5911..3daadafd2e 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 @@ -223,16 +223,6 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte } // Pump interface - @Override - public boolean isTempBasalInProgress() { - return getTempBasal() != null; //TODO: crosscheck here - } - - @Override - public boolean isExtendedBoluslInProgress() { - return getExtendedBolus() != null; //TODO: crosscheck here - } - @Override public int setNewBasalProfile(NSProfile profile) { if (sExecutionService == null) { @@ -298,7 +288,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte @Override public double getTempBasalAbsoluteRate() { - TempBasal tb = getTempBasal(); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { Double baseRate = getBaseBasalRate(); Double tempRate = baseRate * (tb.percent / 100d); @@ -309,25 +299,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte @Override public double getTempBasalRemainingMinutes() { - if (isTempBasalInProgress()) - return getTempBasal().getPlannedRemainingMinutes(); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) + return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); return 0; } - public TempBasal getTempBasal(Date time) { - return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time); - } - - @Override - public TempBasal getTempBasal() { - return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date()); - } - - @Override - public TempBasal getExtendedBolus() { - return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date()); - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); @@ -383,7 +359,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte if (doTempOff) { // If temp in progress - if (isTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); return cancelTempBasal(); @@ -405,9 +381,9 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte if (percentRate > getPumpDescription().maxHighTempPercent) percentRate = getPumpDescription().maxHighTempPercent; // Check if some temp is already in progress - if (isTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { // Correct basal already set ? - if (getTempBasal().percent == percentRate) { + if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent == percentRate) { result.success = true; result.percent = percentRate; result.absolute = getTempBasalAbsoluteRate(); @@ -633,7 +609,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte extended.put("PumpIOB", getDanaRPump().iob); extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString()); extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount); - TempBasal tb = getTempBasal(); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); if (tb != null) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalStart", tb.timeStart.toLocaleString()); @@ -761,11 +737,11 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte if (getDanaRPump().lastBolusTime.getTime() != 0) { ret += "LastBolus: " + DecimalFormatter.to2Decimal(getDanaRPump().lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", getDanaRPump().lastBolusTime) + "\n"; } - if (isTempBasalInProgress()) { - ret += "Temp: " + getTempBasal().toString() + "\n"; + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + ret += "Temp: " + MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString() + "\n"; } - if (isExtendedBoluslInProgress()) { - ret += "Extended: " + getExtendedBolus().toString() + "\n"; + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + ret += "Extended: " + MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString() + "\n"; } if (!veryShort) { ret += "TDD: " + DecimalFormatter.to0Decimal(getDanaRPump().dailyTotalUnits) + " / " + getDanaRPump().maxDailyTotalUnits + " U\n"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended.java index 83a8454f81..70c1cbe00e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusBolusExtended.java @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; @@ -64,14 +65,14 @@ public class MsgStatusBolusExtended extends MessageBase { } public static void updateExtendedBolusInDB() { - DanaRv2Plugin danaRPlugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRPump pump = DanaRPump.getInstance(); Date now = new Date(); try { - if (danaRPlugin.isExtendedBoluslInProgress()) { - TempBasal extendedBolus = danaRPlugin.getExtendedBolus(); + if (treatmentsInterface.isExtendedBoluslInProgress()) { + TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime()); if (pump.isExtendedInProgress) { if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) { // Close current extended diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal.java index c8c59b4f1a..385c8b5747 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgStatusTempBasal.java @@ -12,6 +12,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.events.EventTempBasalChange; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; @@ -61,14 +62,14 @@ public class MsgStatusTempBasal extends MessageBase { } public static void updateTempBasalInDB() { - DanaRv2Plugin danaRPlugin = (DanaRv2Plugin) MainApp.getSpecificPlugin(DanaRv2Plugin.class); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); DanaRPump danaRPump = DanaRPump.getInstance(); Date now = new Date(); try { - if (danaRPlugin.isTempBasalInProgress()) { - TempBasal tempBasal = danaRPlugin.getTempBasal(); + if (treatmentsInterface.isTempBasalInProgress()) { + TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime()); if (danaRPump.isTempBasalInProgress) { if (tempBasal.percent != danaRPump.tempBasalPercent) { // Close current temp basal 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 4d55544129..a609c66fd3 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 @@ -138,16 +138,6 @@ public class MDIPlugin implements PluginBase, PumpInterface { return false; } - @Override - public boolean isTempBasalInProgress() { - return false; - } - - @Override - public boolean isExtendedBoluslInProgress() { - return false; - } - @Override public int setNewBasalProfile(NSProfile profile) { // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); @@ -179,26 +169,11 @@ public class MDIPlugin implements PluginBase, PumpInterface { return 0; } - @Override - public TempBasal getTempBasal() { - return null; - } - - @Override - public TempBasal getExtendedBolus() { - return null; - } - @Override public double getTempBasalRemainingMinutes() { return 0d; } - @Override - public TempBasal getTempBasal(Date time) { - return null; - } - @Override public PumpEnactResult deliverTreatment(InsulinInterface insulinType, Double insulin, Integer carbs, Context context) { PumpEnactResult result = new PumpEnactResult(); 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 edad845092..f1f0fafe99 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 @@ -16,6 +16,8 @@ import com.squareup.otto.Subscribe; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.PumpVirtual.events.EventVirtualPumpUpdateGui; @@ -92,13 +94,13 @@ public class VirtualPumpFragment extends Fragment { public void run() { basaBasalRateView.setText(virtualPumpPlugin.getBaseBasalRate() + "U"); - if (virtualPumpPlugin.isTempBasalInProgress()) { - tempBasalView.setText(virtualPumpPlugin.getTempBasal().toString()); + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasalView.setText(MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).toString()); } else { tempBasalView.setText(""); } - if (virtualPumpPlugin.isExtendedBoluslInProgress()) { - extendedBolusView.setText(virtualPumpPlugin.getExtendedBolus().toString()); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + extendedBolusView.setText(MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()).toString()); } else { extendedBolusView.setText(""); } 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 d3b7cf5736..c86eee0d08 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 @@ -156,16 +156,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return false; } - @Override - public boolean isTempBasalInProgress() { - return getTempBasal() != null; - } - - @Override - public boolean isExtendedBoluslInProgress() { - return getExtendedBolus() != null; - } - @Override public int setNewBasalProfile(NSProfile profile) { // Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile(); @@ -199,40 +189,25 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public double getTempBasalAbsoluteRate() { - if (!isTempBasalInProgress()) + if (!MainApp.getConfigBuilder().isTempBasalInProgress()) return 0; - if (getTempBasal().isAbsolute) { - return getTempBasal().absolute; + if (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).isAbsolute) { + return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).absolute; } else { NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); if (profile == null) return defaultBasalValue; Double baseRate = profile.getBasal(profile.secondsFromMidnight()); - Double tempRate = baseRate * (getTempBasal().percent / 100d); + Double tempRate = baseRate * (MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).percent / 100d); return baseRate + tempRate; } } - @Override - public TempBasal getTempBasal() { - return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(new Date()); - } - - @Override - public TempBasal getExtendedBolus() { - return ConfigBuilderPlugin.getActiveTreatments().getExtendedBolus(new Date()); - } - @Override public double getTempBasalRemainingMinutes() { - if (!isTempBasalInProgress()) + if (!MainApp.getConfigBuilder().isTempBasalInProgress()) return 0; - return getTempBasal().getPlannedRemainingMinutes(); - } - - @Override - public TempBasal getTempBasal(Date time) { - return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(time); + return MainApp.getConfigBuilder().getTempBasal(new Date().getTime()).getPlannedRemainingMinutes(); } @Override @@ -314,7 +289,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { PumpEnactResult result = new PumpEnactResult(); - if (isTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { result = cancelTempBasal(); if (!result.success) return result; @@ -383,9 +358,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { result.success = true; result.isTempCancel = true; result.comment = MainApp.instance().getString(R.string.virtualpump_resultok); - if (isTempBasalInProgress()) { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { result.enacted = true; - TempBasal tb = getTempBasal(); + TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime()); tb.timeEnd = new Date(); try { MainApp.instance().getDbHelper().getDaoTempBasals().update(tb); @@ -407,8 +382,8 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public PumpEnactResult cancelExtendedBolus() { PumpEnactResult result = new PumpEnactResult(); - if (isExtendedBoluslInProgress()) { - TempBasal extendedBolus = getExtendedBolus(); + if (MainApp.getConfigBuilder().isExtendedBoluslInProgress()) { + TempBasal extendedBolus = MainApp.getConfigBuilder().getExtendedBolus(new Date().getTime()); extendedBolus.timeEnd = new Date(); try { MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus); @@ -447,7 +422,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile()); } catch (Exception e) {} TempBasal tb; - if ((tb = getTempBasal()) != null) { + if ((tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime())) != null) { status.put("tempbasalpct", tb.percent); status.put("tempbasalstart", DateUtil.toISOString(tb.timeStart)); status.put("tempbasalremainmin", tb.getPlannedRemainingMinutes()); 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 a21a9b0a6c..afa7753f71 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 @@ -254,10 +254,10 @@ public class SmsCommunicatorPlugin implements PluginBase { if (glucoseStatus != null) reply += MainApp.sResources.getString(R.string.sms_delta) + " " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "; - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments(); - IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round(); - ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals(); - IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round(); + MainApp.getConfigBuilder().updateTotalIOBTreatments(); + IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); + MainApp.getConfigBuilder().updateTotalIOBTempBasals(); + IobTotal basalIob = MainApp.getConfigBuilder().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/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 9cd5181e0f..10d0bb794d 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 @@ -315,9 +315,14 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { lastTempBasalsCalculation = total; } + @Override + public boolean isTempBasalInProgress() { + return getTempBasal(new Date().getTime()) != null; + } + @Nullable @Override - public TempBasal getTempBasal(Date time) { + public TempBasal getTempBasal(long time) { checkForExpired(tempBasals); for (TempBasal t : tempBasals) { if (t.isInProgress(time)) return t; @@ -326,7 +331,13 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { } @Override - public TempBasal getExtendedBolus(Date time) { + public boolean isExtendedBoluslInProgress() { + return getExtendedBolus(new Date().getTime()) != null; //TODO: crosscheck here + } + + @Nullable + @Override + public TempBasal getExtendedBolus(long time) { checkForExpired(extendedBoluses); for (TempBasal t : extendedBoluses) { if (t.isInProgress(time)) return t; @@ -374,4 +385,5 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { initializeData(); } } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java index c7e24d1551..eff04d6a4b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TreatmentsFromHistory/TreatmentsFromHistoryPlugin.java @@ -280,6 +280,16 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf return in5minback; } + @Override + public boolean isTempBasalInProgress() { + return getTempBasal(new Date().getTime()) != null; + } + + @Override + public boolean isExtendedBoluslInProgress() { + return getExtendedBolus(new Date().getTime()) != null; //TODO: crosscheck here + } + @Subscribe public void onStatusEvent(final EventTreatmentChange ev) { initializeData(); @@ -314,7 +324,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf @Nullable @Override - public TempBasal getTempBasal(Date time) { + public TempBasal getTempBasal(long time) { checkForExpired(tempBasals); for (TempBasal t : tempBasals) { if (t.isInProgress(time)) return t; @@ -323,7 +333,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf } @Override - public TempBasal getExtendedBolus(Date time) { + public TempBasal getExtendedBolus(long time) { checkForExpired(extendedBoluses); for (TempBasal t : extendedBoluses) { if (t.isInProgress(time)) return t; 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 f9124e00c0..6a60fdde8c 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 @@ -32,6 +32,7 @@ import info.nightscout.androidaps.db.TempBasal; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.data.IobTotal; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Wear.ActionStringHandler; @@ -345,8 +346,8 @@ public class WatchUpdaterService extends WearableListenerService implements double beginBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime))); double endBasalValue = beginBasalValue; - TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); - TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); + TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(runningTime); + TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime); double tb_before = beginBasalValue; double tb_amount = beginBasalValue; long tb_start = runningTime; @@ -372,7 +373,7 @@ public class WatchUpdaterService extends WearableListenerService implements } //temps - tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(runningTime)); + tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime); if (tb1 == null && tb2 == null) { //no temp stays no temp @@ -405,7 +406,7 @@ public class WatchUpdaterService extends WearableListenerService implements basals.add(basalMap(beginBasalSegmentTime, runningTime, beginBasalValue)); } if(tb1 != null){ - tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(now)); //use "now" to express current situation + tb2 = MainApp.getConfigBuilder().getTempBasal(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)); @@ -420,7 +421,7 @@ public class WatchUpdaterService extends WearableListenerService implements } } } else { - tb2 = MainApp.getConfigBuilder().getTempBasal(new Date(now)); //use "now" to express current situation + tb2 = MainApp.getConfigBuilder().getTempBasal(now); //use "now" to express current situation if(tb2 != null) { //onset at the end double currentAmount = tb2.tempBasalConvertedToAbsolute(new Date(runningTime)); @@ -532,10 +533,10 @@ public class WatchUpdaterService extends WearableListenerService implements } //Temp basal - PumpInterface pump = MainApp.getConfigBuilder(); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); - if (pump.isTempBasalInProgress()) { - TempBasal activeTemp = pump.getTempBasal(); + if (treatmentsInterface.isTempBasalInProgress()) { + TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime()); if (shortString) { status += activeTemp.toStringShort(); } else { @@ -544,10 +545,10 @@ public class WatchUpdaterService extends WearableListenerService implements } //IOB - MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments(); - IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round(); - MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals(); - IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round(); + treatmentsInterface.updateTotalIOBTreatments(); + IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); + treatmentsInterface.updateTotalIOBTempBasals(); + IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round(); status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); if (mPrefs.getBoolean("wear_detailediob", true)) { 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 52ef384573..c06ceda0dd 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,6 +9,8 @@ import android.support.annotation.NonNull; import com.squareup.otto.Subscribe; +import java.util.Date; + import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; @@ -20,6 +22,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.utils.DecimalFormatter; @@ -158,10 +161,10 @@ public class StatuslinePlugin implements PluginBase { } //Temp basal - PumpInterface pump = MainApp.getConfigBuilder(); + TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); - if (pump.isTempBasalInProgress()) { - TempBasal activeTemp = pump.getTempBasal(); + if (treatmentsInterface.isTempBasalInProgress()) { + TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime()); if (shortString) { status += activeTemp.toStringShort(); } else { @@ -170,10 +173,10 @@ public class StatuslinePlugin implements PluginBase { } //IOB - MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments(); - IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round(); - MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals(); - IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round(); + treatmentsInterface.updateTotalIOBTreatments(); + IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); + treatmentsInterface.updateTotalIOBTempBasals(); + IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round(); status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index 64e6692e25..b3d44dbcc4 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -4,6 +4,7 @@ import org.json.JSONObject; import java.util.Date; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.data.IobTotal; @@ -85,7 +86,7 @@ public class BolusWizard { // Insulin from IOB // IOB calculation - TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments(); + TreatmentsInterface treatments = MainApp.getConfigBuilder(); treatments.updateTotalIOBTreatments(); IobTotal bolusIob = treatments.getLastCalculationTreatments().round(); treatments.updateTotalIOBTempBasals();