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

Commit 649a7fb8 authored by Anton Potapov's avatar Anton Potapov
Browse files

Update icons when value changes

Flag: com.android.systemui.volume_redesign
Fixes: 401643986
Test: manual on the phone. Adjust volume add see that the icon changes
Test: atest VolumeDialogScreenshotTest
Change-Id: Iedba525dd33bf52202bb36eeff5d4968b4177150
parent 69c08bc0
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
@@ -78,11 +77,16 @@ constructor(

    private val userVolumeUpdates = MutableStateFlow<VolumeUpdate?>(null)
    private val model: Flow<VolumeDialogStreamModel> =
        interactor.slider
            .filter {
                val currentVolumeUpdate = userVolumeUpdates.value ?: return@filter true
        combine(interactor.slider, userVolumeUpdates) { model, currentVolumeUpdate ->
                currentVolumeUpdate ?: return@combine model
                val lastVolumeUpdateTime = currentVolumeUpdate.timestampMillis
                getTimestampMillis() - lastVolumeUpdateTime > VOLUME_UPDATE_GRACE_PERIOD
                val shouldIgnoreUpdates =
                    getTimestampMillis() - lastVolumeUpdateTime < VOLUME_UPDATE_GRACE_PERIOD
                if (shouldIgnoreUpdates) {
                    model.copy(level = currentVolumeUpdate.newVolumeLevel)
                } else {
                    model
                }
            }
            .stateIn(coroutineScope, SharingStarted.Eagerly, null)
            .filterNotNull()