GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 95a01054 authored by Kainalu Hagiwara's avatar Kainalu Hagiwara Committed by liuche

For #12926 - Add back button to menu.

parent b346266f
......@@ -171,7 +171,15 @@ class DefaultBrowserToolbarController(
trackToolbarItemInteraction(item)
Do exhaustive when (item) {
ToolbarMenu.Item.Back -> sessionUseCases.goBack.invoke(currentSession)
is ToolbarMenu.Item.Back -> {
if (FeatureFlags.tabHistory && item.viewHistory) {
navController.navigate(R.id.action_global_tabHistoryDialogFragment)
} else if (!item.viewHistory) {
sessionUseCases.goBack.invoke(currentSession)
} else {
// Do nothing if tab history feature flag is off and item.viewHistory is true
}
}
is ToolbarMenu.Item.Forward -> {
if (FeatureFlags.tabHistory && item.viewHistory) {
navController.navigate(R.id.action_global_tabHistoryDialogFragment)
......@@ -350,7 +358,7 @@ class DefaultBrowserToolbarController(
@Suppress("ComplexMethod")
private fun trackToolbarItemInteraction(item: ToolbarMenu.Item) {
val eventItem = when (item) {
ToolbarMenu.Item.Back -> Event.BrowserMenuItemTapped.Item.BACK
is ToolbarMenu.Item.Back -> Event.BrowserMenuItemTapped.Item.BACK
is ToolbarMenu.Item.Forward -> Event.BrowserMenuItemTapped.Item.FORWARD
is ToolbarMenu.Item.Reload -> Event.BrowserMenuItemTapped.Item.RELOAD
ToolbarMenu.Item.Stop -> Event.BrowserMenuItemTapped.Item.STOP
......
......@@ -252,6 +252,7 @@ class BrowserToolbarView(
private fun ToolbarMenu.Item.performHapticIfNeeded(view: View) {
if (this is ToolbarMenu.Item.Reload && this.bypassCache ||
this is ToolbarMenu.Item.Back && this.viewHistory ||
this is ToolbarMenu.Item.Forward && this.viewHistory
) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
......
......@@ -74,6 +74,20 @@ class DefaultToolbarMenu(
}
override val menuToolbar by lazy {
val back = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_back,
primaryContentDescription = context.getString(R.string.browser_menu_back),
primaryImageTintResource = primaryTextColor(),
isInPrimaryState = {
session?.canGoBack ?: true
},
secondaryImageTintResource = ThemeManager.resolveAttribute(R.attr.disabled, context),
disableInSecondaryState = true,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = true)) }
) {
onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = false))
}
val forward = BrowserMenuItemToolbar.TwoStateButton(
primaryImageResource = mozilla.components.ui.icons.R.drawable.mozac_ic_forward,
primaryContentDescription = context.getString(R.string.browser_menu_forward),
......@@ -135,7 +149,7 @@ class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.Bookmark)
}
BrowserMenuItemToolbar(listOf(bookmark, share, forward, refresh))
BrowserMenuItemToolbar(listOf(back, forward, bookmark, share, refresh))
}
// Predicates that need to be repeatedly called as the session changes
......
......@@ -13,7 +13,7 @@ interface ToolbarMenu {
data class RequestDesktop(val isChecked: Boolean) : Item()
object FindInPage : Item()
object Share : Item()
object Back : Item()
data class Back(val viewHistory: Boolean) : Item()
data class Forward(val viewHistory: Boolean) : Item()
data class Reload(val bypassCache: Boolean) : Item()
object Stop : Item()
......
......@@ -59,9 +59,10 @@ class CustomTabToolbarMenu(
R.attr.disabled,
context
),
disableInSecondaryState = true
disableInSecondaryState = true,
longClickListener = { onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = true)) }
) {
onItemTapped.invoke(ToolbarMenu.Item.Back)
onItemTapped.invoke(ToolbarMenu.Item.Back(viewHistory = false))
}
val forward = BrowserMenuItemToolbar.TwoStateButton(
......
......@@ -217,7 +217,7 @@ class DefaultBrowserToolbarControllerTest {
@Test
fun handleToolbarBackPress() = runBlockingTest {
val item = ToolbarMenu.Item.Back
val item = ToolbarMenu.Item.Back(false)
val controller = createController(scope = this)
controller.handleToolbarItemInteraction(item)
......@@ -226,6 +226,17 @@ class DefaultBrowserToolbarControllerTest {
verify { sessionUseCases.goBack(currentSession) }
}
@Test
fun handleToolbarBackLongPress() = runBlockingTest {
val item = ToolbarMenu.Item.Back(true)
val controller = createController(scope = this)
controller.handleToolbarItemInteraction(item)
verify { metrics.track(Event.BrowserMenuItemTapped(Event.BrowserMenuItemTapped.Item.BACK)) }
verify { navController.navigate(R.id.action_global_tabHistoryDialogFragment) }
}
@Test
fun handleToolbarForwardPress() = runBlockingTest {
val item = ToolbarMenu.Item.Forward(false)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment