Skip to content

Commit

Permalink
remove unnecessary supported locales logic from the tutorial-renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Nov 20, 2023
1 parent a126a92 commit de740c1
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Locale> = emptySet(),
private val disabledLocales: Set<Locale> = emptySet(),
val showIndicator: Boolean = true,
val showMenu: Boolean = true
) {
Expand Down Expand Up @@ -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 })
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.cru.godtools.base.Settings

enum class PageSet(
internal val feature: String? = null,
private val pages: List<Page>,
internal val pages: List<Page>,
private val supportedLocales: Set<Locale> = emptySet(),
internal val menu: List<Pair<AppBarAction, Action>> = emptyList(),
internal val showUpNavigation: Boolean = true,
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down

This file was deleted.

0 comments on commit de740c1

Please sign in to comment.