diff --git a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java index c401c47574..a624310b10 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TemporaryBasal.java @@ -296,17 +296,17 @@ public class TemporaryBasal implements Interval { Profile profile = MainApp.getConfigBuilder().getProfile(); Double currentBasalRate = profile.getBasal(); double rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); - return DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" + + return getCalcuatedPercentageIfNeeded() + DecimalFormatter.to2Decimal(rate) + "U/h ("+DecimalFormatter.to2Decimal(netExtendedRate)+"E) @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } else if (isAbsolute) { return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } else { // percent return percentRate + "% @" + DateUtil.timeString(date) + - " " + getRealDuration() + "/" + durationInMinutes + "min"; + " " + getRealDuration() + "/" + durationInMinutes + "'"; } } @@ -337,6 +337,31 @@ public class TemporaryBasal implements Interval { } } + private String getCalcuatedPercentageIfNeeded(){ + if (isAbsolute || isFakeExtended) { + + double rate = 0d; + if (isFakeExtended) { + Profile profile = MainApp.getConfigBuilder().getProfile(); + Double currentBasalRate = profile.getBasal(); + rate = (currentBasalRate == null)?0d:(currentBasalRate+netExtendedRate); + } else if (isAbsolute){ + rate = absoluteRate; + } + + if(SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false) && SP.getBoolean(R.string.key_danar_useextended, false)){ + Profile profile = MainApp.getConfigBuilder().getProfile(); + if(profile != null) { + double basal = profile.getBasal(); + if(basal != 0){ + return Math.round(rate*100d/basal) + "% "; + } + } + } + } + return ""; + } + public String toStringVeryShort() { if (isAbsolute || isFakeExtended) { 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 dbbdec2ce1..bb78ea1d0a 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -34,7 +34,9 @@ public interface PumpInterface { PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes); PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes); PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes); - PumpEnactResult cancelTempBasal(); + //some pumps might set a very short temp close to 100% as canecelling a temp can be noisy + //when the cancel request is requested by the user, the pump should always do a real cancel + PumpEnactResult cancelTempBasal(boolean userRequested); PumpEnactResult cancelExtendedBolus(); // Status to be passed to NS 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 b62674c5ae..c6b278955f 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 @@ -20,6 +20,7 @@ import info.nightscout.androidaps.Config; 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.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; @@ -49,6 +50,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL Button extendedBolus; Button extendedBolusCancel; Button tempBasal; + Button tempBasalCancel; Button fill; private static Handler sHandler; @@ -74,6 +76,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel); tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); + tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal); fill = (Button) view.findViewById(R.id.actions_fill); profileSwitch.setOnClickListener(this); @@ -81,6 +84,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL extendedBolus.setOnClickListener(this); extendedBolusCancel.setOnClickListener(this); tempBasal.setOnClickListener(this); + tempBasalCancel.setOnClickListener(this); fill.setOnClickListener(this); updateGUI(); @@ -114,33 +118,59 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL activity.runOnUiThread(new Runnable() { @Override public void run() { - if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() == null) + if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() == null) { + tempTarget.setVisibility(View.GONE); + profileSwitch.setVisibility(View.GONE); + extendedBolus.setVisibility(View.GONE); + extendedBolusCancel.setVisibility(View.GONE); + tempBasal.setVisibility(View.GONE); + tempBasalCancel.setVisibility(View.GONE); + fill.setVisibility(View.GONE); return; + } boolean allowProfileSwitch = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getProfileList().size() > 1; if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !allowProfileSwitch) profileSwitch.setVisibility(View.GONE); else profileSwitch.setVisibility(View.VISIBLE); - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) + + + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) { extendedBolus.setVisibility(View.GONE); - else { - extendedBolus.setVisibility(View.VISIBLE); - } - if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() || MainApp.getConfigBuilder().isFakingTempsByExtendedBoluses()) extendedBolusCancel.setVisibility(View.GONE); - else { - extendedBolusCancel.setVisibility(View.VISIBLE); - ExtendedBolus running = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); - extendedBolusCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + running.toString()); + } else { + if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress()) { + extendedBolus.setVisibility(View.GONE); + extendedBolusCancel.setVisibility(View.VISIBLE); + ExtendedBolus running = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); + extendedBolusCancel.setText(MainApp.instance().getString(R.string.cancel) + " " + running.toString()); + } else { + extendedBolus.setVisibility(View.VISIBLE); + extendedBolusCancel.setVisibility(View.GONE); + } } - if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended() || MainApp.getConfigBuilder().isTempBasalInProgress()) + + + if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) { tempBasal.setVisibility(View.GONE); - else - tempBasal.setVisibility(View.VISIBLE); + tempBasalCancel.setVisibility(View.GONE); + } else { + if (MainApp.getConfigBuilder().isTempBasalInProgress()) { + tempBasal.setVisibility(View.GONE); + tempBasalCancel.setVisibility(View.VISIBLE); + final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + tempBasalCancel.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); + } else { + tempBasal.setVisibility(View.VISIBLE); + tempBasalCancel.setVisibility(View.GONE); + } + } + if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized() || MainApp.getConfigBuilder().isSuspended()) fill.setVisibility(View.GONE); else fill.setVisibility(View.VISIBLE); + if (!Config.APS) tempTarget.setVisibility(View.GONE); else @@ -184,6 +214,17 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL }); } break; + case R.id.actions_canceltempbasal: + if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) { + sHandler.post(new Runnable() { + @Override + public void run() { + pump.cancelTempBasal(true); + Answers.getInstance().logCustom(new CustomEvent("CancelTemp")); + } + }); + } + break; case R.id.actions_settempbasal: NewTempBasalDialog newTempDialog = new NewTempBasalDialog(); newTempDialog.show(manager, "NewTempDialog"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index 51effccb86..0a379a904d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -27,6 +27,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.data.Profile; +import info.nightscout.utils.NumberPicker; import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.SafeParse; @@ -35,14 +36,14 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi RadioButton percentRadio; RadioButton absoluteRadio; RadioGroup basalTypeRadioGroup; - RelativeLayout typeSelectorLayout; + LinearLayout typeSelectorLayout; LinearLayout percentLayout; LinearLayout absoluteLayout; - PlusMinusEditText basalPercent; - PlusMinusEditText basalAbsolute; - PlusMinusEditText duration; + NumberPicker basalPercent; + NumberPicker basalAbsolute; + NumberPicker duration; Handler mHandler; public static HandlerThread mHandlerThread; @@ -65,22 +66,24 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi percentRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_percent_radio); basalTypeRadioGroup = (RadioGroup) view.findViewById(R.id.overview_newtempbasal_radiogroup); absoluteRadio = (RadioButton) view.findViewById(R.id.overview_newtempbasal_absolute_radio); - typeSelectorLayout = (RelativeLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout); + typeSelectorLayout = (LinearLayout) view.findViewById(R.id.overview_newtempbasal_typeselector_layout); PumpDescription pumpDescription = MainApp.getConfigBuilder().getPumpDescription(); - basalPercent = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalpercentinput, R.id.overview_newtempbasal_basalpercent_plus, R.id.overview_newtempbasal_basalpercent_minus, - 100d, 0d, (double) pumpDescription.maxTempPercent, (double) pumpDescription.tempPercentStep, new DecimalFormat("0"), true); + basalPercent = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalpercentinput); + double maxTempPercent = pumpDescription.maxTempPercent; + double tempPercentStep = pumpDescription.tempPercentStep; + basalPercent.setParams(100d, 0d, maxTempPercent, tempPercentStep, new DecimalFormat("0"), true); Profile profile = MainApp.getConfigBuilder().getProfile(); - Double currentBasal = profile.getBasal(); - basalAbsolute = new PlusMinusEditText(view, R.id.overview_newtempbasal_basalabsoluteinput, R.id.overview_newtempbasal_basalabsolute_plus, R.id.overview_newtempbasal_basalabsolute_minus, - currentBasal, 0d, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, new DecimalFormat("0.00"), true); + Double currentBasal = profile != null ? profile.getBasal() : 0d; + basalAbsolute = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_basalabsoluteinput); + basalAbsolute.setParams(currentBasal, 0d, pumpDescription.maxTempAbsolute, pumpDescription.tempAbsoluteStep, new DecimalFormat("0.00"), true); - double tempDurationStep = MainApp.getConfigBuilder().getPumpDescription().tempDurationStep; - double tempMaxDuration = MainApp.getConfigBuilder().getPumpDescription().tempMaxDuration; - duration = new PlusMinusEditText(view, R.id.overview_newtempbasal_duration, R.id.overview_newtempbasal_duration_plus, R.id.overview_newtempbasal_duration_minus, - tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, new DecimalFormat("0"), false); + double tempDurationStep = pumpDescription.tempDurationStep; + double tempMaxDuration = pumpDescription.tempMaxDuration; + duration = (NumberPicker) view.findViewById(R.id.overview_newtempbasal_duration); + duration.setParams(tempDurationStep, tempDurationStep, tempMaxDuration, tempDurationStep, new DecimalFormat("0"), false); if ((pumpDescription.tempBasalStyle & PumpDescription.PERCENT) == PumpDescription.PERCENT && (pumpDescription.tempBasalStyle & PumpDescription.ABSOLUTE) == PumpDescription.ABSOLUTE) { // Both allowed @@ -107,13 +110,6 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi return view; } - @Override - public void onResume() { - super.onResume(); - if (getDialog() != null) - getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - } - @Override public void onClick(View view) { switch (view.getId()) { 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 31907f16dc..ea995d2b6b 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 @@ -509,8 +509,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } @Override - public PumpEnactResult cancelTempBasal() { - PumpEnactResult result = activePump.cancelTempBasal(); + public PumpEnactResult cancelTempBasal(boolean userRequested) { + PumpEnactResult result = activePump.cancelTempBasal(userRequested); if (Config.logCongigBuilderActions) log.debug("cancelTempBasal success: " + result.success + " enacted: " + result.enacted); return result; @@ -559,7 +559,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain if (isTempBasalInProgress()) { if (Config.logCongigBuilderActions) log.debug("applyAPSRequest: cancelTempBasal()"); - result = cancelTempBasal(); + result = cancelTempBasal(false); } else { result = new PumpEnactResult(); result.absolute = request.rate; 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 5d57f3caf1..c68bbb19d7 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 @@ -313,6 +313,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } + pump.cancelTempBasal(true); result = pump.setTempBasalAbsolute(0d, 120); if (!result.success) { OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror), result.comment, null); 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 71f205551e..7e33d1ff8c 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 @@ -175,7 +175,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, LinearLayoutManager llm; LinearLayout acceptTempLayout; - Button cancelTempButton; Button treatmentButton; Button wizardButton; Button calibrationButton; @@ -269,9 +268,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); - cancelTempButton = (Button) view.findViewById(R.id.overview_canceltempbutton); - if (cancelTempButton != null) - cancelTempButton.setOnClickListener(this); treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); treatmentButton.setOnClickListener(this); wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); @@ -415,7 +411,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -436,7 +432,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -450,7 +446,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -464,7 +460,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -478,7 +474,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -492,7 +488,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); } @@ -506,6 +502,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 30); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -520,6 +517,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -534,6 +532,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 2 * 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -548,6 +547,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, sHandler.post(new Runnable() { @Override public void run() { + MainApp.getConfigBuilder().cancelTempBasal(true); PumpEnactResult result = MainApp.getConfigBuilder().setTempBasalAbsolute(0d, 3 * 60); if (!result.success) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); @@ -583,18 +583,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(); treatmentDialogFragment.show(manager, "TreatmentDialog"); break; - case R.id.overview_canceltempbutton: - final PumpInterface pump = MainApp.getConfigBuilder(); - if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - sHandler.post(new Runnable() { - @Override - public void run() { - pump.cancelTempBasal(); - Answers.getInstance().logCustom(new CustomEvent("CancelTemp")); - } - }); - } - break; case R.id.overview_pumpstatus: if (MainApp.getConfigBuilder().isSuspended() || !MainApp.getConfigBuilder().isInitialized()) sHandler.post(new Runnable() { @@ -1016,15 +1004,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } final TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); - if (cancelTempButton != null) { - if (activeTemp != null) { - cancelTempButton.setVisibility(View.VISIBLE); - cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort()); - } else { - cancelTempButton.setVisibility(View.GONE); - } - } - String basalText = ""; if (shorttextmode) { if (activeTemp != null) { @@ -1053,6 +1032,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, basalText += "(" + DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + "U/h)"; } } + if (activeTemp != null) { + baseBasalView.setTextColor(MainApp.sResources.getColor(R.color.basal)); + } else { + baseBasalView.setTextColor(Color.WHITE); + + } + baseBasalView.setText(basalText); final ExtendedBolus extendedBolus = MainApp.getConfigBuilder().getExtendedBolusFromHistory(System.currentTimeMillis()); 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 7ee13df40c..7ed4345093 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 @@ -566,7 +566,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { 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 c3bd70c155..e3b6bf3598 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 @@ -570,7 +570,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { if (MainApp.getConfigBuilder().isInHistoryRealTempBasalInProgress()) return cancelRealTempBasal(); if (MainApp.getConfigBuilder().isInHistoryExtendedBoluslInProgress() && useExtendedBoluses) { 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 7a0eca5da3..bb944b1165 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 @@ -340,7 +340,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, if (MainApp.getConfigBuilder().isTempBasalInProgress()) { if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Stopping temp basal (doTempOff)"); - return cancelTempBasal(); + return cancelTempBasal(false); } result.success = true; result.enacted = false; @@ -507,7 +507,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { PumpEnactResult result = new PumpEnactResult(); if (pump.isTempBasalInProgress) { sExecutionService.tempBasalStop(); 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 b51a0bb66e..ddd05a2e0b 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 @@ -196,7 +196,7 @@ public class MDIPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { PumpEnactResult result = new PumpEnactResult(); result.success = false; result.comment = MainApp.instance().getString(R.string.pumperror); 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 2dfaefe482..b479183b80 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 @@ -57,7 +57,6 @@ public class VirtualPumpFragment extends SubscriberFragment { batteryView = (TextView) view.findViewById(R.id.virtualpump_battery); reservoirView = (TextView) view.findViewById(R.id.virtualpump_reservoir); - updateGUI(); return view; } @@ -73,8 +72,8 @@ public class VirtualPumpFragment extends SubscriberFragment { activity.runOnUiThread(new Runnable() { @Override public void run() { - - basaBasalRateView.setText(VirtualPumpPlugin.getInstance().getBaseBasalRate() + "U"); + VirtualPumpPlugin virtualPump = VirtualPumpPlugin.getInstance(); + basaBasalRateView.setText(virtualPump.getBaseBasalRate() + "U"); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { tempBasalView.setText(MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); } else { @@ -85,8 +84,8 @@ public class VirtualPumpFragment extends SubscriberFragment { } else { extendedBolusView.setText(""); } - batteryView.setText(VirtualPumpPlugin.getInstance().batteryPercent + "%"); - reservoirView.setText(VirtualPumpPlugin.getInstance().reservoirInUnits + "U"); + batteryView.setText(virtualPump.batteryPercent + "%"); + reservoirView.setText(virtualPump.reservoirInUnits + "U"); } }); } 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 b42d1abfd6..7337859c47 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 @@ -204,7 +204,11 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { @Override public double getBaseBasalRate() { - return MainApp.getConfigBuilder().getProfile().getBasal(); + Profile profile = MainApp.getConfigBuilder().getProfile(); + if (profile != null) + return profile.getBasal(); + else + return 0d; } @Override @@ -282,7 +286,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { - result = cancelTempBasal(); + result = cancelTempBasal(false); if (!result.success) return result; } @@ -333,7 +337,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult cancelTempBasal() { + public PumpEnactResult cancelTempBasal(boolean userRequested) { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); result.success = true; 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 ad8679beee..8e5e3bde46 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 @@ -272,7 +272,7 @@ public class SmsCommunicatorPlugin implements PluginBase { LoopPlugin loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) { loopPlugin.setFragmentEnabled(PluginBase.LOOP, false); - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_STOP")); reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled)+ " " + MainApp.sResources.getString(result.success?R.string.smscommunicator_tempbasalcanceled:R.string.smscommunicator_tempbasalcancelfailed); @@ -506,7 +506,7 @@ public class SmsCommunicatorPlugin implements PluginBase { PumpInterface pumpInterface = MainApp.getConfigBuilder(); if (pumpInterface != null) { danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); - PumpEnactResult result = pumpInterface.cancelTempBasal(); + PumpEnactResult result = pumpInterface.cancelTempBasal(true); if (result.success) { reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled); if (danaRPlugin != null) @@ -535,7 +535,7 @@ public class SmsCommunicatorPlugin implements PluginBase { suspendWaitingForConfirmation.processed = true; final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000); - PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(); + PumpEnactResult result = MainApp.getConfigBuilder().cancelTempBasal(true); NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED")); reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " + diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index 4fa5a0d5e2..aeb1f7181d 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -49,7 +49,6 @@ public class NSUpload { data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.absoluteRate + "u/h " + temporaryBasal.durationInMinutes + " min"); // ECOR if (originalExtendedAmount != null) data.put("originalExtendedAmount", originalExtendedAmount); // for back synchronization Bundle bundle = new Bundle(); @@ -88,7 +87,6 @@ public class NSUpload { data.put("pumpId", temporaryBasal.pumpId); data.put("created_at", DateUtil.toISOString(temporaryBasal.date)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalstartnote) + " " + temporaryBasal.percentRate + "% " + temporaryBasal.durationInMinutes + " min"); // ECOR Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); bundle.putString("collection", "treatments"); @@ -111,7 +109,6 @@ public class NSUpload { data.put("eventType", CareportalEvent.TEMPBASAL); data.put("created_at", DateUtil.toISOString(time)); data.put("enteredBy", "openaps://" + MainApp.instance().getString(R.string.app_name)); - data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR if (isFakedTempBasal) data.put("isFakedTempBasal", isFakedTempBasal); if (pumpId != 0) diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index e24f69124d..bc8f416770 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -52,6 +52,19 @@ android:drawableTop="@drawable/icon_actions_starttempbasal" android:text="@string/overview_tempbasal_button" /> +