Merge pull request #769 from jotomo/button-refinement

Button refinement
This commit is contained in:
Milos Kozak 2018-03-17 15:28:41 +01:00 committed by GitHub
commit 6e5d5c4a26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 85 additions and 81 deletions

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.Overview.Dialogs;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;
import android.support.v4.app.DialogFragment;
@ -53,7 +54,6 @@ import info.nightscout.utils.ToastUtils;
public class NewCarbsDialog extends DialogFragment implements OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {
private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class);
private EditText foodText;
private NumberPicker editCarbs;
private TextView dateButton;
@ -66,9 +66,9 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
private Button fav2Button;
private Button fav3Button;
private static final double FAV1_DEFAULT = 5;
private static final double FAV2_DEFAULT = 10;
private static final double FAV3_DEFAULT = 20;
private static final int FAV1_DEFAULT = 5;
private static final int FAV2_DEFAULT = 10;
private static final int FAV3_DEFAULT = 20;
private CheckBox suspendLoopCheckbox;
private CheckBox startActivityTTCheckbox;
private CheckBox startEatingSoonTTCheckbox;
@ -120,8 +120,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
maxCarbs = MainApp.getConfigBuilder().applyCarbsConstraints(Constants.carbsOnlyForCheckLimit);
foodText = view.findViewById(R.id.newcarb_food);
editCarbs = view.findViewById(R.id.newcarb_carbsamount);
editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher);
@ -143,22 +141,17 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
startEatingSoonTTCheckbox.setOnClickListener(this);
startActivityTTCheckbox.setOnClickListener(this);
// TODO prefilling carbs, maybe
// TODO maybe update suggested carbs to target TT when checked
// APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult();
// if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).carbsReq > 0) {
// editCarbs.setValue(((DetermineBasalResultSMB) lastAPSResult).carbsReq);
// }
fav1Button = view.findViewById(R.id.newcarbs_plus1);
fav1Button.setOnClickListener(this);
fav1Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_1, String.valueOf(FAV1_DEFAULT)));
fav1Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT)));
fav2Button = view.findViewById(R.id.newcarbs_plus2);
fav2Button.setOnClickListener(this);
fav2Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_2, String.valueOf(FAV2_DEFAULT)));
fav2Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT)));
fav3Button = view.findViewById(R.id.newcarbs_plus3);
fav3Button.setOnClickListener(this);
fav3Button.setText("+" + SP.getString(R.string.key_carbs_button_increment_3, String.valueOf(FAV3_DEFAULT)));
fav3Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)));
suspendLoopCheckbox = view.findViewById(R.id.newcarbs_suspend_loop);
@ -167,6 +160,10 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
return view;
}
private String toSignedString(int value) {
return value > 0 ? "+" + value : String.valueOf(value);
}
@Override
public synchronized void onClick(View view) {
Calendar calendar = Calendar.getInstance();
@ -201,18 +198,18 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
tpd.show(getActivity().getFragmentManager(), "Timepickerdialog");
break;
case R.id.newcarbs_plus1:
editCarbs.setValue(editCarbs.getValue()
+ SP.getDouble(R.string.key_carbs_button_increment_1, FAV1_DEFAULT));
editCarbs.setValue(Math.max(0, editCarbs.getValue()
+ SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT)));
validateInputs();
break;
case R.id.newcarbs_plus2:
editCarbs.setValue(editCarbs.getValue()
+ SP.getDouble(R.string.key_carbs_button_increment_2, FAV2_DEFAULT));
editCarbs.setValue(Math.max(0, editCarbs.getValue()
+ SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT)));
validateInputs();
break;
case R.id.newcarbs_plus3:
editCarbs.setValue(editCarbs.getValue()
+ SP.getDouble(R.string.key_carbs_button_increment_3, FAV3_DEFAULT));
editCarbs.setValue(Math.max(0, editCarbs.getValue()
+ SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)));
validateInputs();
break;
case R.id.newcarbs_activity_tt:
@ -233,7 +230,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
}
okClicked = true;
try {
final String food = StringUtils.trimToNull(foodText.getText().toString());
final Integer carbs = SafeParse.stringToInt(editCarbs.getText());
Integer carbsAfterConstraints = MainApp.getConfigBuilder().applyCarbsConstraints(carbs);
@ -279,10 +275,6 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
final int finalActivityTTDuration = activityTTDuration;
final int finalEatingSoonTTDuration = eatingSoonTTDuration;
if (StringUtils.isNoneEmpty(food)) {
confirmMessage += "<br/>" + "Food: " + food;
}
if (!initialEventTime.equals(eventTime)) {
confirmMessage += "<br/> Time: " + DateUtil.dateAndTimeString(eventTime);
}
@ -339,15 +331,30 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
MainApp.getDbHelper().createOrUpdate(tempTarget);
}
if (finalCarbsAfterConstraints > 0 || food != null) {
if (finalCarbsAfterConstraints > 0) {
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.date = eventTime.getTime();
detailedBolusInfo.eventType = CareportalEvent.CARBCORRECTION;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
// detailedBolusInfo.food = food;
detailedBolusInfo.context = context;
detailedBolusInfo.source = Source.USER;
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
if (ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo) {
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
}
});
} else {
MainApp.getConfigBuilder().addToHistoryTreatment(detailedBolusInfo);
}
}
}
});

