From f0c1274a613c9199ba6187a29397ecb7686f4520 Mon Sep 17 00:00:00 2001 From: Paul Woitaschek Date: Sun, 18 Jun 2023 08:44:34 +0200 Subject: [PATCH] Only show the review for supported languages. --- .../main/kotlin/voice/review/ReviewTranslated.kt | 15 +++++++++++++++ .../kotlin/voice/review/ShouldShowReviewDialog.kt | 4 +++- .../voice/review/ShouldShowReviewDialogTest.kt | 7 +++++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 review/src/main/kotlin/voice/review/ReviewTranslated.kt diff --git a/review/src/main/kotlin/voice/review/ReviewTranslated.kt b/review/src/main/kotlin/voice/review/ReviewTranslated.kt new file mode 100644 index 0000000000..9f61183fc3 --- /dev/null +++ b/review/src/main/kotlin/voice/review/ReviewTranslated.kt @@ -0,0 +1,15 @@ +package voice.review + +import android.content.Context +import javax.inject.Inject + +class ReviewTranslated +@Inject constructor( + private val context: Context, +) { + + fun translated(): Boolean { + val language = context.resources.configuration.locales[0].language.lowercase() + return language in listOf("en", "de") + } +} diff --git a/review/src/main/kotlin/voice/review/ShouldShowReviewDialog.kt b/review/src/main/kotlin/voice/review/ShouldShowReviewDialog.kt index 234e7960a7..32c13f2e1b 100644 --- a/review/src/main/kotlin/voice/review/ShouldShowReviewDialog.kt +++ b/review/src/main/kotlin/voice/review/ShouldShowReviewDialog.kt @@ -20,10 +20,12 @@ class ShouldShowReviewDialog private val reviewDialogShown: DataStore, private val bookRepository: BookRepository, private val playStateManager: PlayStateManager, + private val reviewTranslated: ReviewTranslated, ) { internal suspend fun shouldShow(): Boolean { - return isNotPlaying() && + return reviewTranslated.translated() && + isNotPlaying() && enoughTimeElapsedSinceInstallation() && reviewDialogNotShown() && listenedForEnoughTime() diff --git a/review/src/test/kotlin/voice/review/ShouldShowReviewDialogTest.kt b/review/src/test/kotlin/voice/review/ShouldShowReviewDialogTest.kt index dab2cd2b85..a464b0c107 100644 --- a/review/src/test/kotlin/voice/review/ShouldShowReviewDialogTest.kt +++ b/review/src/test/kotlin/voice/review/ShouldShowReviewDialogTest.kt @@ -99,10 +99,13 @@ class ShouldShowReviewDialogTest { reviewDialogShown = mockk { every { data } returns flowOf(reviewDialogShown) }, + reviewTranslated = mockk { + every { translated() } returns true + }, ) - val showsreviewDialog = runBlocking { + val showsReviewDialog = runBlocking { shouldShowReviewDialog.shouldShow() } - showsreviewDialog shouldBe expected + showsReviewDialog shouldBe expected } }