mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/6758 - Part 7: Add menu for opening a top site in private tab and removing a top site
This commit is contained in:
parent
31281691e5
commit
5ac336f840
@ -17,13 +17,16 @@ import mozilla.components.feature.media.ext.pauseIfPlaying
|
|||||||
import mozilla.components.feature.media.ext.playIfPaused
|
import mozilla.components.feature.media.ext.playIfPaused
|
||||||
import mozilla.components.feature.media.state.MediaStateMachine
|
import mozilla.components.feature.media.state.MediaStateMachine
|
||||||
import mozilla.components.feature.tab.collections.TabCollection
|
import mozilla.components.feature.tab.collections.TabCollection
|
||||||
|
import mozilla.components.feature.top.sites.TopSite
|
||||||
import mozilla.components.feature.tab.collections.Tab as ComponentTab
|
import mozilla.components.feature.tab.collections.Tab as ComponentTab
|
||||||
import org.mozilla.fenix.BrowserDirection
|
import org.mozilla.fenix.BrowserDirection
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||||
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
||||||
import org.mozilla.fenix.collections.SaveCollectionStep
|
import org.mozilla.fenix.collections.SaveCollectionStep
|
||||||
import org.mozilla.fenix.components.TabCollectionStorage
|
import org.mozilla.fenix.components.TabCollectionStorage
|
||||||
|
import org.mozilla.fenix.components.TopSiteStorage
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.components.metrics.Event
|
import org.mozilla.fenix.components.metrics.Event
|
||||||
import org.mozilla.fenix.components.metrics.MetricController
|
import org.mozilla.fenix.components.metrics.MetricController
|
||||||
@ -82,6 +85,11 @@ interface SessionControlController {
|
|||||||
*/
|
*/
|
||||||
fun handleDeleteCollectionTapped(collection: TabCollection)
|
fun handleDeleteCollectionTapped(collection: TabCollection)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see [TopSiteInteractor.onOpenInPrivateTabClicked]
|
||||||
|
*/
|
||||||
|
fun handleOpenInPrivateTabClicked(topSite: TopSite)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see [TabSessionInteractor.onPauseMediaClicked]
|
* @see [TabSessionInteractor.onPauseMediaClicked]
|
||||||
*/
|
*/
|
||||||
@ -97,6 +105,11 @@ interface SessionControlController {
|
|||||||
*/
|
*/
|
||||||
fun handlePrivateBrowsingLearnMoreClicked()
|
fun handlePrivateBrowsingLearnMoreClicked()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see [TopSiteInteractor.onRemoveTopSiteClicked]
|
||||||
|
*/
|
||||||
|
fun handleRemoveTopSiteClicked(topSite: TopSite)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see [CollectionInteractor.onRenameCollectionTapped]
|
* @see [CollectionInteractor.onRenameCollectionTapped]
|
||||||
*/
|
*/
|
||||||
@ -133,7 +146,7 @@ interface SessionControlController {
|
|||||||
fun handleToggleCollectionExpanded(collection: TabCollection, expand: Boolean)
|
fun handleToggleCollectionExpanded(collection: TabCollection, expand: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions")
|
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||||
class DefaultSessionControlController(
|
class DefaultSessionControlController(
|
||||||
private val activity: HomeActivity,
|
private val activity: HomeActivity,
|
||||||
private val store: HomeFragmentStore,
|
private val store: HomeFragmentStore,
|
||||||
@ -156,6 +169,8 @@ class DefaultSessionControlController(
|
|||||||
get() = activity.components.core.sessionManager
|
get() = activity.components.core.sessionManager
|
||||||
private val tabCollectionStorage: TabCollectionStorage
|
private val tabCollectionStorage: TabCollectionStorage
|
||||||
get() = activity.components.core.tabCollectionStorage
|
get() = activity.components.core.tabCollectionStorage
|
||||||
|
private val topSiteStorage: TopSiteStorage
|
||||||
|
get() = activity.components.core.topSiteStorage
|
||||||
|
|
||||||
override fun handleCloseTab(sessionId: String) {
|
override fun handleCloseTab(sessionId: String) {
|
||||||
closeTab.invoke(sessionId)
|
closeTab.invoke(sessionId)
|
||||||
@ -244,6 +259,17 @@ class DefaultSessionControlController(
|
|||||||
showDeleteCollectionPrompt(collection)
|
showDeleteCollectionPrompt(collection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun handleOpenInPrivateTabClicked(topSite: TopSite) {
|
||||||
|
with(activity) {
|
||||||
|
browsingModeManager.mode = BrowsingMode.Private
|
||||||
|
openToBrowserAndLoad(
|
||||||
|
searchTermOrURL = topSite.url,
|
||||||
|
newTab = true,
|
||||||
|
from = BrowserDirection.FromHome
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun handlePauseMediaClicked() {
|
override fun handlePauseMediaClicked() {
|
||||||
MediaStateMachine.state.pauseIfPlaying()
|
MediaStateMachine.state.pauseIfPlaying()
|
||||||
}
|
}
|
||||||
@ -261,6 +287,12 @@ class DefaultSessionControlController(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun handleRemoveTopSiteClicked(topSite: TopSite) {
|
||||||
|
lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
topSiteStorage.removeTopSite(topSite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun handleRenameCollectionTapped(collection: TabCollection) {
|
override fun handleRenameCollectionTapped(collection: TabCollection) {
|
||||||
showCollectionCreationFragment(
|
showCollectionCreationFragment(
|
||||||
step = SaveCollectionStep.RenameCollection,
|
step = SaveCollectionStep.RenameCollection,
|
||||||
|
@ -7,6 +7,7 @@ package org.mozilla.fenix.home.sessioncontrol
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import mozilla.components.feature.tab.collections.Tab
|
import mozilla.components.feature.tab.collections.Tab
|
||||||
import mozilla.components.feature.tab.collections.TabCollection
|
import mozilla.components.feature.tab.collections.TabCollection
|
||||||
|
import mozilla.components.feature.top.sites.TopSite
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for collection related actions in the [SessionControlInteractor].
|
* Interface for collection related actions in the [SessionControlInteractor].
|
||||||
@ -153,6 +154,21 @@ interface TabSessionInteractor {
|
|||||||
* Interface for top site related actions in the [SessionControlInteractor].
|
* Interface for top site related actions in the [SessionControlInteractor].
|
||||||
*/
|
*/
|
||||||
interface TopSiteInteractor {
|
interface TopSiteInteractor {
|
||||||
|
/**
|
||||||
|
* Opens the given top site in private mode. Called when an user clicks on the "Open in private
|
||||||
|
* tab" top site menu item.
|
||||||
|
*
|
||||||
|
* @param topSite The top site that will be open in private mode.
|
||||||
|
*/
|
||||||
|
fun onOpenInPrivateTabClicked(topSite: TopSite)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given top site. Called when an user clicks on the "Remove" top site menu item.
|
||||||
|
*
|
||||||
|
* @param topSite The top site that will be removed.
|
||||||
|
*/
|
||||||
|
fun onRemoveTopSiteClicked(topSite: TopSite)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects the given top site. Called when a user clicks on a top site.
|
* Selects the given top site. Called when a user clicks on a top site.
|
||||||
*
|
*
|
||||||
@ -202,6 +218,10 @@ class SessionControlInteractor(
|
|||||||
controller.handleDeleteCollectionTapped(collection)
|
controller.handleDeleteCollectionTapped(collection)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onOpenInPrivateTabClicked(topSite: TopSite) {
|
||||||
|
controller.handleOpenInPrivateTabClicked(topSite)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPauseMediaClicked() {
|
override fun onPauseMediaClicked() {
|
||||||
controller.handlePauseMediaClicked()
|
controller.handlePauseMediaClicked()
|
||||||
}
|
}
|
||||||
@ -214,6 +234,10 @@ class SessionControlInteractor(
|
|||||||
controller.handlePrivateBrowsingLearnMoreClicked()
|
controller.handlePrivateBrowsingLearnMoreClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRemoveTopSiteClicked(topSite: TopSite) {
|
||||||
|
controller.handleRemoveTopSiteClicked(topSite)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onRenameCollectionTapped(collection: TabCollection) {
|
override fun onRenameCollectionTapped(collection: TabCollection) {
|
||||||
controller.handleRenameCollectionTapped(collection)
|
controller.handleRenameCollectionTapped(collection)
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites
|
package org.mozilla.fenix.home.sessioncontrol.viewholders.topsites
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import kotlinx.android.synthetic.main.top_site_item.view.*
|
import kotlinx.android.synthetic.main.top_site_item.view.*
|
||||||
import mozilla.components.feature.top.sites.TopSite
|
import mozilla.components.feature.top.sites.TopSite
|
||||||
|
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||||
|
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
|
||||||
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
|
||||||
@ -18,11 +21,26 @@ class TopSiteItemViewHolder(
|
|||||||
private val interactor: TopSiteInteractor
|
private val interactor: TopSiteInteractor
|
||||||
) : RecyclerView.ViewHolder(view) {
|
) : RecyclerView.ViewHolder(view) {
|
||||||
private lateinit var topSite: TopSite
|
private lateinit var topSite: TopSite
|
||||||
|
private var topSiteMenu: TopSiteItemMenu
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
topSiteMenu = TopSiteItemMenu(view.context) {
|
||||||
|
when (it) {
|
||||||
|
is TopSiteItemMenu.Item.OpenInPrivateTab -> interactor.onOpenInPrivateTabClicked(
|
||||||
|
topSite
|
||||||
|
)
|
||||||
|
is TopSiteItemMenu.Item.RemoveTopSite -> interactor.onRemoveTopSiteClicked(topSite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
view.top_site_item.setOnClickListener {
|
view.top_site_item.setOnClickListener {
|
||||||
interactor.onSelectTopSite(topSite.url)
|
interactor.onSelectTopSite(topSite.url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
view.top_site_item.setOnLongClickListener() {
|
||||||
|
topSiteMenu.menuBuilder.build(view.context).show(anchor = it)
|
||||||
|
return@setOnLongClickListener true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bind(topSite: TopSite) {
|
fun bind(topSite: TopSite) {
|
||||||
@ -35,3 +53,31 @@ class TopSiteItemViewHolder(
|
|||||||
const val LAYOUT_ID = R.layout.top_site_item
|
const val LAYOUT_ID = R.layout.top_site_item
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TopSiteItemMenu(
|
||||||
|
private val context: Context,
|
||||||
|
private val onItemTapped: (Item) -> Unit = {}
|
||||||
|
) {
|
||||||
|
sealed class Item {
|
||||||
|
object OpenInPrivateTab : Item()
|
||||||
|
object RemoveTopSite : Item()
|
||||||
|
}
|
||||||
|
|
||||||
|
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
|
||||||
|
|
||||||
|
private val menuItems by lazy {
|
||||||
|
listOf(
|
||||||
|
SimpleBrowserMenuItem(
|
||||||
|
context.getString(R.string.bookmark_menu_open_in_private_tab_button)
|
||||||
|
) {
|
||||||
|
onItemTapped.invoke(Item.OpenInPrivateTab)
|
||||||
|
},
|
||||||
|
|
||||||
|
SimpleBrowserMenuItem(
|
||||||
|
context.getString(R.string.remove_top_site)
|
||||||
|
) {
|
||||||
|
onItemTapped.invoke(Item.RemoveTopSite)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -426,6 +426,8 @@
|
|||||||
<string name="collection_rename">Rename collection</string>
|
<string name="collection_rename">Rename collection</string>
|
||||||
<!-- Text for the button to open tabs of the selected collection -->
|
<!-- Text for the button to open tabs of the selected collection -->
|
||||||
<string name="collection_open_tabs">Open tabs</string>
|
<string name="collection_open_tabs">Open tabs</string>
|
||||||
|
<!-- Text for the menu button to remove a top site -->
|
||||||
|
<string name="remove_top_site">Remove</string>
|
||||||
|
|
||||||
<!-- History -->
|
<!-- History -->
|
||||||
<!-- Text for the button to clear all history -->
|
<!-- Text for the button to clear all history -->
|
||||||
|
Loading…
Reference in New Issue
Block a user