View file

@ -134,25 +134,28 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
dateButton.setOnClickListener(this);
timeButton.setOnClickListener(this);
/*
// This makes it to easy to just bolus insulinReq, which is almost always too much
APSResult lastAPSResult = ConfigBuilderPlugin.getActiveAPS().getLastAPSResult();
if (lastAPSResult != null && lastAPSResult instanceof DetermineBasalResultSMB && ((DetermineBasalResultSMB) lastAPSResult).insulinReq > 0) {
editInsulin.setValue(((DetermineBasalResultSMB )lastAPSResult).insulinReq);
}
*/
plus1Button = (Button) view.findViewById(R.id.newinsulin_plus05);
plus1Button.setOnClickListener(this);
plus1Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_1), String.valueOf(PLUS1_DEFAULT)));
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.setOnClickListener(this);
plus2Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_2), String.valueOf(PLUS2_DEFAULT)));
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.setOnClickListener(this);
plus3Button.setText("+" + SP.getString(MainApp.gs(R.string.key_insulin_button_increment_3), String.valueOf(PLUS3_DEFAULT)));
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);
startESMCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
final Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile != null) {
double tt = SP.getDouble(MainApp.gs(R.string.key_eatingsoon_target), 0d);
if (tt > 0) {
double ttBgAdd = (profile.getTargetLow() - tt) / profile.getIsf();
editInsulin.setValue(editInsulin.getValue() + (isChecked ? ttBgAdd : -ttBgAdd));
}
}
});
recordOnlyCheckbox = (CheckBox) view.findViewById(R.id.newinsulin_record_only);
recordOnlyCheckbox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (dateButton != null) dateButton.setEnabled(isChecked);
@ -164,6 +167,10 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
return view;
}
private String toSignedString(double value) {
return value > 0 ? "+" + value : String.valueOf(value);
}
@Override
public synchronized void onClick(View view) {
Calendar calendar = Calendar.getInstance();
@ -197,25 +204,19 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
tpd.dismissOnPause(true);
tpd.show(getActivity().getFragmentManager(), "Timepickerdialog");
break;
case R.id.newinsulin_start_eating_soon_tt:
final Profile profile = MainApp.getConfigBuilder().getProfile();
double tt = SP.getDouble(R.string.key_eatingsoon_target, 0d);
double ttBgAdd = (tt - profile.getTargetLow()) / profile.getIsf();
editInsulin.setValue(editInsulin.getValue() + (startESMCheckbox.isChecked() ? ttBgAdd : -ttBgAdd));
break;
case R.id.newinsulin_plus05:
editInsulin.setValue(editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT));
editInsulin.setValue(Math.max(0, editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_1), PLUS1_DEFAULT)));
validateInputs();
break;
case R.id.newinsulin_plus10:
editInsulin.setValue(editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT));
editInsulin.setValue(Math.max(0, editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_2), PLUS2_DEFAULT)));
validateInputs();
break;
case R.id.newinsulin_plus20:
editInsulin.setValue(editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT));
editInsulin.setValue(Math.max(0, editInsulin.getValue()
+ SP.getDouble(MainApp.gs(R.string.key_insulin_button_increment_3), PLUS3_DEFAULT)));
validateInputs();
break;
}
@ -242,18 +243,20 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
if (!insulinAfterConstraints.equals(insulin))
confirmMessage += "<br/><font color='" + MainApp.sResources.getColor(R.color.low) + "'>" + MainApp.gs(R.string.bolusconstraintapplied) + "</font>";
double prefTTDuration = SP.getDouble(R.string.key_eatingsoon_duration, 45d);
double ttDuration = prefTTDuration > 0 ? prefTTDuration : 45d;
double prefTT = SP.getDouble(R.string.key_eatingsoon_target, 80d);
double tt = prefTT > 0 ? prefTT : 80d;
Profile currentProfile = MainApp.getConfigBuilder().getProfile();
if(currentProfile == null)
return;
double tt;
if(currentProfile.getUnits().equals(Constants.MMOL))
tt = prefTT > 0 ? Profile.toMgdl(prefTT, Constants.MMOL) : 80d;
else
tt = prefTT > 0 ? prefTT : 80d;
final double finalTT = tt;
if (startESMCheckbox.isChecked()) {
if(currentProfile.getUnits().equals("mmol")){
confirmMessage += "<br/>" + "TT: " + "<font color='" + MainApp.sResources.getColor(R.color.high) + "'>" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min </font>";

View file

@ -1201,8 +1201,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// **** Various treatment buttons ****
if (carbsButton != null) {
if (SP.getBoolean(R.string.key_show_carbs_button, true)
&& !ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo ||
(pump.isInitialized() && !pump.isSuspended())) {
&& (!ConfigBuilderPlugin.getActivePump().getPumpDescription().storesCarbInfo ||
(pump.isInitialized() && !pump.isSuspended()))) {
carbsButton.setVisibility(View.VISIBLE);
} else {
carbsButton.setVisibility(View.GONE);

View file

@ -299,6 +299,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:orientation="horizontal">
<info.nightscout.utils.SingleClickButton

View file

@ -503,6 +503,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:orientation="horizontal">
<info.nightscout.utils.SingleClickButton

View file

@ -600,6 +600,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:orientation="horizontal">
<info.nightscout.utils.SingleClickButton

View file

@ -285,6 +285,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:orientation="horizontal">
<info.nightscout.utils.SingleClickButton

View file

@ -43,7 +43,6 @@
android:id="@+id/carbs_eating_soon_tt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:text="@string/start_eating_soon_tt" />
<CheckBox
@ -76,15 +75,6 @@
android:text="08:20pm" />
</LinearLayout>
<EditText
android:id="@+id/newcarb_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:width="180dp"
android:inputType="text|textCapWords"
android:visibility="gone" />
<info.nightscout.utils.NumberPicker
android:id="@+id/newcarb_carbsamount"
android:layout_width="130dp"

View file

@ -19,12 +19,12 @@
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_insulin_button"
validate:testType="floatNumericRange"
validate:floatminNumber="0.1"
validate:floatminNumber="-5.0"
validate:floatmaxNumber="5.0"
android:defaultValue="0.5"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberDecimal|numberDecimal|numberSigned"
android:maxLines="20"
android:title="First insulin increment"
android:dialogMessage="@string/insulin_increment_button_message"
@ -32,12 +32,12 @@
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_insulin_button"
validate:testType="floatNumericRange"
validate:floatminNumber="0.1"
validate:floatminNumber="-5.0"
validate:floatmaxNumber="5.0"
android:defaultValue="1.0"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberDecimal|numberSigned"
android:maxLines="20"
android:title="Second insulin increment"
android:dialogMessage="@string/insulin_increment_button_message"
@ -45,12 +45,12 @@
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_insulin_button"
validate:testType="floatNumericRange"
validate:floatminNumber="0.1"
validate:floatminNumber="-5.0"
validate:floatmaxNumber="5.0"
android:defaultValue="2.0"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberDecimal|numberSigned"
android:maxLines="20"
android:title="Third insulin increment"
android:dialogMessage="@string/insulin_increment_button_message"
@ -62,39 +62,39 @@
android:title="Carbs" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_carbs_button"
validate:testType="numeric"
validate:minNumber="1"
validate:testType="numericRange"
validate:minNumber="-50"
validate:maxNumber="50"
android:defaultValue="5"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberSigned"
android:maxLines="20"
android:title="First carbs increment"
android:dialogMessage="@string/carb_increment_button_message"
android:key="@string/key_carbs_button_increment_1" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_carbs_button"
validate:testType="numeric"
validate:minNumber="1"
validate:testType="numericRange"
validate:minNumber="-50"
validate:maxNumber="50"
android:defaultValue="10"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberSigned"
android:maxLines="20"
android:title="Second carbs increment"
android:dialogMessage="@string/carb_increment_button_message"
android:key="@string/key_carbs_button_increment_2" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:dependency="@string/key_show_carbs_button"
validate:testType="numeric"
validate:minNumber="1"
validate:testType="numericRange"
validate:minNumber="-50"
validate:maxNumber="50"
android:defaultValue="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:inputType="numberDecimal"
android:inputType="numberSigned"
android:maxLines="20"
android:title="Third carbs increment"
android:dialogMessage="@string/carb_increment_button_message"