NewInsulinDialog: add notes field, use relative time, align style.
This commit is contained in:
parent
719d3d459b
commit
bf7e9e4bf3
3 changed files with 190 additions and 164 deletions
|
@ -9,7 +9,6 @@ import android.support.v7.app.AlertDialog;
|
|||
import android.text.Editable;
|
||||
import android.text.Html;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -18,19 +17,16 @@ import android.view.Window;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
||||
import com.wdullaer.materialdatetimepicker.time.RadialPickerLayout;
|
||||
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -54,16 +50,16 @@ import info.nightscout.utils.SP;
|
|||
import info.nightscout.utils.SafeParse;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
public class NewInsulinDialog extends DialogFragment implements OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
|
||||
import static info.nightscout.utils.DateUtil.now;
|
||||
|
||||
public class NewInsulinDialog extends DialogFragment implements OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(NewInsulinDialog.class);
|
||||
|
||||
private LinearLayout editLayout;
|
||||
private NumberPicker editTime;
|
||||
private NumberPicker editInsulin;
|
||||
|
||||
private TextView dateButton;
|
||||
private TextView timeButton;
|
||||
|
||||
private Date initialEventTime;
|
||||
private Date eventTime;
|
||||
private LinearLayout notesLayout;
|
||||
private EditText notesEdit;
|
||||
|
||||
private Button plus1Button;
|
||||
private Button plus2Button;
|
||||
|
@ -90,6 +86,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
final private TextWatcher textWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
validateInputs();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -98,12 +95,16 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
validateInputs();
|
||||
}
|
||||
};
|
||||
|
||||
private void validateInputs() {
|
||||
Double insulin = SafeParse.stringToDouble(editInsulin.getText());
|
||||
int time = editTime.getValue().intValue();
|
||||
if (Math.abs(time) > 12 * 60) {
|
||||
editTime.setValue(0d);
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.constraintapllied));
|
||||
}
|
||||
Double insulin = editInsulin.getValue();
|
||||
if (insulin > maxInsulin) {
|
||||
editInsulin.setValue(0d);
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.bolusconstraintapplied));
|
||||
|
@ -121,39 +122,34 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
|
||||
startESMCheckbox = view.findViewById(R.id.newinsulin_start_eating_soon_tt);
|
||||
|
||||
recordOnlyCheckbox = view.findViewById(R.id.newinsulin_record_only);
|
||||
recordOnlyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> editLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE));
|
||||
|
||||
editLayout = view.findViewById(R.id.newinsulin_time_layout);
|
||||
editLayout.setVisibility(View.GONE);
|
||||
editTime = view.findViewById(R.id.newinsulin_time);
|
||||
editTime.setParams(0d, -12 * 60d, 12 * 60d, 5d, new DecimalFormat("0"), false, textWatcher);
|
||||
|
||||
maxInsulin = MainApp.getConstraintChecker().getMaxBolusAllowed().value();
|
||||
|
||||
editInsulin = (NumberPicker) view.findViewById(R.id.treatments_newinsulin_amount);
|
||||
|
||||
editInsulin = view.findViewById(R.id.newinsulin_amount);
|
||||
editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, DecimalFormatter.pumpSupportedBolusFormat(), false, textWatcher);
|
||||
|
||||
dateButton = (TextView) view.findViewById(R.id.newinsulin_eventdate);
|
||||
timeButton = (TextView) view.findViewById(R.id.newinsulin_eventtime);
|
||||
|
||||
initialEventTime = new Date();
|
||||
eventTime = new Date(initialEventTime.getTime());
|
||||
dateButton.setText(DateUtil.dateString(eventTime));
|
||||
timeButton.setText(DateUtil.timeString(eventTime));
|
||||
dateButton.setOnClickListener(this);
|
||||
timeButton.setOnClickListener(this);
|
||||
|
||||
plus1Button = (Button) view.findViewById(R.id.newinsulin_plus05);
|
||||
plus1Button = view.findViewById(R.id.newinsulin_plus05);
|
||||
plus1Button.setOnClickListener(this);
|
||||
plus1Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT)));
|
||||
plus2Button = (Button) view.findViewById(R.id.newinsulin_plus10);
|
||||
plus2Button = view.findViewById(R.id.newinsulin_plus10);
|
||||
plus2Button.setOnClickListener(this);
|
||||
plus2Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT)));
|
||||
plus3Button = (Button) view.findViewById(R.id.newinsulin_plus20);
|
||||
plus3Button = view.findViewById(R.id.newinsulin_plus20);
|
||||
plus3Button.setOnClickListener(this);
|
||||
plus3Button.setText(toSignedString(SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT)));
|
||||
|
||||
startESMCheckbox = (CheckBox) view.findViewById(R.id.newinsulin_start_eating_soon_tt);
|
||||
|
||||
recordOnlyCheckbox = (CheckBox) view.findViewById(R.id.newinsulin_record_only);
|
||||
recordOnlyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (dateButton != null) dateButton.setEnabled(isChecked);
|
||||
if (timeButton != null) timeButton.setEnabled(isChecked);
|
||||
});
|
||||
notesLayout = view.findViewById(R.id.newcarbs_notes_layout);
|
||||
notesLayout.setVisibility(SP.getBoolean(R.string.key_show_notes_entry_dialogs, false) ? View.VISIBLE : View.GONE);
|
||||
notesEdit = view.findViewById(R.id.newcarbs_notes);
|
||||
|
||||
setCancelable(true);
|
||||
getDialog().setCanceledOnTouchOutside(false);
|
||||
|
@ -167,8 +163,6 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
|
||||
@Override
|
||||
public synchronized void onClick(View view) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(eventTime);
|
||||
switch (view.getId()) {
|
||||
case R.id.ok:
|
||||
submit();
|
||||
|
@ -176,28 +170,6 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
case R.id.cancel:
|
||||
dismiss();
|
||||
break;
|
||||
case R.id.newinsulin_eventdate:
|
||||
DatePickerDialog dpd = DatePickerDialog.newInstance(
|
||||
this,
|
||||
calendar.get(Calendar.YEAR),
|
||||
calendar.get(Calendar.MONTH),
|
||||
calendar.get(Calendar.DAY_OF_MONTH)
|
||||
);
|
||||
dpd.setThemeDark(true);
|
||||
dpd.dismissOnPause(true);
|
||||
dpd.show(getActivity().getFragmentManager(), "Datepickerdialog");
|
||||
break;
|
||||
case R.id.newinsulin_eventtime:
|
||||
TimePickerDialog tpd = TimePickerDialog.newInstance(
|
||||
this,
|
||||
calendar.get(Calendar.HOUR_OF_DAY),
|
||||
calendar.get(Calendar.MINUTE),
|
||||
DateFormat.is24HourFormat(getActivity())
|
||||
);
|
||||
tpd.setThemeDark(true);
|
||||
tpd.dismissOnPause(true);
|
||||
tpd.show(getActivity().getFragmentManager(), "Timepickerdialog");
|
||||
break;
|
||||
case R.id.newinsulin_plus05:
|
||||
editInsulin.setValue(Math.max(0, editInsulin.getValue()
|
||||
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT)));
|
||||
|
@ -253,14 +225,20 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
final double finalTT = tt;
|
||||
|
||||
if (startESMCheckbox.isChecked()) {
|
||||
if (currentProfile.getUnits().equals("mmol")) {
|
||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
||||
actions.add("TT: " + "<font color='" + MainApp.sResources.getColor(R.color.high) + "'>" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min </font>");
|
||||
} else
|
||||
actions.add("TT: " + "<font color='" + MainApp.sResources.getColor(R.color.high) + "'>" + ((int) tt) + "mg/dl for " + ((int) ttDuration) + " min </font>");
|
||||
}
|
||||
|
||||
if (!initialEventTime.equals(eventTime)) {
|
||||
actions.add("Time: " + DateUtil.dateAndTimeString(eventTime));
|
||||
int timeOffset = editTime.getValue().intValue();
|
||||
final long time = now() + timeOffset * 1000 * 60;
|
||||
if (timeOffset != 0) {
|
||||
actions.add(MainApp.gs(R.string.time) + DateUtil.dateAndTimeString(time));
|
||||
}
|
||||
final String notes = notesEdit.getText().toString();
|
||||
if (!notes.isEmpty()) {
|
||||
actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes);
|
||||
}
|
||||
|
||||
final double finalInsulinAfterConstraints = insulinAfterConstraints;
|
||||
|
@ -269,10 +247,9 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
||||
builder.setTitle(MainApp.gs(R.string.confirmation));
|
||||
builder.setMessage(actions.isEmpty()
|
||||
? MainApp.gs(R.string.no_action_selected)
|
||||
: Html.fromHtml(Joiner.on("<br/>").join(actions)));
|
||||
builder.setPositiveButton(MainApp.gs(R.string.ok), actions.isEmpty() ? null : (dialog, id) -> {
|
||||
if (finalInsulinAfterConstraints > 0 || startESMCheckbox.isChecked()) {
|
||||
builder.setMessage(Html.fromHtml(Joiner.on("<br/>").join(actions)));
|
||||
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
|
||||
synchronized (builder) {
|
||||
if (accepted) {
|
||||
log.debug("guarding: already accepted");
|
||||
|
@ -291,23 +268,21 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||
}
|
||||
|
||||
if (finalInsulinAfterConstraints <= 0.01) {
|
||||
if (finalInsulinAfterConstraints == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recordOnlyCheckbox.isChecked()) {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
detailedBolusInfo.date = eventTime.getTime();
|
||||
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo);
|
||||
} else {
|
||||
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
|
||||
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
|
||||
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
|
||||
detailedBolusInfo.context = context;
|
||||
detailedBolusInfo.source = Source.USER;
|
||||
detailedBolusInfo.notes = notes;
|
||||
if (recordOnlyCheckbox.isChecked()) {
|
||||
detailedBolusInfo.date = time;
|
||||
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo);
|
||||
} else {
|
||||
detailedBolusInfo.date = now();
|
||||
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -325,6 +300,9 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
builder.setMessage(MainApp.gs(R.string.no_action_selected));
|
||||
}
|
||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||
builder.show();
|
||||
dismiss();
|
||||
|
@ -332,20 +310,4 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
|
||||
eventTime.setYear(year - 1900);
|
||||
eventTime.setMonth(monthOfYear);
|
||||
eventTime.setDate(dayOfMonth);
|
||||
dateButton.setText(DateUtil.dateString(eventTime));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
|
||||
eventTime.setHours(hourOfDay);
|
||||
eventTime.setMinutes(minute);
|
||||
eventTime.setSeconds(second);
|
||||
timeButton.setText(DateUtil.timeString(eventTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,20 +16,31 @@
|
|||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="5dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/icon_bolus" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingLeft="15dp"
|
||||
android:paddingRight="15dp"
|
||||
android:paddingTop="10dp"
|
||||
android:textAlignment="center"
|
||||
android:text="@string/overview_insulin_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textColor="@color/colorInsulinButton" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="5dp"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/icon_bolus" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -52,40 +63,69 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@color/listdelimiter" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/newinsulin_time_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/time" />
|
||||
|
||||
<info.nightscout.utils.NumberPicker
|
||||
android:id="@+id/newinsulin_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="end"
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/shortminute" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:padding="5dp">
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/newinsulin_eventdate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:enabled="false"
|
||||
android:padding="5dp"
|
||||
android:text="2017/05/05" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/newinsulin_eventtime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:enabled="false"
|
||||
android:padding="5dp"
|
||||
android:text="08:20pm" />
|
||||
</LinearLayout>
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textStyle="bold"
|
||||
android:text="@string/overview_insulin_label" />
|
||||
|
||||
<info.nightscout.utils.NumberPicker
|
||||
android:id="@+id/treatments_newinsulin_amount"
|
||||
android:layout_width="130dp"
|
||||
android:id="@+id/newinsulin_amount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:layout_marginRight="30dp"
|
||||
android:layout_marginTop="10dp" />
|
||||
android:paddingLeft="5dp"
|
||||
android:paddingRight="5dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/insulin_unit_shortname" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -117,6 +157,30 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/newcarbs_notes_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:width="60dp"
|
||||
android:padding="2dp"
|
||||
android:text="@string/careportal_newnstreatment_notes_label"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/newcarbs_notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/mdtp_done_button" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -999,5 +999,5 @@
|
|||
<string name="openapssmb_maxiob_summary">This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value</string>
|
||||
<string name="time">Time</string>
|
||||
<string name="key_show_notes_entry_dialogs">show_notes_entry_dialogs</string>
|
||||
<string name="overview_show_notes_field_in_dialogs_title">Show notes field in dialogs</string>
|
||||
<string name="overview_show_notes_field_in_dialogs_title">Show notes field in treatment dialogs</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue