From 32108a7c2fa9f4b71136adec9c24127d682287ac Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 16 Mar 2018 21:29:41 +0100 Subject: [PATCH 1/4] Carbs button: fix visibility pref, input type, allow negative increments. --- .../Overview/Dialogs/NewCarbsDialog.java | 48 ++++++++----------- .../plugins/Overview/OverviewFragment.java | 4 +- .../res/layout/overview_newcarbs_dialog.xml | 10 ---- app/src/main/res/xml/pref_overview.xml | 18 +++---- 4 files changed, 30 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java index a60a2f08b9..1d7279ce6e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java @@ -53,7 +53,6 @@ import info.nightscout.utils.ToastUtils; public class NewCarbsDialog extends DialogFragment implements OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class); - private EditText foodText; private NumberPicker editCarbs; private TextView dateButton; @@ -66,9 +65,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private Button fav2Button; private Button fav3Button; - private static final double FAV1_DEFAULT = 5; - private static final double FAV2_DEFAULT = 10; - private static final double FAV3_DEFAULT = 20; + private static final int FAV1_DEFAULT = 5; + private static final int FAV2_DEFAULT = 10; + private static final int FAV3_DEFAULT = 20; private CheckBox suspendLoopCheckbox; private CheckBox startActivityTTCheckbox; private CheckBox startEatingSoonTTCheckbox; @@ -120,8 +119,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit); - foodText = view.findViewById(R.id.newcarb_food); - editCarbs = view.findViewById(R.id.newcarb_carbsamount); editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); @@ -143,22 +140,17 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D startEatingSoonTTCheckbox.setOnClickListener(this); startActivityTTCheckbox.setOnClickListener(this); -// TODO prefilling carbs, maybe -// TODO maybe update suggested carbs to target TT when checked -// APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult(); -// if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).carbsReq > 0) { -// editCarbs.setValue(((DetermineBasalResultSMB) lastAPSResult).carbsReq); -// } - fav1Button = view.findViewById(R.id.newcarbs_plus1); fav1Button.setOnClickListener(this); - fav1Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_1, String.valueOf(FAV1_DEFAULT))); + fav1Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))); + fav2Button = view.findViewById(R.id.newcarbs_plus2); fav2Button.setOnClickListener(this); - fav2Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_2, String.valueOf(FAV2_DEFAULT))); + fav2Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT))); + fav3Button = view.findViewById(R.id.newcarbs_plus3); fav3Button.setOnClickListener(this); - fav3Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_3, String.valueOf(FAV3_DEFAULT))); + fav3Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT))); suspendLoopCheckbox = view.findViewById(R.id.newcarbs_suspend_loop); @@ -167,6 +159,10 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D return view; } + private String toSignedString(int value) { + return value > 0 ? "+" + value : String.valueOf(value); + } + @Override public synchronized void onClick(View view) { Calendar calendar = Calendar.getInstance(); @@ -201,18 +197,18 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D tpd.show(getActivity().getFragmentManager(), "Timepickerdialog"); break; case R.id.newcarbs_plus1: - editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(R.string.key_carbs_button_increment_1, FAV1_DEFAULT)); + editCarbs.setValue(Math.max(0, editCarbs.getValue() + + SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))); validateInputs(); break; case R.id.newcarbs_plus2: - editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(R.string.key_carbs_button_increment_2, FAV2_DEFAULT)); + editCarbs.setValue(Math.max(0, editCarbs.getValue() + + SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT))); validateInputs(); break; case R.id.newcarbs_plus3: - editCarbs.setValue(editCarbs.getValue() - + SP.getDouble(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)); + editCarbs.setValue(Math.max(0, editCarbs.getValue() + + SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT))); validateInputs(); break; case R.id.newcarbs_activity_tt: @@ -233,7 +229,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } okClicked = true; try { - final String food = StringUtils.trimToNull(foodText.getText().toString()); final Integer carbs = SafeParse.stringToInt(editCarbs.getText()); Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs); @@ -279,10 +274,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D final int finalActivityTTDuration = activityTTDuration; final int finalEatingSoonTTDuration = eatingSoonTTDuration; - if (StringUtils.isNoneEmpty(food)) { - confirmMessage += "
" + "Food: " + food; - } - if (!initialEventTime.equals(eventTime)) { confirmMessage += "
Time: " + DateUtil.dateAndTimeString(eventTime); } @@ -339,12 +330,11 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D MainApp.getDbHelper().createOrUpdate(tempTarget); } - if (finalCarbsAfterConstraints > 0 || food != null) { + if (finalCarbsAfterConstraints > 0) { DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.date = eventTime.getTime(); detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; detailedBolusInfo.carbs = finalCarbsAfterConstraints; -// detailedBolusInfo.food = food; detailedBolusInfo.context = context; detailedBolusInfo.source = Source.USER; MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); 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 dedb3c4842..4c1faf5495 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 @@ -1184,8 +1184,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, // **** Various treatment buttons **** if (carbsButton != null) { if (SP.getBoolean(R.string.key_show_carbs_button, true) - && !ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo || - (pump.isInitialized() && !pump.isSuspended())) { + && (!ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo || + (pump.isInitialized() && !pump.isSuspended()))) { carbsButton.setVisibility(View.VISIBLE); } else { carbsButton.setVisibility(View.GONE); diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 3be973c402..64ed498e2e 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -43,7 +43,6 @@ android:id="@+id/carbs_eating_soon_tt" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_marginTop="5dp" android:text="@string/start_eating_soon_tt" /> - - Date: Fri, 16 Mar 2018 22:09:30 +0100 Subject: [PATCH 2/4] Carbs button: send carbs to pump if pump supports carbs. --- .../Overview/Dialogs/NewCarbsDialog.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java index 1d7279ce6e..6813d5a338 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.os.HandlerThread; import android.support.v4.app.DialogFragment; @@ -337,7 +338,23 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D detailedBolusInfo.carbs = finalCarbsAfterConstraints; detailedBolusInfo.context = context; detailedBolusInfo.source = Source.USER; - MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + if (ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo) { + ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } + } + }); + } else { + MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo); + } } } }); From 194c7a2dbca5483a3ebfcf01ef024907b29e5cce Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 16 Mar 2018 22:46:12 +0100 Subject: [PATCH 3/4] Overview: symetric spacing. --- app/src/main/res/layout/overview_fragment.xml | 1 + app/src/main/res/layout/overview_fragment_nsclient.xml | 1 + app/src/main/res/layout/overview_fragment_nsclient_tablet.xml | 1 + app/src/main/res/layout/overview_fragment_smallheight.xml | 1 + 4 files changed, 4 insertions(+) diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml index 64fccac3af..95fdec2c01 100644 --- a/app/src/main/res/layout/overview_fragment.xml +++ b/app/src/main/res/layout/overview_fragment.xml @@ -392,6 +392,7 @@ Date: Fri, 16 Mar 2018 22:53:55 +0100 Subject: [PATCH 4/4] Insulin button: allow negative presets, fix adding TT insulin. --- .../Overview/Dialogs/NewInsulinDialog.java | 51 ++++++++++--------- app/src/main/res/xml/pref_overview.xml | 12 ++--- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java index 89e9a5308e..ddcfadc870 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java @@ -134,25 +134,28 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, dateButton.setOnClickListener(this); timeButton.setOnClickListener(this); -/* - // This makes it to easy to just bolus insulinReq, which is almost always too much - APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult(); - if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).insulinReq > 0) { - editInsulin.setValue(((DetermineBasalResultSMB )lastAPSResult).insulinReq); - } -*/ - plus1Button = (Button) view.findViewById(R.id.newinsulin_plus05); plus1Button.setOnClickListener(this); - plus1Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_1), String.valueOf(PLUS1_DEFAULT))); + plus1Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))); plus2Button = (Button) view.findViewById(R.id.newinsulin_plus10); plus2Button.setOnClickListener(this); - plus2Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_2), String.valueOf(PLUS2_DEFAULT))); + plus2Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))); plus3Button = (Button) view.findViewById(R.id.newinsulin_plus20); plus3Button.setOnClickListener(this); - plus3Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_3), String.valueOf(PLUS3_DEFAULT))); + plus3Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))); startESMCheckbox = (CheckBox) view.findViewById(R.id.newinsulin_start_eating_soon_tt); + startESMCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { + final Profile profile = MainApp.getConfigBuilder().getProfile(); + if (profile != null) { + double tt = SP.getDouble(MainApp.gs(R.string.key_eatingsoon_target), 0d); + if (tt > 0) { + double ttBgAdd = (profile.getTargetLow() - tt) / profile.getIsf(); + editInsulin.setValue(editInsulin.getValue() + (isChecked ? ttBgAdd : -ttBgAdd)); + } + } + }); + recordOnlyCheckbox = (CheckBox) view.findViewById(R.id.newinsulin_record_only); recordOnlyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> { if (dateButton != null) dateButton.setEnabled(isChecked); @@ -164,6 +167,10 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, return view; } + private String toSignedString(double value) { + return value > 0 ? "+" + value : String.valueOf(value); + } + @Override public synchronized void onClick(View view) { Calendar calendar = Calendar.getInstance(); @@ -197,25 +204,19 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, tpd.dismissOnPause(true); tpd.show(getActivity().getFragmentManager(), "Timepickerdialog"); break; - case R.id.newinsulin_start_eating_soon_tt: - final Profile profile = MainApp.getConfigBuilder().getProfile(); - double tt = SP.getDouble(R.string.key_eatingsoon_target, 0d); - double ttBgAdd = (tt - profile.getTargetLow()) / profile.getIsf(); - editInsulin.setValue(editInsulin.getValue() + (startESMCheckbox.isChecked() ? ttBgAdd : -ttBgAdd)); - break; case R.id.newinsulin_plus05: - editInsulin.setValue(editInsulin.getValue() - + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT)); + editInsulin.setValue(Math.max(0, editInsulin.getValue() + + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT))); validateInputs(); break; case R.id.newinsulin_plus10: - editInsulin.setValue(editInsulin.getValue() - + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT)); + editInsulin.setValue(Math.max(0, editInsulin.getValue() + + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT))); validateInputs(); break; case R.id.newinsulin_plus20: - editInsulin.setValue(editInsulin.getValue() - + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT)); + editInsulin.setValue(Math.max(0, editInsulin.getValue() + + SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT))); validateInputs(); break; } @@ -242,18 +243,20 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener, if (!insulinAfterConstraints.equals(insulin)) confirmMessage += "
" + MainApp.gs(R.string.bolusconstraintapplied) + ""; + double prefTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d); double ttDuration = prefTTDuration > 0 ? prefTTDuration : 45d; double prefTT = SP.getDouble(R.string.key_eatingsoon_target, 80d); - double tt = prefTT > 0 ? prefTT : 80d; Profile currentProfile = MainApp.getConfigBuilder().getProfile(); if(currentProfile == null) return; + double tt; if(currentProfile.getUnits().equals(Constants.MMOL)) tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MMOL) : 80d; else tt = prefTT > 0 ? prefTT : 80d; final double finalTT = tt; + if (startESMCheckbox.isChecked()) { if(currentProfile.getUnits().equals("mmol")){ confirmMessage += "
" + "TT: " + "" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min "; diff --git a/app/src/main/res/xml/pref_overview.xml b/app/src/main/res/xml/pref_overview.xml index 28fb012f0a..aa0a188b31 100644 --- a/app/src/main/res/xml/pref_overview.xml +++ b/app/src/main/res/xml/pref_overview.xml @@ -19,12 +19,12 @@