Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #10342 - Part 6: Show "Delete from history" instead of "Remove" f…
Browse files Browse the repository at this point in the history
…or top frecent sites in the top site menu
  • Loading branch information
gabrielluong authored and jonalmeida committed Aug 26, 2020
1 parent 40120ac commit 4f76699
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -83,6 +84,7 @@ class TopSiteItemViewHolder(

class TopSiteItemMenu(
private val context: Context,
private val isPinnedSite: Boolean,
private val onItemTapped: (Item) -> Unit = {}
) {
sealed class Item {
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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. -->
Expand Down

0 comments on commit 4f76699

Please sign in to comment.