From 3342d9daa3b9bed877761e9638d173cbfefa502b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 19 Dec 2017 14:47:55 +0100 Subject: [PATCH 1/3] don't show single connection timeouts on the watch --- .../info/nightscout/androidaps/plugins/Wear/WearPlugin.java | 2 ++ .../main/java/info/nightscout/androidaps/queue/QueueThread.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 00f62bd2c0..3316d68d12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -215,6 +215,8 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { + if(ev.result == null) return; + String status; if(ev.result.success){ status = MainApp.sResources.getString(R.string.success); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 2c568cdccd..885d388db5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -59,7 +59,7 @@ public class QueueThread extends Thread { } if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { - MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult())); + MainApp.bus().post(new EventDismissBolusprogressIfRunning(null)); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout))); log.debug("QUEUE: timed out"); pump.stopConnecting(); From e11a4f6d4222949c50c416867515d6f9b2e3f107 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 19 Dec 2017 22:41:43 +0100 Subject: [PATCH 2/3] Use autosensdata for wizard instead of APSResult --- .../plugins/Overview/Dialogs/WizardDialog.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 464c422596..5e3e187d17 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 @@ -53,6 +53,8 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; @@ -439,7 +441,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); // COB only if AMA is selected - if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) { + if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin) { cobLayout.setVisibility(View.VISIBLE); cobAvailable = true; } else { @@ -483,12 +485,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com // COB Double c_cob = 0d; if (cobAvailable && cobCheckbox.isChecked()) { - if (ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) { - try { - c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB")); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis()); + + if(autosensData != null && autosensData.time > System.currentTimeMillis() - 11 * 60 * 1000L) { + c_cob = autosensData.cob; } } From 8fdd16c305cdb495b453e9752d63cbc0aff7343f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 26 Dec 2017 00:27:34 +0100 Subject: [PATCH 3/3] QuickWizard detailed settings --- .../Overview => data}/QuickWizard.java | 85 +----- .../androidaps/data/QuickWizardEntry.java | 242 ++++++++++++++++++ .../Dialogs/EditQuickWizardDialog.java | 92 ++++++- .../Overview/Dialogs/WizardDialog.java | 32 +-- .../plugins/Overview/OverviewFragment.java | 46 +++- .../plugins/Overview/OverviewPlugin.java | 1 + .../activities/QuickWizardListActivity.java | 7 +- .../info/nightscout/utils/BolusWizard.java | 16 +- .../overview_editquickwizard_dialog.xml | 119 +++++++-- app/src/main/res/values/arrays.xml | 39 +++ app/src/main/res/values/strings.xml | 11 + 11 files changed, 529 insertions(+), 161 deletions(-) rename app/src/main/java/info/nightscout/androidaps/{plugins/Overview => data}/QuickWizard.java (50%) create mode 100644 app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java similarity index 50% rename from app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java rename to app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java index 2962575a68..587d7f86a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/QuickWizard.java +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizard.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.Overview; +package info.nightscout.androidaps.data; import android.content.SharedPreferences; import android.preference.PreferenceManager; @@ -9,11 +9,7 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Date; - import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.utils.DateUtil; /** * Created by mike on 12.10.2016. @@ -22,84 +18,7 @@ import info.nightscout.utils.DateUtil; public class QuickWizard { private static Logger log = LoggerFactory.getLogger(QuickWizard.class); - public class QuickWizardEntry { - public JSONObject storage; - public int position; - - /* - { - buttonText: "Meal", - carbs: 36, - validFrom: 8 * 60 * 60, // seconds from midnight - validTo: 9 * 60 * 60, // seconds from midnight - } - */ - public QuickWizardEntry() { - String emptyData = "{\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340}"; - try { - storage = new JSONObject(emptyData); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - position = -1; - } - - public QuickWizardEntry(JSONObject entry, int position) { - storage = entry; - this.position = position; - } - - public Boolean isActive() { - return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo(); - } - - public String buttonText() { - try { - return storage.getString("buttonText"); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - return ""; - } - - public Integer carbs() { - try { - return storage.getInt("carbs"); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - return 0; - } - - public Date validFromDate() { - return DateUtil.toDate(validFrom()); - } - - public Date validToDate() { - return DateUtil.toDate(validTo()); - } - - public Integer validFrom() { - try { - return storage.getInt("validFrom"); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - return 0; - } - - public Integer validTo() { - try { - return storage.getInt("validTo"); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - return 0; - } - - } - - JSONArray storage = new JSONArray(); + private JSONArray storage = new JSONArray(); public void setData(JSONArray newData) { storage = newData; diff --git a/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java new file mode 100644 index 0000000000..e6130402b5 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/data/QuickWizardEntry.java @@ -0,0 +1,242 @@ +package info.nightscout.androidaps.data; + +import org.json.JSONException; +import org.json.JSONObject; +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.db.BgReading; +import info.nightscout.androidaps.db.TempTarget; +import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; +import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.utils.BolusWizard; +import info.nightscout.utils.DateUtil; +import info.nightscout.utils.SP; + +/** + * Created by mike on 25.12.2017. + */ + +public class QuickWizardEntry { + private static Logger log = LoggerFactory.getLogger(QuickWizardEntry.class); + + public JSONObject storage; + public int position; + + public static final int YES = 0; + public static final int NO = 1; + public static final int POSITIVE_ONLY = 2; + public static final int NEGATIVE_ONLY = 3; + + /* + { + buttonText: "Meal", + carbs: 36, + validFrom: 8 * 60 * 60, // seconds from midnight + validTo: 9 * 60 * 60, // seconds from midnight + useBG: 0, + useCOB: 0, + useBolusIOB: 0, + useBasalIOB: 0, + useTrend: 0, + useSuperBolus: 0, + useTemptarget: 0 + } + */ + public QuickWizardEntry() { + String emptyData = "{\"buttonText\":\"\",\"carbs\":0,\"validFrom\":0,\"validTo\":86340}"; + try { + storage = new JSONObject(emptyData); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + position = -1; + } + + public QuickWizardEntry(JSONObject entry, int position) { + storage = entry; + this.position = position; + } + + public Boolean isActive() { + return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo(); + } + + public BolusWizard doCalc(Profile profile, TempTarget tempTarget, BgReading lastBG) { + BolusWizard wizard = new BolusWizard(); + + //BG + double bg = 0; + if (lastBG != null && useBG() == YES) { + bg = lastBG.valueToUnits(profile.getUnits()); + } + + // COB + double cob = 0d; + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis()); + if (autosensData != null && useCOB() == YES) { + cob = autosensData.cob; + } + + // Temp target + if (useTempTarget() == NO) { + tempTarget = null; + } + + // Bolus IOB + boolean bolusIOB = false; + if (useBolusIOB() == YES) { + bolusIOB = true; + } + + // Basal IOB + TreatmentsInterface treatments = MainApp.getConfigBuilder(); + treatments.updateTotalIOBTempBasals(); + IobTotal basalIob = treatments.getLastCalculationTempBasals().round(); + boolean basalIOB = false; + if (useBasalIOB() == YES) { + basalIOB = true; + } else if (useBasalIOB() == POSITIVE_ONLY && basalIob.iob > 0) { + basalIOB = true; + } else if (useBasalIOB() == NEGATIVE_ONLY && basalIob.iob < 0) { + basalIOB = true; + } + + // SuperBolus + boolean superBolus = false; + if (useSuperBolus() == YES && SP.getBoolean(R.string.key_usesuperbolus, false)) { + superBolus = true; + } + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) + superBolus = false; + + // Trend + GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); + boolean trend = false; + if (useTrend() == YES) { + trend = true; + } else if (useTrend() == POSITIVE_ONLY && glucoseStatus != null && glucoseStatus.short_avgdelta > 0) { + trend = true; + } else if (useTrend() == NEGATIVE_ONLY && glucoseStatus != null && glucoseStatus.short_avgdelta < 0) { + trend = true; + } + + wizard.doCalc(profile, tempTarget, carbs(), cob, bg, 0d, bolusIOB, basalIOB, superBolus, trend); + return wizard; + } + + public String buttonText() { + try { + return storage.getString("buttonText"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return ""; + } + + public Integer carbs() { + try { + return storage.getInt("carbs"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return 0; + } + + public Date validFromDate() { + return DateUtil.toDate(validFrom()); + } + + public Date validToDate() { + return DateUtil.toDate(validTo()); + } + + public Integer validFrom() { + try { + return storage.getInt("validFrom"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return 0; + } + + public Integer validTo() { + try { + return storage.getInt("validTo"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return 0; + } + + public int useBG() { + try { + return storage.getInt("useBG"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return YES; + } + + public int useCOB() { + try { + return storage.getInt("useCOB"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return NO; + } + + public int useBolusIOB() { + try { + return storage.getInt("useBolusIOB"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return YES; + } + + public int useBasalIOB() { + try { + return storage.getInt("useBasalIOB"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return YES; + } + + public int useTrend() { + try { + return storage.getInt("useTrend"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return NO; + } + + public int useSuperBolus() { + try { + return storage.getInt("useSuperBolus"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return NO; + } + + public int useTempTarget() { + try { + return storage.getInt("useTempTarget"); + } catch (JSONException e) { + log.error("Unhandled exception", e); + } + return NO; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java index 95bcea7908..2751b800bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/EditQuickWizardDialog.java @@ -9,7 +9,6 @@ import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.EditText; import android.widget.Spinner; @@ -17,13 +16,13 @@ import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.SimpleDateFormat; import java.util.ArrayList; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.QuickWizard; +import info.nightscout.androidaps.data.QuickWizardEntry; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.QuickWizard; import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange; import info.nightscout.utils.DateUtil; import info.nightscout.utils.SafeParse; @@ -31,19 +30,25 @@ import info.nightscout.utils.SafeParse; public class EditQuickWizardDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class); - QuickWizard.QuickWizardEntry entry = new QuickWizard().newEmptyItem(); + QuickWizardEntry entry = new QuickWizard().newEmptyItem(); QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard; EditText buttonEdit; EditText carbsEdit; Spinner fromSpinner; Spinner toSpinner; - Button okButton; + Spinner useBGSpinner; + Spinner useCOBSpinner; + Spinner useBolusIOBSpinner; + Spinner useBasalIOBSpinner; + Spinner useTrendSpinner; + Spinner useSuperBolusSpinner; + Spinner useTempTargetSpinner; public EditQuickWizardDialog() { } - public void setData(QuickWizard.QuickWizardEntry data) { + public void setData(QuickWizardEntry data) { entry = data; } @@ -58,8 +63,16 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic carbsEdit = (EditText) view.findViewById(R.id.overview_editquickwizard_carbs_edit); fromSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_from_spinner); toSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_to_spinner); - okButton = (Button) view.findViewById(R.id.overview_editquickwizard_ok_button); - okButton.setOnClickListener(this); + useBGSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebg_spinner); + useCOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usecob_spinner); + useBolusIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebolusiob_spinner); + useBasalIOBSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usebasaliob_spinner); + useTrendSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetrend_spinner); + useSuperBolusSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usesuperbolus_spinner); + useTempTargetSpinner = (Spinner) view.findViewById(R.id.overview_editquickwizard_usetemptarget_spinner); + + view.findViewById(R.id.ok).setOnClickListener(this); + view.findViewById(R.id.cancel).setOnClickListener(this); int posFrom = 0; int posTo = 95; @@ -83,6 +96,14 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic fromSpinner.setSelection(posFrom); toSpinner.setSelection(posTo); + setSelection(useBGSpinner, entry.useBG()); + setSelection(useCOBSpinner, entry.useCOB()); + setSelection(useBolusIOBSpinner, entry.useBolusIOB()); + setSelection(useBasalIOBSpinner, entry.useBasalIOB()); + setSelection(useTrendSpinner, entry.useTrend()); + setSelection(useSuperBolusSpinner, entry.useSuperBolus()); + setSelection(useTempTargetSpinner, entry.useTempTarget()); + return view; } @@ -96,7 +117,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic @Override public void onClick(View v) { switch (v.getId()) { - case R.id.overview_editquickwizard_ok_button: + case R.id.ok: if (fromSpinner.getSelectedItem() == null) return; if (toSpinner.getSelectedItem() == null) return; try { @@ -106,13 +127,64 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic entry.storage.put("validFrom", validFromInt); int validToInt = DateUtil.toSeconds(toSpinner.getSelectedItem().toString()); entry.storage.put("validTo", validToInt); + entry.storage.put("useBG", getSelection(useBGSpinner)); + entry.storage.put("useCOB", getSelection(useCOBSpinner)); + entry.storage.put("useBolusIOB", getSelection(useBolusIOBSpinner)); + entry.storage.put("useBasalIOB", getSelection(useBasalIOBSpinner)); + entry.storage.put("useTrend", getSelection(useTrendSpinner)); + entry.storage.put("useSuperBolus", getSelection(useSuperBolusSpinner)); + entry.storage.put("useTempTarget", getSelection(useTempTargetSpinner)); } catch (JSONException e) { log.error("Unhandled exception", e); } quickWizard.addOrUpdate(entry); dismiss(); MainApp.bus().post(new EventQuickWizardChange()); - break; + break; + case R.id.cancel: + dismiss(); + break; + } + } + + int getSelection(Spinner spinner) { + String value = spinner.getSelectedItem().toString(); + if (value.equals(MainApp.sResources.getString(R.string.yes))) + return QuickWizardEntry.YES; + if (value.equals(MainApp.sResources.getString(R.string.no))) + return QuickWizardEntry.NO; + if (value.equals(MainApp.sResources.getString(R.string.positiveonly))) + return QuickWizardEntry.POSITIVE_ONLY; + if (value.equals(MainApp.sResources.getString(R.string.negativeonly))) + return QuickWizardEntry.NEGATIVE_ONLY; + return QuickWizardEntry.NO; + } + + void setSelection(Spinner spinner, int value) { + String selection; + switch (value) { + case QuickWizardEntry.YES: + selection = MainApp.sResources.getString(R.string.yes); + break; + case QuickWizardEntry.NO: + selection = MainApp.sResources.getString(R.string.no); + break; + case QuickWizardEntry.POSITIVE_ONLY: + selection = MainApp.sResources.getString(R.string.positiveonly); + break; + case QuickWizardEntry.NEGATIVE_ONLY: + selection = MainApp.sResources.getString(R.string.negativeonly); + break; + default: + selection = MainApp.sResources.getString(R.string.no); + break; + } + + for (int i = 0; i < spinner.getCount(); i++) { + if (spinner.getItemAtPosition(i).toString().equalsIgnoreCase(selection)) { + spinner.setSelection(i); + break; + } } } } 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 654764839c..eb46af6b30 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 @@ -104,7 +104,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com Integer calculatedCarbs = 0; Double calculatedTotalInsulin = 0d; JSONObject boluscalcJSON; - boolean cobAvailable = false; Context context; @@ -140,25 +139,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com MainApp.bus().unregister(this); } - @Subscribe - public void onStatusEvent(final EventOpenAPSUpdateGui e) { - Activity activity = getActivity(); - if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) { - cobLayout.setVisibility(View.VISIBLE); - cobAvailable = true; - } else { - cobLayout.setVisibility(View.GONE); - cobAvailable = false; - } - calculateInsulin(); - } - }); - } - @Subscribe public void onStatusEvent(final EventNewBG e) { Activity activity = getActivity(); @@ -441,14 +421,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U"); basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); - // COB only if AMA is selected - if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin) { - cobLayout.setVisibility(View.VISIBLE); - cobAvailable = true; - } else { - cobLayout.setVisibility(View.GONE); - cobAvailable = false; - } calculateInsulin(); } @@ -485,7 +457,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com // COB Double c_cob = 0d; - if (cobAvailable && cobCheckbox.isChecked()) { + if (cobCheckbox.isChecked()) { AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis()); if(autosensData != null && autosensData.time > System.currentTimeMillis() - 11 * 60 * 1000L) { @@ -531,7 +503,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com bgTrendInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromTrend) + "U"); // COB - if (cobAvailable && cobCheckbox.isChecked()) { + if (cobCheckbox.isChecked()) { cob.setText(DecimalFormatter.to2Decimal(c_cob) + "g IC: " + DecimalFormatter.to1Decimal(wizard.ic)); cobInsulin.setText(DecimalFormatter.to2Decimal(wizard.insulinFromCOB) + "U"); } else { 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 c531b080c0..e94f921882 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 @@ -60,6 +60,7 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.data.QuickWizardEntry; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; @@ -97,6 +98,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.CalibrationDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog; +import info.nightscout.androidaps.plugins.Overview.activities.QuickWizardListActivity; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; @@ -115,7 +117,7 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SingleClickButton; import info.nightscout.utils.ToastUtils; -public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { +public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener, View.OnLongClickListener { private static Logger log = LoggerFactory.getLogger(OverviewFragment.class); TextView timeView; @@ -253,6 +255,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, acceptTempButton.setOnClickListener(this); quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton); quickWizardButton.setOnClickListener(this); + quickWizardButton.setOnLongClickListener(this); calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton); if (calibrationButton != null) calibrationButton.setOnClickListener(this); @@ -577,6 +580,17 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } + @Override + public boolean onLongClick(View v) { + switch (v.getId()) { + case R.id.overview_quickwizardbutton: + Intent i = new Intent(v.getContext(), QuickWizardListActivity.class); + startActivity(i); + return true; + } + return false; + } + private void onClickAcceptTemp() { if (ConfigBuilderPlugin.getActiveLoop() != null) { ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false); @@ -620,11 +634,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final Profile profile = MainApp.getConfigBuilder().getProfile(); final TempTarget tempTarget = MainApp.getConfigBuilder().getTempTargetFromHistory(); - QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); + final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && actualBg != null) { quickWizardButton.setVisibility(View.VISIBLE); - BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, actualBg.valueToUnits(profile.getUnits()), 0d, true, true, false, false); + final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg); final JSONObject boluscalcJSON = new JSONObject(); try { @@ -683,6 +696,26 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } accepted = true; if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) { + if (wizard.superBolus) { + final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + if (activeloop != null) { + activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); + MainApp.bus().post(new EventRefreshOverview("WizardDialog")); + } + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } + } + }); + } DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD; detailedBolusInfo.insulin = finalInsulinAfterConstraints; @@ -1087,12 +1120,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, tempTargetView.setLongClickable(true); // QuickWizard button - QuickWizard.QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); + QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; - BolusWizard wizard = new BolusWizard(); - wizard.doCalc(profile, tempTarget, quickWizardEntry.carbs(), 0d, lastBG.valueToUnits(units), 0d, true, true, false, false); + BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG); text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U"; quickWizardButton.setText(text); if (wizard.calculatedTotalInsulin <= 0) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index 57aa5a8054..eb31ae66ed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.QuickWizard; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java index 9fc731b4f5..237575c328 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/activities/QuickWizardListActivity.java @@ -1,9 +1,9 @@ package info.nightscout.androidaps.plugins.Overview.activities; import android.app.Activity; +import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -15,13 +15,11 @@ import android.widget.TextView; import com.squareup.otto.Subscribe; -import java.text.SimpleDateFormat; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.QuickWizard; import info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; -import info.nightscout.androidaps.plugins.Overview.QuickWizard; import info.nightscout.androidaps.plugins.Overview.events.EventQuickWizardChange; import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; @@ -153,6 +151,7 @@ public class QuickWizardListActivity extends AppCompatActivity implements View.O break; } } + @Subscribe public void onStatusEvent(final EventQuickWizardChange ev) { updateGUI(); diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index 5a683f1aaa..ac710dc51f 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -14,15 +14,15 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; public class BolusWizard { // Inputs - Profile specificProfile = null; - TempTarget tempTarget; + private Profile specificProfile = null; + private TempTarget tempTarget; public Integer carbs = 0; - Double bg = 0d; - Double correction; - Boolean includeBolusIOB = true; - Boolean includeBasalIOB = true; - Boolean superBolus = false; - Boolean trend = false; + private Double bg = 0d; + private Double correction; + private Boolean includeBolusIOB = true; + private Boolean includeBasalIOB = true; + public Boolean superBolus = false; + private Boolean trend = false; // Intermediate public Double sens = 0d; diff --git a/app/src/main/res/layout/overview_editquickwizard_dialog.xml b/app/src/main/res/layout/overview_editquickwizard_dialog.xml index 29515f7c79..405af2ae59 100644 --- a/app/src/main/res/layout/overview_editquickwizard_dialog.xml +++ b/app/src/main/res/layout/overview_editquickwizard_dialog.xml @@ -5,68 +5,149 @@ tools:context="info.nightscout.androidaps.plugins.Overview.Dialogs.EditQuickWizardDialog"> + android:layout_margin="15dp" + android:orientation="vertical"> + android:inputType="text" /> + android:inputType="numberDecimal" /> + android:layout_height="wrap_content" + android:orientation="horizontal"> -