tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 01070bea7966a232f59a9af0d862df4b158f4ea5
parent 1d293fda8b4d2e823ff345f28a4c29c20918946e
Author: t-p-white <towhite@mozilla.com>
Date:   Wed, 10 Dec 2025 22:29:00 +0000

Bug 2005178 - Renamed ShowPlayStoreReviewPrompt to ShowReviewPromptBinding r=android-reviewers,marcin

Differential Revision: https://phabricator.services.mozilla.com/D275768

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt | 8++++----
Dmobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPrompt.kt | 64----------------------------------------------------------------
Amobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowReviewPromptBinding.kt | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmobile/android/fenix/app/src/test/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPromptTest.kt | 8++++----
4 files changed, 72 insertions(+), 72 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -154,7 +154,7 @@ import org.mozilla.fenix.pbmlock.NavigationOrigin import org.mozilla.fenix.pbmlock.observePrivateModeLock import org.mozilla.fenix.perf.MarkersFragmentLifecycleCallbacks import org.mozilla.fenix.perf.StartupTimeline -import org.mozilla.fenix.reviewprompt.ShowPlayStoreReviewPrompt +import org.mozilla.fenix.reviewprompt.ShowReviewPromptBinding import org.mozilla.fenix.search.SearchDialogFragment import org.mozilla.fenix.search.awesomebar.AwesomeBarComposable import org.mozilla.fenix.search.toolbar.DefaultSearchSelectorController @@ -267,7 +267,7 @@ class HomeFragment : Fragment() { registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> voiceSearchFeature?.get()?.handleVoiceSearchResult(result.resultCode, result.data) } - private val showPlayStoreReviewPrompt = ViewBoundFeatureWrapper<ShowPlayStoreReviewPrompt>() + private val showReviewPromptBinding = ViewBoundFeatureWrapper<ShowReviewPromptBinding>() override fun onCreate(savedInstanceState: Bundle?) { // DO NOT ADD ANYTHING ABOVE THIS getProfilerTime CALL! @@ -956,8 +956,8 @@ class HomeFragment : Fragment() { view = view, ) - showPlayStoreReviewPrompt.set( - feature = ShowPlayStoreReviewPrompt( + showReviewPromptBinding.set( + feature = ShowReviewPromptBinding( appStore = requireComponents.appStore, promptController = requireComponents.playStoreReviewPromptController, activityRef = WeakReference(activity), diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPrompt.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPrompt.kt @@ -1,64 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.fenix.reviewprompt - -import android.app.Activity -import androidx.navigation.NavDirections -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.launch -import mozilla.components.lib.state.helpers.AbstractBinding -import org.mozilla.fenix.NavGraphDirections -import org.mozilla.fenix.components.AppStore -import org.mozilla.fenix.components.PlayStoreReviewPromptController -import org.mozilla.fenix.components.appstate.AppAction -import org.mozilla.fenix.components.appstate.AppState -import org.mozilla.fenix.reviewprompt.ReviewPromptState.Eligible.Type -import java.lang.ref.WeakReference - -/** - * A feature that shows either the Google Play Review Prompt or the built-in review prompt based - * on the eligibility. - */ -class ShowPlayStoreReviewPrompt( - private val appStore: AppStore, - private val promptController: PlayStoreReviewPromptController, - private val activityRef: WeakReference<Activity>, - private val uiScope: CoroutineScope, - private val navigationDirection: (NavDirections) -> Unit, - mainDispatcher: CoroutineDispatcher = Dispatchers.Main, -) : AbstractBinding<AppState>(appStore, mainDispatcher) { - - override suspend fun onState(flow: Flow<AppState>) { - flow.map { it.reviewPrompt } - .distinctUntilChanged() - .collect { - when (it) { - ReviewPromptState.Unknown, ReviewPromptState.NotEligible -> {} - - is ReviewPromptState.Eligible -> { - when (it.type) { - Type.PlayStore -> tryShowPlayStorePrompt() - Type.Custom -> navigationDirection.invoke(CUSTOM_PROMPT_DIRECTION) - } - appStore.dispatch(AppAction.ReviewPromptAction.ReviewPromptShown) - } - } - } - } - - private fun tryShowPlayStorePrompt() = uiScope.launch { - val activity = activityRef.get() ?: return@launch - promptController.tryPromptReview(activity) - } - - companion object { - private val CUSTOM_PROMPT_DIRECTION = NavGraphDirections.actionGlobalCustomReviewPromptDialogFragment() - } -} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowReviewPromptBinding.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/ShowReviewPromptBinding.kt @@ -0,0 +1,64 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.reviewprompt + +import android.app.Activity +import androidx.navigation.NavDirections +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.launch +import mozilla.components.lib.state.helpers.AbstractBinding +import org.mozilla.fenix.NavGraphDirections +import org.mozilla.fenix.components.AppStore +import org.mozilla.fenix.components.PlayStoreReviewPromptController +import org.mozilla.fenix.components.appstate.AppAction +import org.mozilla.fenix.components.appstate.AppState +import org.mozilla.fenix.reviewprompt.ReviewPromptState.Eligible.Type +import java.lang.ref.WeakReference + +/** + * A feature that shows either the Google Play Review Prompt or the built-in review prompt based + * on the eligibility. + */ +class ShowReviewPromptBinding( + private val appStore: AppStore, + private val promptController: PlayStoreReviewPromptController, + private val activityRef: WeakReference<Activity>, + private val uiScope: CoroutineScope, + private val navigationDirection: (NavDirections) -> Unit, + mainDispatcher: CoroutineDispatcher = Dispatchers.Main, +) : AbstractBinding<AppState>(appStore, mainDispatcher) { + + override suspend fun onState(flow: Flow<AppState>) { + flow.map { it.reviewPrompt } + .distinctUntilChanged() + .collect { + when (it) { + ReviewPromptState.Unknown, ReviewPromptState.NotEligible -> {} + + is ReviewPromptState.Eligible -> { + when (it.type) { + Type.PlayStore -> tryShowPlayStorePrompt() + Type.Custom -> navigationDirection.invoke(CUSTOM_PROMPT_DIRECTION) + } + appStore.dispatch(AppAction.ReviewPromptAction.ReviewPromptShown) + } + } + } + } + + private fun tryShowPlayStorePrompt() = uiScope.launch { + val activity = activityRef.get() ?: return@launch + promptController.tryPromptReview(activity) + } + + companion object { + private val CUSTOM_PROMPT_DIRECTION = NavGraphDirections.actionGlobalCustomReviewPromptDialogFragment() + } +} diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPromptTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/reviewprompt/ShowPlayStoreReviewPromptTest.kt @@ -52,7 +52,7 @@ class ShowPlayStoreReviewPromptTest { reviewPrompt = ReviewPromptState.Eligible(ReviewPromptState.Eligible.Type.Custom), ), ) - val feature = ShowPlayStoreReviewPrompt( + val feature = ShowReviewPromptBinding( appStore, promptController, activityRef, @@ -87,7 +87,7 @@ class ShowPlayStoreReviewPromptTest { ), middlewares = listOf(captureMiddleware), ) - val feature = ShowPlayStoreReviewPrompt( + val feature = ShowReviewPromptBinding( appStore, promptController, activityRef, @@ -116,7 +116,7 @@ class ShowPlayStoreReviewPromptTest { ), middlewares = listOf(captureMiddleware), ) - val feature = ShowPlayStoreReviewPrompt( + val feature = ShowReviewPromptBinding( appStore, promptController, activityRef, @@ -143,7 +143,7 @@ class ShowPlayStoreReviewPromptTest { ), middlewares = listOf(captureMiddleware), ) - val feature = ShowPlayStoreReviewPrompt( + val feature = ShowReviewPromptBinding( appStore, promptController, activityRef,