Cleanup mmol/mgdl handling in Dialogs
This commit is contained in:
parent
50eef089ea
commit
83da3447ac
|
@ -51,6 +51,7 @@ import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
|
import info.nightscout.utils.DefaultValueHelper;
|
||||||
import info.nightscout.utils.FabricPrivacy;
|
import info.nightscout.utils.FabricPrivacy;
|
||||||
import info.nightscout.utils.HardLimits;
|
import info.nightscout.utils.HardLimits;
|
||||||
import info.nightscout.utils.JsonHelper;
|
import info.nightscout.utils.JsonHelper;
|
||||||
|
@ -210,19 +211,22 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
boolean erase = false;
|
boolean erase = false;
|
||||||
|
|
||||||
|
String units = MainApp.getConfigBuilder().getProfileUnits();
|
||||||
|
DefaultValueHelper helper = new DefaultValueHelper();
|
||||||
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
|
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
|
||||||
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
defaultDuration = helper.determineEatingSoonTTDuration();
|
||||||
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);
|
defaultTarget = helper.determineEatingSoonTT(units);
|
||||||
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
|
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
|
||||||
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);
|
defaultDuration = helper.determineActivityTTDuration();
|
||||||
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);
|
defaultTarget = helper.determineActivityTT(units);
|
||||||
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
|
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
|
||||||
defaultDuration = SP.getDouble(R.string.key_hypo_duration, 0d);
|
defaultDuration = helper.determineHypoTTDuration();
|
||||||
defaultTarget = SP.getDouble(R.string.key_hypo_target, 0d);
|
defaultTarget = helper.determineHypoTT(units);
|
||||||
} else {
|
} else {
|
||||||
defaultDuration = 0;
|
defaultDuration = 0;
|
||||||
erase = true;
|
erase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultTarget != 0 || erase) {
|
if (defaultTarget != 0 || erase) {
|
||||||
editTemptarget.setValue(defaultTarget);
|
editTemptarget.setValue(defaultTarget);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
import info.nightscout.utils.DefaultValueHelper;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
|
@ -322,26 +323,25 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
|
||||||
if (currentProfile == null)
|
if (currentProfile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int activityTTDuration = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration);
|
final String units = currentProfile.getUnits();
|
||||||
activityTTDuration = activityTTDuration > 0 ? activityTTDuration : Constants.defaultActivityTTDuration;
|
DefaultValueHelper helper = new DefaultValueHelper();
|
||||||
double activityTT = SP.getDouble(R.string.key_activity_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl);
|
|
||||||
activityTT = activityTT > 0 ? activityTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl;
|
|
||||||
|
|
||||||
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
|
int activityTTDuration = helper.determineActivityTTDuration();
|
||||||
eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration;
|
double activityTT = helper.determineActivityTT(units);
|
||||||
double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl);
|
|
||||||
eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl;
|
|
||||||
|
|
||||||
int hypoTTDuration = SP.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration);
|
int eatingSoonTTDuration = helper.determineEatingSoonTTDuration();
|
||||||
hypoTTDuration = hypoTTDuration > 0 ? hypoTTDuration : Constants.defaultHypoTTDuration;
|
double eatingSoonTT = helper.determineEatingSoonTT(units);
|
||||||
double hypoTT = SP.getDouble(R.string.key_hypo_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultHypoTTmmol : Constants.defaultHypoTTmgdl);
|
|
||||||
hypoTT = hypoTT > 0 ? hypoTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultHypoTTmmol : Constants.defaultHypoTTmgdl;
|
int hypoTTDuration = helper.determineHypoTTDuration();
|
||||||
|
double hypoTT = helper.determineHypoTT(units);
|
||||||
|
|
||||||
if (startActivityTTCheckbox.isChecked()) {
|
if (startActivityTTCheckbox.isChecked()) {
|
||||||
|
String unitLabel = "mg/dl";
|
||||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " mmol/l (" + activityTTDuration + " min)</font>");
|
unitLabel = "mmol/l";
|
||||||
} else
|
}
|
||||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to0Decimal(activityTT) + " mg/dl (" + activityTTDuration + " min)</font>");
|
|
||||||
|
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)</font>");
|
||||||
|
|
||||||
}
|
}
|
||||||
if (startEatingSoonTTCheckbox.isChecked()) {
|
if (startEatingSoonTTCheckbox.isChecked()) {
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
package info.nightscout.utils;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param units
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double determineEatingSoonTT(String units) {
|
||||||
|
double value = SP.getDouble(R.string.key_eatingsoon_target, this.getDefaultEatingSoonTT(units));
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param units
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double determineActivityTT(String units) {
|
||||||
|
double value = SP.getDouble(R.string.key_activity_target, this.getDefaultActivityTT(units));
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param units
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double determineHypoTT(String units) {
|
||||||
|
double value = SP.getDouble(R.string.key_hypo_target, this.getDefaultHypoTT(units));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue