For #10342 - Part 6: Show "Delete from history" instead of "Remove" for top frecent sites in the top site menu

pull/35/head
Gabriel Luong 4 years ago committed by Jonathan Almeida
parent 40120ac98f
commit 4f76699ab7

@ -15,6 +15,7 @@ import mozilla.components.browser.menu.BrowserMenuBuilder
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
import mozilla.components.feature.top.sites.TopSite
import mozilla.components.feature.top.sites.TopSite.Type.DEFAULT
import mozilla.components.feature.top.sites.TopSite.Type.FRECENT
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView
@ -27,23 +28,23 @@ class TopSiteItemViewHolder(
private val interactor: TopSiteInteractor
) : ViewHolder(view) {
private lateinit var topSite: TopSite
private var topSiteMenu: TopSiteItemMenu
init {
topSiteMenu = TopSiteItemMenu(view.context) {
when (it) {
is TopSiteItemMenu.Item.OpenInPrivateTab -> interactor.onOpenInPrivateTabClicked(
topSite
)
is TopSiteItemMenu.Item.RemoveTopSite -> interactor.onRemoveTopSiteClicked(topSite)
}
}
top_site_item.setOnClickListener {
interactor.onSelectTopSite(topSite.url, topSite.type === DEFAULT)
}
top_site_item.setOnLongClickListener {
val topSiteMenu = TopSiteItemMenu(view.context, topSite.type != FRECENT) { item ->
when (item) {
is TopSiteItemMenu.Item.OpenInPrivateTab -> interactor.onOpenInPrivateTabClicked(
topSite
)
is TopSiteItemMenu.Item.RemoveTopSite -> interactor.onRemoveTopSiteClicked(
topSite
)
}
}
val menu = topSiteMenu.menuBuilder.build(view.context).show(anchor = it)
it.setOnTouchListener @SuppressLint("ClickableViewAccessibility") { v, event ->
onTouchEvent(v, event, menu)
@ -83,6 +84,7 @@ class TopSiteItemViewHolder(
class TopSiteItemMenu(
private val context: Context,
private val isPinnedSite: Boolean,
private val onItemTapped: (Item) -> Unit = {}
) {
sealed class Item {
@ -99,9 +101,12 @@ class TopSiteItemMenu(
) {
onItemTapped.invoke(Item.OpenInPrivateTab)
},
SimpleBrowserMenuItem(
context.getString(R.string.remove_top_site)
if (isPinnedSite) {
context.getString(R.string.remove_top_site)
} else {
context.getString(R.string.delete_from_history)
}
) {
onItemTapped.invoke(Item.RemoveTopSite)
}

@ -544,6 +544,8 @@
<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>
<!-- Text for the menu button to delete a top site from history -->
<string name="delete_from_history">Delete from history</string>
<!-- Postfix for private WebApp titles, placeholder is replaced with app name -->
<string name="pwa_site_controls_title_private">%1$s (Private Mode)</string>
<!-- Button in the current tab tray header in multiselect mode. Saved the selected tabs to a collection when pressed. -->

Loading…
Cancel
Save