diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
index a60a2f08b9..6813d5a338 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
@@ -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 += "
" + "Food: " + food;
- }
-
if (!initialEventTime.equals(eventTime)) {
confirmMessage += "
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);
+ }
}
}
});
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java
index 89e9a5308e..ddcfadc870 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewInsulinDialog.java
@@ -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 += "
" + MainApp.gs(R.string.bolusconstraintapplied) + "";
+
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 += "
" + "TT: " + "" + Profile.toMmol(tt, Constants.MGDL) + " mmol for " + ((int) ttDuration) + " min ";
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
index 0dbaedef6d..3dd6b04f40 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
@@ -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);
diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml
index c1372c5826..4628167d35 100644
--- a/app/src/main/res/layout/overview_fragment.xml
+++ b/app/src/main/res/layout/overview_fragment.xml
@@ -299,6 +299,7 @@
-
-