From de740c106c1862ca05e791dd4f0817239be11e4c Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Mon, 20 Nov 2023 13:06:39 -0700 Subject: [PATCH] remove unnecessary supported locales logic from the tutorial-renderer --- .../kotlin/org/cru/godtools/tutorial/Page.kt | 10 +------- .../org/cru/godtools/tutorial/PageSet.kt | 4 +--- .../tutorial/layout/TutorialLayout.kt | 2 +- .../TutorialFeaturesLayout+Preview.kt | 3 +-- .../TutorialOnboardingLayout+Preview.kt | 3 +-- .../org/cru/godtools/tutorial/PageSetTest.kt | 4 ---- .../org/cru/godtools/tutorial/PageTest.kt | 23 ------------------- 7 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageTest.kt diff --git a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/Page.kt b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/Page.kt index 94fb12aad7..c69276ef72 100644 --- a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/Page.kt +++ b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/Page.kt @@ -3,8 +3,6 @@ package org.cru.godtools.tutorial import androidx.annotation.DrawableRes import androidx.annotation.RawRes import androidx.annotation.StringRes -import java.util.Locale -import org.ccci.gto.android.common.util.includeFallbacks internal enum class Page( @StringRes val title: Int? = null, @@ -13,8 +11,6 @@ internal enum class Page( @StringRes val action: Int? = null, @RawRes val animation: Int? = null, @DrawableRes val image: Int? = null, - private val supportedLocales: Set = emptySet(), - private val disabledLocales: Set = emptySet(), val showIndicator: Boolean = true, val showMenu: Boolean = true ) { @@ -105,9 +101,5 @@ internal enum class Page( content = R.string.tutorial_tips_start_text, animation = R.raw.anim_tutorial_tips_light, showMenu = false - ); - - fun supportsLocale(locale: Locale) = - (supportedLocales.isEmpty() || sequenceOf(locale).includeFallbacks().any { it in supportedLocales }) && - (disabledLocales.isEmpty() || sequenceOf(locale).includeFallbacks().none { it in disabledLocales }) + ) } diff --git a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/PageSet.kt b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/PageSet.kt index 6c38be08f0..1a55206b4c 100644 --- a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/PageSet.kt +++ b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/PageSet.kt @@ -7,7 +7,7 @@ import org.cru.godtools.base.Settings enum class PageSet( internal val feature: String? = null, - private val pages: List, + internal val pages: List, private val supportedLocales: Set = emptySet(), internal val menu: List> = emptyList(), internal val showUpNavigation: Boolean = true, @@ -60,8 +60,6 @@ enum class PageSet( fun supportsLocale(locale: Locale?) = locale != null && sequenceOf(locale).includeFallbacks().any { supportedLocales.contains(it) } - internal fun pagesFor(locale: Locale) = pages.filter { it.supportsLocale(locale) } - companion object { val DEFAULT = ONBOARDING } diff --git a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/TutorialLayout.kt b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/TutorialLayout.kt index 887d75b43a..f71015ab32 100644 --- a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/TutorialLayout.kt +++ b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/TutorialLayout.kt @@ -42,7 +42,7 @@ import org.cru.godtools.tutorial.analytics.model.TutorialAnalyticsScreenEvent internal fun TutorialLayout(pageSet: PageSet, onTutorialAction: (Action) -> Unit = {}) { val coroutineScope = rememberCoroutineScope() val locale = LocalAppLanguage.current - val pages = remember(pageSet, locale) { pageSet.pagesFor(locale) } + val pages = pageSet.pages val pagerState = rememberPagerState { pages.size } val currentPage by remember { derivedStateOf { pages[pagerState.currentPage] } } diff --git a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/features/TutorialFeaturesLayout+Preview.kt b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/features/TutorialFeaturesLayout+Preview.kt index 0eb2895e3d..d292c15aa9 100644 --- a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/features/TutorialFeaturesLayout+Preview.kt +++ b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/features/TutorialFeaturesLayout+Preview.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview -import java.util.Locale import org.cru.godtools.tutorial.PageSet import org.cru.godtools.tutorial.layout.TutorialPageLayout @@ -16,7 +15,7 @@ import org.cru.godtools.tutorial.layout.TutorialPageLayout widthDp = 5 * 393 ) private fun FeaturesTutorialPreview() = Row { - PageSet.FEATURES.pagesFor(Locale.ENGLISH).forEach { + PageSet.FEATURES.pages.forEach { TutorialPageLayout(it, modifier = Modifier.weight(1f)) } } diff --git a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/onboarding/TutorialOnboardingLayout+Preview.kt b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/onboarding/TutorialOnboardingLayout+Preview.kt index 1ac6843ed3..0daa1a1635 100644 --- a/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/onboarding/TutorialOnboardingLayout+Preview.kt +++ b/ui/tutorial-renderer/src/main/kotlin/org/cru/godtools/tutorial/layout/onboarding/TutorialOnboardingLayout+Preview.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview -import java.util.Locale import org.cru.godtools.tutorial.PageSet import org.cru.godtools.tutorial.layout.TutorialPageLayout @@ -16,7 +15,7 @@ import org.cru.godtools.tutorial.layout.TutorialPageLayout widthDp = 4 * 393 ) private fun OnboardingTutorial() = Row { - PageSet.ONBOARDING.pagesFor(Locale.ENGLISH).forEach { + PageSet.ONBOARDING.pages.forEach { TutorialPageLayout(it, modifier = Modifier.weight(1f)) } } diff --git a/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageSetTest.kt b/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageSetTest.kt index 98fa65aa8b..05dda526f1 100644 --- a/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageSetTest.kt +++ b/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageSetTest.kt @@ -1,10 +1,6 @@ package org.cru.godtools.tutorial import java.util.Locale -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.allOf -import org.hamcrest.Matchers.hasItem -import org.hamcrest.Matchers.hasItems import org.hamcrest.Matchers.not import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue diff --git a/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageTest.kt b/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageTest.kt deleted file mode 100644 index 738e63d9f9..0000000000 --- a/ui/tutorial-renderer/src/test/kotlin/org/cru/godtools/tutorial/PageTest.kt +++ /dev/null @@ -1,23 +0,0 @@ -package org.cru.godtools.tutorial - -import java.util.Locale -import org.junit.Assert.assertTrue -import org.junit.Test - -class PageTest { - @Test - fun testSupportsLocaleOnboarding() { - with(Locale.ENGLISH) { - assertTrue(Page.ONBOARDING_WELCOME.supportsLocale(this)) - assertTrue(Page.ONBOARDING_SHARE.supportsLocale(this)) - } - with(Locale("en", "AU")) { - assertTrue(Page.ONBOARDING_WELCOME.supportsLocale(this)) - assertTrue(Page.ONBOARDING_SHARE.supportsLocale(this)) - } - with(Locale.GERMAN) { - assertTrue(Page.ONBOARDING_WELCOME.supportsLocale(this)) - assertTrue(Page.ONBOARDING_SHARE.supportsLocale(this)) - } - } -}