1
0
Fork 0

For #6229 - Remove all tab options from custom tab context menu

master
ekager 2019-10-24 21:38:15 -07:00 committed by Emily Kager
parent 6435a503ca
commit fb17ae2258
4 changed files with 96 additions and 20 deletions

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.browser
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.graphics.Color
@ -73,12 +74,12 @@ import org.mozilla.fenix.components.toolbar.ToolbarIntegration
import org.mozilla.fenix.downloads.DownloadService
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.enterToImmersiveMode
import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.isInExperiment
import org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior
import org.mozilla.fenix.settings.SupportUtils
@ -235,16 +236,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
feature = ContextMenuFeature(
fragmentManager = parentFragmentManager,
store = store,
candidates = ContextMenuCandidate.defaultCandidates(
context,
context.components.useCases.tabsUseCases,
context.components.useCases.contextMenuUseCases,
view,
FenixSnackbarDelegate(
view,
if (getSessionById()?.isCustomTabSession() == true) null else nestedScrollQuickAction
)
),
candidates = getContextMenuCandidates(context, view),
engineView = view.engineView,
useCases = context.components.useCases.contextMenuUseCases,
customTabId = customTabSessionId
@ -404,6 +396,14 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
}
}
/**
* Returns a list of context menu items [ContextMenuCandidate] for the context menu
*/
protected abstract fun getContextMenuCandidates(
context: Context,
view: View
): List<ContextMenuCandidate>
private fun adjustBackgroundAndNavigate(directions: NavDirections) {
context?.let {
swipeRefresh?.background = ColorDrawable(Color.TRANSPARENT)
@ -521,7 +521,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
if (session.source == Session.Source.ACTION_VIEW) {
sessionManager.remove(session)
} else {
val isLastSession = sessionManager.sessionsOfType(private = session.private).count() == 1
val isLastSession =
sessionManager.sessionsOfType(private = session.private).count() == 1
sessionManager.remove(session, true)
return !isLastSession // Jump to tab overview if last session was removed
}

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.browser
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
@ -23,6 +24,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.transition.TransitionInflater
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.fragment_browser.*
import kotlinx.android.synthetic.main.fragment_browser.view.*
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.*
import kotlinx.coroutines.Dispatchers.IO
@ -32,6 +34,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.browser.session.Session
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.lib.state.ext.consumeFrom
@ -50,11 +53,11 @@ import org.mozilla.fenix.components.toolbar.BrowserToolbarController
import org.mozilla.fenix.components.toolbar.BrowserToolbarViewInteractor
import org.mozilla.fenix.components.toolbar.QuickActionSheetAction
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getDimenInDip
import org.mozilla.fenix.ext.increaseTapArea
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.getDimenInDip
import org.mozilla.fenix.home.sessioncontrol.SessionControlChange
import org.mozilla.fenix.home.sessioncontrol.TabCollection
import org.mozilla.fenix.mvi.getManagedEmitter
@ -391,13 +394,28 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
val xOffset = it.dimen(R.dimen.tp_onboarding_x_offset)
// Positioning the popup above the tp anchor.
val yOffset = -containerHeight - (browserToolbarView.view.height / THREE * 2) + triangleHeight
val yOffset =
-containerHeight - (browserToolbarView.view.height / THREE * 2) + triangleHeight
trackingOnboarding.showAsDropDown(tpIcon, xOffset, yOffset)
it.settings().incrementTrackingProtectionOnboardingCount()
}
}
override fun getContextMenuCandidates(
context: Context,
view: View
): List<ContextMenuCandidate> = ContextMenuCandidate.defaultCandidates(
context,
context.components.useCases.tabsUseCases,
context.components.useCases.contextMenuUseCases,
view,
FenixSnackbarDelegate(
view,
nestedScrollQuickAction
)
)
private fun shouldShowTrackingProtectionOnboarding(session: Session) =
context?.settings()?.shouldShowTrackingProtectionOnboarding ?: false &&
session.trackerBlockingEnabled && session.trackersBlocked.isNotEmpty()

View File

@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.browser
import android.content.Context
import android.view.View
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.contextmenu.ContextMenuUseCases
import mozilla.components.feature.contextmenu.DefaultSnackbarDelegate
class CustomTabContextMenuCandidate {
companion object {
/**
* Returns the default list of context menu candidates for custom tabs/external apps.
*
*/
fun defaultCandidates(
context: Context,
contextMenuUseCases: ContextMenuUseCases,
snackBarParentView: View,
snackbarDelegate: ContextMenuCandidate.SnackbarDelegate = DefaultSnackbarDelegate()
): List<ContextMenuCandidate> = listOf(
ContextMenuCandidate.createCopyLinkCandidate(
context,
snackBarParentView,
snackbarDelegate
),
ContextMenuCandidate.createShareLinkCandidate(context),
ContextMenuCandidate.createSaveImageCandidate(context, contextMenuUseCases),
ContextMenuCandidate.createCopyImageLocationCandidate(
context,
snackBarParentView,
snackbarDelegate
)
)
}
}

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.customtabs
import android.content.Context
import android.view.Gravity
import android.view.View
import androidx.core.view.isGone
@ -14,6 +15,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import mozilla.components.browser.session.Session
import mozilla.components.concept.engine.manifest.WebAppManifestParser
import mozilla.components.concept.engine.manifest.getOrNull
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.pwa.ext.getTrustedScope
import mozilla.components.feature.pwa.ext.trustedOrigins
import mozilla.components.feature.pwa.feature.WebAppActivityFeature
@ -25,6 +27,8 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BaseBrowserFragment
import org.mozilla.fenix.browser.CustomTabContextMenuCandidate
import org.mozilla.fenix.browser.FenixSnackbarDelegate
import org.mozilla.fenix.components.toolbar.BrowserToolbarController
import org.mozilla.fenix.components.toolbar.BrowserToolbarInteractor
import org.mozilla.fenix.ext.components
@ -76,7 +80,8 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
updateLayoutMargins(inFullScreen = !toolbarVisible)
},
owner = this,
view = toolbar)
view = toolbar
)
if (manifest != null) {
activity.lifecycle.addObserver(
@ -143,11 +148,11 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
val directions =
ExternalAppBrowserFragmentDirections
.actionExternalAppBrowserFragmentToTrackingProtectionPanelDialogFragment(
sessionId = session.id,
url = session.url,
trackingProtectionEnabled = session.trackerBlockingEnabled,
gravity = getAppropriateLayoutGravity()
)
sessionId = session.id,
url = session.url,
trackingProtectionEnabled = session.trackerBlockingEnabled,
gravity = getAppropriateLayoutGravity()
)
nav(R.id.externalAppBrowserFragment, directions)
}
@ -161,5 +166,18 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler {
}
}
override fun getContextMenuCandidates(
context: Context,
view: View
): List<ContextMenuCandidate> = CustomTabContextMenuCandidate.defaultCandidates(
context,
context.components.useCases.contextMenuUseCases,
view,
FenixSnackbarDelegate(
view,
null
)
)
override fun getAppropriateLayoutGravity() = Gravity.TOP
}