2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

[fenix] Fixes https://github.com/mozilla-mobile/fenix/issues/1517 - Filter private sessions when updating the tab counter

This commit is contained in:
Vlad Baicu 2019-04-10 18:20:13 +03:00 committed by Emily Kager
parent f26f567915
commit 465ad95bf9
2 changed files with 11 additions and 12 deletions

View File

@ -11,9 +11,7 @@ import android.view.ViewGroup
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.toolbar.Toolbar import mozilla.components.concept.toolbar.Toolbar
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.asActivity
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
/** /**
@ -21,7 +19,8 @@ import java.lang.ref.WeakReference
*/ */
class TabCounterToolbarButton( class TabCounterToolbarButton(
private val sessionManager: SessionManager, private val sessionManager: SessionManager,
private val showTabs: () -> Unit private val showTabs: () -> Unit,
private val isPrivate: Boolean
) : Toolbar.Action { ) : Toolbar.Action {
private var reference: WeakReference<TabCounter> = WeakReference<TabCounter>(null) private var reference: WeakReference<TabCounter> = WeakReference<TabCounter>(null)
@ -30,12 +29,9 @@ class TabCounterToolbarButton(
val view = TabCounter(parent.context).apply { val view = TabCounter(parent.context).apply {
reference = WeakReference(this) reference = WeakReference(this)
setCount( setCount(sessionManager.sessions.count {
(sessionManager.sessions it.private == isPrivate
.filter { })
(context.asActivity() as? HomeActivity)?.browsingModeManager?.isPrivate == it.private
}).size
)
setOnClickListener { setOnClickListener {
it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) it.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
showTabs.invoke() showTabs.invoke()
@ -58,7 +54,9 @@ class TabCounterToolbarButton(
override fun bind(view: View) = Unit override fun bind(view: View) = Unit
private fun updateCount() { private fun updateCount() {
reference.get()?.setCountWithAnimation(sessionManager.sessions.size) reference.get()?.setCountWithAnimation(sessionManager.sessions.count {
it.private == isPrivate
})
} }
private val sessionManagerObserver = object : SessionManager.Observer { private val sessionManagerObserver = object : SessionManager.Observer {

View File

@ -39,10 +39,11 @@ class ToolbarIntegration(
val tabsAction = TabCounterToolbarButton( val tabsAction = TabCounterToolbarButton(
sessionManager, sessionManager,
showTabs = { {
Navigation.findNavController(toolbar) Navigation.findNavController(toolbar)
.navigate(BrowserFragmentDirections.actionBrowserFragmentToHomeFragment()) .navigate(BrowserFragmentDirections.actionBrowserFragmentToHomeFragment())
} },
isPrivate
) )
toolbar.addBrowserAction(tabsAction) toolbar.addBrowserAction(tabsAction)
} }