diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/ExtendedBolusDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/ExtendedBolusDialog.kt
index b78f410aa7..2ea30fb0e7 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/ExtendedBolusDialog.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/ExtendedBolusDialog.kt
@@ -60,7 +60,8 @@ class ExtendedBolusDialog : DialogFragmentWithDate() {
val insulinAfterConstraint = MainApp.getConstraintChecker().applyExtendedBolusConstraints(Constraint(insulin)).value()
actions.add(MainApp.gs(R.string.formatinsulinunits, insulinAfterConstraint))
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
- if (abs(insulinAfterConstraint - insulin) > 0.01) actions.add(MainApp.gs(R.string.constraintapllied))
+ if (abs(insulinAfterConstraint - insulin) > 0.01)
+ actions.add("" + MainApp.gs(R.string.constraintapllied) + "")
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("
").join(actions))) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/TempBasalDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/TempBasalDialog.kt
index 48dc1c9873..6c9c81e7b2 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/TempBasalDialog.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/dialogs/TempBasalDialog.kt
@@ -88,7 +88,8 @@ class TempBasalDialog : DialogFragmentWithDate() {
absolute = MainApp.getConstraintChecker().applyBasalConstraints(Constraint(basalAbsoluteInput), profile).value()
actions.add(MainApp.gs(R.string.pump_basebasalrate, absolute))
actions.add(MainApp.gs(R.string.duration) + ": " + MainApp.gs(R.string.format_mins, durationInMinutes))
- if (abs(absolute - basalAbsoluteInput) > 0.01) actions.add(MainApp.gs(R.string.constraintapllied))
+ if (abs(absolute - basalAbsoluteInput) > 0.01)
+ actions.add("" + MainApp.gs(R.string.constraintapllied) + "")
}
activity?.let { activity ->
OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("
").join(actions))) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
index eedaf22b0b..b5086c3072 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/careportal/Dialogs/NewNSTreatmentDialog.java
@@ -204,16 +204,15 @@ public class NewNSTreatmentDialog extends AppCompatDialogFragment implements Vie
boolean erase = false;
String units = ProfileFunctions.getSystemUnits();
- DefaultValueHelper helper = new DefaultValueHelper();
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
- defaultDuration = helper.determineEatingSoonTTDuration();
- defaultTarget = helper.determineEatingSoonTT();
+ defaultDuration = DefaultValueHelper.determineEatingSoonTTDuration();
+ defaultTarget = DefaultValueHelper.determineEatingSoonTT();
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
- defaultDuration = helper.determineActivityTTDuration();
- defaultTarget = helper.determineActivityTT();
+ defaultDuration = DefaultValueHelper.determineActivityTTDuration();
+ defaultTarget = DefaultValueHelper.determineActivityTT();
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
- defaultDuration = helper.determineHypoTTDuration();
- defaultTarget = helper.determineHypoTT();
+ defaultDuration = DefaultValueHelper.determineHypoTTDuration();
+ defaultTarget = DefaultValueHelper.determineHypoTT();
} else if (editDuration.getValue() != 0) {
defaultDuration = editDuration.getValue();
} else {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
index 963eb3cf3f..9aa64ff1d6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java
@@ -84,13 +84,11 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
-import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
-import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity;
import info.nightscout.androidaps.plugins.general.overview.dialogs.CalibrationDialog;
-import info.nightscout.androidaps.plugins.general.overview.dialogs.NewCarbsDialog;
+import info.nightscout.androidaps.plugins.general.overview.dialogs.CarbsDialog;
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewInsulinDialog;
import info.nightscout.androidaps.plugins.general.overview.dialogs.NewTreatmentDialog;
import info.nightscout.androidaps.plugins.general.overview.dialogs.ProfileSwitchDialog;
@@ -759,33 +757,30 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (manager != null)
pvd.show(manager, "ProfileViewDialog");
} else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) {
- DefaultValueHelper defHelper = new DefaultValueHelper();
- double target = Profile.toMgdl(defHelper.determineEatingSoonTT(), ProfileFunctions.getSystemUnits());
+ double target = Profile.toMgdl(DefaultValueHelper.determineEatingSoonTT(), ProfileFunctions.getSystemUnits());
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
- .duration(defHelper.determineEatingSoonTTDuration())
+ .duration(DefaultValueHelper.determineEatingSoonTTDuration())
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(target)
.high(target);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (item.getTitle().equals(MainApp.gs(R.string.activity))) {
- DefaultValueHelper defHelper = new DefaultValueHelper();
- double target = Profile.toMgdl(defHelper.determineActivityTT(), ProfileFunctions.getSystemUnits());
+ double target = Profile.toMgdl(DefaultValueHelper.determineActivityTT(), ProfileFunctions.getSystemUnits());
TempTarget tempTarget = new TempTarget()
.date(now())
- .duration(defHelper.determineActivityTTDuration())
+ .duration(DefaultValueHelper.determineActivityTTDuration())
.reason(MainApp.gs(R.string.activity))
.source(Source.USER)
.low(target)
.high(target);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) {
- DefaultValueHelper defHelper = new DefaultValueHelper();
- double target = Profile.toMgdl(defHelper.determineHypoTT(), ProfileFunctions.getSystemUnits());
+ double target = Profile.toMgdl(DefaultValueHelper.determineHypoTT(), ProfileFunctions.getSystemUnits());
TempTarget tempTarget = new TempTarget()
.date(now())
- .duration(defHelper.determineHypoTTDuration())
+ .duration(DefaultValueHelper.determineHypoTTDuration())
.reason(MainApp.gs(R.string.hypo))
.source(Source.USER)
.low(target)
@@ -868,7 +863,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
new NewInsulinDialog().show(manager, "InsulinDialog");
break;
case R.id.overview_carbsbutton:
- new NewCarbsDialog().show(manager, "CarbsDialog");
+ new CarbsDialog().show(manager, "Overview");
break;
case R.id.overview_pumpstatus:
if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended() || !ConfigBuilderPlugin.getPlugin().getActivePump().isInitialized())
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CarbsDialog.kt
new file mode 100644
index 0000000000..761e74eb0c
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/CarbsDialog.kt
@@ -0,0 +1,220 @@
+package info.nightscout.androidaps.plugins.general.overview.dialogs
+
+import android.os.Bundle
+import android.text.Editable
+import android.text.TextWatcher
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import com.google.common.base.Joiner
+import info.nightscout.androidaps.Constants
+import info.nightscout.androidaps.MainApp
+import info.nightscout.androidaps.R
+import info.nightscout.androidaps.data.Profile
+import info.nightscout.androidaps.db.CareportalEvent
+import info.nightscout.androidaps.db.DatabaseHelper
+import info.nightscout.androidaps.db.Source
+import info.nightscout.androidaps.db.TempTarget
+import info.nightscout.androidaps.interfaces.Constraint
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
+import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
+import info.nightscout.androidaps.plugins.treatments.CarbsGenerator
+import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
+import info.nightscout.androidaps.utils.*
+import kotlinx.android.synthetic.main.notes.*
+import kotlinx.android.synthetic.main.okcancel.*
+import kotlinx.android.synthetic.main.overview_carbs_dialog.*
+import org.slf4j.LoggerFactory
+import java.text.DecimalFormat
+import java.util.*
+import kotlin.math.max
+
+class CarbsDialog : DialogFragmentWithDate() {
+ private val log = LoggerFactory.getLogger(CarbsDialog::class.java)
+
+ companion object {
+ private const val FAV1_DEFAULT = 5
+ private const val FAV2_DEFAULT = 10
+ private const val FAV3_DEFAULT = 20
+ }
+
+ private var maxCarbs = MainApp.getConstraintChecker().maxCarbsAllowed.value().toDouble()
+
+ private val textWatcher: TextWatcher = object : TextWatcher {
+ override fun afterTextChanged(s: Editable) {
+ validateInputs()
+ }
+
+ override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
+ override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
+ }
+
+ private fun validateInputs() {
+ val time = overview_carbs_time.value.toInt()
+ if (time > 12 * 60 || time < -12 * 60) {
+ overview_carbs_time.value = 0.0
+ ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.constraintapllied))
+ }
+ val duration = overview_carbs_duration.value
+ if (duration > 10) {
+ overview_carbs_duration.value = 0.0
+ ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.constraintapllied))
+ }
+ val carbs = overview_carbs_carbs.value.toInt()
+ if (carbs > maxCarbs) {
+ overview_carbs_carbs.value = 0.0
+ ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.carbsconstraintapplied))
+ }
+ }
+
+ override fun onSaveInstanceState(savedInstanceState: Bundle) {
+ super.onSaveInstanceState(savedInstanceState)
+ savedInstanceState.putDouble("overview_carbs_time", overview_carbs_time.value)
+ savedInstanceState.putDouble("overview_carbs_duration", overview_carbs_duration.value)
+ savedInstanceState.putDouble("overview_carbs_carbs", overview_carbs_carbs.value)
+ }
+
+ override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?): View? {
+ onCreateView()
+ return inflater.inflate(R.layout.overview_carbs_dialog, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ overview_carbs_time.setParams(savedInstanceState?.getDouble("overview_carbs_time")
+ ?: 0.0, -12 * 60.0, 12 * 60.0, 5.0, DecimalFormat("0"), false, ok, textWatcher)
+
+ overview_carbs_duration.setParams(savedInstanceState?.getDouble("overview_carbs_duration")
+ ?: 0.0, 0.0, 10.0, 1.0, DecimalFormat("0"), false, ok, textWatcher)
+
+ overview_carbs_carbs.setParams(savedInstanceState?.getDouble("overview_carbs_carbs")
+ ?: 0.0, 0.0, maxCarbs, 1.0, DecimalFormat("0"), false, ok, textWatcher)
+
+ overview_carbs_plus1.text = toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))
+ overview_carbs_plus1.setOnClickListener {
+ overview_carbs_carbs.value = max(0.0, overview_carbs_carbs.value
+ + SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT))
+ validateInputs()
+ }
+
+ overview_carbs_plus2.text = toSignedString(SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT))
+ overview_carbs_plus2.setOnClickListener {
+ overview_carbs_carbs.value = max(0.0, overview_carbs_carbs.value
+ + SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT))
+ validateInputs()
+ }
+
+ overview_carbs_plus3.text = toSignedString(SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT))
+ overview_carbs_plus3.setOnClickListener {
+ overview_carbs_carbs.value = max(0.0, overview_carbs_carbs.value
+ + SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT))
+ validateInputs()
+ }
+
+ DatabaseHelper.actualBg()?.let { bgReading ->
+ if (bgReading.value < 72)
+ overview_carbs_hypo_tt.setChecked(true)
+ }
+ overview_carbs_hypo_tt.setOnClickListener {
+ overview_carbs_activity_tt.isChecked = false
+ overview_carbs_eating_soon_tt.isChecked = false
+ }
+ overview_carbs_activity_tt.setOnClickListener {
+ overview_carbs_hypo_tt.isChecked = false
+ overview_carbs_eating_soon_tt.isChecked = false
+ }
+ overview_carbs_eating_soon_tt.setOnClickListener {
+ overview_carbs_hypo_tt.isChecked = false
+ overview_carbs_activity_tt.isChecked = false
+ }
+ }
+
+ private fun toSignedString(value: Int): String {
+ return if (value > 0) "+$value" else value.toString()
+ }
+
+ override fun submit() {
+ val carbs = overview_carbs_carbs.value.toInt()
+ val carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(Constraint(carbs)).value()
+ val units = ProfileFunctions.getSystemUnits()
+ val activityTTDuration = DefaultValueHelper.determineActivityTTDuration()
+ val activityTT = DefaultValueHelper.determineActivityTT()
+ val eatingSoonTTDuration = DefaultValueHelper.determineEatingSoonTTDuration()
+ val eatingSoonTT = DefaultValueHelper.determineEatingSoonTT()
+ val hypoTTDuration = DefaultValueHelper.determineHypoTTDuration()
+ val hypoTT = DefaultValueHelper.determineHypoTT()
+ val actions: LinkedList = LinkedList()
+ val unitLabel = if (units == Constants.MMOL) MainApp.gs(R.string.mmol) else MainApp.gs(R.string.mgdl)
+
+ val activitySelected = overview_carbs_activity_tt.isChecked
+ if (activitySelected)
+ actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")")
+ val eatingSoonSelected = overview_carbs_eating_soon_tt.isChecked
+ if (eatingSoonSelected)
+ actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " " + unitLabel + " (" + eatingSoonTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")")
+ val hypoSelected = overview_carbs_hypo_tt.isChecked
+ if (hypoSelected)
+ actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(hypoTT) + " " + unitLabel + " (" + hypoTTDuration + " " + MainApp.gs(R.string.unit_minute_short) + ")")
+
+ val timeOffset = overview_carbs_time.value.toInt()
+ val time = DateUtil.now() + timeOffset * 1000 * 60
+ if (timeOffset != 0)
+ actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time))
+ val duration = overview_carbs_duration.value.toInt()
+ if (duration > 0)
+ actions.add(MainApp.gs(R.string.duration) + ": " + duration + MainApp.gs(R.string.shorthour))
+ if (carbs > 0)
+ actions.add(MainApp.gs(R.string.carbs) + ": " + "" + MainApp.gs(R.string.format_carbs, carbsAfterConstraints) + "")
+ if (carbsAfterConstraints != carbs)
+ actions.add("" + MainApp.gs(R.string.carbsconstraintapplied) + "")
+ val notes = notes.text.toString()
+ if (notes.isNotEmpty())
+ actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes)
+
+ if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) {
+ activity?.let { activity ->
+ OKDialog.showConfirmation(activity, HtmlHelper.fromHtml(Joiner.on("
").join(actions))) {
+ if (activitySelected) {
+ val tempTarget = TempTarget()
+ .date(System.currentTimeMillis())
+ .duration(activityTTDuration)
+ .reason(MainApp.gs(R.string.activity))
+ .source(Source.USER)
+ .low(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
+ .high(Profile.toMgdl(activityTT, ProfileFunctions.getSystemUnits()))
+ TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
+ } else if (eatingSoonSelected) {
+ val tempTarget = TempTarget()
+ .date(System.currentTimeMillis())
+ .duration(eatingSoonTTDuration)
+ .reason(MainApp.gs(R.string.eatingsoon))
+ .source(Source.USER)
+ .low(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
+ .high(Profile.toMgdl(eatingSoonTT, ProfileFunctions.getSystemUnits()))
+ TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
+ } else if (hypoSelected) {
+ val tempTarget = TempTarget()
+ .date(System.currentTimeMillis())
+ .duration(hypoTTDuration)
+ .reason(MainApp.gs(R.string.hypo))
+ .source(Source.USER)
+ .low(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
+ .high(Profile.toMgdl(hypoTT, ProfileFunctions.getSystemUnits()))
+ TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
+ }
+ if (carbsAfterConstraints > 0) {
+ if (duration == 0) {
+ CarbsGenerator.createCarb(carbsAfterConstraints, time, CareportalEvent.CARBCORRECTION, notes)
+ } else {
+ CarbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes)
+ NSUpload.uploadEvent(CareportalEvent.NOTE, DateUtil.now() - 2000, MainApp.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset))
+ }
+ }
+ }
+ }
+ } else
+ OKDialog.show(activity, "", MainApp.gs(R.string.no_action_selected), null)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java
deleted file mode 100644
index 36cfd07be9..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/NewCarbsDialog.java
+++ /dev/null
@@ -1,443 +0,0 @@
-package info.nightscout.androidaps.plugins.general.overview.dialogs;
-
-import android.os.Bundle;
-import androidx.fragment.app.DialogFragment;
-import androidx.appcompat.app.AlertDialog;
-import android.text.Editable;
-import android.text.Html;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.view.WindowManager;
-import android.widget.Button;
-import android.widget.CompoundButton;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.RadioButton;
-
-import com.google.common.base.Joiner;
-
-import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
-import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.text.DecimalFormat;
-import java.util.LinkedList;
-import java.util.List;
-
-import info.nightscout.androidaps.Constants;
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.db.BgReading;
-import info.nightscout.androidaps.db.CareportalEvent;
-import info.nightscout.androidaps.db.DatabaseHelper;
-import info.nightscout.androidaps.db.Source;
-import info.nightscout.androidaps.db.TempTarget;
-import info.nightscout.androidaps.interfaces.Constraint;
-import info.nightscout.androidaps.plugins.treatments.CarbsGenerator;
-import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
-import info.nightscout.androidaps.utils.DateUtil;
-import info.nightscout.androidaps.utils.DecimalFormatter;
-import info.nightscout.androidaps.utils.DefaultValueHelper;
-import info.nightscout.androidaps.utils.NumberPicker;
-import info.nightscout.androidaps.utils.SP;
-import info.nightscout.androidaps.utils.ToastUtils;
-
-import static info.nightscout.androidaps.utils.DateUtil.now;
-
-public class NewCarbsDialog extends DialogFragment implements OnClickListener, CompoundButton.OnCheckedChangeListener {
- private static Logger log = LoggerFactory.getLogger(NewCarbsDialog.class);
-
- private static final int FAV1_DEFAULT = 5;
- private static final int FAV2_DEFAULT = 10;
- private static final int FAV3_DEFAULT = 20;
-
- private RadioButton startActivityTTCheckbox;
- private RadioButton startEatingSoonTTCheckbox;
- private RadioButton startHypoTTCheckbox;
- private boolean togglingTT;
-
- private NumberPicker editTime;
- private NumberPicker editDuration;
- private NumberPicker editCarbs;
- private Integer maxCarbs;
-
- private EditText notesEdit;
-
- //one shot guards
- private boolean accepted;
- private boolean okClicked;
-
- public NewCarbsDialog() {
- }
-
- final private TextWatcher textWatcher = new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {
- validateInputs();
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- };
-
- private void validateInputs() {
- int time = editTime.getValue().intValue();
- if (time > 12 * 60 || time < -12 * 60) {
- editTime.setValue(0d);
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.constraintapllied));
- }
- Double duration = editDuration.getValue();
- if (duration > 10) {
- editDuration.setValue(0d);
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.constraintapllied));
- }
- int carbs = editCarbs.getValue().intValue();
- if (carbs > maxCarbs) {
- editCarbs.setValue(0d);
- ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.carbsconstraintapplied));
- }
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.overview_newcarbs_dialog, container, false);
-
- view.findViewById(R.id.ok).setOnClickListener(this);
- view.findViewById(R.id.cancel).setOnClickListener(this);
-
- getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
- getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
-
- startActivityTTCheckbox = view.findViewById(R.id.newcarbs_activity_tt);
- startActivityTTCheckbox.setOnCheckedChangeListener(this);
- startEatingSoonTTCheckbox = view.findViewById(R.id.newcarbs_eating_soon_tt);
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(this);
- startHypoTTCheckbox = view.findViewById(R.id.newcarbs_hypo_tt);
-
- editTime = view.findViewById(R.id.newcarbs_time);
- editTime.setParams(0d, -12 * 60d, 12 * 60d, 5d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), textWatcher);
-
- editDuration = view.findViewById(R.id.new_carbs_duration);
- editDuration.setParams(0d, 0d, 10d, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), textWatcher);
-
- maxCarbs = MainApp.getConstraintChecker().getMaxCarbsAllowed().value();
-
- editCarbs = view.findViewById(R.id.newcarb_carbsamount);
- editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, view.findViewById(R.id.ok), textWatcher);
-
- Button fav1Button = view.findViewById(R.id.newcarbs_plus1);
- fav1Button.setOnClickListener(this);
- fav1Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_1, FAV1_DEFAULT)));
-
- Button fav2Button = view.findViewById(R.id.newcarbs_plus2);
- fav2Button.setOnClickListener(this);
- fav2Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_2, FAV2_DEFAULT)));
-
- Button fav3Button = view.findViewById(R.id.newcarbs_plus3);
- fav3Button.setOnClickListener(this);
- fav3Button.setText(toSignedString(SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)));
-
- LinearLayout 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);
-
- BgReading bgReading = DatabaseHelper.actualBg();
- if (bgReading != null && bgReading.value < 72) {
- startHypoTTCheckbox.setChecked(true);
- // see #onCheckedChanged why listeners are registered like this
- startHypoTTCheckbox.setOnClickListener(this);
- } else {
- startHypoTTCheckbox.setOnCheckedChangeListener(this);
- }
-
- setCancelable(true);
- getDialog().setCanceledOnTouchOutside(false);
-
- //recovering state if there is something
- if (savedInstanceState != null) {
- editCarbs.setValue(savedInstanceState.getDouble("editCarbs"));
- editTime.setValue(savedInstanceState.getDouble("editTime"));
- editDuration.setValue(savedInstanceState.getDouble("editDuration"));
- }
- return view;
- }
-
- private String toSignedString(int value) {
- return value > 0 ? "+" + value : String.valueOf(value);
- }
-
-
- @Override
- public void onSaveInstanceState(Bundle carbsDialogState) {
- carbsDialogState.putBoolean("startActivityTTCheckbox",startActivityTTCheckbox.isChecked());
- carbsDialogState.putBoolean("startEatingSoonTTCheckbox", startEatingSoonTTCheckbox.isChecked());
- carbsDialogState.putBoolean("startHypoTTCheckbox", startHypoTTCheckbox.isChecked());
- carbsDialogState.putDouble("editTime", editTime.getValue());
- carbsDialogState.putDouble("editDuration", editDuration.getValue());
- carbsDialogState.putDouble("editCarbs", editCarbs.getValue());
- super.onSaveInstanceState(carbsDialogState);
- }
-
-
- @Override
- public synchronized void onClick(View view) {
- switch (view.getId()) {
- case R.id.ok:
- submit();
- break;
- case R.id.cancel:
- dismiss();
- break;
- case R.id.newcarbs_plus1:
- 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(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(Math.max(0, editCarbs.getValue()
- + SP.getInt(R.string.key_carbs_button_increment_3, FAV3_DEFAULT)));
- validateInputs();
- break;
- case R.id.newcarbs_activity_tt:
- if (togglingTT) {
- togglingTT = false;
- break;
- }
- startActivityTTCheckbox.setOnClickListener(null);
- startActivityTTCheckbox.setOnCheckedChangeListener(null);
- startActivityTTCheckbox.setChecked(false);
- startActivityTTCheckbox.setOnCheckedChangeListener(this);
- break;
- case R.id.newcarbs_eating_soon_tt:
- if (togglingTT) {
- togglingTT = false;
- break;
- }
- startEatingSoonTTCheckbox.setOnClickListener(null);
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(null);
- startEatingSoonTTCheckbox.setChecked(false);
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(this);
- break;
- case R.id.newcarbs_hypo_tt:
- if (togglingTT) {
- togglingTT = false;
- break;
- }
- startHypoTTCheckbox.setOnClickListener(null);
- startHypoTTCheckbox.setOnCheckedChangeListener(null);
- startHypoTTCheckbox.setChecked(false);
- startHypoTTCheckbox.setOnCheckedChangeListener(this);
- break;
- }
- }
-
-
-
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- // Logic to disable a selected radio when pressed: when a checked radio
- // is pressed, no CheckChanged event is triggered, so register a Click event
- // when checking a radio. Since Click events come after CheckChanged events,
- // the Click event is triggered immediately after this. Thus, set togglingTT
- // var to true, so that the first Click event fired after this is ignored.
- // Radios remove themselves from Click events once unchecked.
- // Since radios are not in a group, their state is manually updated here.
- switch (buttonView.getId()) {
- case R.id.newcarbs_activity_tt:
- togglingTT = true;
- startActivityTTCheckbox.setOnClickListener(this);
-
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(null);
- startEatingSoonTTCheckbox.setChecked(false);
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(this);
-
- startHypoTTCheckbox.setOnCheckedChangeListener(null);
- startHypoTTCheckbox.setChecked(false);
- startHypoTTCheckbox.setOnCheckedChangeListener(this);
- break;
- case R.id.newcarbs_eating_soon_tt:
- togglingTT = true;
- startEatingSoonTTCheckbox.setOnClickListener(this);
-
- startActivityTTCheckbox.setOnCheckedChangeListener(null);
- startActivityTTCheckbox.setChecked(false);
- startActivityTTCheckbox.setOnCheckedChangeListener(this);
-
- startHypoTTCheckbox.setOnCheckedChangeListener(null);
- startHypoTTCheckbox.setChecked(false);
- startHypoTTCheckbox.setOnCheckedChangeListener(this);
- break;
- case R.id.newcarbs_hypo_tt:
- togglingTT = true;
- startHypoTTCheckbox.setOnClickListener(this);
-
- startActivityTTCheckbox.setOnCheckedChangeListener(null);
- startActivityTTCheckbox.setChecked(false);
- startActivityTTCheckbox.setOnCheckedChangeListener(this);
-
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(null);
- startEatingSoonTTCheckbox.setChecked(false);
- startEatingSoonTTCheckbox.setOnCheckedChangeListener(this);
- break;
- }
- }
-
- private void submit() {
- if (okClicked) {
- log.debug("guarding: ok already clicked");
- dismiss();
- return;
- }
- okClicked = true;
- try {
- final Profile currentProfile = ProfileFunctions.getInstance().getProfile();
- if (currentProfile == null) {
- return;
- }
-
- int carbs = editCarbs.getValue().intValue();
- Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
-
- final String units = ProfileFunctions.getSystemUnits();
- DefaultValueHelper helper = new DefaultValueHelper();
-
- int activityTTDuration = helper.determineActivityTTDuration();
- double activityTT = helper.determineActivityTT();
-
- int eatingSoonTTDuration = helper.determineEatingSoonTTDuration();
- double eatingSoonTT = helper.determineEatingSoonTT();
-
- int hypoTTDuration = helper.determineHypoTTDuration();
- double hypoTT = helper.determineHypoTT();
-
- List actions = new LinkedList<>();
-
- if (startActivityTTCheckbox.isChecked()) {
- String unitLabel = "mg/dl";
- if (units.equals(Constants.MMOL)) {
- unitLabel = "mmol/l";
- }
- actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)");
- }
- if (startEatingSoonTTCheckbox.isChecked()) {
- if (units.equals(Constants.MMOL)) {
- actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(eatingSoonTT) + " mmol/l (" + eatingSoonTTDuration + " min)");
- } else {
- actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(eatingSoonTT) + " mg/dl (" + eatingSoonTTDuration + " min)");
- }
- }
- if (startHypoTTCheckbox.isChecked()) {
- if (units.equals(Constants.MMOL)) {
- actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to1Decimal(hypoTT) + " mmol/l (" + hypoTTDuration + " min)");
- } else {
- actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "" + DecimalFormatter.to0Decimal(hypoTT) + " mg/dl (" + hypoTTDuration + " min)");
- }
- }
-
- 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));
- }
- int duration = editDuration.getValue().intValue();
- if (duration > 0) {
- actions.add(MainApp.gs(R.string.duration) + ": " + duration + MainApp.gs(R.string.shorthour));
- }
- if (carbs > 0) {
- actions.add(MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + "");
- }
- if (!carbsAfterConstraints.equals(carbs)) {
- actions.add("" + MainApp.gs(R.string.carbsconstraintapplied) + "");
- }
- final String notes = notesEdit.getText().toString();
- if (!notes.isEmpty()) {
- actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes);
- }
-
- final double finalActivityTT = activityTT;
- final int finalActivityTTDuration = activityTTDuration;
- final double finalEatigSoonTT = eatingSoonTT;
- final int finalEatingSoonTTDuration = eatingSoonTTDuration;
- final double finalHypoTT = hypoTT;
- final int finalHypoTTDuration = hypoTTDuration;
-
- final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
- builder.setTitle(MainApp.gs(R.string.confirmation));
- if (carbsAfterConstraints > 0 || startActivityTTCheckbox.isChecked()
- || startEatingSoonTTCheckbox.isChecked() || startHypoTTCheckbox.isChecked()) {
- builder.setMessage(Html.fromHtml(Joiner.on("
").join(actions)));
- builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
- synchronized (builder) {
- if (accepted) {
- log.debug("guarding: already accepted");
- return;
- }
- accepted = true;
-
- if (startActivityTTCheckbox.isChecked()) {
- TempTarget tempTarget = new TempTarget()
- .date(System.currentTimeMillis())
- .duration(finalActivityTTDuration)
- .reason(MainApp.gs(R.string.activity))
- .source(Source.USER)
- .low(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits()))
- .high(Profile.toMgdl(finalActivityTT, ProfileFunctions.getSystemUnits()));
- TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
- } else if (startEatingSoonTTCheckbox.isChecked()) {
- TempTarget tempTarget = new TempTarget()
- .date(System.currentTimeMillis())
- .duration(finalEatingSoonTTDuration)
- .reason(MainApp.gs(R.string.eatingsoon))
- .source(Source.USER)
- .low(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()))
- .high(Profile.toMgdl(finalEatigSoonTT, ProfileFunctions.getSystemUnits()));
- TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
- } else if (startHypoTTCheckbox.isChecked()) {
- TempTarget tempTarget = new TempTarget()
- .date(System.currentTimeMillis())
- .duration(finalHypoTTDuration)
- .reason(MainApp.gs(R.string.hypo))
- .source(Source.USER)
- .low(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits()))
- .high(Profile.toMgdl(finalHypoTT, ProfileFunctions.getSystemUnits()));
- TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
- }
-
- if (carbsAfterConstraints > 0) {
- if (duration == 0) {
- CarbsGenerator.createCarb(carbsAfterConstraints, time, CareportalEvent.CARBCORRECTION, notes);
- } else {
- CarbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes);
- NSUpload.uploadEvent(CareportalEvent.NOTE, now() - 2000, MainApp.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset));
- }
- }
- }
- });
- } else {
- builder.setMessage(MainApp.gs(R.string.no_action_selected));
- }
- builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
- builder.show();
- dismiss();
- } catch (Exception e) {
- log.error("Unhandled exception", e);
- }
- }
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/TempTargetDialog.kt
index 513a072174..79a3c396f6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/TempTargetDialog.kt
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/TempTargetDialog.kt
@@ -68,19 +68,18 @@ class TempTargetDialog : DialogFragmentWithDate() {
override fun onItemSelected(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
val defaultDuration: Double
val defaultTarget: Double
- val helper = DefaultValueHelper()
when (reasonList[position]) {
MainApp.gs(R.string.eatingsoon) -> {
- defaultDuration = helper.determineEatingSoonTTDuration().toDouble()
- defaultTarget = helper.determineEatingSoonTT()
+ defaultDuration = DefaultValueHelper.determineEatingSoonTTDuration().toDouble()
+ defaultTarget = DefaultValueHelper.determineEatingSoonTT()
}
MainApp.gs(R.string.activity) -> {
- defaultDuration = helper.determineActivityTTDuration().toDouble()
- defaultTarget = helper.determineActivityTT()
+ defaultDuration = DefaultValueHelper.determineActivityTTDuration().toDouble()
+ defaultTarget = DefaultValueHelper.determineActivityTT()
}
MainApp.gs(R.string.hypo) -> {
- defaultDuration = helper.determineHypoTTDuration().toDouble()
- defaultTarget = helper.determineHypoTT()
+ defaultDuration = DefaultValueHelper.determineHypoTTDuration().toDouble()
+ defaultTarget = DefaultValueHelper.determineHypoTT()
}
MainApp.gs(R.string.cancel) -> {
defaultDuration = 0.0
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java b/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java
deleted file mode 100644
index 7ea507e280..0000000000
--- a/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package info.nightscout.androidaps.utils;
-
-import info.nightscout.androidaps.Constants;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.data.Profile;
-import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
-
-public class DefaultValueHelper {
-
- /**
- * returns the corresponding EatingSoon TempTarget based on the given units (MMOL / MGDL)
- *
- * @param units
- * @return
- */
- public double getDefaultEatingSoonTT(String units) {
- return Constants.MMOL.equals(units) ? Constants.defaultEatingSoonTTmmol
- : Constants.defaultEatingSoonTTmgdl;
- }
-
- /**
- * returns the corresponding Activity TempTarget based on the given units (MMOL / MGDL)
- *
- * @param units
- * @return
- */
- public double getDefaultActivityTT(String units) {
- return Constants.MMOL.equals(units) ? Constants.defaultActivityTTmmol
- : Constants.defaultActivityTTmgdl;
- }
-
- /**
- * returns the corresponding Hypo TempTarget based on the given units (MMOL / MGDL)
- *
- * @param units
- * @return
- */
- public double getDefaultHypoTT(String units) {
- return Constants.MMOL.equals(units) ? Constants.defaultHypoTTmmol
- : Constants.defaultHypoTTmgdl;
- }
-
- /**
- * returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
- *
- * @return
- */
- public double determineEatingSoonTT() {
- String units = ProfileFunctions.getSystemUnits();
- double value = SP.getDouble(R.string.key_eatingsoon_target, this.getDefaultEatingSoonTT(units));
- value = Profile.toCurrentUnits(value);
- return value > 0 ? value : this.getDefaultEatingSoonTT(units);
- }
-
- public int determineEatingSoonTTDuration() {
- int value = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
- return value > 0 ? value : Constants.defaultEatingSoonTTDuration;
- }
-
-
- /**
- * returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
- *
- * @return
- */
- public double determineActivityTT() {
- String units = ProfileFunctions.getSystemUnits();
- double value = SP.getDouble(R.string.key_activity_target, this.getDefaultActivityTT(units));
- value = Profile.toCurrentUnits(value);
- return value > 0 ? value : this.getDefaultActivityTT(units);
- }
-
- public int determineActivityTTDuration() {
- int value = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration);
- return value > 0 ? value : Constants.defaultActivityTTDuration;
- }
-
- /**
- * returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
- *
- * @return
- */
- public double determineHypoTT() {
- String units = ProfileFunctions.getSystemUnits();
- double value = SP.getDouble(R.string.key_hypo_target, this.getDefaultHypoTT(units));
- value = Profile.toCurrentUnits(value);
- return value > 0 ? value : this.getDefaultHypoTT(units);
- }
-
- public int determineHypoTTDuration() {
- int value = SP.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration);
- return value > 0 ? value : Constants.defaultHypoTTDuration;
- }
-
-}
diff --git a/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.kt
new file mode 100644
index 0000000000..7b40d5d35b
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/utils/DefaultValueHelper.kt
@@ -0,0 +1,95 @@
+package info.nightscout.androidaps.utils
+
+import info.nightscout.androidaps.Constants
+import info.nightscout.androidaps.R
+import info.nightscout.androidaps.data.Profile
+import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
+
+object DefaultValueHelper {
+ /**
+ * returns the corresponding EatingSoon TempTarget based on the given units (MMOL / MGDL)
+ *
+ * @param units
+ * @return
+ */
+ fun getDefaultEatingSoonTT(units: String): Double {
+ return if (Constants.MMOL == units) Constants.defaultEatingSoonTTmmol else Constants.defaultEatingSoonTTmgdl
+ }
+
+ /**
+ * returns the corresponding Activity TempTarget based on the given units (MMOL / MGDL)
+ *
+ * @param units
+ * @return
+ */
+ fun getDefaultActivityTT(units: String): Double {
+ return if (Constants.MMOL == units) Constants.defaultActivityTTmmol else Constants.defaultActivityTTmgdl
+ }
+
+ /**
+ * returns the corresponding Hypo TempTarget based on the given units (MMOL / MGDL)
+ *
+ * @param units
+ * @return
+ */
+ fun getDefaultHypoTT(units: String): Double {
+ return if (Constants.MMOL == units) Constants.defaultHypoTTmmol else Constants.defaultHypoTTmgdl
+ }
+
+ /**
+ * returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
+ *
+ * @return
+ */
+ @JvmStatic
+ fun determineEatingSoonTT(): Double {
+ val units = ProfileFunctions.getSystemUnits()
+ var value = SP.getDouble(R.string.key_eatingsoon_target, getDefaultEatingSoonTT(units))
+ value = Profile.toCurrentUnits(value)
+ return if (value > 0) value else getDefaultEatingSoonTT(units)
+ }
+
+ @JvmStatic
+ fun determineEatingSoonTTDuration(): Int {
+ val value = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration)
+ return if (value > 0) value else Constants.defaultEatingSoonTTDuration
+ }
+
+ /**
+ * returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
+ *
+ * @return
+ */
+ @JvmStatic
+ fun determineActivityTT(): Double {
+ val units = ProfileFunctions.getSystemUnits()
+ var value = SP.getDouble(R.string.key_activity_target, getDefaultActivityTT(units))
+ value = Profile.toCurrentUnits(value)
+ return if (value > 0) value else getDefaultActivityTT(units)
+ }
+
+ @JvmStatic
+ fun determineActivityTTDuration(): Int {
+ val value = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration)
+ return if (value > 0) value else Constants.defaultActivityTTDuration
+ }
+
+ /**
+ * returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
+ *
+ * @return
+ */
+ @JvmStatic
+ fun determineHypoTT(): Double {
+ val units = ProfileFunctions.getSystemUnits()
+ var value = SP.getDouble(R.string.key_hypo_target, getDefaultHypoTT(units))
+ value = Profile.toCurrentUnits(value)
+ return if (value > 0) value else getDefaultHypoTT(units)
+ }
+
+ @JvmStatic
+ fun determineHypoTTDuration(): Int {
+ val value = SP.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration)
+ return if (value > 0) value else Constants.defaultHypoTTDuration
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/actions_care_dialog.xml b/app/src/main/res/layout/actions_care_dialog.xml
index ccc2b15812..28c05ee7b7 100644
--- a/app/src/main/res/layout/actions_care_dialog.xml
+++ b/app/src/main/res/layout/actions_care_dialog.xml
@@ -1,11 +1,13 @@
+ android:padding="10dp"
+ tools:context=".plugins.general.actions.dialogs.CareDialog">
+ android:padding="10dp"
+ tools:context=".plugins.general.actions.dialogs.ExtendedBolusDialog">
+ android:padding="10dp"
+ tools:context=".plugins.general.actions.dialogs.FillDialog">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/overview_newcarbs_dialog.xml b/app/src/main/res/layout/overview_newcarbs_dialog.xml
deleted file mode 100644
index 457e11c15d..0000000000
--- a/app/src/main/res/layout/overview_newcarbs_dialog.xml
+++ /dev/null
@@ -1,223 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/src/main/res/layout/overview_profileswitch_dialog.xml b/app/src/main/res/layout/overview_profileswitch_dialog.xml
index 153a08da01..2353f4ddfa 100644
--- a/app/src/main/res/layout/overview_profileswitch_dialog.xml
+++ b/app/src/main/res/layout/overview_profileswitch_dialog.xml
@@ -1,11 +1,13 @@
+ android:padding="10dp"
+ tools:context=".plugins.general.overview.dialogs.ProfileSwitchDialog">
+ android:contentDescription="@string/careportal_profileswitch"
+ android:src="@drawable/icon_actions_profileswitch" />
-
+
+ android:padding="10dp"
+ tools:context=".plugins.general.overview.dialogs.TempTargetDialog">