This commit is contained in:
Milos Kozak 2017-10-06 13:15:57 +02:00
commit 4db82fd275
7 changed files with 96 additions and 6 deletions

View file

@ -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<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.activity));
reasonList.add(MainApp.sResources.getString(R.string.manual));
ArrayAdapter<CharSequence> adapterReason = new ArrayAdapter<CharSequence>(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) {

View file

@ -506,7 +506,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) {
result.enacted = false;
result.success = true;

View file

@ -503,7 +503,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) {
result.enacted = false;
result.success = true;

View file

@ -429,7 +429,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface,
}
if (percent > getPumpDescription().maxTempPercent)
percent = getPumpDescription().maxTempPercent;
TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis());
TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis());
if (runningTB != null && runningTB.percentRate == percent) {
result.enacted = false;
result.success = true;

View file

@ -3,6 +3,7 @@ package info.nightscout.utils;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
@ -119,6 +120,22 @@ public class NumberPicker extends LinearLayout implements View.OnKeyListener,
plusButton.setOnTouchListener(this);
plusButton.setOnKeyListener(this);
plusButton.setOnClickListener(this);
this.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
value = SafeParse.stringToDouble(editText.getText().toString());
}
});
}
public void removeTextChangedListener(TextWatcher textWatcher) {

View file

@ -707,5 +707,14 @@
<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_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>

View file

@ -3,6 +3,33 @@
<PreferenceCategory
android:key="others"
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
android:title="@string/fillbolus_title">
<EditTextPreference