From d2491ca429e84ec361cda516ba3ff729afea2c6c Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 4 Apr 2018 19:59:16 +0200 Subject: [PATCH 01/25] NewCarbsDialog: add duration, help. --- .../Overview/Dialogs/NewCarbsDialog.java | 260 +++++++++--------- .../fragments/TreatmentsBolusFragment.java | 4 + .../TreatmentsTempTargetFragment.java | 12 +- .../res/layout/overview_newcarbs_dialog.xml | 158 +++++++++-- 4 files changed, 274 insertions(+), 160 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 19119450df..1725fed14f 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,5 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.HandlerThread; @@ -9,7 +8,6 @@ import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.Html; import android.text.TextWatcher; -import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -18,20 +16,16 @@ import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.RadioButton; -import android.widget.TextView; import com.google.common.base.Joiner; -import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; -import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout; -import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.text.DecimalFormat; -import java.util.Calendar; -import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -45,6 +39,8 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.Loop.APSResult; +import info.nightscout.androidaps.plugins.OpenAPSSMB.DetermineBasalResultSMB; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; @@ -54,16 +50,10 @@ import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; import info.nightscout.utils.ToastUtils; -public class NewCarbsDialog extends DialogFragment implements OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener, CompoundButton.OnCheckedChangeListener { +public class NewCarbsDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class); - private NumberPicker editCarbs; - - private TextView dateButton; - private TextView timeButton; - - private Date initialEventTime; - private Date eventTime; + private ImageView helpView; private Button fav1Button; private Button fav2Button; @@ -77,6 +67,11 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D private RadioButton startHypoTTCheckbox; private boolean togglingTT; + private NumberPicker editTime; + private LinearLayout durationLayout; + private NumberPicker editDuration; + private NumberPicker editCarbs; + private Integer maxCarbs; //one shot guards @@ -104,6 +99,16 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D }; private void validateInputs() { + Integer time = SafeParse.stringToInt(editTime.getText()); + if (time > 12 * 60 || time < -12 * 60) { + editTime.setValue(0d); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.carbsconstraintapplied)); + } + Integer duration = SafeParse.stringToInt(editDuration.getText()); + if (duration > 10) { + editDuration.setValue(0d); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.carbsconstraintapplied)); + } Integer carbs = SafeParse.stringToInt(editCarbs.getText()); if (carbs > maxCarbs) { editCarbs.setValue(0d); @@ -122,10 +127,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); + helpView = view.findViewById(R.id.newcarbs_help); + helpView.setOnClickListener(this); + maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value(); editCarbs = view.findViewById(R.id.newcarb_carbsamount); - editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); @@ -135,15 +142,13 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D startHypoTTCheckbox = view.findViewById(R.id.newcarbs_hypo_tt); startHypoTTCheckbox.setOnCheckedChangeListener(this); - dateButton = view.findViewById(R.id.newcarbs_eventdate); - timeButton = view.findViewById(R.id.newcarb_eventtime); + editTime = view.findViewById(R.id.newcarbs_time); + editTime.setParams(0d, -12 * 60d, 12 * 60d, 5d, new DecimalFormat("0"), false, textWatcher); - initialEventTime = new Date(); - eventTime = new Date(initialEventTime.getTime()); - dateButton.setText(DateUtil.dateString(eventTime)); - timeButton.setText(DateUtil.timeString(eventTime)); - dateButton.setOnClickListener(this); - timeButton.setOnClickListener(this); + durationLayout = view.findViewById(R.id.newcarbs_duration_layout); + durationLayout.setVisibility(MainApp.engineeringMode ? View.VISIBLE : View.GONE); + editDuration = view.findViewById(R.id.new_carbs_duration); + editDuration.setParams(0d, 0d, 10d, 1d, new DecimalFormat("0"), false, textWatcher); fav1Button = view.findViewById(R.id.newcarbs_plus1); fav1Button.setOnClickListener(this); @@ -168,8 +173,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D @Override public synchronized void onClick(View view) { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(eventTime); switch (view.getId()) { case R.id.ok: submit(); @@ -177,27 +180,16 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D case R.id.cancel: dismiss(); break; - case R.id.newcarbs_eventdate: - DatePickerDialog dpd = DatePickerDialog.newInstance( - this, - calendar.get(Calendar.YEAR), - calendar.get(Calendar.MONTH), - calendar.get(Calendar.DAY_OF_MONTH) - ); - dpd.setThemeDark(true); - dpd.dismissOnPause(true); - dpd.show(getActivity().getFragmentManager(), "Datepickerdialog"); - break; - case R.id.newcarb_eventtime: - TimePickerDialog tpd = TimePickerDialog.newInstance( - this, - calendar.get(Calendar.HOUR_OF_DAY), - calendar.get(Calendar.MINUTE), - DateFormat.is24HourFormat(getActivity()) - ); - tpd.setThemeDark(true); - tpd.dismissOnPause(true); - tpd.show(getActivity().getFragmentManager(), "Timepickerdialog"); + case R.id.newcarbs_help: + AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); + builder.setTitle("Help"); + builder.setMessage(Html.fromHtml("Time: relative offset to now
" + + "Duration: splits carb up over entered time, one every 15m
" + + "
" + + "Did I ever tell you the story about the old tree and the wooden house? So " + + "anyway, there I was, in the middle of the forest with all my clothes gone.
" + + "
Also: blablabla")); + builder.show(); break; case R.id.newcarbs_plus1: editCarbs.setValue(Math.max(0, editCarbs.getValue() @@ -352,6 +344,11 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(hypoTT) + " mg/dl (" + hypoTTDuration + " min)"); } + int duration = SafeParse.stringToInt(editDuration.getText()); + if (duration > 0) { + actions.add("Duration: " + editDuration.getText() + "h"); + } + final double finalActivityTT = activityTT; final int finalActivityTTDuration = activityTTDuration; final double finalEatigSoonTT = eatingSoonTT; @@ -359,83 +356,74 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D final double finalHypoTT = hypoTT; final int finalHypoTTDuration = hypoTTDuration; - if (!initialEventTime.equals(eventTime)) { - actions.add("Time: " + DateUtil.dateAndTimeString(eventTime)); + long timeOffset = editTime.getValue().longValue(); + final long time = DateUtil.now() + timeOffset * 1000 * 60; + if (timeOffset != 0) { + actions.add("Time: " + DateUtil.dateAndTimeString(time)); } - final int finalCarbsAfterConstraints = carbsAfterConstraints; - - final Context context = getContext(); - final AlertDialog.Builder builder = new AlertDialog.Builder(context); - + final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(MainApp.gs(R.string.confirmation)); - builder.setMessage(actions.isEmpty() - ? MainApp.gs(R.string.no_action_selected) - : Html.fromHtml(Joiner.on("
").join(actions))); - builder.setPositiveButton(MainApp.gs(R.string.ok), actions.isEmpty() ? null : (dialog, id) -> { - synchronized (builder) { - if (accepted) { - log.debug("guarding: already accepted"); - return; - } - accepted = true; + if (carbsAfterConstraints > 0 || startActivityTTCheckbox.isChecked() + || startEatingSoonTTCheckbox.isChecked() || startHypoTTCheckbox.isChecked()) { + builder.setMessage(Html.fromHtml(Joiner.on("
").join(actions))); + builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { + synchronized (builder) { + if (accepted) { + log.debug("guarding: already accepted"); + return; + } + accepted = true; - if (startActivityTTCheckbox.isChecked()) { - TempTarget tempTarget = new TempTarget() - .date(System.currentTimeMillis()) - .duration(finalActivityTTDuration) - .reason(MainApp.gs(R.string.activity)) - .source(Source.USER) - .low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); - } else if (startEatingSoonTTCheckbox.isChecked()) { - TempTarget tempTarget = new TempTarget() - .date(System.currentTimeMillis()) - .duration(finalEatingSoonTTDuration) - .reason(MainApp.gs(R.string.eatingsoon)) - .source(Source.USER) - .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); - } else if (startHypoTTCheckbox.isChecked()) { - TempTarget tempTarget = new TempTarget() - .date(System.currentTimeMillis()) - .duration(finalHypoTTDuration) - .reason(MainApp.gs(R.string.hypo)) - .source(Source.USER) - .low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())) - .high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())); - MainApp.getDbHelper().createOrUpdate(tempTarget); - } + if (startActivityTTCheckbox.isChecked()) { + TempTarget tempTarget = new TempTarget() + .date(System.currentTimeMillis()) + .duration(finalActivityTTDuration) + .reason(MainApp.gs(R.string.activity)) + .source(Source.USER) + .low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())) + .high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits())); + MainApp.getDbHelper().createOrUpdate(tempTarget); + } else if (startEatingSoonTTCheckbox.isChecked()) { + TempTarget tempTarget = new TempTarget() + .date(System.currentTimeMillis()) + .duration(finalEatingSoonTTDuration) + .reason(MainApp.gs(R.string.eatingsoon)) + .source(Source.USER) + .low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())) + .high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits())); + MainApp.getDbHelper().createOrUpdate(tempTarget); + } else if (startHypoTTCheckbox.isChecked()) { + TempTarget tempTarget = new TempTarget() + .date(System.currentTimeMillis()) + .duration(finalHypoTTDuration) + .reason(MainApp.gs(R.string.hypo)) + .source(Source.USER) + .low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())) + .high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits())); + MainApp.getDbHelper().createOrUpdate(tempTarget); + } - if (finalCarbsAfterConstraints > 0) { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.date = eventTime.getTime(); - detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION; - detailedBolusInfo.carbs = finalCarbsAfterConstraints; - detailedBolusInfo.context = context; - detailedBolusInfo.source = Source.USER; - 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); - } + if (carbsAfterConstraints > 0) { + if (duration == 0) { + createCarb(carbsAfterConstraints, time); + } else { + double remainingCarbs = carbsAfterConstraints; + long carbTime = time; + long smallCarbAmount = Math.round(remainingCarbs / (editDuration.getValue() * 4)); + if (smallCarbAmount == 0) smallCarbAmount = 1; + while (remainingCarbs > 0) { + createCarb(smallCarbAmount, carbTime); + remainingCarbs -= smallCarbAmount; + carbTime += 15 * 60 * 1000; } - }); - } else { - TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo); + } } } - } - }); + }); + } else { + builder.setMessage(MainApp.gs(R.string.no_action_selected)); + } builder.setNegativeButton(MainApp.gs(R.string.cancel), null); builder.show(); dismiss(); @@ -444,19 +432,29 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D } } - @Override - public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) { - eventTime.setYear(year - 1900); - eventTime.setMonth(monthOfYear); - eventTime.setDate(dayOfMonth); - dateButton.setText(DateUtil.dateString(eventTime)); - } - - @Override - public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) { - eventTime.setHours(hourOfDay); - eventTime.setMinutes(minute); - eventTime.setSeconds(second); - timeButton.setText(DateUtil.timeString(eventTime)); + private void createCarb(long carbs, long time) { + DetailedBolusInfo carbInfo = new DetailedBolusInfo(); + carbInfo.date = time; + carbInfo.eventType = CareportalEvent.CARBCORRECTION; + carbInfo.carbs = carbs; + carbInfo.context = getContext(); + carbInfo.source = Source.USER; + if (ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo) { + ConfigBuilderPlugin.getCommandQueue().bolus(carbInfo, 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 { + TreatmentsPlugin.getPlugin().addToHistoryTreatment(carbInfo); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java index 87626ed4cd..ae977d4024 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java @@ -89,6 +89,10 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View. holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); else holder.iob.setTextColor(holder.carbs.getCurrentTextColor()); + if (t.date > DateUtil.now()) + holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorScheduled)); + else + holder.date.setTextColor(holder.carbs.getCurrentTextColor()); holder.remove.setTag(t); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java index d018efd97b..5ce79636b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsTempTargetFragment.java @@ -84,14 +84,10 @@ public class TreatmentsTempTargetFragment extends SubscriberFragment implements holder.reasonLabel.setText(""); holder.reasonColon.setText(""); } - if (tempTarget.isInProgress()) { - if (tempTarget == currentlyActiveTarget) { - // active as newest - holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorInProgress)); - } else { - // other's that might become active again after the latest (overlapping) is over - holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); - } + if (tempTarget.isInProgress() && tempTarget == currentlyActiveTarget) { + holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive)); + } else if (tempTarget.date > DateUtil.now()) { + holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorScheduled)); } else { holder.date.setTextColor(holder.reasonColon.getCurrentTextColor()); } diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 25ca0d75d2..944352af83 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -11,6 +11,7 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + - - + android:layout_height="wrap_content" + android:layout_gravity="center" + android:orientation="horizontal"> + + + + + + + + + android:paddingTop="5dp" + android:visibility="gone"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Date: Wed, 11 Apr 2018 01:29:40 +0200 Subject: [PATCH 02/25] Color active/scheduled bolus/carbs and TT entries in treatment tab. --- app/src/main/res/values/colors.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 318e93d9d8..a0b229946e 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -49,7 +49,7 @@ #FFDD7792 #ca77dd - #c45026 + #de7550 #1b5e20 #47c8ff From f8d022ba87cb7ca90412195d3c2df17403b1f54b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 11 Apr 2018 12:59:28 +0200 Subject: [PATCH 03/25] NewCarbsDialog: prefill with carbsReq. --- .../Overview/Dialogs/NewCarbsDialog.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 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 1725fed14f..93ba7c9d81 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 @@ -132,9 +132,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value(); - editCarbs = view.findViewById(R.id.newcarb_carbsamount); - editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); - startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); startActivityTTCheckbox.setOnCheckedChangeListener(this); startEatingSoonTTCheckbox = view.findViewById(R.id.newcarbs_eating_soon_tt); @@ -150,6 +147,22 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C editDuration = view.findViewById(R.id.new_carbs_duration); editDuration.setParams(0d, 0d, 10d, 1d, new DecimalFormat("0"), false, textWatcher); + editCarbs = view.findViewById(R.id.newcarb_carbsamount); + editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); + + if (MainApp.engineeringMode) { + // use SMB's carbs required as preset, check hypo TT if any + if (ConfigBuilderPlugin.getActiveAPS() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null) { + APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult(); + if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).carbsReq > 0) { + editCarbs.setValue(((DetermineBasalResultSMB) lastAPSResult).carbsReq); + startHypoTTCheckbox.setOnCheckedChangeListener(null); + startHypoTTCheckbox.setChecked(true); + startHypoTTCheckbox.setOnClickListener(this); + } + } + } + fav1Button = view.findViewById(R.id.newcarbs_plus1); fav1Button.setOnClickListener(this); fav1Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))); From 61cce65947b980a1e2ca97f82a7f80e38889cb3a Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Wed, 11 Apr 2018 15:22:38 +0200 Subject: [PATCH 04/25] Revert "NewCarbsDialog: prefill with carbsReq." This reverts commit f8d022ba87cb7ca90412195d3c2df17403b1f54b. --- .../Overview/Dialogs/NewCarbsDialog.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 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 93ba7c9d81..1725fed14f 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 @@ -132,6 +132,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value(); + editCarbs = view.findViewById(R.id.newcarb_carbsamount); + editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); + startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt); startActivityTTCheckbox.setOnCheckedChangeListener(this); startEatingSoonTTCheckbox = view.findViewById(R.id.newcarbs_eating_soon_tt); @@ -147,22 +150,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C editDuration = view.findViewById(R.id.new_carbs_duration); editDuration.setParams(0d, 0d, 10d, 1d, new DecimalFormat("0"), false, textWatcher); - editCarbs = view.findViewById(R.id.newcarb_carbsamount); - editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); - - if (MainApp.engineeringMode) { - // use SMB's carbs required as preset, check hypo TT if any - if (ConfigBuilderPlugin.getActiveAPS() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null) { - APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult(); - if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).carbsReq > 0) { - editCarbs.setValue(((DetermineBasalResultSMB) lastAPSResult).carbsReq); - startHypoTTCheckbox.setOnCheckedChangeListener(null); - startHypoTTCheckbox.setChecked(true); - startHypoTTCheckbox.setOnClickListener(this); - } - } - } - fav1Button = view.findViewById(R.id.newcarbs_plus1); fav1Button.setOnClickListener(this); fav1Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))); From b1f66d086a76d9e60a817fff9faa62e703058872 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 12 Apr 2018 00:42:12 +0200 Subject: [PATCH 05/25] Fix overshoot on last carb record. --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 2 +- 1 file changed, 1 insertion(+), 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 1725fed14f..8bd7c98f88 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 @@ -413,7 +413,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C long smallCarbAmount = Math.round(remainingCarbs / (editDuration.getValue() * 4)); if (smallCarbAmount == 0) smallCarbAmount = 1; while (remainingCarbs > 0) { - createCarb(smallCarbAmount, carbTime); + createCarb(Math.min(smallCarbAmount, (long) remainingCarbs), carbTime); remainingCarbs -= smallCarbAmount; carbTime += 15 * 60 * 1000; } From 5ef2502b4f461783d50ab627c9e64557cc706a39 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 12 Apr 2018 00:50:28 +0200 Subject: [PATCH 06/25] Saner types. --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 8bd7c98f88..ef12b1ca0f 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 @@ -408,12 +408,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C if (duration == 0) { createCarb(carbsAfterConstraints, time); } else { - double remainingCarbs = carbsAfterConstraints; + long remainingCarbs = carbsAfterConstraints; long carbTime = time; long smallCarbAmount = Math.round(remainingCarbs / (editDuration.getValue() * 4)); if (smallCarbAmount == 0) smallCarbAmount = 1; while (remainingCarbs > 0) { - createCarb(Math.min(smallCarbAmount, (long) remainingCarbs), carbTime); + createCarb(Math.min(smallCarbAmount, remainingCarbs), carbTime); remainingCarbs -= smallCarbAmount; carbTime += 15 * 60 * 1000; } From a075d87da1916dc21d10334d283c8fb78223d81b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 12 Apr 2018 20:52:07 +0200 Subject: [PATCH 07/25] Remove help dialog. (cherry picked from commit b1ef8e1) --- .../Overview/Dialogs/NewCarbsDialog.java | 20 +------------------ .../res/layout/overview_newcarbs_dialog.xml | 13 ++++-------- 2 files changed, 5 insertions(+), 28 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 ef12b1ca0f..28e21bf0c4 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 @@ -16,7 +16,6 @@ import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.CompoundButton; -import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RadioButton; @@ -39,8 +38,6 @@ import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.Loop.APSResult; -import info.nightscout.androidaps.plugins.OpenAPSSMB.DetermineBasalResultSMB; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.DateUtil; @@ -53,8 +50,6 @@ import info.nightscout.utils.ToastUtils; public class NewCarbsDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener { private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class); - private ImageView helpView; - private Button fav1Button; private Button fav2Button; private Button fav3Button; @@ -127,9 +122,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - helpView = view.findViewById(R.id.newcarbs_help); - helpView.setOnClickListener(this); - maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value(); editCarbs = view.findViewById(R.id.newcarb_carbsamount); @@ -147,6 +139,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C durationLayout = view.findViewById(R.id.newcarbs_duration_layout); durationLayout.setVisibility(MainApp.engineeringMode ? View.VISIBLE : View.GONE); + editDuration = view.findViewById(R.id.new_carbs_duration); editDuration.setParams(0d, 0d, 10d, 1d, new DecimalFormat("0"), false, textWatcher); @@ -180,17 +173,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C case R.id.cancel: dismiss(); break; - case R.id.newcarbs_help: - AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); - builder.setTitle("Help"); - builder.setMessage(Html.fromHtml("Time: relative offset to now
" + - "Duration: splits carb up over entered time, one every 15m
" + - "
" + - "Did I ever tell you the story about the old tree and the wooden house? So " + - "anyway, there I was, in the middle of the forest with all my clothes gone.
" + - "
Also: blablabla")); - builder.show(); - break; case R.id.newcarbs_plus1: editCarbs.setValue(Math.max(0, editCarbs.getValue() + SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))); diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 944352af83..92fe1fc05d 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -36,20 +36,15 @@ - -
Date: Thu, 12 Apr 2018 21:28:32 +0200 Subject: [PATCH 08/25] Align style of labels, i18n. --- .../res/layout/overview_newcarbs_dialog.xml | 19 +++++++++++-------- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 38dca30d8e..8d416467ef 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -125,7 +125,8 @@ android:layout_width="60dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="Time" /> + android:textStyle="bold" + android:text="@string/time" /> + android:text="@string/shortminute" /> + android:textStyle="bold" + android:text="@string/duration"/> + android:text="@string/shorthour"/> + android:textStyle="bold" + android:text="@string/overview_carbs_label" /> + android:text="@string/shortgramm" /> Connection timed out Food g + m + h ]]> kJ En @@ -995,4 +997,5 @@ openapsmb_max_iob Maximum total IOB OpenAPS can\'t go over [U] This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value + Time From bf02edd871a8e5dba5d837bb877b3d608e099533 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 12 Apr 2018 21:43:55 +0200 Subject: [PATCH 09/25] Make visibility of notes field a preference. --- .../androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java | 5 ++++- .../androidaps/plugins/Overview/Dialogs/WizardDialog.java | 3 +++ app/src/main/res/layout/overview_newcarbs_dialog.xml | 4 ++-- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_overview.xml | 4 ++++ 5 files changed, 15 insertions(+), 3 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 8e0baabd99..ad603fa321 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 @@ -56,6 +56,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C private Button fav2Button; private Button fav3Button; + private LinearLayout notesLayout; private EditText notesEdit; private static final int FAV1_DEFAULT = 5; @@ -159,7 +160,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C fav3Button.setOnClickListener(this); fav3Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT))); - notesEdit = (EditText) view.findViewById(R.id.newcarbs_notes); + notesLayout = view.findViewById(R.id.newcarbs_notes_layout); + notesLayout.setVisibility(SP.getBoolean(R.string.key_show_notes_entry_dialogs, false) ? View.VISIBLE : View.GONE); + notesEdit = view.findViewById(R.id.newcarbs_notes); setCancelable(true); getDialog().setCanceledOnTouchOutside(false); 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 263bc7e090..b988a368fc 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 @@ -105,6 +105,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com NumberPicker editCorr; NumberPicker editCarbTime; + LinearLayout notesLayout; EditText notesEdit; Integer calculatedCarbs = 0; @@ -209,6 +210,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com superbolus = (TextView) view.findViewById(R.id.treatments_wizard_sb); superbolusInsulin = (TextView) view.findViewById(R.id.treatments_wizard_sbinsulin); + notesLayout = view.findViewById(R.id.treatments_wizard_notes_layout); + notesLayout.setVisibility(SP.getBoolean(R.string.key_show_notes_entry_dialogs, false) ? View.VISIBLE : View.GONE); notesEdit = (EditText) view.findViewById(R.id.newcarbs_notes); bgTrend = (TextView) view.findViewById(R.id.treatments_wizard_bgtrend); diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml index 8d416467ef..09774fcd08 100644 --- a/app/src/main/res/layout/overview_newcarbs_dialog.xml +++ b/app/src/main/res/layout/overview_newcarbs_dialog.xml @@ -237,6 +237,7 @@ + android:layout_height="wrap_content" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 58c4eebc40..c205d0624a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -998,4 +998,6 @@ Maximum total IOB OpenAPS can\'t go over [U] This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value Time + show_notes_entry_dialogs + Show notes field in dialogs diff --git a/app/src/main/res/xml/pref_overview.xml b/app/src/main/res/xml/pref_overview.xml index aa0a188b31..a3d8245aa8 100644 --- a/app/src/main/res/xml/pref_overview.xml +++ b/app/src/main/res/xml/pref_overview.xml @@ -112,5 +112,9 @@ android:summary="@string/show_calibration_button_summary"/> + \ No newline at end of file From 10b9171afe943f7b3d72b13cce8c346293a1dd86 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 13 Apr 2018 00:48:57 +0200 Subject: [PATCH 10/25] Distribute carbs strictly within timeframe --- .../plugins/Overview/Dialogs/NewCarbsDialog.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 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 ad603fa321..fa02b14ab0 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 @@ -401,13 +401,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C createCarb(carbsAfterConstraints, time, finalNotes); } else { long remainingCarbs = carbsAfterConstraints; - long carbTime = time; - long smallCarbAmount = Math.round(remainingCarbs / (editDuration.getValue() * 4)); - if (smallCarbAmount == 0) smallCarbAmount = 1; - while (remainingCarbs > 0) { - createCarb(Math.min(smallCarbAmount, remainingCarbs), carbTime, finalNotes); + int ticks = (duration * 4); //duration guaranteed to be integer greater zero + for (int i = 0; i < ticks; i++){ + long carbTime = time + i * 15 * 60 * 1000; + long smallCarbAmount = Math.round((1d * remainingCarbs) / (ticks-i)); //on last iteration (ticks-i) is 1 -> smallCarbAmount == remainingCarbs remainingCarbs -= smallCarbAmount; - carbTime += 15 * 60 * 1000; + createCarb(smallCarbAmount, carbTime, finalNotes); } } } From efcc02775bcb495b2a36c1df78176b2a2cf0b43d Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 13 Apr 2018 21:20:11 +0200 Subject: [PATCH 11/25] FillDialog: add missed validation, notes field, align style. --- .../plugins/Actions/dialogs/FillDialog.java | 151 +++++++++----- .../plugins/Treatments/TreatmentsPlugin.java | 2 +- .../java/info/nightscout/utils/NSUpload.java | 8 +- .../main/res/layout/actions_fill_dialog.xml | 192 +++++++++++------- 4 files changed, 218 insertions(+), 135 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index b3b15bf7fb..ba53b40935 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -5,7 +5,9 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import android.text.Editable; import android.text.Html; +import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -14,6 +16,8 @@ import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.LinearLayout; import com.crashlytics.android.answers.CustomEvent; import com.google.common.base.Joiner; @@ -21,8 +25,6 @@ import com.google.common.base.Joiner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import info.nightscout.androidaps.Constants; -import java.text.DecimalFormat; import java.util.LinkedList; import java.util.List; @@ -41,6 +43,9 @@ import info.nightscout.utils.NSUpload; import info.nightscout.utils.NumberPicker; import info.nightscout.utils.SP; import info.nightscout.utils.SafeParse; +import info.nightscout.utils.ToastUtils; + +import static info.nightscout.utils.DateUtil.now; public class FillDialog extends DialogFragment implements OnClickListener { private static Logger log = LoggerFactory.getLogger(FillDialog.class); @@ -49,11 +54,35 @@ public class FillDialog extends DialogFragment implements OnClickListener { double amount2 = 0d; double amount3 = 0d; - NumberPicker editInsulin; CheckBox pumpSiteChangeCheckbox; CheckBox insulinCartridgeChangeCheckbox; - public FillDialog() { + NumberPicker editInsulin; + + private LinearLayout notesLayout; + private EditText notesEdit; + + final private TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + validateInputs(); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + + private void validateInputs() { + int time = editInsulin.getValue().intValue(); + if (Math.abs(time) > 12 * 60) { + editInsulin.setValue(0d); + ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.constraintapllied)); + } } @Override @@ -67,45 +96,47 @@ public class FillDialog extends DialogFragment implements OnClickListener { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - pumpSiteChangeCheckbox = view.findViewById(R.id.catheter_change); - insulinCartridgeChangeCheckbox = view.findViewById(R.id.cartridge_change); + pumpSiteChangeCheckbox = view.findViewById(R.id.fill_catheter_change); + insulinCartridgeChangeCheckbox = view.findViewById(R.id.fill_cartridge_change); Double maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value(); double bolusstep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep; - editInsulin = view.findViewById(R.id.treatments_newtreatment_insulinamount); - editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, DecimalFormatter.pumpSupportedBolusFormat(), false); + editInsulin = view.findViewById(R.id.fill_insulinamount); + editInsulin.setParams(0d, 0d, maxInsulin, bolusstep, DecimalFormatter.pumpSupportedBolusFormat(), false, textWatcher); - //setup preset buttons - Button button1 = (Button) view.findViewById(R.id.fill_preset_button1); - Button button2 = (Button) view.findViewById(R.id.fill_preset_button2); - Button button3 = (Button) view.findViewById(R.id.fill_preset_button3); + Button preset1Button = view.findViewById(R.id.fill_preset_button1); amount1 = SP.getDouble("fill_button1", 0.3); - amount2 = SP.getDouble("fill_button2", 0d); - amount3 = SP.getDouble("fill_button3", 0d); - if (amount1 > 0) { - button1.setVisibility(View.VISIBLE); - button1.setText(DecimalFormatter.toPumpSupportedBolus(amount1)); // + "U"); - button1.setOnClickListener(this); + preset1Button.setVisibility(View.VISIBLE); + preset1Button.setText(DecimalFormatter.toPumpSupportedBolus(amount1)); // + "U"); + preset1Button.setOnClickListener(this); } else { - button1.setVisibility(View.GONE); + preset1Button.setVisibility(View.GONE); } + Button preset2Button = view.findViewById(R.id.fill_preset_button2); + amount2 = SP.getDouble("fill_button2", 0d); if (amount2 > 0) { - button2.setVisibility(View.VISIBLE); - button2.setText(DecimalFormatter.toPumpSupportedBolus(amount2)); // + "U"); - button2.setOnClickListener(this); + preset2Button.setVisibility(View.VISIBLE); + preset2Button.setText(DecimalFormatter.toPumpSupportedBolus(amount2)); // + "U"); + preset2Button.setOnClickListener(this); } else { - button2.setVisibility(View.GONE); + preset2Button.setVisibility(View.GONE); } + Button preset3Button = view.findViewById(R.id.fill_preset_button3); + amount3 = SP.getDouble("fill_button3", 0d); if (amount3 > 0) { - button3.setVisibility(View.VISIBLE); - button3.setText(DecimalFormatter.toPumpSupportedBolus(amount3)); // + "U"); - button3.setOnClickListener(this); + preset3Button.setVisibility(View.VISIBLE); + preset3Button.setText(DecimalFormatter.toPumpSupportedBolus(amount3)); // + "U"); + preset3Button.setOnClickListener(this); } else { - button3.setVisibility(View.GONE); + preset3Button.setVisibility(View.GONE); } + notesLayout = view.findViewById(R.id.fill_notes_layout); + notesLayout.setVisibility(SP.getBoolean(R.string.key_show_notes_entry_dialogs, false) ? View.VISIBLE : View.GONE); + notesEdit = view.findViewById(R.id.fill_notes); + setCancelable(true); getDialog().setCanceledOnTouchOutside(false); return view; @@ -154,42 +185,50 @@ public class FillDialog extends DialogFragment implements OnClickListener { if (insulinCartridgeChangeCheckbox.isChecked()) confirmMessage.add("" + "" + getString(R.string.record_insulin_cartridge_change) + ""); + final String notes = notesEdit.getText().toString(); + if (!notes.isEmpty()) { + confirmMessage.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes); + } + final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Context context = getContext(); AlertDialog.Builder builder = new AlertDialog.Builder(context); - if (confirmMessage.isEmpty()) - confirmMessage.add(MainApp.gs(R.string.no_action_selected)); - builder.setTitle(MainApp.gs(R.string.confirmation)); - builder.setMessage(Html.fromHtml(Joiner.on("
").join(confirmMessage))); - builder.setPositiveButton(getString(R.string.primefill), (dialog, id) -> { - if (finalInsulinAfterConstraints > 0) { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.insulin = finalInsulinAfterConstraints; - detailedBolusInfo.context = context; - detailedBolusInfo.source = Source.USER; - detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) - 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.sResources.getString(R.string.treatmentdeliveryerror)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); + if (insulinAfterConstraints > 0 || pumpSiteChangeCheckbox.isChecked() || insulinCartridgeChangeCheckbox.isChecked()) { + builder.setMessage(Html.fromHtml(Joiner.on("
").join(confirmMessage))); + builder.setPositiveButton(getString(R.string.primefill), (dialog, id) -> { + if (finalInsulinAfterConstraints > 0) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.insulin = finalInsulinAfterConstraints; + detailedBolusInfo.context = context; + detailedBolusInfo.source = Source.USER; + detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) + detailedBolusInfo.notes = notes; + 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.sResources.getString(R.string.treatmentdeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } } - } - }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); - } - long now = System.currentTimeMillis(); - if (pumpSiteChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now); - if (insulinCartridgeChangeCheckbox.isChecked()) NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now + 1000); - }); + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); + } + if (pumpSiteChangeCheckbox.isChecked()) + NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now(), notes); + if (insulinCartridgeChangeCheckbox.isChecked()) + NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now() + 1000, notes); + }); + } else { + builder.setMessage(MainApp.gs(R.string.no_action_selected)); + } builder.setNegativeButton(getString(R.string.cancel), null); builder.show(); dismiss(); 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 2f5135c0cb..8f82f71c35 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 @@ -452,7 +452,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface //log.debug("Adding new Treatment record" + carbsTreatment); } if (newRecordCreated && detailedBolusInfo.isValid) - NSUpload.uploadBolusWizardRecord(detailedBolusInfo); + NSUpload.uploadTreatmentRecord(detailedBolusInfo); return newRecordCreated; } diff --git a/app/src/main/java/info/nightscout/utils/NSUpload.java b/app/src/main/java/info/nightscout/utils/NSUpload.java index c56c4f1a51..e617191732 100644 --- a/app/src/main/java/info/nightscout/utils/NSUpload.java +++ b/app/src/main/java/info/nightscout/utils/NSUpload.java @@ -7,6 +7,7 @@ import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.annotation.Nullable; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; @@ -258,7 +259,7 @@ public class NSUpload { } } - public static void uploadBolusWizardRecord(DetailedBolusInfo detailedBolusInfo) { + public static void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) { JSONObject data = new JSONObject(); try { data.put("eventType", detailedBolusInfo.eventType); @@ -500,7 +501,7 @@ public class NSUpload { } } - public static void uploadEvent(String careportalEvent, long time) { + public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) { Context context = MainApp.instance().getApplicationContext(); Bundle bundle = new Bundle(); bundle.putString("action", "dbAdd"); @@ -510,6 +511,9 @@ public class NSUpload { data.put("eventType", careportalEvent); data.put("created_at", DateUtil.toISOString(time)); data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name))); + if (notes != null) { + data.put("notes", notes); + } } catch (JSONException e) { log.error("Unhandled exception", e); } diff --git a/app/src/main/res/layout/actions_fill_dialog.xml b/app/src/main/res/layout/actions_fill_dialog.xml index 18a5886246..f1ee50c3ca 100644 --- a/app/src/main/res/layout/actions_fill_dialog.xml +++ b/app/src/main/res/layout/actions_fill_dialog.xml @@ -1,97 +1,137 @@ - + android:layout_height="wrap_content"> + + - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_gravity="center" + android:orientation="horizontal"> -