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

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

Merge "Replaces unnecessary collectLatest with collect" into main

parents c3d5ea44 4f52f105
Loading
Loading
Loading
Loading
+9 −6
Original line number Original line Diff line number Diff line
@@ -46,7 +46,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith


@@ -64,14 +63,10 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {


    private val underTest by lazy { kosmos.quickSettingsShadeSceneActionsViewModel }
    private val underTest by lazy { kosmos.quickSettingsShadeSceneActionsViewModel }


    @Before
    fun setUp() {
        underTest.activateIn(testScope)
    }

    @Test
    @Test
    fun upTransitionSceneKey_deviceLocked_lockscreen() =
    fun upTransitionSceneKey_deviceLocked_lockscreen() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
            lockDevice()
@@ -85,6 +80,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun upTransitionSceneKey_deviceLocked_keyguardDisabled_gone() =
    fun upTransitionSceneKey_deviceLocked_keyguardDisabled_gone() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
            lockDevice()
@@ -98,6 +94,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun upTransitionSceneKey_deviceUnlocked_gone() =
    fun upTransitionSceneKey_deviceUnlocked_gone() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
            lockDevice()
@@ -113,6 +110,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    fun downTransitionSceneKey_deviceLocked_bottomAligned_lockscreen() =
    fun downTransitionSceneKey_deviceLocked_bottomAligned_lockscreen() =
        testScope.runTest {
        testScope.runTest {
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
            lockDevice()
@@ -127,6 +125,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    fun downTransitionSceneKey_deviceUnlocked_bottomAligned_gone() =
    fun downTransitionSceneKey_deviceUnlocked_bottomAligned_gone() =
        testScope.runTest {
        testScope.runTest {
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            kosmos.fakeShadeRepository.setDualShadeAlignedToBottom(true)
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            lockDevice()
            lockDevice()
@@ -141,6 +140,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() =
    fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
@@ -157,6 +157,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() =
    fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
            kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true)
@@ -174,6 +175,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun backTransitionSceneKey_notEditing_Home() =
    fun backTransitionSceneKey_notEditing_Home() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)


            assertThat((actions?.get(Back) as? UserActionResult.ChangeScene)?.toScene)
            assertThat((actions?.get(Back) as? UserActionResult.ChangeScene)?.toScene)
@@ -183,6 +185,7 @@ class QuickSettingsShadeSceneActionsViewModelTest : SysuiTestCase() {
    @Test
    @Test
    fun backTransition_editing_noDestination() =
    fun backTransition_editing_noDestination() =
        testScope.runTest {
        testScope.runTest {
            underTest.activateIn(this)
            val actions by collectLastValue(underTest.actions)
            val actions by collectLastValue(underTest.actions)
            kosmos.editModeViewModel.startEditing()
            kosmos.editModeViewModel.startEditing()


+1 −2
Original line number Original line Diff line number Diff line
@@ -35,7 +35,6 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.Test
@@ -123,7 +122,7 @@ class SceneActionsViewModelTest : SysuiTestCase() {
        override suspend fun hydrateActions(
        override suspend fun hydrateActions(
            setActions: (Map<UserAction, UserActionResult>) -> Unit,
            setActions: (Map<UserAction, UserActionResult>) -> Unit,
        ) {
        ) {
            upstream.collectLatest { setActions(it) }
            upstream.collect { setActions(it) }
        }
        }
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -155,7 +155,7 @@ constructor(
                    emptyFlow()
                    emptyFlow()
                }
                }
            }
            }
            .collectLatest { messageViewModel -> message.value = messageViewModel }
            .collect { messageViewModel -> message.value = messageViewModel }
    }
    }


    private suspend fun listenForSimBouncerEvents() {
    private suspend fun listenForSimBouncerEvents() {
@@ -170,7 +170,7 @@ constructor(
                    emptyFlow()
                    emptyFlow()
                }
                }
            }
            }
            .collectLatest {
            .collect {
                if (it != null) {
                if (it != null) {
                    message.value = it
                    message.value = it
                } else {
                } else {
+1 −2
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.bouncer.domain.interactor.BouncerInteractor
import com.android.systemui.scene.ui.viewmodel.SceneActionsViewModel
import com.android.systemui.scene.ui.viewmodel.SceneActionsViewModel
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map


/**
/**
@@ -46,7 +45,7 @@ constructor(
                    Swipe(SwipeDirection.Down) to UserActionResult(prevScene),
                    Swipe(SwipeDirection.Down) to UserActionResult(prevScene),
                )
                )
            }
            }
            .collectLatest { actions -> setActions(actions) }
            .collect { actions -> setActions(actions) }
    }
    }


    @AssistedFactory
    @AssistedFactory
+7 −9
Original line number Original line Diff line number Diff line
@@ -160,7 +160,7 @@ constructor(
            launch {
            launch {
                userSwitcher.selectedUser
                userSwitcher.selectedUser
                    .map { it.image.toBitmap() }
                    .map { it.image.toBitmap() }
                    .collectLatest { _selectedUserImage.value = it }
                    .collect { _selectedUserImage.value = it }
            }
            }


            launch {
            launch {
@@ -187,34 +187,32 @@ constructor(
                                )
                                )
                            }
                            }
                    }
                    }
                    .collectLatest { _userSwitcherDropdown.value = it }
                    .collect { _userSwitcherDropdown.value = it }
            }
            }


            launch {
            launch {
                combine(wipeDialogMessage, lockoutDialogMessage) { _, _ -> createDialogViewModel() }
                combine(wipeDialogMessage, lockoutDialogMessage) { _, _ -> createDialogViewModel() }
                    .collectLatest { _dialogViewModel.value = it }
                    .collect { _dialogViewModel.value = it }
            }
            }


            launch {
            launch { actionButtonInteractor.actionButton.collect { _actionButton.value = it } }
                actionButtonInteractor.actionButton.collectLatest { _actionButton.value = it }
            }


            launch {
            launch {
                authMethodViewModel
                authMethodViewModel
                    .map { authMethod -> isSideBySideSupported(authMethod) }
                    .map { authMethod -> isSideBySideSupported(authMethod) }
                    .collectLatest { _isSideBySideSupported.value = it }
                    .collect { _isSideBySideSupported.value = it }
            }
            }


            launch {
            launch {
                authMethodViewModel
                authMethodViewModel
                    .map { authMethod -> isFoldSplitRequired(authMethod) }
                    .map { authMethod -> isFoldSplitRequired(authMethod) }
                    .collectLatest { _isFoldSplitRequired.value = it }
                    .collect { _isFoldSplitRequired.value = it }
            }
            }


            launch {
            launch {
                message.isLockoutMessagePresent
                message.isLockoutMessagePresent
                    .map { lockoutMessagePresent -> !lockoutMessagePresent }
                    .map { lockoutMessagePresent -> !lockoutMessagePresent }
                    .collectLatest { _isInputEnabled.value = it }
                    .collect { _isInputEnabled.value = it }
            }
            }


            awaitCancellation()
            awaitCancellation()
Loading