mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/21561 - Enable/Disable the feature from the customization menu
This commit is contained in:
parent
08a71a5366
commit
ad0f428f39
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<TopSite>,
|
||||
collections: List<TabCollection>,
|
||||
expandedCollections: Set<Long>,
|
||||
@ -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<Adapt
|
||||
return items
|
||||
}
|
||||
|
||||
private fun HomeFragmentState.toAdapterList(context: Context): List<AdapterItem> = when (mode) {
|
||||
private fun HomeFragmentState.toAdapterList(): List<AdapterItem> = 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) {
|
||||
|
||||
|
@ -159,7 +159,7 @@ class CustomizationFragment : PreferenceFragmentCompat() {
|
||||
}
|
||||
|
||||
requirePreference<SwitchPreference>(R.string.pref_key_pocket_homescreen_recommendations).apply {
|
||||
isVisible = false
|
||||
isVisible = FeatureFlags.isPocketRecommendationsFeatureEnabled(context)
|
||||
isChecked = context.settings().pocketRecommendations
|
||||
onPreferenceChangeListener = CustomizeHomeMetricsUpdater()
|
||||
}
|
||||
|
@ -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<SwitchPreference>(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 {
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -49,8 +49,6 @@
|
||||
<string name="preferences_nimbus_experiments">Nimbus Experiments</string>
|
||||
<!-- Label for using the nimbus collections preview -->
|
||||
<string name="preferences_nimbus_use_preview_collection">Use Nimbus Preview Collection (requires restart)</string>
|
||||
<!-- Label for the Pocket articles recommendations on homescreen -->
|
||||
<string name="preferences_pocket_homescreen_recommendations">Debug only. Enable Pocket recommended articles on homescreen.</string>
|
||||
|
||||
<!-- A secret menu option in the tabs tray for making a tab inactive for testing. -->
|
||||
<string name="inactive_tabs_menu_item">Make inactive</string>
|
||||
|
@ -25,9 +25,4 @@
|
||||
android:key="@string/pref_key_nimbus_use_preview"
|
||||
android:title="@string/preferences_nimbus_use_preview_collection"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_key_pocket_homescreen_recommendations"
|
||||
android:title="@string/preferences_pocket_homescreen_recommendations"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
||||
|
@ -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<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
@ -173,7 +170,6 @@ class SessionControlViewTest {
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
@ -202,7 +198,6 @@ class SessionControlViewTest {
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
|
||||
val results = normalModeAdapterItems(
|
||||
testContext,
|
||||
topSites,
|
||||
collections,
|
||||
expandedCollections,
|
||||
@ -229,14 +224,8 @@ class SessionControlViewTest {
|
||||
val recentTabs = emptyList<RecentTab.Tab>()
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
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<RecentTab.Tab>()
|
||||
val historyMetadata = emptyList<HistoryMetadataGroup>()
|
||||
val pocketArticles = emptyList<PocketRecommendedStory>()
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user