From 9e9ae3cf914fd838a42e047f5fbb3a7b3084a4b0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 2 Jan 2020 00:40:03 +0100 Subject: [PATCH] Allow date in CarbsDialog --- .../nightscout/androidaps/dialogs/CarbsDialog.kt | 13 ++++++++----- app/src/main/res/layout/dialog_carbs.xml | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt index 4e0e2980e8..de457068c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -155,7 +155,7 @@ class CarbsDialog : DialogFragmentWithDate() { 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 + val time = eventTime + timeOffset * 1000 * 60 if (timeOffset != 0) actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(time)) val duration = overview_carbs_duration.value.toInt() @@ -170,12 +170,15 @@ class CarbsDialog : DialogFragmentWithDate() { if (notes.isNotEmpty()) actions.add(MainApp.gs(R.string.careportal_newnstreatment_notes_label) + ": " + notes) + if (eventTimeChanged) + actions.add(MainApp.gs(R.string.time) + ": " + DateUtil.dateAndTimeString(eventTime)) + if (carbsAfterConstraints > 0 || activitySelected || eatingSoonSelected || hypoSelected) { activity?.let { activity -> OKDialog.showConfirmation(activity, MainApp.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), Runnable { if (activitySelected) { val tempTarget = TempTarget() - .date(System.currentTimeMillis()) + .date(eventTime) .duration(activityTTDuration) .reason(MainApp.gs(R.string.activity)) .source(Source.USER) @@ -184,7 +187,7 @@ class CarbsDialog : DialogFragmentWithDate() { TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget) } else if (eatingSoonSelected) { val tempTarget = TempTarget() - .date(System.currentTimeMillis()) + .date(eventTime) .duration(eatingSoonTTDuration) .reason(MainApp.gs(R.string.eatingsoon)) .source(Source.USER) @@ -193,7 +196,7 @@ class CarbsDialog : DialogFragmentWithDate() { TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget) } else if (hypoSelected) { val tempTarget = TempTarget() - .date(System.currentTimeMillis()) + .date(eventTime) .duration(hypoTTDuration) .reason(MainApp.gs(R.string.hypo)) .source(Source.USER) @@ -206,7 +209,7 @@ class CarbsDialog : DialogFragmentWithDate() { 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)) + NSUpload.uploadEvent(CareportalEvent.NOTE, time - 2000, MainApp.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) } } }, null) diff --git a/app/src/main/res/layout/dialog_carbs.xml b/app/src/main/res/layout/dialog_carbs.xml index 9a95d19144..fdf83cff5b 100644 --- a/app/src/main/res/layout/dialog_carbs.xml +++ b/app/src/main/res/layout/dialog_carbs.xml @@ -204,6 +204,8 @@ + +