Make mutable state flow in the bind function scope

Since the binder self is a singleton, we should always create a new
mutable state flow for the heights of the toolbar components.

Test: Manually tested. See bug.
Bug: 394739225
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: Iedaf058dbfa58bc54681e354300362935b8c7665
diff --git a/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
index d997ec5..cb4ab57 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ThemePickerToolbarBinder.kt
@@ -44,9 +44,7 @@
 import javax.inject.Inject
 import javax.inject.Singleton
 import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.flow.combine
-import kotlinx.coroutines.flow.filterNotNull
 import kotlinx.coroutines.launch
 
 @Singleton
@@ -54,9 +52,6 @@
 @Inject
 constructor(private val defaultToolbarBinder: DefaultToolbarBinder) : ToolbarBinder {
 
-    private val _toolbarHeights: MutableStateFlow<ToolbarHeightsViewModel?> = MutableStateFlow(null)
-    private val toolbarHeights = _toolbarHeights.asStateFlow().filterNotNull()
-
     override fun bind(
         navButton: FrameLayout,
         toolbar: Toolbar,
@@ -66,6 +61,8 @@
         lifecycleOwner: LifecycleOwner,
         onNavBack: () -> Unit,
     ) {
+        val toolbarHeights: MutableStateFlow<ToolbarHeightsViewModel?> = MutableStateFlow(null)
+
         defaultToolbarBinder.bind(
             navButton,
             toolbar,
@@ -86,8 +83,8 @@
             object : OnGlobalLayoutListener {
                 override fun onGlobalLayout() {
                     if (navButton.height != 0) {
-                        _toolbarHeights.value =
-                            _toolbarHeights.value?.copy(navButtonHeight = navButton.height)
+                        toolbarHeights.value =
+                            toolbarHeights.value?.copy(navButtonHeight = navButton.height)
                                 ?: ToolbarHeightsViewModel(navButtonHeight = navButton.height)
                     }
                     navButton.viewTreeObserver.removeOnGlobalLayoutListener(this)
@@ -99,8 +96,8 @@
             object : OnGlobalLayoutListener {
                 override fun onGlobalLayout() {
                     if (toolbar.height != 0) {
-                        _toolbarHeights.value =
-                            _toolbarHeights.value?.copy(toolbarHeight = toolbar.height)
+                        toolbarHeights.value =
+                            toolbarHeights.value?.copy(toolbarHeight = toolbar.height)
                                 ?: ToolbarHeightsViewModel(toolbarHeight = toolbar.height)
                     }
                     navButton.viewTreeObserver.removeOnGlobalLayoutListener(this)
@@ -112,8 +109,8 @@
             object : OnGlobalLayoutListener {
                 override fun onGlobalLayout() {
                     if (applyButton.height != 0) {
-                        _toolbarHeights.value =
-                            _toolbarHeights.value?.copy(applyButtonHeight = applyButton.height)
+                        toolbarHeights.value =
+                            toolbarHeights.value?.copy(applyButtonHeight = applyButton.height)
                                 ?: ToolbarHeightsViewModel(applyButtonHeight = applyButton.height)
                     }
                     applyButton.viewTreeObserver.removeOnGlobalLayoutListener(this)
@@ -184,7 +181,8 @@
                 launch {
                     combine(toolbarHeights, viewModel.isToolbarCollapsed, ::Pair).collect {
                         (toolbarHeights, isToolbarCollapsed) ->
-                        val (navButtonHeight, toolbarHeight, applyButtonHeight) = toolbarHeights
+                        val (navButtonHeight, toolbarHeight, applyButtonHeight) =
+                            toolbarHeights ?: return@collect
                         navButtonHeight ?: return@collect
                         toolbarHeight ?: return@collect
                         applyButtonHeight ?: return@collect