Skip to content

Commit

Permalink
For mozilla-mobile#20586 - Put everything behing a secret setting
Browse files Browse the repository at this point in the history
Not ready for prime-time. Lot of work still to be done.
  • Loading branch information
Mugurell authored and mergify[bot] committed Aug 23, 2021
1 parent 6ae8c90 commit 05f74eb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.mozilla.fenix.home.sessioncontrol

import android.content.Context
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.lifecycle.LifecycleOwner
Expand All @@ -17,6 +18,7 @@ import mozilla.components.feature.top.sites.TopSite
import mozilla.components.service.pocket.PocketRecommendedStory
import org.mozilla.fenix.components.tips.Tip
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.historymetadata.HistoryMetadataGroup
import org.mozilla.fenix.home.HomeFragmentState
import org.mozilla.fenix.home.HomeFragmentStore
Expand All @@ -29,6 +31,7 @@ import org.mozilla.fenix.home.recenttabs.view.RecentTabsItemPosition
// When we remove the tabs from the home screen this will get much simpler again.
@Suppress("ComplexMethod", "LongParameterList")
private fun normalModeAdapterItems(
context: Context,
topSites: List<TopSite>,
collections: List<TabCollection>,
expandedCollections: Set<Long>,
Expand Down Expand Up @@ -72,7 +75,7 @@ private fun normalModeAdapterItems(
showCollections(collections, expandedCollections, items)
}

if (pocketArticles.isNotEmpty()) {
if (context.settings().pocketRecommendations && pocketArticles.isNotEmpty()) {
items.add(AdapterItem.PocketStoriesItem)
}

Expand Down Expand Up @@ -191,8 +194,9 @@ private fun onboardingAdapterItems(onboardingState: OnboardingState): List<Adapt
return items
}

private fun HomeFragmentState.toAdapterList(): List<AdapterItem> = when (mode) {
private fun HomeFragmentState.toAdapterList(context: Context): List<AdapterItem> = when (mode) {
is Mode.Normal -> normalModeAdapterItems(
context,
topSites,
collections,
expandedCollections,
Expand Down Expand Up @@ -245,7 +249,7 @@ class SessionControlView(
}

fun update(state: HomeFragmentState) {
val stateAdapterList = state.toAdapterList()
val stateAdapterList = state.toAdapterList(view.context)
if (homeScreenViewModel.shouldScrollToTopSites) {
sessionControlAdapter.submitList(stateAdapterList) {

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1131,4 +1131,9 @@ class Settings(private val appContext: Context) : PreferencesHolder {
appContext.getPreferenceKey(R.string.pref_key_credit_cards_save_and_autofill_cards),
default = true
)

var pocketRecommendations by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_pocket_homescreen_recommendations),
default = false
)
}
1 change: 1 addition & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,5 @@
<string name="pref_key_nimbus_experiments" translatable="false">pref_key_nimbus_experiments</string>
<string name="pref_key_nimbus_use_preview" translatable="false">pref_key_nimbus_use_preview</string>
<string name="pref_key_history_metadata_feature" translatable="false">pref_key_history_metadata_feature</string>
<string name="pref_key_pocket_homescreen_recommendations" translatable="false">pref_key_pocket_homescreen_recommendations</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/static_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<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>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/xml/secret_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@
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>

0 comments on commit 05f74eb

Please sign in to comment.