From 5503e330e24152fc798bcdd127646e20c155317b Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Thu, 14 Mar 2024 13:39:23 -0600 Subject: [PATCH] switch secondTranslation to secondLanguageAvailable --- .../org/cru/godtools/ui/tools/SquareToolCard.kt | 4 +--- .../kotlin/org/cru/godtools/ui/tools/ToolCard.kt | 2 +- .../org/cru/godtools/ui/tools/ToolCardPresenter.kt | 6 +++--- .../org/cru/godtools/ui/tools/ToolViewModels.kt | 2 +- .../org/cru/godtools/ui/tools/VariantToolCard.kt | 4 ++-- .../godtools/ui/tools/SquareToolCardPaparazziTest.kt | 3 +-- .../cru/godtools/ui/tools/ToolCardPresenterTest.kt | 12 ++++++------ .../org/cru/godtools/ui/tools/VariantToolCardTest.kt | 4 ++-- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/SquareToolCard.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/SquareToolCard.kt index a5c99f1278..840c278e5b 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/SquareToolCard.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/SquareToolCard.kt @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.width import androidx.compose.material3.ElevatedCard import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState -import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState @@ -156,8 +155,7 @@ fun SquareToolCard( @Composable private fun SquareToolCardSecondLanguage(state: ToolCard.State) = ToolCardInfoContent { - val secondTranslation by rememberUpdatedState(state.secondTranslation) - val available by remember { derivedStateOf { secondTranslation != null } } + val available by rememberUpdatedState(state.secondLanguageAvailable) AvailableInLanguage( state.secondLanguage, diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCard.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCard.kt index d6c15335a3..dc3da94159 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCard.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCard.kt @@ -18,7 +18,7 @@ object ToolCard { val appLanguage: Language? = null, val appTranslation: Translation? = null, val secondLanguage: Language? = null, - val secondTranslation: Translation? = null, + val secondLanguageAvailable: Boolean = false, val availableLanguages: Int = 0, val downloadProgress: DownloadProgress? = null, val eventSink: (Event) -> Unit = {}, diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardPresenter.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardPresenter.kt index ba56302a5a..f8315d2a55 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardPresenter.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolCardPresenter.kt @@ -94,9 +94,9 @@ class ToolCardPresenter @Inject constructor( appLanguage = if (loadAppLanguage) languagesRepository.rememberLanguage(appLocale) else null, appTranslation = appTranslation, secondLanguage = secondLanguage, - secondTranslation = when (secondLanguage?.code) { - translation.value?.languageCode -> null - else -> secondTranslation + secondLanguageAvailable = when (secondLanguage?.code) { + translation.value?.languageCode -> false + else -> secondTranslation != null }, availableLanguages = when { !loadAvailableLanguages -> 0 diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt index 0bf3d9134d..e712db170d 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/ToolViewModels.kt @@ -157,7 +157,7 @@ class ToolViewModels @Inject constructor( appLanguage = appLanguage.collectAsState().value, appTranslation = appTranslation.collectAsState().value.value, secondLanguage = secondLanguage, - secondTranslation = secondTranslation.collectAsState().value, + secondLanguageAvailable = secondTranslation.collectAsState().value != null, availableLanguages = availableLanguages.collectAsState().value.size, downloadProgress = downloadProgress.collectAsState().value, eventSink = eventSink, diff --git a/app/src/main/kotlin/org/cru/godtools/ui/tools/VariantToolCard.kt b/app/src/main/kotlin/org/cru/godtools/ui/tools/VariantToolCard.kt index fd41c8aa6e..4d2f1661ce 100644 --- a/app/src/main/kotlin/org/cru/godtools/ui/tools/VariantToolCard.kt +++ b/app/src/main/kotlin/org/cru/godtools/ui/tools/VariantToolCard.kt @@ -28,7 +28,7 @@ internal fun VariantToolCard(state: ToolCard.State, modifier: Modifier = Modifie val appLanguage by rememberUpdatedState(state.appLanguage) val appTranslation by rememberUpdatedState(state.appTranslation) val secondLanguage by rememberUpdatedState(state.secondLanguage) - val secondTranslation by rememberUpdatedState(state.secondTranslation) + val secondLanguageAvailable by rememberUpdatedState(state.secondLanguageAvailable) val languageCount by rememberUpdatedState(state.availableLanguages) val eventSink by rememberUpdatedState(state.eventSink) @@ -73,7 +73,7 @@ internal fun VariantToolCard(state: ToolCard.State, modifier: Modifier = Modifie if (secondLanguage != null) { // TODO: I believe we need to suppress the "Unavailable in" prefix for this phrase - AvailableInLanguage(secondLanguage, available = secondTranslation != null) + AvailableInLanguage(secondLanguage, available = secondLanguageAvailable) } } } diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/SquareToolCardPaparazziTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/SquareToolCardPaparazziTest.kt index 4fe0c90199..8ffdb5423f 100644 --- a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/SquareToolCardPaparazziTest.kt +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/SquareToolCardPaparazziTest.kt @@ -24,7 +24,6 @@ import org.cru.godtools.downloadmanager.DownloadProgress import org.cru.godtools.model.Language import org.cru.godtools.model.Tool import org.cru.godtools.model.randomTool -import org.cru.godtools.model.randomTranslation import org.junit.Rule class SquareToolCardPaparazziTest { @@ -38,7 +37,7 @@ class SquareToolCardPaparazziTest { ), banner = mockk(), secondLanguage = Language(Locale.FRENCH), - secondTranslation = randomTranslation() + secondLanguageAvailable = true, ) @BeforeTest diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/ToolCardPresenterTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/ToolCardPresenterTest.kt index bb8225048c..6a2e440d4f 100644 --- a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/ToolCardPresenterTest.kt +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/ToolCardPresenterTest.kt @@ -287,9 +287,9 @@ class ToolCardPresenterTest { } // endregion ToolCard.State.secondLanguage - // region ToolCard.State.secondTranslation + // region ToolCard.State.secondLanguageAvailable @Test - fun `ToolCardState - secondTranslation`() = runTest { + fun `ToolCardState - secondLanguageAvailable`() = runTest { toolFlow.value = randomTool(TOOL) val language = Language(Locale.FRENCH) val translation = randomTranslation(TOOL, Locale.FRENCH) @@ -298,12 +298,12 @@ class ToolCardPresenterTest { presentFunction = { presenter.present(tool = toolFlow.collectAsState().value, secondLanguage = language) } ) { frTranslationFlow.emit(translation) - assertEquals(translation, expectMostRecentItem().secondTranslation) + assertTrue(expectMostRecentItem().secondLanguageAvailable) } } @Test - fun `ToolCardState - secondTranslation - Doesn't match the language for the main translation`() = runTest { + fun `ToolCardState - secondLanguageAvailable - Doesn't match the language for the main translation`() = runTest { toolFlow.value = randomTool(TOOL) val translation = randomTranslation(TOOL, Locale.ENGLISH) @@ -318,12 +318,12 @@ class ToolCardPresenterTest { enTranslationFlow.emit(translation) assertNotNull(expectMostRecentItem()) { state -> - assertNull(state.secondTranslation) + assertFalse(state.secondLanguageAvailable) assertEquals(translation, state.translation) } } } - // endregion ToolCard.State.secondTranslation + // endregion ToolCard.State.secondLanguageAvailable // region ToolCard.State.availableLanguages @Test diff --git a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardTest.kt b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardTest.kt index 69ad1dbdac..01930bfa33 100644 --- a/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardTest.kt +++ b/app/src/testDebug/kotlin/org/cru/godtools/ui/tools/VariantToolCardTest.kt @@ -132,7 +132,7 @@ class VariantToolCardTest { appLanguage = Language(Locale.ENGLISH), appTranslation = null, secondLanguage = Language(Locale.FRENCH), - secondTranslation = randomTranslation(), + secondLanguageAvailable = true, ), ) } @@ -153,7 +153,7 @@ class VariantToolCardTest { appLanguage = Language(Locale.ENGLISH), appTranslation = randomTranslation(), secondLanguage = Language(Locale.FRENCH), - secondTranslation = null, + secondLanguageAvailable = false, ), ) }