Bug 1870939 - Add Share Page to PageActions in Toolbar

fenix/125.0
Harrison Oglesby 4 months ago committed by mergify[bot]
parent 1cad570d3c
commit ff3f340c91

@ -46,6 +46,7 @@ import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.appstate.AppAction
import org.mozilla.fenix.components.toolbar.BrowserToolbarView
import org.mozilla.fenix.components.toolbar.IncompleteRedesignToolbarFeature
import org.mozilla.fenix.components.toolbar.ToolbarMenu
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
@ -163,6 +164,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
browserToolbarView.view.addPageAction(readerModeAction)
initTranslationsAction(context, view)
initSharePageAction(context)
initReviewQualityCheck(context, view)
thumbnailsFeature.set(
@ -274,6 +276,25 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
}
}
private fun initSharePageAction(context: Context) {
if (!IncompleteRedesignToolbarFeature(context.settings()).isEnabled) {
return
}
val sharePageAction =
BrowserToolbar.Button(
imageDrawable = AppCompatResources.getDrawable(
context,
R.drawable.mozac_ic_share_android_24,
)!!,
contentDescription = getString(R.string.browser_menu_share),
iconTintColorResource = ThemeManager.resolveAttribute(R.attr.textPrimary, context),
listener = { browserToolbarInteractor.onShareActionClicked() },
)
browserToolbarView.view.addPageAction(sharePageAction)
}
private fun initTranslationsAction(context: Context, view: View) {
if (!context.settings().enableTranslations) {
return

@ -7,11 +7,13 @@ package org.mozilla.fenix.components.toolbar
import androidx.navigation.NavController
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.EngineView
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.service.glean.private.NoExtras
import mozilla.components.support.ktx.kotlin.isUrl
@ -19,6 +21,7 @@ import mozilla.components.ui.tabcounter.TabCounterMenu
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.ReaderMode
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserAnimator
import org.mozilla.fenix.browser.BrowserAnimator.Companion.getToolbarNavOptions
@ -69,6 +72,11 @@ interface BrowserToolbarController {
* @see [BrowserToolbarInteractor.onTranslationsButtonClicked]
*/
fun handleTranslationsButtonClick()
/**
* @see [BrowserToolbarInteractor.onShareActionClicked]
*/
fun onShareActionClicked()
}
private const val MAX_DISPLAY_NUMBER_SHOPPING_CFR = 3
@ -229,6 +237,31 @@ class DefaultBrowserToolbarController(
navController.navigateSafe(R.id.browserFragment, directions)
}
override fun onShareActionClicked() {
val directions = NavGraphDirections.actionGlobalShareFragment(
sessionId = currentSession?.id,
data = arrayOf(
ShareData(
url = getProperUrl(currentSession),
title = currentSession?.content?.title,
),
),
showPage = true,
)
navController.navigate(directions)
}
private fun getProperUrl(currentSession: SessionState?): String? {
return currentSession?.id?.let {
val currentTab = store.state.findTab(it)
if (currentTab?.readerState?.active == true) {
currentTab.readerState.activeUrl
} else {
currentSession.content.url
}
}
}
companion object {
internal const val TELEMETRY_BROWSER_IDENTIFIER = "browserMenu"
}

@ -48,6 +48,11 @@ interface BrowserToolbarInteractor {
* action.
*/
fun onTranslationsButtonClicked()
/**
* Opens the share fragment. Called when the user clicks the "Share" action in the toolbar.
*/
fun onShareActionClicked()
}
/**
@ -114,4 +119,8 @@ class DefaultBrowserToolbarInteractor(
override fun onTranslationsButtonClicked() {
browserToolbarController.handleTranslationsButtonClick()
}
override fun onShareActionClicked() {
browserToolbarController.onShareActionClicked()
}
}

Loading…
Cancel
Save