This commit is contained in:
Milos Kozak 2018-04-12 10:32:52 +02:00
parent 5eee8054c4
commit 0a377eb98e

View file

@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
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.NSUpload; import info.nightscout.utils.NSUpload;
import info.nightscout.utils.NumberPicker; import info.nightscout.utils.NumberPicker;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -694,24 +695,24 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
} }
} }
} else if (options.executeTempTarget) { } else if (options.executeTempTarget) {
try { final int duration = JsonHelper.safeGetInt(data, "duration");
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) { final double targetBottom = JsonHelper.safeGetDouble(data, "targetBottom");
TempTarget tempTarget = new TempTarget() final double targetTop = JsonHelper.safeGetDouble(data, "targetTop");
.date(eventTime.getTime()) final String reason = JsonHelper.safeGetString(data, "reason", "");
.duration(data.getInt("duration")) if ((targetBottom != 0d && targetTop != 0d) || duration == 0) {
.reason(data.getString("reason")) TempTarget tempTarget = new TempTarget()
.source(Source.USER); .date(eventTime.getTime())
if (tempTarget.durationInMinutes != 0) { .duration(duration)
tempTarget.low(Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits())) .reason(reason)
.high(Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits())); .source(Source.USER);
} else { if (tempTarget.durationInMinutes != 0) {
tempTarget.low(0).high(0); tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits()))
} .high(Profile.toMgdl(targetTop, profile.getUnits()));
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget); } else {
FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget")); tempTarget.low(0).high(0);
} }
} catch (JSONException e) { TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
log.error("Unhandled exception", e); FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget"));
} }
} else { } else {
NSUpload.uploadCareportalEntryToNS(data); NSUpload.uploadCareportalEntryToNS(data);