Merge pull request #444 from AdrianLxM/temptarget-presets

Temptarget presets
This commit is contained in:
Milos Kozak 2017-10-06 13:15:06 +02:00 committed by GitHub
commit 32d6e06b07
3 changed files with 76 additions and 3 deletions

View file

@ -14,6 +14,7 @@ import android.text.format.DateFormat;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
@ -194,19 +195,55 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
profileSpinner.setSelection(p); profileSpinner.setSelection(p);
} }
final Double bg = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL);
// temp target // temp target
ArrayList<CharSequence> reasonList = new ArrayList<CharSequence>(); final ArrayList<CharSequence> reasonList = new ArrayList<CharSequence>();
reasonList.add(MainApp.sResources.getString(R.string.manual));
reasonList.add(MainApp.sResources.getString(R.string.eatingsoon)); reasonList.add(MainApp.sResources.getString(R.string.eatingsoon));
reasonList.add(MainApp.sResources.getString(R.string.activity)); reasonList.add(MainApp.sResources.getString(R.string.activity));
reasonList.add(MainApp.sResources.getString(R.string.manual));
ArrayAdapter<CharSequence> adapterReason = new ArrayAdapter<CharSequence>(getContext(), ArrayAdapter<CharSequence> adapterReason = new ArrayAdapter<CharSequence>(getContext(),
R.layout.spinner_centered, reasonList); R.layout.spinner_centered, reasonList);
reasonSpinner.setAdapter(adapterReason); 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 // bg
bgUnitsView.setText(units); 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); editBg = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_bginput);
editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget); editTemptarget = (NumberPicker) view.findViewById(R.id.careportal_newnstreatment_temptarget);
if (profile == null) { if (profile == null) {

View file

@ -707,5 +707,14 @@
<string name="key_wizard_include_trend_bg">wizard_include_trend_bg</string> <string name="key_wizard_include_trend_bg">wizard_include_trend_bg</string>
<string name="key_wizard_include_bolus_iob">wizard_include_bolus_iob</string> <string name="key_wizard_include_bolus_iob">wizard_include_bolus_iob</string>
<string name="key_wizard_include_basal_iob">wizard_include_basal_iob</string> <string name="key_wizard_include_basal_iob">wizard_include_basal_iob</string>
<string name="default_temptargets">Default Temp-Targets</string>
<string name="eatingsoon_duration">eatingsoon duration</string>
<string name="eatingsoon_target">eatingsoon target</string>
<string name="activity_duration">activity duration</string>
<string name="activity_target">activity target</string>
<string name="key_eatingsoon_duration">eatingsoon_duration</string>
<string name="key_eatingsoon_target">eatingsoon_target</string>
<string name="key_activity_duration">activity_duration</string>
<string name="key_activity_target">activity_target</string>
</resources> </resources>

View file

@ -3,6 +3,33 @@
<PreferenceCategory <PreferenceCategory
android:key="others" android:key="others"
android:title="@string/othersettings_title"> android:title="@string/othersettings_title">
<PreferenceScreen
android:title="@string/default_temptargets">
<EditTextPreference
android:title="@string/eatingsoon_duration"
android:key="@string/key_eatingsoon_duration"
android:defaultValue="0"
android:inputType="number">
</EditTextPreference>
<EditTextPreference
android:title="@string/eatingsoon_target"
android:key="@string/key_eatingsoon_target"
android:defaultValue="0"
android:inputType="numberDecimal">
</EditTextPreference>
<EditTextPreference
android:title="@string/activity_duration"
android:key="@string/key_activity_duration"
android:defaultValue="0"
android:inputType="number">
</EditTextPreference>
<EditTextPreference
android:title="@string/activity_target"
android:key="@string/key_activity_target"
android:defaultValue="0"
android:inputType="numberDecimal">
</EditTextPreference>
</PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:title="@string/fillbolus_title"> android:title="@string/fillbolus_title">
<EditTextPreference <EditTextPreference