Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 323a8f0d authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Refresh to non null state for new tiles on creation

When a new tile (QSTileViewModel + QSTileViewModelAdapter) is created,
we launch a collection to have a first state. The problem is that
when we moved from SharedFlow (without initial state) to StateFlow
(with `null` initial state), calling `first` just returns `null` and
stops the collection. Instead, continue collecting until we have a non
null state. This has a couple of effects:

* Non null state in dumps if QS has never been opened (or has just been
  opened).
* This translates in tiles already showing UI state on first open as
  opposed to appearing blank.
* Also, it should reduce the number of updates to UI on first opening
  the shade.

Test: manual
Test: atest com.android.systemui.qs
Test: atest CtsTileServiceTestCases
Fixes: 356621310
Fixes: 346392367
Flag: com.android.systemui.qs_new_tiles

Change-Id: Id2a86d183e01e828b5c273ff7864dd6a0e44dd80
parent a9f30c2a
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -39,10 +39,10 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collectIndexed
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch

// TODO(b/http://b/299909989): Use QSTileViewModel directly after the rollout
@@ -87,8 +87,9 @@ constructor(
                        }
                    }
                }
                // Warm up tile with some initial state
                launch { qsTileViewModel.state.first() }
                // Warm up tile with some initial state. Because `state` is a StateFlow with initial
                // state `null`, we collect until it's not null.
                launch { qsTileViewModel.state.takeWhile { it == null }.collect {} }
            }

        // QSTileHost doesn't call this when userId is initialized