2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

For #10342 - Part 4: Use the TopSitesFeature in the HomeFragment for displaying top sites

This commit is contained in:
Gabriel Luong 2020-08-18 17:55:52 -04:00 committed by Jonathan Almeida
parent 46aa6a003e
commit 1f564c10ce
11 changed files with 88 additions and 7 deletions

View File

@ -31,6 +31,11 @@ object FeatureFlags {
*/ */
const val newSearchExperience = true const val newSearchExperience = true
/**
* Enables showing the top frequently visited sites
*/
val topFrecentSite = Config.channel.isNightlyOrDebug
/** /**
* Enables wait til first contentful paint * Enables wait til first contentful paint
*/ */

View File

@ -255,6 +255,8 @@ class Core(private val context: Context, private val crashReporter: CrashReporti
*/ */
val thumbnailStorage by lazy { ThumbnailStorage(context) } val thumbnailStorage by lazy { ThumbnailStorage(context) }
val pinnedSiteStorage by lazy { PinnedSiteStorage(context) }
val topSiteStorage by lazy { val topSiteStorage by lazy {
val defaultTopSites = mutableListOf<Pair<String, String>>() val defaultTopSites = mutableListOf<Pair<String, String>>()
@ -286,7 +288,7 @@ class Core(private val context: Context, private val crashReporter: CrashReporti
} }
DefaultTopSitesStorage( DefaultTopSitesStorage(
PinnedSiteStorage(context), pinnedSiteStorage,
historyStorage, historyStorage,
defaultTopSites defaultTopSites
) )

View File

@ -68,7 +68,10 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.top.sites.TopSitesConfig
import mozilla.components.feature.top.sites.TopSitesFeature
import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
@ -96,6 +99,7 @@ import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor import org.mozilla.fenix.home.sessioncontrol.SessionControlInteractor
import org.mozilla.fenix.home.sessioncontrol.SessionControlView import org.mozilla.fenix.home.sessioncontrol.SessionControlView
import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder import org.mozilla.fenix.home.sessioncontrol.viewholders.CollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.DefaultTopSitesView
import org.mozilla.fenix.onboarding.FenixOnboarding import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.settings.SupportUtils import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.SupportUtils.SumoTopic.HELP import org.mozilla.fenix.settings.SupportUtils.SumoTopic.HELP
@ -159,6 +163,8 @@ class HomeFragment : Fragment() {
private var sessionControlView: SessionControlView? = null private var sessionControlView: SessionControlView? = null
private lateinit var currentMode: CurrentMode private lateinit var currentMode: CurrentMode
private val topSitesFeature = ViewBoundFeatureWrapper<TopSitesFeature>()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
postponeEnterTransition() postponeEnterTransition()
@ -192,15 +198,23 @@ class HomeFragment : Fragment() {
collections = components.core.tabCollectionStorage.cachedTabCollections, collections = components.core.tabCollectionStorage.cachedTabCollections,
expandedCollections = emptySet(), expandedCollections = emptySet(),
mode = currentMode.getCurrentMode(), mode = currentMode.getCurrentMode(),
topSites = StrictMode.allowThreadDiskReads().resetPoliciesAfter { topSites = components.core.topSiteStorage.cachedTopSites,
components.core.topSiteStorage.cachedTopSites
},
tip = FenixTipManager(listOf(MigrationTipProvider(requireContext()))).getTip(), tip = FenixTipManager(listOf(MigrationTipProvider(requireContext()))).getTip(),
showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome
) )
) )
} }
topSitesFeature.set(
feature = TopSitesFeature(
view = DefaultTopSitesView(homeFragmentStore),
storage = components.core.topSiteStorage,
config = ::getTopSitesConfig
),
owner = this,
view = view
)
_sessionControlInteractor = SessionControlInteractor( _sessionControlInteractor = SessionControlInteractor(
DefaultSessionControlController( DefaultSessionControlController(
activity = activity, activity = activity,
@ -234,6 +248,15 @@ class HomeFragment : Fragment() {
return view return view
} }
/**
* Returns a [TopSitesConfig] which specifies how many top sites to display and whether or
* not frequently visited sites should be displayed.
*/
private fun getTopSitesConfig(): TopSitesConfig {
val settings = requireContext().settings()
return TopSitesConfig(settings.topSitesMaxLimit, settings.showTopFrecentSites)
}
/** /**
* The [SessionControlView] is forced to update with our current state when we call * The [SessionControlView] is forced to update with our current state when we call
* [HomeFragment.onCreateView] in order to be able to draw everything at once with the current * [HomeFragment.onCreateView] in order to be able to draw everything at once with the current

View File

@ -0,0 +1,19 @@
/* 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.home.sessioncontrol.viewholders.topsites
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.view.TopSitesView
import org.mozilla.fenix.home.HomeFragmentAction
import org.mozilla.fenix.home.HomeFragmentStore
class DefaultTopSitesView(
val store: HomeFragmentStore
) : TopSitesView {
override fun displayTopSites(topSites: List<TopSite>) {
store.dispatch(HomeFragmentAction.TopSitesChange(topSites))
}
}

View File

@ -14,6 +14,7 @@ import kotlinx.android.synthetic.main.top_site_item.*
import mozilla.components.browser.menu.BrowserMenuBuilder import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.feature.top.sites.TopSite import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite.Type.DEFAULT
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView import org.mozilla.fenix.ext.loadIntoView
@ -39,7 +40,7 @@ class TopSiteItemViewHolder(
} }
top_site_item.setOnClickListener { top_site_item.setOnClickListener {
interactor.onSelectTopSite(topSite.url, topSite.isDefault) interactor.onSelectTopSite(topSite.url, topSite.type === DEFAULT)
} }
top_site_item.setOnLongClickListener { top_site_item.setOnLongClickListener {

View File

@ -31,6 +31,12 @@ class SecretSettingsFragment : PreferenceFragmentCompat() {
onPreferenceChangeListener = SharedPreferenceUpdater() onPreferenceChangeListener = SharedPreferenceUpdater()
} }
requirePreference<SwitchPreference>(R.string.pref_key_enable_top_frecent_sites).apply {
isVisible = FeatureFlags.topFrecentSite
isChecked = context.settings().showTopFrecentSites
onPreferenceChangeListener = SharedPreferenceUpdater()
}
requirePreference<SwitchPreference>(R.string.pref_key_wait_first_paint).apply { requirePreference<SwitchPreference>(R.string.pref_key_wait_first_paint).apply {
isVisible = FeatureFlags.waitUntilPaintToDraw isVisible = FeatureFlags.waitUntilPaintToDraw
isChecked = context.settings().waitToShowPageUntilFirstPaint isChecked = context.settings().waitToShowPageUntilFirstPaint

View File

@ -54,6 +54,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
const val showLoginsSecureWarningMaxCount = 1 const val showLoginsSecureWarningMaxCount = 1
const val trackingProtectionOnboardingMaximumCount = 1 const val trackingProtectionOnboardingMaximumCount = 1
const val pwaVisitsToShowPromptMaxCount = 3 const val pwaVisitsToShowPromptMaxCount = 3
const val topSitesMaxCount = 16
const val FENIX_PREFERENCES = "fenix_preferences" const val FENIX_PREFERENCES = "fenix_preferences"
private const val showSearchWidgetCFRMaxCount = 3 private const val showSearchWidgetCFRMaxCount = 3
@ -103,6 +104,12 @@ class Settings(private val appContext: Context) : PreferencesHolder {
featureFlag = FeatureFlags.newSearchExperience featureFlag = FeatureFlags.newSearchExperience
) )
var showTopFrecentSites by featureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_enable_top_frecent_sites),
default = false,
featureFlag = FeatureFlags.topFrecentSite
)
var waitToShowPageUntilFirstPaint by featureFlagPreference( var waitToShowPageUntilFirstPaint by featureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_wait_first_paint), appContext.getPreferenceKey(R.string.pref_key_wait_first_paint),
default = false, default = false,
@ -829,6 +836,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = 0 default = 0
) )
val topSitesMaxLimit by intPreference(
appContext.getPreferenceKey(R.string.pref_key_top_sites_max_limit),
default = topSitesMaxCount
)
fun setOpenTabsCount(count: Int) { fun setOpenTabsCount(count: Int) {
preferences.edit().putInt( preferences.edit().putInt(
appContext.getPreferenceKey(R.string.pref_key_open_tabs_count), appContext.getPreferenceKey(R.string.pref_key_open_tabs_count),

View File

@ -165,10 +165,16 @@
<string name="pref_key_testing_stage" translatable="false">pref_key_testing_stage</string> <string name="pref_key_testing_stage" translatable="false">pref_key_testing_stage</string>
<string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string> <string name="pref_key_encryption_key_generated" translatable="false">pref_key_encryption_key_generated</string>
<!-- Top Sites -->
<string name="default_top_sites_added" translatable="false">pref_key_pocket_top_site_added</string> <string name="default_top_sites_added" translatable="false">pref_key_pocket_top_site_added</string>
<string name="pref_key_top_sites_size" translatable="false">pref_key_top_sites_size</string> <string name="pref_key_top_sites_size" translatable="false">pref_key_top_sites_size</string>
<!-- Maximum number of top sites to display -->
<string name="pref_key_top_sites_max_limit" translatable="false">pref_key_top_sites_max_limit</string>
<!-- Whether or not the top frecent sites are shown along with pinned top sites -->
<string name="pref_key_enable_top_frecent_sites" translatable="false">pref_key_top_frecent_sites</string>
<!-- A value of `true` means the PWA dialog has been showed or user already has PWAs installed--> <!-- A value of `true` means the PWA dialog has been showed or user already has PWAs installed -->
<string name="pref_key_user_knows_about_pwa" translatable="false">pref_key_user_knows_about_pwa</string> <string name="pref_key_user_knows_about_pwa" translatable="false">pref_key_user_knows_about_pwa</string>
<string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string> <string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string>

View File

@ -34,6 +34,8 @@
<string name="preferences_debug_settings">Secret Settings</string> <string name="preferences_debug_settings">Secret Settings</string>
<!-- Label for the new search experience preference --> <!-- Label for the new search experience preference -->
<string name="preferences_debug_settings_use_new_search_experience">Use New Search Experience</string> <string name="preferences_debug_settings_use_new_search_experience">Use New Search Experience</string>
<!-- Label for the show top frequently visited sites preference -->
<string name="preferences_debug_settings_enable_top_frecent_sites">Show Top Frequently Visited Sites</string>
<!-- Label for the wait until first paint preference --> <!-- Label for the wait until first paint preference -->
<string name="preferences_debug_settings_wait_first_paint">Wait Until First Paint To Show Page Content</string> <string name="preferences_debug_settings_wait_first_paint">Wait Until First Paint To Show Page Content</string>
<!-- Label for showing Synced Tabs in the tabs tray --> <!-- Label for showing Synced Tabs in the tabs tray -->

View File

@ -9,6 +9,11 @@
android:key="@string/pref_key_use_new_search_experience" android:key="@string/pref_key_use_new_search_experience"
android:title="@string/preferences_debug_settings_use_new_search_experience" android:title="@string/preferences_debug_settings_use_new_search_experience"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_enable_top_frecent_sites"
android:title="@string/preferences_debug_settings_enable_top_frecent_sites"
app:iconSpaceReserved="false" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="@string/pref_key_wait_first_paint" android:key="@string/pref_key_wait_first_paint"

View File

@ -28,7 +28,7 @@ class MigratingFenixApplication : FenixApplication() {
.migrateHistory(this.components.core.lazyHistoryStorage) .migrateHistory(this.components.core.lazyHistoryStorage)
.migrateBookmarks( .migrateBookmarks(
this.components.core.lazyBookmarksStorage, this.components.core.lazyBookmarksStorage,
this.components.core.topSiteStorage.storage this.components.core.pinnedSiteStorage
) )
.migrateLogins(this.components.core.lazyPasswordsStorage) .migrateLogins(this.components.core.lazyPasswordsStorage)
.migrateFxa(lazy { this.components.backgroundServices.accountManager }) .migrateFxa(lazy { this.components.backgroundServices.accountManager })