mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/16587: Make sure tab counter correctly reflects private/normal tab counts
This commit is contained in:
parent
df087718e1
commit
0e37184204
@ -11,6 +11,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
|
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
|
||||||
|
import mozilla.components.browser.state.selector.selectedTab
|
||||||
|
import mozilla.components.browser.state.store.BrowserStore
|
||||||
import mozilla.components.concept.toolbar.Toolbar
|
import mozilla.components.concept.toolbar.Toolbar
|
||||||
import mozilla.components.lib.state.ext.flowScoped
|
import mozilla.components.lib.state.ext.flowScoped
|
||||||
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
import mozilla.components.support.ktx.android.content.res.resolveAttribute
|
||||||
@ -24,7 +26,6 @@ import java.lang.ref.WeakReference
|
|||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class TabCounterToolbarButton(
|
class TabCounterToolbarButton(
|
||||||
private val lifecycleOwner: LifecycleOwner,
|
private val lifecycleOwner: LifecycleOwner,
|
||||||
private val isPrivate: Boolean,
|
|
||||||
private val onItemTapped: (TabCounterMenu.Item) -> Unit = {},
|
private val onItemTapped: (TabCounterMenu.Item) -> Unit = {},
|
||||||
private val showTabs: () -> Unit
|
private val showTabs: () -> Unit
|
||||||
) : Toolbar.Action {
|
) : Toolbar.Action {
|
||||||
@ -37,7 +38,7 @@ class TabCounterToolbarButton(
|
|||||||
val settings = parent.context.components.settings
|
val settings = parent.context.components.settings
|
||||||
|
|
||||||
store.flowScoped(lifecycleOwner) { flow ->
|
store.flowScoped(lifecycleOwner) { flow ->
|
||||||
flow.map { state -> state.getNormalOrPrivateTabs(isPrivate).size }
|
flow.map { state -> state.getNormalOrPrivateTabs(isPrivate(store)).size }
|
||||||
.ifChanged()
|
.ifChanged()
|
||||||
.collect { tabs -> updateCount(tabs) }
|
.collect { tabs -> updateCount(tabs) }
|
||||||
}
|
}
|
||||||
@ -58,7 +59,7 @@ class TabCounterToolbarButton(
|
|||||||
|
|
||||||
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
|
||||||
override fun onViewAttachedToWindow(v: View?) {
|
override fun onViewAttachedToWindow(v: View?) {
|
||||||
setCount(store.state.getNormalOrPrivateTabs(isPrivate).size)
|
setCount(store.state.getNormalOrPrivateTabs(isPrivate(store)).size)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewDetachedFromWindow(v: View?) { /* no-op */ }
|
override fun onViewDetachedFromWindow(v: View?) { /* no-op */ }
|
||||||
@ -77,4 +78,8 @@ class TabCounterToolbarButton(
|
|||||||
private fun updateCount(count: Int) {
|
private fun updateCount(count: Int) {
|
||||||
reference.get()?.setCountWithAnimation(count)
|
reference.get()?.setCountWithAnimation(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isPrivate(store: BrowserStore): Boolean {
|
||||||
|
return store.state.selectedTab?.content?.private ?: false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user