From d9aced595b5919b12e14616bc54b16c95bd6266b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 25 Mar 2021 03:23:28 +0100 Subject: [PATCH] make new ValueWithUnit translatable --- .../androidaps/dialogs/CarbsDialog.kt | 8 +- .../androidaps/dialogs/CareDialog.kt | 4 +- .../androidaps/dialogs/FillDialog.kt | 4 +- .../androidaps/dialogs/InsulinDialog.kt | 4 +- .../androidaps/dialogs/TempTargetDialog.kt | 8 +- .../androidaps/dialogs/TreatmentDialog.kt | 4 +- .../androidaps/plugins/aps/loop/LoopPlugin.kt | 2 +- .../nsclient/NSClientAddUpdateWorker.kt | 10 +- .../general/nsclient/NSClientRemoveWorker.kt | 4 +- .../general/wear/ActionStringHandler.kt | 2 +- .../plugins/treatments/CarbsGenerator.kt | 4 +- .../fragments/TreatmentsCareportalFragment.kt | 2 +- .../fragments/TreatmentsTempTargetFragment.kt | 2 +- .../androidaps/utils/wizard/BolusWizard.kt | 8 +- .../plugins/pump/combo/ComboPlugin.java | 2 +- .../androidaps/data/DetailedBolusInfo.java | 2 +- .../plugins/general/nsclient/NSUpload.java | 2 +- .../nightscout/androidaps/utils/Translator.kt | 34 +------ .../database/entities/XXXValueWithUnit.kt | 93 +++++++++++++++++-- .../pump/omnipod/eros/data/ActiveBolus.java | 3 +- 20 files changed, 125 insertions(+), 77 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 921402500d..c11400c7b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CarbsDialog.kt @@ -223,7 +223,7 @@ class CarbsDialog : DialogFragmentWithDate() { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.carbs), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { when { activitySelected -> { - uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.ACTIVITY.text), XXXValueWithUnit.fromGlucoseUnit(activityTT, units) , XXXValueWithUnit.Minute(activityTTDuration)) + uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY), XXXValueWithUnit.fromGlucoseUnit(activityTT, units) , XXXValueWithUnit.Minute(activityTTDuration)) disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( timestamp = System.currentTimeMillis(), duration = TimeUnit.MINUTES.toMillis(activityTTDuration.toLong()), @@ -239,7 +239,7 @@ class CarbsDialog : DialogFragmentWithDate() { } eatingSoonSelected -> { - uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units) , XXXValueWithUnit.Minute(eatingSoonTTDuration)) + uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units) , XXXValueWithUnit.Minute(eatingSoonTTDuration)) disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( timestamp = System.currentTimeMillis(), duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), @@ -255,7 +255,7 @@ class CarbsDialog : DialogFragmentWithDate() { } hypoSelected -> { - uel.log(Action.TT, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.HYPOGLYCEMIA.text), XXXValueWithUnit.fromGlucoseUnit(hypoTT, units) , XXXValueWithUnit.Minute(hypoTTDuration)) + uel.log(Action.TT, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA), XXXValueWithUnit.fromGlucoseUnit(hypoTT, units) , XXXValueWithUnit.Minute(hypoTTDuration)) disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( timestamp = System.currentTimeMillis(), duration = TimeUnit.MINUTES.toMillis(hypoTTDuration.toLong()), @@ -272,7 +272,7 @@ class CarbsDialog : DialogFragmentWithDate() { } if (carbsAfterConstraints > 0) { if (duration == 0) { - carbsGenerator.createCarb(carbsAfterConstraints, time, TherapyEvent.Type.CARBS_CORRECTION.text, notes) + carbsGenerator.createCarb(carbsAfterConstraints, time, TherapyEvent.Type.CARBS_CORRECTION, notes) } else { carbsGenerator.generateCarbs(carbsAfterConstraints, time, duration, notes) nsUpload.uploadEvent(TherapyEvent.Type.NOTE.text, DateUtil.now() - 2000, resourceHelper.gs(R.string.generated_ecarbs_note, carbsAfterConstraints, duration, timeOffset)) diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt index 3d3066789a..91cc6cf5e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/CareDialog.kt @@ -204,7 +204,7 @@ class CareDialog : DialogFragmentWithDate() { therapyEvent.glucoseType = meterType therapyEvent.glucose = binding.bg.value valuesWithUnit.add(XXXValueWithUnit.fromGlucoseUnit(binding.bg.value.toDouble(), profileFunction.getUnits())) - valuesWithUnit.add(XXXValueWithUnit.TherapyEvent(meterType.text)) + valuesWithUnit.add(XXXValueWithUnit.TherapyEventMeterType(meterType)) } if (options == EventType.NOTE || options == EventType.EXERCISE) { actions.add(resourceHelper.gs(R.string.careportal_newnstreatment_duration_label) + ": " + resourceHelper.gs(R.string.format_mins, binding.duration.value.toInt())) @@ -229,7 +229,7 @@ class CareDialog : DialogFragmentWithDate() { aapsLogger.error(LTag.BGSOURCE, "Error while saving therapy event", it) }) valuesWithUnit.add(0, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }) - valuesWithUnit.add(1, XXXValueWithUnit.TherapyEvent(therapyEvent.type.text)) + valuesWithUnit.add(1, XXXValueWithUnit.TherapyEventType(therapyEvent.type)) uel.log(Action.CAREPORTAL, notes, valuesWithUnit) }, null) } diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt index d7dd130926..63f1032ed3 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/FillDialog.kt @@ -141,7 +141,7 @@ class FillDialog : DialogFragmentWithDate() { requestPrimeBolus(insulinAfterConstraints, notes) } if (siteChange) { - uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEvent(TherapyEvent.Type.CANNULA_CHANGE.text)) + uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEventType(TherapyEvent.Type.CANNULA_CHANGE)) disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction( timestamp = eventTime, type = TherapyEvent.Type.CANNULA_CHANGE, @@ -155,7 +155,7 @@ class FillDialog : DialogFragmentWithDate() { } if (insulinChange) { // add a second for case of both checked - uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEvent(TherapyEvent.Type.INSULIN_CHANGE.text)) + uel.log(Action.CAREPORTAL, notes, XXXValueWithUnit.TherapyEventType(TherapyEvent.Type.INSULIN_CHANGE)) disposable += repository.runTransactionForResult(InsertTherapyEventIfNewTransaction( timestamp = eventTime + 1000, type = TherapyEvent.Type.INSULIN_CHANGE, diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt index 1a8291a732..12f771edb1 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/InsulinDialog.kt @@ -190,7 +190,7 @@ class InsulinDialog : DialogFragmentWithDate() { activity?.let { activity -> OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.bolus), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { if (eatingSoonChecked) { - uel.log(Action.TT, notes, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units), XXXValueWithUnit.Minute(eatingSoonTTDuration)) + uel.log(Action.TT, notes, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(eatingSoonTT, units), XXXValueWithUnit.Minute(eatingSoonTTDuration)) disposable += repository.runTransactionForResult(InsertTemporaryTargetAndCancelCurrentTransaction( timestamp = System.currentTimeMillis(), duration = TimeUnit.MINUTES.toMillis(eatingSoonTTDuration.toLong()), @@ -206,7 +206,7 @@ class InsulinDialog : DialogFragmentWithDate() { } if (insulinAfterConstraints > 0) { val detailedBolusInfo = DetailedBolusInfo() - detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text + detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS detailedBolusInfo.insulin = insulinAfterConstraints detailedBolusInfo.context = context detailedBolusInfo.source = Source.USER diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt index 0ec1282f59..67c7d7cfde 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TempTargetDialog.kt @@ -182,10 +182,10 @@ class TempTargetDialog : DialogFragmentWithDate() { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.careportal_temporarytarget), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { val units = profileFunction.getUnits() when(reason) { - resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.EATING_SOON.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) - resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.ACTIVITY.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) - resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.HYPOGLYCEMIA.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) - resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEvent(TemporaryTarget.Reason.CUSTOM.text), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) + resourceHelper.gs(R.string.eatingsoon) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.EATING_SOON), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) + resourceHelper.gs(R.string.activity) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.ACTIVITY), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) + resourceHelper.gs(R.string.hypo) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.HYPOGLYCEMIA), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) + resourceHelper.gs(R.string.manual) -> uel.log(Action.TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }, XXXValueWithUnit.TherapyEventTTReason(TemporaryTarget.Reason.CUSTOM), XXXValueWithUnit.fromGlucoseUnit(target, units), XXXValueWithUnit.Minute(duration)) resourceHelper.gs(R.string.stoptemptarget) -> uel.log(Action.CANCEL_TT, XXXValueWithUnit.Timestamp(eventTime).takeIf { eventTimeChanged }) } if (target == 0.0 || duration == 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt index 93c2b51d3f..9d79c8d9d3 100644 --- a/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt +++ b/app/src/main/java/info/nightscout/androidaps/dialogs/TreatmentDialog.kt @@ -133,8 +133,8 @@ class TreatmentDialog : DialogFragmentWithDate() { OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.overview_treatment_label), HtmlHelper.fromHtml(Joiner.on("
").join(actions)), { uel.log(Action.TREATMENT, XXXValueWithUnit.Insulin(insulin ).takeIf { insulin != 0.0 }, XXXValueWithUnit.Gram(carbs).takeIf { carbs != 0 }) val detailedBolusInfo = DetailedBolusInfo() - if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = TherapyEvent.Type.CARBS_CORRECTION.text - if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text + if (insulinAfterConstraints == 0.0) detailedBolusInfo.eventType = TherapyEvent.Type.CARBS_CORRECTION + if (carbsAfterConstraints == 0) detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS detailedBolusInfo.insulin = insulinAfterConstraints detailedBolusInfo.carbs = carbsAfterConstraints.toDouble() detailedBolusInfo.context = context diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt index 6abeea43b0..b80d78ef5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.kt @@ -596,7 +596,7 @@ open class LoopPlugin @Inject constructor( // deliver SMB val detailedBolusInfo = DetailedBolusInfo() detailedBolusInfo.lastKnownBolusTime = treatmentsPlugin.lastBolusTime - detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS.text + detailedBolusInfo.eventType = TherapyEvent.Type.CORRECTION_BOLUS detailedBolusInfo.insulin = request.smb detailedBolusInfo.isSMB = true detailedBolusInfo.source = Source.USER diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt index c6ac4f361b..09f6b27e2d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientAddUpdateWorker.kt @@ -87,7 +87,7 @@ class NSClientAddUpdateWorker( .also { result -> result.inserted.forEach { tt -> uel.log(UserEntry.Action.TT_FROM_NS, - XXXValueWithUnit.TherapyEvent(tt.reason.text), + XXXValueWithUnit.TherapyEventTTReason(tt.reason), XXXValueWithUnit.Mgdl(tt.lowTarget), XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, XXXValueWithUnit.Minute(tt.duration.toInt() / 60000) @@ -95,7 +95,7 @@ class NSClientAddUpdateWorker( } result.invalidated.forEach { tt -> uel.log(UserEntry.Action.TT_DELETED_FROM_NS, - XXXValueWithUnit.TherapyEvent(tt.reason.text), + XXXValueWithUnit.TherapyEventTTReason(tt.reason), XXXValueWithUnit.Mgdl(tt.lowTarget), XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, XXXValueWithUnit.Minute(tt.duration.toInt() / 60000) @@ -103,7 +103,7 @@ class NSClientAddUpdateWorker( } result.ended.forEach { tt -> uel.log(UserEntry.Action.TT_CANCELED_FROM_NS, - XXXValueWithUnit.TherapyEvent(tt.reason.text), + XXXValueWithUnit.TherapyEventTTReason(tt.reason), XXXValueWithUnit.Mgdl(tt.lowTarget), XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, XXXValueWithUnit.Minute(tt.duration.toInt() / 60000) @@ -134,14 +134,14 @@ class NSClientAddUpdateWorker( uel.log(UserEntry.Action.CAREPORTAL_FROM_NS, it.note ?: "", XXXValueWithUnit.Timestamp(it.timestamp), - XXXValueWithUnit.TherapyEvent(it.type.text) + XXXValueWithUnit.TherapyEventType(it.type) ) } result.invalidated.forEach { uel.log(UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, it.note ?: "", XXXValueWithUnit.Timestamp(it.timestamp), - XXXValueWithUnit.TherapyEvent(it.type.text) + XXXValueWithUnit.TherapyEventType(it.type) ) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt index fd7cdf1322..db6a6405ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSClientRemoveWorker.kt @@ -69,7 +69,7 @@ class NSClientRemoveWorker( result.invalidated.forEach { tt -> uel.log( UserEntry.Action.TT_DELETED_FROM_NS, - XXXValueWithUnit.TherapyEvent(tt.reason.text), + XXXValueWithUnit.TherapyEventTTReason(tt.reason), XXXValueWithUnit.Mgdl(tt.lowTarget), XXXValueWithUnit.Mgdl(tt.highTarget).takeIf { tt.lowTarget != tt.highTarget }, XXXValueWithUnit.Minute(tt.duration.toInt() / 60000).takeIf { tt.duration != 0L } @@ -90,7 +90,7 @@ class NSClientRemoveWorker( uel.log( UserEntry.Action.CAREPORTAL_DELETED_FROM_NS, (it.note ?: ""), XXXValueWithUnit.Timestamp(it.timestamp), - XXXValueWithUnit.TherapyEvent(it.type.text)) + XXXValueWithUnit.TherapyEventType(it.type)) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt index 8216e093fc..9e672abbb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.kt @@ -545,7 +545,7 @@ class ActionStringHandler @Inject constructor( private fun doECarbs(carbs: Int, time: Long, duration: Int) { if (carbs > 0) { if (duration == 0) { - carbsGenerator.createCarb(carbs, time, TherapyEvent.Type.CARBS_CORRECTION.text, "watch") + carbsGenerator.createCarb(carbs, time, TherapyEvent.Type.CARBS_CORRECTION, "watch") } else { carbsGenerator.generateCarbs(carbs, time, duration, "watch eCarbs") } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt index 7f9dbc94c3..adc64bdfe1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/CarbsGenerator.kt @@ -31,11 +31,11 @@ class CarbsGenerator @Inject constructor( val carbTime = startTime + i * 15 * 60 * 1000 val smallCarbAmount = (1.0 * remainingCarbs / (ticks - i)).roundToInt() //on last iteration (ticks-i) is 1 -> smallCarbAmount == remainingCarbs remainingCarbs -= smallCarbAmount.toLong() - if (smallCarbAmount > 0) createCarb(smallCarbAmount, carbTime, TherapyEvent.Type.MEAL_BOLUS.text, notes) + if (smallCarbAmount > 0) createCarb(smallCarbAmount, carbTime, TherapyEvent.Type.MEAL_BOLUS, notes) } } - fun createCarb(carbs: Int, time: Long, eventType: String, notes: String) { + fun createCarb(carbs: Int, time: Long, eventType: TherapyEvent.Type, notes: String) { val carbInfo = DetailedBolusInfo() carbInfo.date = time carbInfo.eventType = eventType diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt index 268faa39b3..dd497a61d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsCareportalFragment.kt @@ -197,7 +197,7 @@ class TreatmentsCareportalFragment : DaggerFragment() { resourceHelper.gs(R.string.notes_label) + ": " + (therapyEvent.note ?: "") + "\n" + resourceHelper.gs(R.string.date) + ": " + dateUtil.dateAndTimeString(therapyEvent.timestamp) OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.removerecord), text, Runnable { - uel.log(Action.CAREPORTAL_REMOVED, therapyEvent.note , XXXValueWithUnit.Timestamp(therapyEvent.timestamp), XXXValueWithUnit.TherapyEvent(therapyEvent.type.text)) + uel.log(Action.CAREPORTAL_REMOVED, therapyEvent.note , XXXValueWithUnit.Timestamp(therapyEvent.timestamp), XXXValueWithUnit.TherapyEventType(therapyEvent.type)) disposable += repository.runTransactionForResult(InvalidateTherapyEventTransaction(therapyEvent.id)) .subscribe({ val id = therapyEvent.interfaceIDs.nightscoutId diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt index 77a0a7dbf2..c481cde64c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/fragments/TreatmentsTempTargetFragment.kt @@ -197,7 +197,7 @@ class TreatmentsTempTargetFragment : DaggerFragment() { ${dateUtil.dateAndTimeString(tempTarget.timestamp)} """.trimIndent(), { _: DialogInterface?, _: Int -> - uel.log(Action.TT_REMOVED, XXXValueWithUnit.Timestamp(tempTarget.timestamp), XXXValueWithUnit.TherapyEvent(tempTarget.reason.text), XXXValueWithUnit.Mgdl(tempTarget.lowTarget), XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget }, XXXValueWithUnit.Minute(tempTarget.duration.toInt())) + uel.log(Action.TT_REMOVED, XXXValueWithUnit.Timestamp(tempTarget.timestamp), XXXValueWithUnit.TherapyEventTTReason(tempTarget.reason), XXXValueWithUnit.Mgdl(tempTarget.lowTarget), XXXValueWithUnit.Mgdl(tempTarget.highTarget).takeIf { tempTarget.lowTarget != tempTarget.highTarget }, XXXValueWithUnit.Minute(tempTarget.duration.toInt())) disposable += repository.runTransactionForResult(InvalidateTemporaryTargetTransaction(tempTarget.id)) .subscribe({ val id = tempTarget.interfaceIDs.nightscoutId diff --git a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt index 9b7465e896..ad9fed31aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/wizard/BolusWizard.kt @@ -340,7 +340,7 @@ class BolusWizard @Inject constructor( val confirmMessage = confirmMessageAfterConstraints(advisor = true) OKDialog.showConfirmation(ctx, resourceHelper.gs(R.string.boluswizard), confirmMessage, { DetailedBolusInfo().apply { - eventType = TherapyEvent.Type.CORRECTION_BOLUS.text + eventType = TherapyEvent.Type.CORRECTION_BOLUS insulin = insulinAfterConstraints carbs = 0.0 context = ctx @@ -350,7 +350,7 @@ class BolusWizard @Inject constructor( boluscalc = nsJSON() source = Source.USER notes = this@BolusWizard.notes - uel.log(Action.BOLUS_ADVISOR, notes, XXXValueWithUnit.TherapyEvent(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints)) + uel.log(Action.BOLUS_ADVISOR, notes, XXXValueWithUnit.TherapyEventType(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints)) if (insulin > 0) { commandQueue.bolus(this, object : Callback() { override fun run() { @@ -404,7 +404,7 @@ class BolusWizard @Inject constructor( } } DetailedBolusInfo().apply { - eventType = TherapyEvent.Type.BOLUS_WIZARD.text + eventType = TherapyEvent.Type.BOLUS_WIZARD insulin = insulinAfterConstraints carbs = this@BolusWizard.carbs.toDouble() context = ctx @@ -414,7 +414,7 @@ class BolusWizard @Inject constructor( boluscalc = nsJSON() source = Source.USER notes = this@BolusWizard.notes - uel.log(Action.BOLUS, notes, XXXValueWithUnit.TherapyEvent(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints), XXXValueWithUnit.Gram(this@BolusWizard.carbs).takeIf { this@BolusWizard.carbs != 0 }, XXXValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 }) + uel.log(Action.BOLUS, notes, XXXValueWithUnit.TherapyEventType(eventType), XXXValueWithUnit.Insulin(insulinAfterConstraints), XXXValueWithUnit.Gram(this@BolusWizard.carbs).takeIf { this@BolusWizard.carbs != 0 }, XXXValueWithUnit.Minute(carbTime).takeIf { carbTime != 0 }) if (insulin > 0 || pump.pumpDescription.storesCarbInfo) { commandQueue.bolus(this, object : Callback() { override fun run() { diff --git a/combo/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/combo/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index 8c9f0864ac..7d2d927835 100644 --- a/combo/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/combo/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -1158,7 +1158,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr dbi.pumpId = dbi.date; dbi.source = Source.PUMP; dbi.insulin = pumpBolus.amount; - dbi.eventType = TherapyEvent.Type.CORRECTION_BOLUS.getText(); + dbi.eventType = TherapyEvent.Type.CORRECTION_BOLUS; if (treatmentsPlugin.addToHistoryTreatment(dbi, true)) { updated = true; } diff --git a/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java b/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java index b544f9b284..cddf4c1a55 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java +++ b/core/src/main/java/info/nightscout/androidaps/data/DetailedBolusInfo.java @@ -16,7 +16,7 @@ import info.nightscout.androidaps.db.Source; public class DetailedBolusInfo { public long date = System.currentTimeMillis(); public long lastKnownBolusTime; - public String eventType = TherapyEvent.Type.MEAL_BOLUS.getText(); + public TherapyEvent.Type eventType = TherapyEvent.Type.MEAL_BOLUS; public double insulin = 0; public double carbs = 0; public int source = Source.NONE; diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java b/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java index 78887a73b9..d21961aca4 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/NSUpload.java @@ -248,7 +248,7 @@ public class NSUpload { public void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) { JSONObject data = new JSONObject(); try { - data.put("eventType", detailedBolusInfo.eventType); + data.put("eventType", detailedBolusInfo.eventType.getText()); if (detailedBolusInfo.insulin != 0d) data.put("insulin", detailedBolusInfo.insulin); if (detailedBolusInfo.carbs != 0d) data.put("carbs", (int) detailedBolusInfo.carbs); data.put("created_at", DateUtil.toISOString(detailedBolusInfo.date)); diff --git a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt index a53d892724..a87f4701e3 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt @@ -14,39 +14,7 @@ class Translator @Inject internal constructor( ) { @Deprecated("use type instead of string") - fun translate(text: String): String = - when (text) { - TherapyEvent.Type.FINGER_STICK_BG_VALUE.text -> resourceHelper.gs(R.string.careportal_bgcheck) - TherapyEvent.Type.SNACK_BOLUS.text -> resourceHelper.gs(R.string.careportal_snackbolus) - TherapyEvent.Type.MEAL_BOLUS.text -> resourceHelper.gs(R.string.careportal_mealbolus) - TherapyEvent.Type.CORRECTION_BOLUS.text -> resourceHelper.gs(R.string.careportal_correctionbolus) - TherapyEvent.Type.CARBS_CORRECTION.text -> resourceHelper.gs(R.string.careportal_carbscorrection) - TherapyEvent.Type.BOLUS_WIZARD.text -> resourceHelper.gs(R.string.boluswizard) - TherapyEvent.Type.COMBO_BOLUS.text -> resourceHelper.gs(R.string.careportal_combobolus) - TherapyEvent.Type.ANNOUNCEMENT.text -> resourceHelper.gs(R.string.careportal_announcement) - TherapyEvent.Type.NOTE.text -> resourceHelper.gs(R.string.careportal_note) - TherapyEvent.Type.QUESTION.text -> resourceHelper.gs(R.string.careportal_question) - TherapyEvent.Type.EXERCISE.text -> resourceHelper.gs(R.string.careportal_exercise) - TherapyEvent.Type.CANNULA_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpsitechange) - TherapyEvent.Type.PUMP_BATTERY_CHANGE.text -> resourceHelper.gs(R.string.careportal_pumpbatterychange) - TherapyEvent.Type.SENSOR_STARTED.text -> resourceHelper.gs(R.string.careportal_cgmsensorstart) - TherapyEvent.Type.SENSOR_STOPPED.text -> resourceHelper.gs(R.string.careportal_cgm_sensor_stop) - TherapyEvent.Type.SENSOR_CHANGE.text -> resourceHelper.gs(R.string.careportal_cgmsensorinsert) - TherapyEvent.Type.INSULIN_CHANGE.text -> resourceHelper.gs(R.string.careportal_insulincartridgechange) - TherapyEvent.Type.DAD_ALERT.text -> resourceHelper.gs(R.string.careportal_dad_alert) - TherapyEvent.Type.TEMPORARY_BASAL_START.text -> resourceHelper.gs(R.string.careportal_tempbasalstart) - TherapyEvent.Type.TEMPORARY_BASAL_END.text -> resourceHelper.gs(R.string.careportal_tempbasalend) - TherapyEvent.Type.PROFILE_SWITCH.text -> resourceHelper.gs(R.string.careportal_profileswitch) - TherapyEvent.Type.TEMPORARY_TARGET.text -> resourceHelper.gs(R.string.careportal_temporarytarget) - TherapyEvent.Type.TEMPORARY_TARGET_CANCEL.text -> resourceHelper.gs(R.string.careportal_temporarytargetcancel) - TherapyEvent.Type.APS_OFFLINE.text -> resourceHelper.gs(R.string.careportal_openapsoffline) - TherapyEvent.Type.NS_MBG.text -> resourceHelper.gs(R.string.careportal_mbg) - TherapyEvent.MeterType.FINGER.text -> resourceHelper.gs(R.string.glucosetype_finger) - TherapyEvent.MeterType.SENSOR.text -> resourceHelper.gs(R.string.glucosetype_sensor) - TherapyEvent.MeterType.MANUAL.text -> resourceHelper.gs(R.string.manual) - - else -> resourceHelper.gs(R.string.unknown) - } + fun translate(text: String): String = "" fun translate(action: Action): String = when(action) { Action.BOLUS -> resourceHelper.gs(R.string.uel_bolus) diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/XXXValueWithUnit.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/XXXValueWithUnit.kt index a9a6f53c38..477c940cb1 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/XXXValueWithUnit.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/XXXValueWithUnit.kt @@ -28,17 +28,13 @@ sealed class XXXValueWithUnit { class Percent(val value: Int) : XXXValueWithUnit() - class TherapyEvent(val value: String) : XXXValueWithUnit() + class TherapyEventType(val value: TherapyEvent.Type) : XXXValueWithUnit() - class TherapyEventType(val value: info.nightscout.androidaps.database.entities.TherapyEvent.Type) : XXXValueWithUnit() - - class TherapyEventMeterType(val value: info.nightscout.androidaps.database.entities.TherapyEvent.MeterType) : XXXValueWithUnit() + class TherapyEventMeterType(val value: TherapyEvent.MeterType) : XXXValueWithUnit() class TherapyEventTTReason(val value: TemporaryTarget.Reason) : XXXValueWithUnit() - - - class StringResource(@StringRes val value: Int, val params : List = listOf()) : XXXValueWithUnit() + class StringResource(@StringRes val value: Int, val params: List = listOf()) : XXXValueWithUnit() companion object { @@ -50,10 +46,93 @@ sealed class XXXValueWithUnit { } } +fun List.toPresentationString(translator: Translator) = concat + +// TODO Move to destination module, then uncomment +fun XXXValueWithUnit.toPresentationString(translator: Translator) : String = when(this){ + is XXXValueWithUnit.Gram -> "$value ${translator.translate(UserEntry.Units.G)}" + is XXXValueWithUnit.Hour -> "$value ${translator.translate(UserEntry.Units.H)}" + is XXXValueWithUnit.Minute -> "$value ${translator.translate(UserEntry.Units.G)}" + is XXXValueWithUnit.Percent -> "$value ${translator.translate(UserEntry.Units.Percent)}" + is XXXValueWithUnit.Insulin -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U) + is XXXValueWithUnit.UnitPerHour -> "" // DecimalFormatter.to2Decimal(value) + translator.translate(UserEntry.Units.U_H) + is XXXValueWithUnit.SimpleInt -> value.toString() + is XXXValueWithUnit.SimpleString -> value + is XXXValueWithUnit.StringResource -> "" //resourceHelper.gs(value, params.map { it.toPresentationString(translator) }) // recursively resolve params + is XXXValueWithUnit.TherapyEventMeterType -> translator.translate(value) + is XXXValueWithUnit.TherapyEventTTReason -> translator.translate(value) + is XXXValueWithUnit.TherapyEventType -> translator.translate(value) + is XXXValueWithUnit.Timestamp -> "" // TODO dateUtil.dateAndTimeAndSecondsString(value) + is XXXValueWithUnit.Mgdl -> { + // if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mg_Dl) + // else DecimalFormatter.to1Decimal(value/Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mmol_L) + "" + } + + is XXXValueWithUnit.Mmoll -> { + // if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(value) + translator.translate(UserEntry.Units.Mmol_L) + // else DecimalFormatter.to1Decimal(value * Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mg_Dl) + "" + } + + XXXValueWithUnit.UNKNOWN -> "" +} + + + /*** * Idea: Leverage sealed classes for units * Advantage: it is clear what type of data a Unit contains. Still we are exhaustive on when * * The condition "condition" that is used to check if an item should be logged can be replaced by .takeIf { condition }. * The value then would not have to be handled but the logging could simply discard null value. + * + * [x] new sealed classes + * [x] use entry type directly, not String + * [ ] database + * [ ] generate presentation string + * [ ] update fragment + * [ ] generate csv + * */ + +// just do develop here +interface Translator { + + fun translate(action: UserEntry.Action): String + fun translate(units: UserEntry.Units): String + fun translate(meterType: TherapyEvent.MeterType): String + fun translate(type: TherapyEvent.Type): String + fun translate(reason: TemporaryTarget.Reason): String +} + +/* +var valuesWithUnitString = "" +var rStringParam = 0 +val separator = " " +for(v in current.values) { + if (rStringParam >0) + rStringParam-- + else + when (v.unit) { + UserEntry.Units.Timestamp -> valuesWithUnitString += dateUtil.dateAndTimeAndSecondsString(v.lValue) + separator + UserEntry.Units.TherapyEvent -> valuesWithUnitString += translator.translate(v.sValue) + separator + UserEntry.Units.R_String -> { + rStringParam = v.lValue.toInt() + when (rStringParam) { // + 0 -> valuesWithUnitString += resourceHelper.gs(v.iValue) + separator + 1 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value()) + separator + 2 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value()) + separator + 3 -> valuesWithUnitString += resourceHelper.gs(v.iValue, current.values[current.values.indexOf(v)+1].value(), current.values[current.values.indexOf(v)+2].value(), current.values[current.values.indexOf(v)+3].value()) + separator + 4 -> rStringParam = 0 + } + } + UserEntry.Units.Mg_Dl -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue) + translator.translate(UserEntry.Units.Mg_Dl) + separator else DecimalFormatter.to1Decimal(v.dValue/Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mmol_L) + separator + UserEntry.Units.Mmol_L -> valuesWithUnitString += if (profileFunction.getUnits()==Constants.MGDL) DecimalFormatter.to0Decimal(v.dValue*Constants.MMOLL_TO_MGDL) + translator.translate(UserEntry.Units.Mg_Dl) + separator else DecimalFormatter.to1Decimal(v.dValue) + translator.translate(UserEntry.Units.Mmol_L) + separator + UserEntry.Units.U_H, UserEntry.Units.U + -> valuesWithUnitString += DecimalFormatter.to2Decimal(v.dValue) + translator.translate(v.unit) + separator + UserEntry.Units.G, UserEntry.Units.M, UserEntry.Units.H, UserEntry.Units.Percent + -> valuesWithUnitString += v.iValue.toString() + translator.translate(v.unit) + separator + else -> valuesWithUnitString += if (v.iValue != 0 || v.sValue != "") { v.value().toString() + separator } else "" + } +}*/ diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/data/ActiveBolus.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/data/ActiveBolus.java index 171685878b..ae7a2b830b 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/data/ActiveBolus.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/data/ActiveBolus.java @@ -5,6 +5,7 @@ import org.json.JSONException; import org.json.JSONObject; import info.nightscout.androidaps.data.DetailedBolusInfo; +import info.nightscout.androidaps.database.entities.TherapyEvent; import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.LTag; @@ -16,7 +17,7 @@ import info.nightscout.androidaps.logging.LTag; public class ActiveBolus { private long date; private long lastKnownBolusTime; - private String eventType; + private TherapyEvent.Type eventType; private double insulin; private double carbs; private int source;