Carbs button: fix visibility pref, input type, allow negative increments.
This commit is contained in:
parent
b6ce7c03c6
commit
32108a7c2f
4 changed files with 30 additions and 50 deletions
|
@ -53,7 +53,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 +65,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 +119,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 +140,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 +159,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 +197,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 +229,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 +274,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,12 +330,11 @@ 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);
|
||||
|
|
|
@ -1184,8 +1184,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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue