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

Commit a09bd1c0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Hide ambient cue when IME shows." into main

parents 3861c749 0ef63aee
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -78,29 +78,29 @@ class AmbientCueRepositoryTest : SysuiTestCase() {
        )

    @Test
    fun isVisible_whenHasActions_true() =
    fun isRootViewAttached_whenHasActions_true() =
        kosmos.runTest {
            val actions by collectLastValue(underTest.actions)
            val isVisible by collectLastValue(underTest.isVisible)
            val isRootViewAttached by collectLastValue(underTest.isRootViewAttached)
            runCurrent()
            verify(smartSpaceSession)
                .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture())
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(allTargets)
            advanceUntilIdle()
            assertThat(isVisible).isTrue()
            assertThat(isRootViewAttached).isTrue()
        }

    @Test
    fun isVisible_whenNoActions_false() =
    fun isRootViewAttached_whenNoActions_false() =
        kosmos.runTest {
            val actions by collectLastValue(underTest.actions)
            val isVisible by collectLastValue(underTest.isVisible)
            val isRootViewAttached by collectLastValue(underTest.isRootViewAttached)
            runCurrent()
            verify(smartSpaceSession)
                .addOnTargetsAvailableListener(any(), onTargetsAvailableListenerCaptor.capture())
            onTargetsAvailableListenerCaptor.firstValue.onTargetsAvailable(listOf(invalidTarget1))
            advanceUntilIdle()
            assertThat(isVisible).isFalse()
            assertThat(isRootViewAttached).isFalse()
        }

    @Test
+10 −10
Original line number Diff line number Diff line
@@ -37,19 +37,19 @@ class AmbientCueInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()

    @Test
    fun isVisible_setTrue_true() =
    fun isRootViewAttached_setTrue_true() =
        kosmos.runTest {
            val isVisible by collectLastValue(ambientCueInteractor.isVisible)
            ambientCueInteractor.setIsVisible(true)
            assertThat(isVisible).isTrue()
            val isRootViewAttached by collectLastValue(ambientCueInteractor.isRootViewAttached)
            ambientCueInteractor.setRootViewAttached(true)
            assertThat(isRootViewAttached).isTrue()
        }

    @Test
    fun isVisible_setFalse_False() =
    fun isRootViewAttached_setFalse_False() =
        kosmos.runTest {
            val isVisible by collectLastValue(ambientCueInteractor.isVisible)
            ambientCueInteractor.setIsVisible(false)
            assertThat(isVisible).isFalse()
            val isRootViewAttached by collectLastValue(ambientCueInteractor.isRootViewAttached)
            ambientCueInteractor.setRootViewAttached(false)
            assertThat(isRootViewAttached).isFalse()
        }

    @Test
