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

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

Merge "Make dndMode not lazy" into main

parents 13abc837 45a5dffb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -58,7 +58,9 @@ class ModesTileDataInteractorTest : SysuiTestCase() {
    private val dispatcher = kosmos.testDispatcher
    private val zenModeRepository = kosmos.fakeZenModeRepository

    private val underTest = ModesTileDataInteractor(context, kosmos.zenModeInteractor, dispatcher)
    private val underTest by lazy {
        ModesTileDataInteractor(context, kosmos.zenModeInteractor, dispatcher)
    }

    @Before
    fun setUp() {
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val activeNotificationListRepository = kosmos.activeNotificationListRepository
    private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository

    private val underTest = kosmos.emptyShadeViewModel
    private val underTest by lazy { kosmos.emptyShadeViewModel }

    companion object {
        @JvmStatic
+4 −4
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ class ZenModeInteractorTest : SysuiTestCase() {
    private val settingsRepository = kosmos.secureSettingsRepository
    private val deviceProvisioningRepository = kosmos.fakeDeviceProvisioningRepository

    private val underTest = kosmos.zenModeInteractor
    private val underTest by lazy { kosmos.zenModeInteractor }

    @Test
    fun isZenAvailable_off() =
@@ -176,13 +176,13 @@ class ZenModeInteractorTest : SysuiTestCase() {
    @Test
    fun shouldAskForZenDuration_changesWithSetting() =
        kosmos.runTest {
            val manualDnd = TestModeBuilder().makeManualDnd().setActive(true).build()
            val manualDnd by collectLastValue(underTest.dndMode)

            settingsRepository.setInt(ZEN_DURATION, ZEN_DURATION_FOREVER)
            assertThat(underTest.shouldAskForZenDuration(manualDnd)).isFalse()
            assertThat(underTest.shouldAskForZenDuration(manualDnd!!)).isFalse()

            settingsRepository.setInt(ZEN_DURATION, ZEN_DURATION_PROMPT)
            assertThat(underTest.shouldAskForZenDuration(manualDnd)).isTrue()
            assertThat(underTest.shouldAskForZenDuration(manualDnd!!)).isTrue()
        }

    @Test
+15 −6
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
@@ -123,11 +124,19 @@ constructor(
     * explicitly wants a shortcut to DND). Please prefer using [modes] or [activeModes] in all
     * other scenarios.
     */
    val dndMode: StateFlow<ZenMode?> by lazy {
        ModesUi.assertInNewMode()
    val dndMode: StateFlow<ZenMode?> =
        if (ModesUi.isEnabled)
            zenModeRepository.modes
                .map { modes -> modes.singleOrNull { it.isManualDnd } }
            .stateIn(scope = backgroundScope, started = SharingStarted.Eagerly, initialValue = null)
                .stateIn(
                    scope = backgroundScope,
                    started = SharingStarted.Eagerly,
                    initialValue = null,
                )
        else MutableStateFlow<ZenMode?>(null)
        get() {
            ModesUi.assertInNewMode()
            return field
        }

    /** Flow returning the currently active mode(s), if any. */