Skip to content

Commit

Permalink
For mozilla-mobile#3440 - Reduce BrowserFragment require calls
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods authored and ekager committed Sep 10, 2019
1 parent 8d363d6 commit 16115f5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
43 changes: 22 additions & 21 deletions app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
@Suppress("ComplexMethod", "LongMethod")
@CallSuper
protected open fun initializeUI(view: View): Session? {
val sessionManager = requireComponents.core.sessionManager
val context = requireContext()
val sessionManager = context.components.core.sessionManager

return getSessionById()?.also { session ->

val browserToolbarController = DefaultBrowserToolbarController(
context!!,
context,
findNavController(),
(activity as HomeActivity).browsingModeManager,
findInPageLauncher = { findInPageIntegration.withFeature { it.launch() } },
Expand All @@ -162,13 +163,13 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
viewModel = viewModel,
getSupportUrl = {
SupportUtils.getSumoURLForTopic(
context!!,
context,
SupportUtils.SumoTopic.HELP
)
},
openInFenixIntent = Intent(context, IntentReceiverActivity::class.java).also {
it.action = Intent.ACTION_VIEW
it.flags = Intent.FLAG_ACTIVITY_NEW_TASK
openInFenixIntent = Intent(context, IntentReceiverActivity::class.java).apply {
action = Intent.ACTION_VIEW
flags = Intent.FLAG_ACTIVITY_NEW_TASK
},
bottomSheetBehavior = QuickActionSheetBehavior.from(nestedScrollQuickAction)
)
Expand All @@ -192,7 +193,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs

findInPageIntegration.set(
feature = FindInPageIntegration(
sessionManager = requireComponents.core.sessionManager,
sessionManager = sessionManager,
sessionId = customTabSessionId,
stub = view.stubFindInPage,
engineView = view.engineView,
Expand All @@ -211,8 +212,8 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
requireFragmentManager(),
sessionManager,
FenixContextMenuCandidate.defaultCandidates(
requireContext(),
requireComponents.useCases.tabsUseCases,
context,
context.components.useCases.tabsUseCases,
view,
FenixSnackbarDelegate(
view,
Expand All @@ -226,19 +227,19 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
)

windowFeature.set(
feature = WindowFeature(requireComponents.core.sessionManager),
feature = WindowFeature(sessionManager),
owner = this,
view = view
)

downloadsFeature.set(
feature = DownloadsFeature(
requireContext().applicationContext,
context.applicationContext,
sessionManager = sessionManager,
fragmentManager = childFragmentManager,
sessionId = customTabSessionId,
downloadManager = FetchDownloadManager(
requireContext().applicationContext,
context.applicationContext,
DownloadService::class
),
onNeedToRequestPermissions = { permissions ->
Expand All @@ -250,7 +251,7 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs

appLinksFeature.set(
feature = AppLinksFeature(
requireContext(),
context,
sessionManager = sessionManager,
sessionId = customTabSessionId,
interceptLinkClicks = true,
Expand Down Expand Up @@ -285,11 +286,11 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
)

val accentHighContrastColor =
ThemeManager.resolveAttribute(R.attr.accentHighContrast, requireContext())
ThemeManager.resolveAttribute(R.attr.accentHighContrast, context)

sitePermissionsFeature.set(
feature = SitePermissionsFeature(
context = requireContext(),
context = context,
sessionManager = sessionManager,
fragmentManager = requireFragmentManager(),
promptsStyling = SitePermissionsFeature.PromptsStyling(
Expand Down Expand Up @@ -347,12 +348,12 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
@Suppress("ConstantConditionIf")
if (FeatureFlags.pullToRefreshEnabled) {
val primaryTextColor =
ThemeManager.resolveAttribute(R.attr.primaryText, requireContext())
ThemeManager.resolveAttribute(R.attr.primaryText, context)
view.swipeRefresh.setColorSchemeColors(primaryTextColor)
swipeRefreshFeature.set(
feature = SwipeRefreshFeature(
requireComponents.core.sessionManager,
requireComponents.useCases.sessionUseCases.reload,
sessionManager,
context.components.useCases.sessionUseCases.reload,
view.swipeRefresh,
customTabSessionId
),
Expand Down Expand Up @@ -472,9 +473,9 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
*/
protected open fun removeSessionIfNeeded(): Boolean {
getSessionById()?.let { session ->
if (session.source == Session.Source.ACTION_VIEW) requireComponents.core.sessionManager.remove(
session
)
if (session.source == Session.Source.ACTION_VIEW) {
requireComponents.core.sessionManager.remove(session)
}
}
return false
}
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.mozilla.fenix.components.toolbar.BrowserInteractor
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.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.home.sessioncontrol.SessionControlChange
Expand Down Expand Up @@ -86,19 +87,20 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
}

override fun initializeUI(view: View): Session? {
val sessionManager = requireComponents.core.sessionManager
val context = requireContext()
val sessionManager = context.components.core.sessionManager

return super.initializeUI(view)?.also {

readerViewFeature.set(
feature = ReaderViewFeature(
requireContext(),
requireComponents.core.engine,
requireComponents.core.sessionManager,
context,
context.components.core.engine,
sessionManager,
view.readerViewControlsBar
) { available ->
if (available) {
requireComponents.analytics.metrics.track(Event.ReaderModeAvailable)
context.components.analytics.metrics.track(Event.ReaderModeAvailable)
}

browserStore.apply {
Expand Down Expand Up @@ -153,16 +155,18 @@ class BrowserFragment : BaseBrowserFragment(), BackHandler {
browserToolbarController: BrowserToolbarController,
session: Session?
): BrowserToolbarViewInteractor {
val context = requireContext()

val interactor = BrowserInteractor(
context = context!!,
context = context,
store = browserStore,
browserToolbarController = browserToolbarController,
quickActionSheetController = DefaultQuickActionSheetController(
context = context!!,
context = context,
navController = findNavController(),
currentSession = getSessionById()
?: requireComponents.core.sessionManager.selectedSessionOrThrow,
appLinksUseCases = requireComponents.useCases.appLinksUseCases,
?: context.components.core.sessionManager.selectedSessionOrThrow,
appLinksUseCases = context.components.useCases.appLinksUseCases,
bookmarkTapped = {
lifecycleScope.launch { bookmarkTapped(it) }
}
Expand Down

0 comments on commit 16115f5

Please sign in to comment.