diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index bef44d40b..79c736f31 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -344,15 +344,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs toolbar.visibility = View.VISIBLE nestedScrollQuickAction.visibility = View.VISIBLE } - view.swipeRefresh.apply { - val (topMargin, bottomMargin) = if (inFullScreen) 0 to 0 else getEngineMargins() - (layoutParams as CoordinatorLayout.LayoutParams).setMargins( - 0, - topMargin, - 0, - bottomMargin - ) - } + updateLayoutMargins(inFullScreen) }, owner = this, view = view @@ -526,6 +518,13 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs */ protected abstract fun getAppropriateLayoutGravity(): Int + protected fun updateLayoutMargins(inFullScreen: Boolean) { + view?.swipeRefresh?.apply { + val (topMargin, bottomMargin) = if (inFullScreen) 0 to 0 else getEngineMargins() + (layoutParams as CoordinatorLayout.LayoutParams).setMargins(0, topMargin, 0, bottomMargin) + } + } + /** * Updates the site permissions rules based on user settings. */ diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 0db566fc0..d07b22338 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -25,6 +25,7 @@ import mozilla.components.concept.engine.Engine import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy import mozilla.components.concept.engine.mediaquery.PreferredColorScheme import mozilla.components.concept.fetch.Client +import mozilla.components.feature.customtabs.store.CustomTabsServiceStore import mozilla.components.feature.media.MediaFeature import mozilla.components.feature.media.RecordingDevicesNotificationFeature import mozilla.components.feature.media.state.MediaStateMachine @@ -83,6 +84,11 @@ class Core(private val context: Context) { BrowserStore() } + /** + * The [CustomTabsServiceStore] holds global custom tabs related data. + */ + val customTabsStore by lazy { CustomTabsServiceStore() } + /** * The session manager component provides access to a centralized registry of * all browser sessions (i.e. tabs). It is initialized here to persist and restore diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt index fad51ec24..baa76a4a2 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsIntegration.kt @@ -5,7 +5,6 @@ package org.mozilla.fenix.customtabs import android.app.Activity -import android.content.Context import android.view.Gravity import android.view.View import androidx.appcompat.content.res.AppCompatResources @@ -25,11 +24,10 @@ import org.mozilla.fenix.ext.settings import org.mozilla.fenix.theme.ThemeManager class CustomTabsIntegration( - context: Context, sessionManager: SessionManager, toolbar: BrowserToolbar, sessionId: String, - activity: Activity?, + activity: Activity, quickActionbar: NestedScrollView, engineLayout: View, onItemTapped: (ToolbarMenu.Item) -> Unit = {} @@ -59,24 +57,24 @@ class CustomTabsIntegration( val task = LottieCompositionFactory .fromRawRes( - context, - ThemeManager.resolveAttribute(R.attr.shieldLottieFile, context) + activity, + ThemeManager.resolveAttribute(R.attr.shieldLottieFile, activity) ) task.addListener { result -> val lottieDrawable = LottieDrawable() lottieDrawable.composition = result toolbar.displayTrackingProtectionIcon = - context.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories + activity.settings.shouldUseTrackingProtection && FeatureFlags.etpCategories toolbar.displaySeparatorView = false toolbar.setTrackingProtectionIcons( iconOnNoTrackersBlocked = AppCompatResources.getDrawable( - context, + activity, R.drawable.ic_tracking_protection_enabled )!!, iconOnTrackersBlocked = lottieDrawable, iconDisabledForSite = AppCompatResources.getDrawable( - context, + activity, R.drawable.ic_tracking_protection_disabled )!! ) @@ -85,7 +83,7 @@ class CustomTabsIntegration( private val customTabToolbarMenu by lazy { CustomTabToolbarMenu( - context, + activity, sessionManager, sessionId, onItemTapped = onItemTapped @@ -98,8 +96,8 @@ class CustomTabsIntegration( sessionId, menuBuilder = customTabToolbarMenu.menuBuilder, menuItemIndex = START_OF_MENU_ITEMS_INDEX, - window = activity?.window, - closeListener = { activity?.finish() } + window = activity.window, + closeListener = { activity.finish() } ) override fun start() { diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt index 016cddf82..8ed621ca6 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/CustomTabsService.kt @@ -10,4 +10,5 @@ import org.mozilla.fenix.ext.components class CustomTabsService : AbstractCustomTabsService() { override val engine: Engine by lazy { applicationContext.components.core.engine } + override val customTabsServiceStore by lazy { applicationContext.components.core.customTabsStore } } diff --git a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt index 03d280562..389c4e477 100644 --- a/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/customtabs/ExternalAppBrowserFragment.kt @@ -11,6 +11,8 @@ import kotlinx.android.synthetic.main.fragment_browser.view.* import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ObsoleteCoroutinesApi import mozilla.components.browser.session.Session +import mozilla.components.feature.pwa.ext.trustedOrigins +import mozilla.components.feature.pwa.feature.WebAppHideToolbarFeature import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.support.base.feature.BackHandler @@ -19,6 +21,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.browser.BaseBrowserFragment import org.mozilla.fenix.components.toolbar.BrowserToolbarController import org.mozilla.fenix.components.toolbar.BrowserToolbarInteractor +import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents @@ -30,14 +33,16 @@ import org.mozilla.fenix.ext.requireComponents class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler { private val customTabsIntegration = ViewBoundFeatureWrapper() + private val hideToolbarFeature = ViewBoundFeatureWrapper() override fun initializeUI(view: View): Session? { return super.initializeUI(view)?.also { + val activity = requireActivity() + val components = activity.components customTabSessionId?.let { customTabSessionId -> customTabsIntegration.set( feature = CustomTabsIntegration( - requireContext(), requireComponents.core.sessionManager, toolbar, customTabSessionId, @@ -48,11 +53,36 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), BackHandler { ), owner = this, view = view) + + hideToolbarFeature.set( + feature = WebAppHideToolbarFeature( + requireComponents.core.sessionManager, + toolbar, + customTabSessionId, + emptyList() + ) { toolbarVisible -> + updateLayoutMargins(inFullScreen = !toolbarVisible) + }, + owner = this, + view = toolbar) } consumeFrom(browserStore) { browserToolbarView.update(it) } + + consumeFrom(components.core.customTabsStore) { state -> + getSessionById() + ?.let { session -> session.customTabConfig?.sessionToken } + ?.let { token -> state.tabs[token] } + ?.let { tabState -> + hideToolbarFeature.withFeature { + it.onTrustedScopesChange(tabState.trustedOrigins) + } + } + } + + updateLayoutMargins(false) } }