From 19e8a7888c4d7d107d7549265a273f5dddc79116 Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Wed, 6 Mar 2024 14:42:00 +0100 Subject: [PATCH] Rename UiText.asString to resolve This better matches its purpose of resolving according to the given resolve args. --- .idea/ktfmt.xml | 6 ++++++ .../kotlin/de/sipgate/dachlatten/android/text/UiTextExt.kt | 2 +- .../kotlin/de/sipgate/dachlatten/android/text/UiTextTest.kt | 2 +- .../kotlin/de/sipgate/dachlatten/compose/text/UiTextExt.kt | 2 +- .../kotlin/de/sipgate/dachlatten/compose/text/UiTextTest.kt | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .idea/ktfmt.xml diff --git a/.idea/ktfmt.xml b/.idea/ktfmt.xml new file mode 100644 index 0000000..f0d6dab --- /dev/null +++ b/.idea/ktfmt.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/dachlatten-android/src/main/kotlin/de/sipgate/dachlatten/android/text/UiTextExt.kt b/dachlatten-android/src/main/kotlin/de/sipgate/dachlatten/android/text/UiTextExt.kt index 9752401..e056a49 100644 --- a/dachlatten-android/src/main/kotlin/de/sipgate/dachlatten/android/text/UiTextExt.kt +++ b/dachlatten-android/src/main/kotlin/de/sipgate/dachlatten/android/text/UiTextExt.kt @@ -7,7 +7,7 @@ import de.sipgate.dachlatten.text.TranslatedText import de.sipgate.dachlatten.text.UiText import java.util.Locale -fun UiText.asString(resources: Resources, fallbackLocale: Locale? = null) = when (this) { +fun UiText.resolve(resources: Resources, fallbackLocale: Locale? = null) = when (this) { is UiText.DynamicString -> value is UiText.StringResource -> resources.getString(resId, *(args.toTypedArray())) is UiText.MultiLangString -> { diff --git a/dachlatten-android/src/test/kotlin/de/sipgate/dachlatten/android/text/UiTextTest.kt b/dachlatten-android/src/test/kotlin/de/sipgate/dachlatten/android/text/UiTextTest.kt index 5b50e65..d25ab64 100644 --- a/dachlatten-android/src/test/kotlin/de/sipgate/dachlatten/android/text/UiTextTest.kt +++ b/dachlatten-android/src/test/kotlin/de/sipgate/dachlatten/android/text/UiTextTest.kt @@ -116,6 +116,6 @@ class UiTextTest { } private fun expectResolvedResourceString(expected: String, uiText: UiText, fallbackLocale: Locale? = null) { - assertEquals(expected, uiText.asString(context.resources, fallbackLocale)) + assertEquals(expected, uiText.resolve(context.resources, fallbackLocale)) } } diff --git a/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/text/UiTextExt.kt b/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/text/UiTextExt.kt index 8452b69..71e89ce 100644 --- a/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/text/UiTextExt.kt +++ b/dachlatten-compose/src/main/kotlin/de/sipgate/dachlatten/compose/text/UiTextExt.kt @@ -11,7 +11,7 @@ import de.sipgate.dachlatten.text.UiText import java.util.Locale @Composable -fun UiText.asString(fallbackLocale: Locale? = null) = when (this) { +fun UiText.resolve(fallbackLocale: Locale? = null) = when (this) { is UiText.DynamicString -> value is UiText.StringResource -> stringResource(id = resId, formatArgs = args.toTypedArray()) is UiText.MultiLangString -> { diff --git a/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/text/UiTextTest.kt b/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/text/UiTextTest.kt index ca636fb..f74edf2 100644 --- a/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/text/UiTextTest.kt +++ b/dachlatten-compose/src/test/kotlin/de/sipgate/dachlatten/compose/text/UiTextTest.kt @@ -45,7 +45,7 @@ class UiTextTest { assertThrows { composeTestRule.setContent { - uiText.asString() + uiText.resolve() } } } @@ -72,7 +72,7 @@ class UiTextTest { private fun expectResolvedComposeString(expected: String, uiText: UiText, fallbackLocale: Locale? = null) { composeTestRule.setContent { - val resolvedString = uiText.asString(fallbackLocale) + val resolvedString = uiText.resolve(fallbackLocale) /* * This is needed because the Strings we have packaged with Robolectric