From bd93fc1adb3ed99c3ac80b557e1bd26a09b9351f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 6 Oct 2017 02:52:04 +0200 Subject: [PATCH 1/2] temp target presets --- .../Dialogs/NewNSTreatmentDialog.java | 43 +++++++++++++++++-- app/src/main/res/values/strings.xml | 9 ++++ app/src/main/res/xml/pref_others.xml | 24 +++++++---- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index cc337d6c00..ec5a267dcc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -14,6 +14,7 @@ import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.EditText; @@ -194,19 +195,55 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick profileSpinner.setSelection(p); } + final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL); + // temp target - ArrayList reasonList = new ArrayList(); + final ArrayList reasonList = new ArrayList(); + reasonList.add(MainApp.sResources.getString(R.string.manual)); reasonList.add(MainApp.sResources.getString(R.string.eatingsoon)); reasonList.add(MainApp.sResources.getString(R.string.activity)); - reasonList.add(MainApp.sResources.getString(R.string.manual)); ArrayAdapter adapterReason = new ArrayAdapter(getContext(), R.layout.spinner_centered, reasonList); reasonSpinner.setAdapter(adapterReason); + reasonSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + double defaultDuration = 0; + double defaultTarget = 0; + if(profile!=null){ + defaultTarget = bg.doubleValue(); + } + boolean erase = false; + + if(MainApp.sResources.getString(R.string.eatingsoon).equals(reasonList.get(position))){ + defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d); + defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);; + } else if (MainApp.sResources.getString(R.string.activity).equals(reasonList.get(position))){ + defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);; + defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);; + } else { + defaultDuration = 0; + erase = true; + } + if(defaultTarget != 0 || erase){ + editTemptarget.setValue(defaultTarget); + } + if(defaultDuration != 0){ + editDuration.setValue(defaultDuration); + } else if (erase){ + editDuration.setValue(0d); + } + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); // bg bgUnitsView.setText(units); - Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL); editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput); editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget); if (profile == null) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bb7831fff1..d92828ed99 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -707,5 +707,14 @@ wizard_include_trend_bg wizard_include_bolus_iob wizard_include_basal_iob + Default Temp-Targets + eatingsoon duration + eatingsoon target + activity duration + activity target + eatingsoon_duration + eatingsoon_target + activity_duration + activity_target diff --git a/app/src/main/res/xml/pref_others.xml b/app/src/main/res/xml/pref_others.xml index 47178dbc25..da7f498148 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -4,22 +4,28 @@ android:key="others" android:title="@string/othersettings_title"> + android:title="@string/default_temptargets"> + android:title="@string/eatingsoon_duration" + android:key="@string/key_eatingsoon_duration" + android:defaultValue="0" + android:inputType="number"> + + From 7f403166c78b222b6f25ec306703f349d2fdea13 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 6 Oct 2017 03:05:36 +0200 Subject: [PATCH 2/2] restore preferences --- app/src/main/res/xml/pref_others.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/src/main/res/xml/pref_others.xml b/app/src/main/res/xml/pref_others.xml index da7f498148..e0b5f02c5b 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -30,6 +30,27 @@ android:inputType="numberDecimal"> + + + + + + + +