1
0
Fork 0

For #10989 - Fixes memory leak caused by retaining the TabTrayView and TabsFeature

master
Jeff Boek 2020-06-02 23:03:20 -07:00 committed by Emily Kager
parent 06d9133cb9
commit bc53b94feb
2 changed files with 34 additions and 19 deletions

View File

@ -24,7 +24,9 @@ import mozilla.components.browser.state.selector.privateTabs
import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.state.BrowserState
import mozilla.components.concept.engine.prompt.ShareData import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.tabstray.Tab import mozilla.components.concept.tabstray.Tab
import mozilla.components.feature.tabs.tabstray.TabsFeature
import mozilla.components.lib.state.ext.consumeFrom import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode import org.mozilla.fenix.browser.browsingmode.BrowsingMode
@ -36,7 +38,10 @@ import org.mozilla.fenix.utils.allowUndo
@SuppressWarnings("TooManyFunctions") @SuppressWarnings("TooManyFunctions")
class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor { class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
private lateinit var tabTrayView: TabTrayView private val tabsFeature = ViewBoundFeatureWrapper<TabsFeature>()
private var _tabTrayView: TabTrayView? = null
private val tabTrayView: TabTrayView
get() = _tabTrayView!!
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -59,11 +64,26 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
tabTrayView = TabTrayView( val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate
_tabTrayView = TabTrayView(
view.tabLayout, view.tabLayout,
this, this,
(activity as HomeActivity).browsingModeManager.mode.isPrivate, isPrivate,
requireContext().resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE requireContext().resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
) { tabsFeature.get()?.filterTabs(it) }
tabsFeature.set(
TabsFeature(
tabTrayView.view.tabsTray,
view.context.components.core.store,
view.context.components.useCases.tabsUseCases,
view.context.components.useCases.thumbnailUseCases,
{ it.content.private == isPrivate },
{ }
),
viewLifecycleOwner,
view
) )
tabLayout.setOnClickListener { tabLayout.setOnClickListener {
@ -90,6 +110,11 @@ class TabTrayDialogFragment : AppCompatDialogFragment(), TabTrayInteractor {
} }
} }
override fun onDestroyView() {
super.onDestroyView()
_tabTrayView = null
}
override fun onTabClosed(tab: Tab) { override fun onTabClosed(tab: Tab) {
val sessionManager = view?.context?.components?.core?.sessionManager val sessionManager = view?.context?.components?.core?.sessionManager
val snapshot = sessionManager val snapshot = sessionManager

View File

@ -26,7 +26,6 @@ import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.tabstray.BrowserTabsTray import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.concept.tabstray.Tab import mozilla.components.concept.tabstray.Tab
import mozilla.components.concept.tabstray.TabsTray import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.feature.tabs.tabstray.TabsFeature
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -45,8 +44,9 @@ interface TabTrayInteractor {
class TabTrayView( class TabTrayView(
private val container: ViewGroup, private val container: ViewGroup,
private val interactor: TabTrayInteractor, private val interactor: TabTrayInteractor,
private val isPrivate: Boolean, isPrivate: Boolean,
private val startingInLandscape: Boolean startingInLandscape: Boolean,
private val filterTabs: ((TabSessionState) -> Boolean) -> Unit
) : LayoutContainer, TabsTray.Observer, TabLayout.OnTabSelectedListener { ) : LayoutContainer, TabsTray.Observer, TabLayout.OnTabSelectedListener {
val fabView = LayoutInflater.from(container.context) val fabView = LayoutInflater.from(container.context)
.inflate(R.layout.component_tabstray_fab, container, true) .inflate(R.layout.component_tabstray_fab, container, true)
@ -57,7 +57,7 @@ class TabTrayView(
val isPrivateModeSelected: Boolean get() = view.tab_layout.selectedTabPosition == PRIVATE_TAB_ID val isPrivateModeSelected: Boolean get() = view.tab_layout.selectedTabPosition == PRIVATE_TAB_ID
private val behavior = BottomSheetBehavior.from(view.tab_wrapper) private val behavior = BottomSheetBehavior.from(view.tab_wrapper)
private var tabsFeature: TabsFeature
private var tabTrayItemMenu: TabTrayItemMenu private var tabTrayItemMenu: TabTrayItemMenu
private var hasLoaded = false private var hasLoaded = false
@ -96,15 +96,6 @@ class TabTrayView(
view.tab_layout.addOnTabSelectedListener(this) view.tab_layout.addOnTabSelectedListener(this)
tabsFeature = TabsFeature(
view.tabsTray,
view.context.components.core.store,
view.context.components.useCases.tabsUseCases,
view.context.components.useCases.thumbnailUseCases,
{ it.content.private == isPrivate },
{ }
)
val tabs = if (isPrivate) { val tabs = if (isPrivate) {
view.context.components.core.store.state.privateTabs view.context.components.core.store.state.privateTabs
} else { } else {
@ -160,8 +151,7 @@ class TabTrayView(
interactor.onNewTabTapped(isPrivateModeSelected) interactor.onNewTabTapped(isPrivateModeSelected)
} }
tabsTray.register(this) tabsTray.register(this, view)
tabsFeature.start()
} }
fun expand() { fun expand() {
@ -180,7 +170,7 @@ class TabTrayView(
} }
toggleFabText(isPrivateModeSelected) toggleFabText(isPrivateModeSelected)
tabsFeature.filterTabs(filter) filterTabs.invoke(filter)
updateState(view.context.components.core.store.state) updateState(view.context.components.core.store.state)
} }