diff --git a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt index 789eba230f..d621137f94 100644 --- a/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt +++ b/app/src/main/java/org/mozilla/fenix/FeatureFlags.kt @@ -4,6 +4,10 @@ package org.mozilla.fenix +import android.content.Context +import mozilla.components.support.locale.LocaleManager +import mozilla.components.support.locale.LocaleManager.getSystemDefault + /** * A single source for setting feature flags that are mostly based on build type. */ @@ -73,4 +77,12 @@ object FeatureFlags { * Enables showing search groupings in the History. */ val showHistorySearchGroups = Config.channel.isNightlyOrDebug + + /** + * Show Pocket recommended stories on home. + */ + fun isPocketRecommendationsFeatureEnabled(context: Context): Boolean { + return Config.channel.isNightlyOrDebug && + "en-US" == LocaleManager.getCurrentLocale(context)?.toLanguageTag() ?: getSystemDefault().toLanguageTag() + } } diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 4b238230b2..46b0cd6b70 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -252,13 +252,17 @@ class HomeFragment : Fragment() { ) } - if (requireContext().settings().pocketRecommendations) { - lifecycleScope.launch(IO) { + lifecycleScope.launch(IO) { + if (FeatureFlags.isPocketRecommendationsFeatureEnabled(requireContext()) && + requireContext().settings().pocketRecommendations + ) { val categories = components.core.pocketStoriesService.getStories() .groupBy { story -> story.category } .map { (category, stories) -> PocketRecommendedStoryCategory(category, stories) } homeFragmentStore.dispatch(HomeFragmentAction.PocketStoriesCategoriesChange(categories)) + } else { + homeFragmentStore.dispatch(HomeFragmentAction.PocketStoriesChange(emptyList())) } } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt index 497c61ec61..0903563cf7 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlView.kt @@ -4,7 +4,6 @@ package org.mozilla.fenix.home.sessioncontrol -import android.content.Context import android.view.View import androidx.annotation.VisibleForTesting import androidx.lifecycle.LifecycleOwner @@ -32,7 +31,6 @@ import org.mozilla.fenix.utils.Settings @Suppress("ComplexMethod", "LongParameterList") @VisibleForTesting internal fun normalModeAdapterItems( - context: Context, topSites: List, collections: List, expandedCollections: Set, @@ -82,7 +80,7 @@ internal fun normalModeAdapterItems( showCollections(collections, expandedCollections, items) } - if (context.settings().pocketRecommendations && pocketStories.isNotEmpty()) { + if (pocketStories.isNotEmpty()) { shouldShowCustomizeHome = true items.add(AdapterItem.PocketStoriesItem) } @@ -150,9 +148,8 @@ private fun onboardingAdapterItems(onboardingState: OnboardingState): List = when (mode) { +private fun HomeFragmentState.toAdapterList(): List = when (mode) { is Mode.Normal -> normalModeAdapterItems( - context, topSites, collections, expandedCollections, @@ -216,7 +213,7 @@ class SessionControlView( interactor.showOnboardingDialog() } - val stateAdapterList = state.toAdapterList(view.context) + val stateAdapterList = state.toAdapterList() if (homeScreenViewModel.shouldScrollToTopSites) { sessionControlAdapter.submitList(stateAdapterList) { diff --git a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt index c485c6ca02..607c59cc45 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/CustomizationFragment.kt @@ -159,7 +159,7 @@ class CustomizationFragment : PreferenceFragmentCompat() { } requirePreference(R.string.pref_key_pocket_homescreen_recommendations).apply { - isVisible = false + isVisible = FeatureFlags.isPocketRecommendationsFeatureEnabled(context) isChecked = context.settings().pocketRecommendations onPreferenceChangeListener = CustomizeHomeMetricsUpdater() } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt index 8f50dfa773..2ace1c605b 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SecretSettingsFragment.kt @@ -11,7 +11,6 @@ import android.widget.Toast import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference -import org.mozilla.fenix.Config import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.R import org.mozilla.fenix.ext.components @@ -77,24 +76,6 @@ class SecretSettingsFragment : PreferenceFragmentCompat() { isChecked = context.settings().nimbusUsePreview onPreferenceChangeListener = SharedPreferenceUpdater() } - - requirePreference(R.string.pref_key_pocket_homescreen_recommendations).apply { - isVisible = Config.channel.isDebug - isChecked = context.settings().pocketRecommendations - onPreferenceChangeListener = object : SharedPreferenceUpdater() { - override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { - (newValue as? Boolean)?.let { - if (it) { - context.components.core.pocketStoriesService.startPeriodicStoriesRefresh() - } else { - context.components.core.pocketStoriesService.stopPeriodicStoriesRefresh() - } - } - - return super.onPreferenceChange(preference, newValue) - } - } - } } companion object { diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index f76639ab54..5c9c94d0fd 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -1175,6 +1175,6 @@ class Settings(private val appContext: Context) : PreferencesHolder { var pocketRecommendations by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_pocket_homescreen_recommendations), - default = false + default = true ) } diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index 1135d467dc..21913fbd10 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -49,8 +49,6 @@ Nimbus Experiments Use Nimbus Preview Collection (requires restart) - - Debug only. Enable Pocket recommended articles on homescreen. Make inactive diff --git a/app/src/main/res/xml/secret_settings_preferences.xml b/app/src/main/res/xml/secret_settings_preferences.xml index 96eeeb71a3..e45009d1c8 100644 --- a/app/src/main/res/xml/secret_settings_preferences.xml +++ b/app/src/main/res/xml/secret_settings_preferences.xml @@ -25,9 +25,4 @@ android:key="@string/pref_key_nimbus_use_preview" android:title="@string/preferences_nimbus_use_preview_collection" app:iconSpaceReserved="false" /> - diff --git a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt index c1514572c9..11e9afd02a 100644 --- a/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/sessioncontrol/SessionControlViewTest.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.home.sessioncontrol import androidx.recyclerview.widget.RecyclerView import io.mockk.every import io.mockk.mockk -import io.mockk.spyk import io.mockk.verify import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType @@ -19,7 +18,6 @@ import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse import org.junit.Test import org.junit.runner.RunWith -import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.historymetadata.HistoryMetadataGroup import org.mozilla.fenix.home.HomeFragmentState @@ -145,7 +143,6 @@ class SessionControlViewTest { val pocketArticles = emptyList() val results = normalModeAdapterItems( - testContext, topSites, collections, expandedCollections, @@ -173,7 +170,6 @@ class SessionControlViewTest { val pocketArticles = emptyList() val results = normalModeAdapterItems( - testContext, topSites, collections, expandedCollections, @@ -202,7 +198,6 @@ class SessionControlViewTest { val pocketArticles = emptyList() val results = normalModeAdapterItems( - testContext, topSites, collections, expandedCollections, @@ -229,14 +224,8 @@ class SessionControlViewTest { val recentTabs = emptyList() val historyMetadata = emptyList() val pocketArticles = listOf(PocketRecommendedStory("", "", "", "", "", 1, 1)) - val context = spyk(testContext) - - val settings: Settings = mockk() - every { settings.pocketRecommendations } returns true - every { context.settings() } returns settings val results = normalModeAdapterItems( - context, topSites, collections, expandedCollections, @@ -262,14 +251,8 @@ class SessionControlViewTest { val recentTabs = emptyList() val historyMetadata = emptyList() val pocketArticles = emptyList() - val context = spyk(testContext) - - val settings: Settings = mockk() - every { settings.pocketRecommendations } returns true - every { context.settings() } returns settings val results = normalModeAdapterItems( - context, topSites, collections, expandedCollections,