2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00
And also add CustomTabsServiceStore
This commit is contained in:
Tiger Oakes 2019-09-20 10:28:49 -07:00 committed by Emily Kager
parent 14aab129d6
commit 222adb3656
5 changed files with 55 additions and 21 deletions

View File

@ -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.
*/

View File

@ -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

View File

@ -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() {

View File

@ -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 }
}

View File

@ -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<CustomTabsIntegration>()
private val hideToolbarFeature = ViewBoundFeatureWrapper<WebAppHideToolbarFeature>()
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)
}
}