2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/19876 - Part 2: Add a Home screen button to the browser toolbar

This commit is contained in:
Gabriel Luong 2021-06-07 11:52:19 -04:00
parent 0e5e244e45
commit 155c119513
6 changed files with 48 additions and 0 deletions

View File

@ -76,6 +76,14 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
)
}
val homeAction = BrowserToolbar.Button(
imageDrawable = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_home)!!,
contentDescription = requireContext().getString(R.string.browser_toolbar_home),
listener = browserToolbarInteractor::onHomeButtonClicked
)
browserToolbarView.view.addNavigationAction(homeAction)
val readerModeAction =
BrowserToolbar.ToggleButton(
image = AppCompatResources.getDrawable(requireContext(), R.drawable.ic_readermode)!!,

View File

@ -23,6 +23,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.readermode.ReaderModeController
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.components.toolbar.interactor.BrowserToolbarInteractor
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
import org.mozilla.fenix.ext.nav
@ -40,6 +41,11 @@ interface BrowserToolbarController {
fun handleTabCounterClick()
fun handleTabCounterItemInteraction(item: TabCounterMenu.Item)
fun handleReaderModePressed(enabled: Boolean)
/**
* @see [BrowserToolbarInteractor.onHomeButtonClicked]
*/
fun handleHomeButtonClick()
}
class DefaultBrowserToolbarController(
@ -157,6 +163,12 @@ class DefaultBrowserToolbarController(
}
}
override fun handleHomeButtonClick() {
navController.navigateBlockingForAsyncNavGraph(
BrowserFragmentDirections.actionGlobalHome()
)
}
companion object {
internal const val TELEMETRY_BROWSER_IDENTIFIER = "browserMenu"
}

View File

@ -22,6 +22,11 @@ interface BrowserToolbarInteractor {
fun onTabCounterMenuItemTapped(item: TabCounterMenu.Item)
fun onScrolled(offset: Int)
fun onReaderModePressed(enabled: Boolean)
/**
* Navigates to the Home screen. Called when a user taps on the Home button.
*/
fun onHomeButtonClicked()
}
/**
@ -68,4 +73,8 @@ class DefaultBrowserToolbarInteractor(
override fun onReaderModePressed(enabled: Boolean) {
browserToolbarController.handleReaderModePressed(enabled)
}
override fun onHomeButtonClicked() {
browserToolbarController.handleHomeButtonClick()
}
}

View File

@ -173,6 +173,10 @@
<!-- Browser menu label for editing a bookmark -->
<string name="browser_menu_edit">Edit</string>
<!-- Browser Toolbar -->
<!-- Content description for the Home screen button on the browser toolbar -->
<string name="browser_toolbar_home">Home screen</string>
<!-- Error message to show when the user tries to access a scheme not
handled by the app (Ex: blob, tel etc) -->
<string name="unknown_scheme_error_message">Unable to connect. Unrecognizable URL scheme.</string>

View File

@ -312,6 +312,14 @@ class DefaultBrowserToolbarControllerTest {
verify(exactly = 0) { engineView.setVerticalClipping(10) }
}
@Test
fun handleHomeButtonClick() {
val controller = createController()
controller.handleHomeButtonClick()
verify { navController.navigate(BrowserFragmentDirections.actionGlobalHome()) }
}
private fun createController(
activity: HomeActivity = this.activity,
customTabSessionId: String? = null

View File

@ -68,4 +68,11 @@ class DefaultBrowserToolbarInteractorTest {
verify { browserToolbarMenuController.handleToolbarItemInteraction(item) }
}
@Test
fun onHomeButtonClicked() {
interactor.onHomeButtonClicked()
verify { browserToolbarController.handleHomeButtonClick() }
}
}