|
|
|
@ -5,15 +5,18 @@
|
|
|
|
|
package org.mozilla.fenix.shopping.middleware
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import mozilla.components.feature.tabs.TabsUseCases
|
|
|
|
|
import mozilla.components.lib.state.Middleware
|
|
|
|
|
import mozilla.components.lib.state.MiddlewareContext
|
|
|
|
|
import org.mozilla.fenix.settings.SupportUtils
|
|
|
|
|
import org.mozilla.fenix.shopping.store.ReviewQualityCheckAction
|
|
|
|
|
import org.mozilla.fenix.shopping.store.ReviewQualityCheckMiddleware
|
|
|
|
|
import org.mozilla.fenix.shopping.store.ReviewQualityCheckState
|
|
|
|
|
|
|
|
|
|
private const val PARAM_UTM_CAMPAIGN_KEY = "utm_campaign"
|
|
|
|
|
private const val PARAM_UTM_CAMPAIGN_VALUE = "fakespot-by-mozilla"
|
|
|
|
|
private const val PARAM_UTM_TERM_KEY = "utm_term"
|
|
|
|
|
private const val PARAM_UTM_TERM_VALUE = "core-sheet"
|
|
|
|
|
private const val POWERED_BY_URL =
|
|
|
|
|
"https://www.fakespot.com/review-checker?utm_source=review-checker" +
|
|
|
|
|
"&utm_campaign=fakespot-by-mozilla&utm_medium=inproduct&utm_term=core-sheet"
|
|
|
|
@ -25,13 +28,11 @@ private const val TERMS_OF_USE_URL = "https://www.fakespot.com/terms"
|
|
|
|
|
*
|
|
|
|
|
* @property selectOrAddUseCase UseCase instance used to open new tabs.
|
|
|
|
|
* @property context Context used to get SUMO urls.
|
|
|
|
|
* @property scope [CoroutineScope] used to launch coroutines.
|
|
|
|
|
*/
|
|
|
|
|
class ReviewQualityCheckNavigationMiddleware(
|
|
|
|
|
private val selectOrAddUseCase: TabsUseCases.SelectOrAddUseCase,
|
|
|
|
|
private val context: Context,
|
|
|
|
|
private val scope: CoroutineScope,
|
|
|
|
|
) : Middleware<ReviewQualityCheckState, ReviewQualityCheckAction> {
|
|
|
|
|
) : ReviewQualityCheckMiddleware {
|
|
|
|
|
|
|
|
|
|
override fun invoke(
|
|
|
|
|
context: MiddlewareContext<ReviewQualityCheckState, ReviewQualityCheckAction>,
|
|
|
|
@ -49,7 +50,7 @@ class ReviewQualityCheckNavigationMiddleware(
|
|
|
|
|
|
|
|
|
|
private fun processAction(
|
|
|
|
|
action: ReviewQualityCheckAction.NavigationMiddlewareAction,
|
|
|
|
|
) = scope.launch {
|
|
|
|
|
) {
|
|
|
|
|
selectOrAddUseCase.invoke(actionToUrl(action))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -61,21 +62,24 @@ class ReviewQualityCheckNavigationMiddleware(
|
|
|
|
|
private fun actionToUrl(
|
|
|
|
|
action: ReviewQualityCheckAction.NavigationMiddlewareAction,
|
|
|
|
|
) = when (action) {
|
|
|
|
|
// Placeholder SUMO urls to be used until the Fakespot SUMO pages are added in 1854277
|
|
|
|
|
is ReviewQualityCheckAction.OpenExplainerLearnMoreLink -> SupportUtils.getSumoURLForTopic(
|
|
|
|
|
is ReviewQualityCheckAction.OpenExplainerLearnMoreLink,
|
|
|
|
|
ReviewQualityCheckAction.OpenOnboardingLearnMoreLink,
|
|
|
|
|
-> appendUTMParams(
|
|
|
|
|
SupportUtils.getSumoURLForTopic(
|
|
|
|
|
context,
|
|
|
|
|
SupportUtils.SumoTopic.HELP,
|
|
|
|
|
SupportUtils.SumoTopic.REVIEW_QUALITY_CHECK,
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
is ReviewQualityCheckAction.OpenOnboardingTermsLink -> TERMS_OF_USE_URL
|
|
|
|
|
|
|
|
|
|
is ReviewQualityCheckAction.OpenOnboardingLearnMoreLink -> SupportUtils.getSumoURLForTopic(
|
|
|
|
|
context,
|
|
|
|
|
SupportUtils.SumoTopic.HELP,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
is ReviewQualityCheckAction.OpenOnboardingPrivacyPolicyLink -> PRIVACY_POLICY_URL
|
|
|
|
|
|
|
|
|
|
is ReviewQualityCheckAction.OpenPoweredByLink -> POWERED_BY_URL
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun appendUTMParams(url: String): String = Uri.parse(url).buildUpon()
|
|
|
|
|
.appendQueryParameter(PARAM_UTM_CAMPAIGN_KEY, PARAM_UTM_CAMPAIGN_VALUE)
|
|
|
|
|
.appendQueryParameter(PARAM_UTM_TERM_KEY, PARAM_UTM_TERM_VALUE)
|
|
|
|
|
.build().toString()
|
|
|
|
|