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

Commit ac7a0d77 authored by Anton Potapov's avatar Anton Potapov
Browse files

Bind the new sliders to the state updates.

This CL makes updates slider values from the state and updates the
state when the slider value changes

Flag: com.android.systemui.volume_redesign
Test: manual on foldable. Adjust volume of different streams
Bug: 369992924
Change-Id: I39da31fab1b5598722b16d051ca18d96e97d0bbd
parent 046855a0
Loading
Loading
Loading
Loading
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.sliders.domain.interactor

import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.VolumeDialogController
import com.android.systemui.plugins.fakeVolumeDialogController
import com.android.systemui.testKosmos
import com.android.systemui.volume.dialog.sliders.domain.model.volumeDialogSliderType
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
class VolumeDialogSliderInteractorTest : SysuiTestCase() {

    private val kosmos = testKosmos()

    private lateinit var underTest: VolumeDialogSliderInteractor

    @Before
    fun setUp() {
        underTest = kosmos.volumeDialogSliderInteractor
    }

    @Test
    fun settingStreamVolume_setsActiveStream() =
        with(kosmos) {
            testScope.runTest {
                runCurrent()
                // initialize the stream model
                fakeVolumeDialogController.setStreamVolume(volumeDialogSliderType.audioStream, 0)

                val sliderModel by collectLastValue(underTest.slider)
                underTest.setStreamVolume(1)
                runCurrent()

                assertThat(sliderModel!!.isActive).isTrue()
            }
        }

    @Test
    fun streamVolumeIs_minMaxAreEnforced() =
        with(kosmos) {
            testScope.runTest {
                runCurrent()
                fakeVolumeDialogController.updateState {
                    states.put(
                        volumeDialogSliderType.audioStream,
                        VolumeDialogController.StreamState().apply {
                            levelMin = 0
                            level = 2
                            levelMax = 1
                        },
                    )
                }

                val sliderModel by collectLastValue(underTest.slider)
                runCurrent()

                assertThat(sliderModel!!.level).isEqualTo(1)
            }
        }
}
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
        android:showDividers="middle" />

    <LinearLayout
        android:id="@+id/volume_dialog"
        android:layout_width="@dimen/volume_dialog_width"
        android:layout_height="wrap_content"
        android:background="@drawable/volume_dialog_background"
@@ -50,9 +51,7 @@
            android:layout_width="@dimen/volume_dialog_button_size"
            android:layout_height="@dimen/volume_dialog_button_size" />

        <include
            android:id="@+id/volume_dialog_slider"
            layout="@layout/volume_dialog_slider" />
        <include layout="@layout/volume_dialog_slider" />

        <Button
            android:id="@+id/volume_dialog_settings"
+2 −2
Original line number Diff line number Diff line
@@ -105,8 +105,8 @@ constructor(
            scope.trySend(VolumeDialogEventModel.ShowSafetyWarning(flags))
        }

        override fun onAccessibilityModeChanged(showA11yStream: Boolean) {
            scope.trySend(VolumeDialogEventModel.AccessibilityModeChanged(showA11yStream))
        override fun onAccessibilityModeChanged(showA11yStream: Boolean?) {
            scope.trySend(VolumeDialogEventModel.AccessibilityModeChanged(showA11yStream == true))
        }

        // Captions button is remove from the Volume Dialog
Loading