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..e0b5f02c5b 100644 --- a/app/src/main/res/xml/pref_others.xml +++ b/app/src/main/res/xml/pref_others.xml @@ -3,6 +3,33 @@ + + + + + + + + + +