From 2a03d1d7ca5970a483b401cac214d03f9da05069 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 3 Apr 2021 15:39:43 +0200 Subject: [PATCH] Remove presentation of StringResource with Param to avoid crash Move String used in uel.log to core --- .../automation/actions/ActionProfileSwitchPercent.kt | 3 +-- automation/src/main/res/values/strings.xml | 1 - .../androidaps/utils/UserEntryPresentationHelper.kt | 6 ++++-- core/src/main/res/values/strings.xml | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt index 71c9e8aef6..d18739524a 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionProfileSwitchPercent.kt @@ -43,8 +43,7 @@ class ActionProfileSwitchPercent(injector: HasAndroidInjector) : Action(injector override fun doAction(callback: Callback) { uel.log(UserEntry.Action.PROFILE_SWITCH, Sources.Automation, title, - if (duration.value == 0) XXXValueWithUnit.StringResource( R.string.startprofileforever, listOf(XXXValueWithUnit.Percent(pct.value.toInt()))) - else XXXValueWithUnit.StringResource( R.string.startprofile, listOf(XXXValueWithUnit.Percent(pct.value.toInt()), XXXValueWithUnit.Minute(duration.value)))) + XXXValueWithUnit.StringResource( R.string.startprofile, listOf(XXXValueWithUnit.Percent(pct.value.toInt()), XXXValueWithUnit.Minute(duration.value)))) activePlugin.activeTreatments.doProfileSwitch(duration.value, pct.value.toInt(), 0) callback.result(PumpEnactResult(injector).success(true).comment(R.string.ok))?.run() } diff --git a/automation/src/main/res/values/strings.xml b/automation/src/main/res/values/strings.xml index b8ee4c099a..2e23b54761 100644 --- a/automation/src/main/res/values/strings.xml +++ b/automation/src/main/res/values/strings.xml @@ -25,7 +25,6 @@ Already set Profile percentage Start profile %1$d%% - Start profile %1$d%% for %2$d min Percent [%]: Send SMS: %1$s Send SMS to all numbers diff --git a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt index d0ed1c8105..f51dd16fe0 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/UserEntryPresentationHelper.kt @@ -93,7 +93,8 @@ class UserEntryPresentationHelper @Inject constructor( is XXXValueWithUnit.UnitPerHour -> DecimalFormatter.to2Decimal(valueWithUnit.value) + translator.translate(UserEntry.Units.U_H) is XXXValueWithUnit.SimpleInt -> valueWithUnit.value.toString() is XXXValueWithUnit.SimpleString -> valueWithUnit.value - is XXXValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value /*, valueWithUnit.params.map { it.value() }*/) //Todo Fix StringResource with Param +// is XXXValueWithUnit.StringResource -> resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map{ it.value() }.toTypedArray()) //Todo Fix StringResource with Param + is XXXValueWithUnit.StringResource -> if (valueWithUnit.params.size > 0 ) valueWithUnit.params.joinToString(separator = " ") { value -> toPresentationString(value) } else resourceHelper.gs(valueWithUnit.value) //To help debugging is XXXValueWithUnit.TherapyEventMeterType -> translator.translate(valueWithUnit.value) is XXXValueWithUnit.TherapyEventTTReason -> translator.translate(valueWithUnit.value) is XXXValueWithUnit.TherapyEventType -> translator.translate(valueWithUnit.value) @@ -170,7 +171,8 @@ class UserEntryPresentationHelper @Inject constructor( is XXXValueWithUnit.UnitPerHour -> unitPerHour = DecimalFormatter.to2Decimal(valueWithUnit.value) is XXXValueWithUnit.SimpleInt -> other = if (other == "") valueWithUnit.value.toString() else other + " / " + valueWithUnit.value.toString() is XXXValueWithUnit.SimpleString -> other = if (other == "") valueWithUnit.value else other + " / " + valueWithUnit.value - is XXXValueWithUnit.StringResource -> stringResource = if (stringResource == "") resourceHelper.gs(valueWithUnit.value, valueWithUnit.params) else stringResource + " / " + resourceHelper.gs(valueWithUnit.value, valueWithUnit.params) +// is XXXValueWithUnit.StringResource -> stringResource = if (stringResource == "") resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map { it.value() }.toTypedArray()) else stringResource + " / " + resourceHelper.gs(valueWithUnit.value, valueWithUnit.params.map { it.value() }.toTypedArray()) + is XXXValueWithUnit.StringResource -> if (valueWithUnit.params.size == 0) { stringResource = if (stringResource == "") resourceHelper.gs(valueWithUnit.value) else stringResource + " / " + resourceHelper.gs(valueWithUnit.value)} is XXXValueWithUnit.TherapyEventMeterType -> therapyEvent = if (therapyEvent == "") translator.translate(valueWithUnit.value) else therapyEvent + " / " + translator.translate(valueWithUnit.value) is XXXValueWithUnit.TherapyEventTTReason -> therapyEvent = if (therapyEvent == "") translator.translate(valueWithUnit.value) else therapyEvent + " / " + translator.translate(valueWithUnit.value) is XXXValueWithUnit.TherapyEventType -> therapyEvent = if (therapyEvent == "") translator.translate(valueWithUnit.value) else therapyEvent + " / " + translator.translate(valueWithUnit.value) diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 9001f6f958..54a271834d 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -217,6 +217,7 @@ No profile selected + Start profile %1$d%% for %2$d min * Only discrete values no ranges are supported as granularity for basal/bolus in virtual pump.