prefill bg value in careportal dialog

This commit is contained in:
Milos Kozak 2017-02-14 15:09:22 +01:00
parent ac82e2b044
commit e00045155e
2 changed files with 38 additions and 14 deletions

View file

@ -13,11 +13,13 @@ import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
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.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RadioButton; import android.widget.RadioButton;
@ -44,6 +46,7 @@ import java.util.Date;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -264,10 +267,32 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
// meterRadioButton.setChecked(true); // meterRadioButton.setChecked(true);
// } // }
if (units.equals(Constants.MMOL)) Double bg = NSProfile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile != null ? profile.getUnits() : Constants.MGDL);
editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, 0d, 0d, 40d, 0.1d, new DecimalFormat("0.0"), false); if (profile == null)
editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
else if (profile.getUnits().equals(Constants.MMOL))
editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
else else
editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, 0d, 0d, 500d, 1d, new DecimalFormat("0"), false); editBg = new PlusMinusEditText(view, R.id.careportal_newnstreatment_bginput, R.id.careportal_newnstreatment_bg_plus, R.id.careportal_newnstreatment_bg_minus, bg, 0d, 500d, 1d, new DecimalFormat("0"), false);
bgInputEdit.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (sensorRadioButton.isChecked()) meterRadioButton.setChecked(true);
}
});
sensorRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
if (profile == null) return;
Double bg = NSProfile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits());
editBg.setValue(bg);
}
});
Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit); Integer maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit);
editCarbs = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbsinput, R.id.careportal_newnstreatment_carbs_plus, R.id.careportal_newnstreatment_carbs_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false); editCarbs = new PlusMinusEditText(view, R.id.careportal_newnstreatment_carbsinput, R.id.careportal_newnstreatment_carbs_plus, R.id.careportal_newnstreatment_carbs_minus, 0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false);
@ -330,7 +355,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
this, this,
calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE), calendar.get(Calendar.MINUTE),
df.is24HourFormat(context) DateFormat.is24HourFormat(context)
); );
tpd.setThemeDark(true); tpd.setThemeDark(true);
tpd.dismissOnPause(true); tpd.dismissOnPause(true);
@ -588,7 +613,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
public void run() { public void run() {
try { try {
String profile = data.getString("profile"); String profile = data.getString("profile");
NSProfile nsProfile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); NSProfile nsProfile = ConfigBuilderPlugin.getActiveProfile().getProfile();
nsProfile.setActiveProfile(profile); nsProfile.setActiveProfile(profile);
PumpInterface pump = MainApp.getConfigBuilder(); PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null) { if (pump != null) {
@ -598,8 +623,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
} else { } else {
log.error("No active pump selected"); log.error("No active pump selected");
} }
if (MainApp.getConfigBuilder().getActiveProfile() instanceof CircadianPercentageProfilePlugin) { if (ConfigBuilderPlugin.getActiveProfile() instanceof CircadianPercentageProfilePlugin) {
CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) MainApp.getConfigBuilder().getActiveProfile(); CircadianPercentageProfilePlugin cpp = (CircadianPercentageProfilePlugin) ConfigBuilderPlugin.getActiveProfile();
data.put("CircadianPercentageProfile", true); data.put("CircadianPercentageProfile", true);
data.put("timeshift", cpp.timeshift); data.put("timeshift", cpp.timeshift);
data.put("percentage", cpp.percentage); data.put("percentage", cpp.percentage);
@ -623,8 +648,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
tempTarget.duration = data.getInt("duration"); tempTarget.duration = data.getInt("duration");
tempTarget.reason = data.getString("reason"); tempTarget.reason = data.getString("reason");
if(tempTarget.duration != 0) { if(tempTarget.duration != 0) {
tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits());
tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits());
} else { } else {
tempTarget.low = 0; tempTarget.low = 0;
tempTarget.high = 0; tempTarget.high = 0;
@ -635,9 +660,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
dao.createIfNotExists(tempTarget); dao.createIfNotExists(tempTarget);
MainApp.bus().post(new EventTempTargetRangeChange()); MainApp.bus().post(new EventTempTargetRangeChange());
ConfigBuilderPlugin.uploadCareportalEntryToNS(data); ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
} catch (JSONException e) { } catch (JSONException | SQLException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View file

@ -94,14 +94,15 @@
android:id="@+id/careportal_newnstreatment_meter" android:id="@+id/careportal_newnstreatment_meter"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="false"
android:text="@string/careportal_newnstreatment_meter" /> android:text="@string/careportal_newnstreatment_meter" />
<RadioButton <RadioButton
android:id="@+id/careportal_newnstreatment_sensor" android:id="@+id/careportal_newnstreatment_sensor"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/careportal_newnstreatment_sensor" /> android:text="@string/careportal_newnstreatment_sensor"
android:checked="true" />
<RadioButton <RadioButton
android:id="@+id/careportal_newnstreatment_other" android:id="@+id/careportal_newnstreatment_other"