@@ -77,7 +77,7 @@ class AmbientCueInteractorTest : SysuiTestCase() {
    fun isImeVisible_setTrue_true() =
        kosmos.runTest {
            val isImeVisible by collectLastValue(ambientCueInteractor.isImeVisible)
            ambientCueInteractor.setIsImeVisible(true)
            ambientCueInteractor.setImeVisible(true)
            assertThat(isImeVisible).isTrue()
        }

@@ -85,7 +85,7 @@ class AmbientCueInteractorTest : SysuiTestCase() {
    fun isImeVisible_setFalse_false() =
        kosmos.runTest {
            val isImeVisible by collectLastValue(ambientCueInteractor.isImeVisible)
            ambientCueInteractor.setIsImeVisible(false)
            ambientCueInteractor.setImeVisible(false)
            assertThat(isImeVisible).isFalse()
        }
}
+29 −3
Original line number Diff line number Diff line
@@ -50,7 +50,8 @@ class AmbientCueViewModelTest : SysuiTestCase() {
    @Test
    fun isVisible_timesOut() =
        kosmos.runTest {
            ambientCueInteractor.setIsVisible(true)
            ambientCueInteractor.setRootViewAttached(true)
            ambientCueInteractor.setImeVisible(false)
            runCurrent()
            assertThat(viewModel.isVisible).isTrue()

@@ -63,7 +64,8 @@ class AmbientCueViewModelTest : SysuiTestCase() {
    @Test
    fun isVisible_whenExpanded_doesntTimeOut() =
        kosmos.runTest {
            ambientCueInteractor.setIsVisible(true)
            ambientCueInteractor.setRootViewAttached(true)
            ambientCueInteractor.setImeVisible(false)
            runCurrent()
            assertThat(viewModel.isVisible).isTrue()

@@ -74,6 +76,30 @@ class AmbientCueViewModelTest : SysuiTestCase() {
            assertThat(viewModel.isVisible).isTrue()
        }

    @Test
    fun isVisible_imeNotVisible_true() =
        kosmos.runTest {
            ambientCueInteractor.setRootViewAttached(true)
            ambientCueInteractor.setImeVisible(false)
            runCurrent()

            assertThat(viewModel.isVisible).isTrue()
        }

    @Test
    fun isVisible_imeVisible_false() =
        kosmos.runTest {
            ambientCueInteractor.setRootViewAttached(true)
            ambientCueInteractor.setImeVisible(false)
            runCurrent()
            assertThat(viewModel.isVisible).isTrue()

            ambientCueInteractor.setImeVisible(true)
            runCurrent()

            assertThat(viewModel.isVisible).isFalse()
        }

    @Test
    fun onClick_collapses() =
        kosmos.runTest {
@@ -91,7 +117,7 @@ class AmbientCueViewModelTest : SysuiTestCase() {
                    )
                )
            ambientCueRepository.fake.setActions(testActions)
            ambientCueInteractor.setIsVisible(true)
            ambientCueInteractor.setRootViewAttached(true)
            viewModel.expand()
            runCurrent()

+4 −4
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ interface AmbientCueRepository {
    /** Chips that should be visible on the UI. */
    val actions: StateFlow<List<ActionModel>>

    /** If hint (or chips list) should be visible. */
    val isVisible: MutableStateFlow<Boolean>
    /** If the root view is attached to the WindowManager. */
    val isRootViewAttached: MutableStateFlow<Boolean>

    /** If IME is visible or not. */
    val isImeVisible: MutableStateFlow<Boolean>
@@ -145,14 +145,14 @@ constructor(
                    Log.i(TAG, "SmartSpace session closed")
                }
            }
            .onEach { actions -> isVisible.update { actions.isNotEmpty() } }
            .onEach { actions -> isRootViewAttached.update { actions.isNotEmpty() } }
            .stateIn(
                scope = backgroundScope,
                started = SharingStarted.WhileSubscribed(),
                initialValue = emptyList(),
            )

    override val isVisible: MutableStateFlow<Boolean> = MutableStateFlow(false)
    override val isRootViewAttached: MutableStateFlow<Boolean> = MutableStateFlow(false)

    override val isImeVisible: MutableStateFlow<Boolean> = MutableStateFlow(false)

+5 −5
Original line number Diff line number Diff line
@@ -23,15 +23,15 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

class AmbientCueInteractor @Inject constructor(private val repository: AmbientCueRepository) {
    val isVisible: StateFlow<Boolean> = repository.isVisible
    val isRootViewAttached: StateFlow<Boolean> = repository.isRootViewAttached
    val actions: StateFlow<List<ActionModel>> = repository.actions
    val isImeVisible: StateFlow<Boolean> = repository.isImeVisible

    fun setIsVisible(visible: Boolean) {
        repository.isVisible.update { visible }
    fun setRootViewAttached(isAttached: Boolean) {
        repository.isRootViewAttached.update { isAttached }
    }

    fun setIsImeVisible(visible: Boolean) {
        repository.isImeVisible.update { visible }
    fun setImeVisible(isVisible: Boolean) {
        repository.isImeVisible.update { isVisible }
    }
}
Loading