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

Commit 1639f57b authored by Anton Potapov's avatar Anton Potapov
Browse files

Don't hide a slider if it's already being shown in the VolumeDialog

As the VolumeDialogImpl we want to continue showing a slider if it has
already being shown in the dialog.

Flag: com.android.systemui.volume_redesign
Bug: 369992924
Test: atest VolumeDialogSlidersInteractorTest
Change-Id: I8a6c10f60fb2ac9bcb9d1e7688d4d233ef7d775f
parent 108818e1
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -155,6 +155,30 @@ class VolumeDialogSlidersInteractorTest : SysuiTestCase() {
            }
        }

    @Test
    fun activeStreamChanges_showBoth() {
        with(kosmos) {
            testScope.runTest {
                runCurrent()
                fakeVolumeDialogController.updateState {
                    activeStream = AudioManager.STREAM_SYSTEM
                    states.put(AudioManager.STREAM_MUSIC, buildStreamState())
                    states.put(AudioManager.STREAM_SYSTEM, buildStreamState())
                }
                val slidersModel by collectLastValue(underTest.sliders)
                runCurrent()

                fakeVolumeDialogController.updateState { activeStream = AudioManager.STREAM_MUSIC }
                runCurrent()

                assertThat(slidersModel!!.slider)
                    .isEqualTo(VolumeDialogSliderType.Stream(AudioManager.STREAM_MUSIC))
                assertThat(slidersModel!!.floatingSliders)
                    .containsExactly(VolumeDialogSliderType.Stream(AudioManager.STREAM_SYSTEM))
            }
        }
    }

    private fun buildStreamState(
        build: VolumeDialogController.StreamState.() -> Unit = {}
    ): VolumeDialogController.StreamState {
+11 −6
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.runningReduce
import kotlinx.coroutines.flow.stateIn

private const val DEFAULT_STREAM = AudioManager.STREAM_MUSIC
@@ -54,13 +55,17 @@ constructor(
        volumeDialogStateInteractor.volumeDialogState
            .filter { it.streamModels.isNotEmpty() }
            .map { stateModel ->
                val sliderTypes =
                    stateModel.streamModels.values
                        .filter { streamModel -> shouldShowSliders(stateModel, streamModel) }
                        .sortedWith(streamsSorter)
                        .map { model -> model.toType() }
                LinkedHashSet(sliderTypes)
            }
            .map { models ->
                val sliderTypes: List<VolumeDialogSliderType> =
                    models.map { model -> model.toType() }
            .runningReduce { sliderTypes, newSliderTypes ->
                newSliderTypes.apply { addAll(sliderTypes) }
            }
            .map { sliderTypes ->
                VolumeDialogSlidersModel(
                    slider = sliderTypes.first(),
                    floatingSliders = sliderTypes.drop(1),