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

Commit 031e5cd3 authored by Olivier St-Onge's avatar Olivier St-Onge Committed by Android (Google) Code Review
Browse files

Merge "Only allow current tiles to be resized." into main

parents e72031df 47e1cd56
Loading
Loading
Loading
Loading
+59 −14
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository
import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository
import com.android.systemui.qs.panels.data.repository.qsPreferencesRepository
import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -40,15 +41,16 @@ class IconTilesInteractorTest : SysuiTestCase() {
        testKosmos().apply {
            defaultLargeTilesRepository =
                object : DefaultLargeTilesRepository {
                    override val defaultLargeTiles: Set<TileSpec> = setOf(TileSpec.create("large"))
                    override val defaultLargeTiles: Set<TileSpec> = setOf(largeTile)
                }
            currentTilesInteractor.setTiles(listOf(largeTile, smallTile))
        }
    private val underTest = with(kosmos) { iconTilesInteractor }

    @Test
    fun isIconTile_returnsCorrectValue() {
        assertThat(underTest.isIconTile(TileSpec.create("large"))).isFalse()
        assertThat(underTest.isIconTile(TileSpec.create("small"))).isTrue()
        assertThat(underTest.isIconTile(largeTile)).isFalse()
        assertThat(underTest.isIconTile(smallTile)).isTrue()
    }

    @OptIn(ExperimentalCoroutinesApi::class)
@@ -56,14 +58,21 @@ class IconTilesInteractorTest : SysuiTestCase() {
    fun isIconTile_updatesFromSharedPreferences() =
        with(kosmos) {
            testScope.runTest {
                val spec = TileSpec.create("newTile")

                // Assert that new tile defaults to icon
                assertThat(underTest.isIconTile(TileSpec.create("newTile"))).isTrue()
                assertThat(underTest.isIconTile(spec)).isTrue()

                // Add the tile
                currentTilesInteractor.addTile(spec)
                runCurrent()

                qsPreferencesRepository.setLargeTilesSpecs(setOf(TileSpec.create("newTile")))
                // Resize it to large
                qsPreferencesRepository.setLargeTilesSpecs(setOf(spec))
                runCurrent()

                // Assert that the new tile was added to the large tiles set
                assertThat(underTest.isIconTile(TileSpec.create("newTile"))).isFalse()
                assertThat(underTest.isIconTile(spec)).isFalse()
            }
        }

@@ -72,21 +81,57 @@ class IconTilesInteractorTest : SysuiTestCase() {
    fun resize_updatesSharedPreferences() =
        with(kosmos) {
            testScope.runTest {
                qsPreferencesRepository.setLargeTilesSpecs(setOf())
                val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs)
                runCurrent()

                val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs)
                val spec = TileSpec.create("large")
                // Assert that the tile is removed from the large tiles after resizing
                underTest.resize(largeTile)
                runCurrent()
                assertThat(latest).doesNotContain(largeTile)

                // Assert that the tile is added to the large tiles after resizing
                underTest.resize(spec)
                underTest.resize(largeTile)
                runCurrent()
                assertThat(latest).contains(spec)
                assertThat(latest).contains(largeTile)
            }
        }

                // Assert that the tile is removed from the large tiles after resizing
                underTest.resize(spec)
    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    fun removingTile_updatesSharedPreferences() =
        with(kosmos) {
            testScope.runTest {
                val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs)
                runCurrent()
                assertThat(latest).doesNotContain(spec)

                // Remove the large tile from the current tiles
                currentTilesInteractor.removeTiles(listOf(largeTile))
                runCurrent()

                // Assert that it resized to small
                assertThat(latest).doesNotContain(largeTile)
            }
        }

    @OptIn(ExperimentalCoroutinesApi::class)
    @Test
    fun resizingNonCurrentTile_doesNothing() =
        with(kosmos) {
            testScope.runTest {
                val latest by collectLastValue(qsPreferencesRepository.largeTilesSpecs)
                val newTile = TileSpec.create("newTile")

                // Remove the large tile from the current tiles
                underTest.resize(newTile)
                runCurrent()

                // Assert that it's still small
                assertThat(latest).doesNotContain(newTile)
            }
        }

    private companion object {
        private val largeTile = TileSpec.create("large")
        private val smallTile = TileSpec.create("small")
    }
}
+4 −7
Original line number Diff line number Diff line
@@ -24,8 +24,7 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testCase
import com.android.systemui.kosmos.testScope
import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository
import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository
import com.android.systemui.qs.panels.domain.interactor.qsPreferencesInteractor
import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.res.R
@@ -56,11 +55,9 @@ class QuickQuickSettingsViewModelTest : SysuiTestCase() {

    private val kosmos =
        testKosmos().apply {
            defaultLargeTilesRepository =
                object : DefaultLargeTilesRepository {
                    override val defaultLargeTiles: Set<TileSpec> =
            qsPreferencesInteractor.setLargeTilesSpecs(
                tiles.filter { it.spec.startsWith(PREFIX_LARGE) }.toSet()
                }
            )
        }

    private val underTest = kosmos.quickQuickSettingsViewModel
+26 −1
Original line number Diff line number Diff line
@@ -22,10 +22,12 @@ import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.qs.panels.data.repository.DefaultLargeTilesRepository
import com.android.systemui.qs.panels.shared.model.PanelsLog
import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor
import com.android.systemui.qs.pipeline.shared.TileSpec
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

@@ -35,19 +37,38 @@ class IconTilesInteractor
@Inject
constructor(
    repo: DefaultLargeTilesRepository,
    private val currentTilesInteractor: CurrentTilesInteractor,
    private val preferencesInteractor: QSPreferencesInteractor,
    @PanelsLog private val logBuffer: LogBuffer,
    @Application private val applicationScope: CoroutineScope
) {

    val largeTilesSpecs =
        preferencesInteractor.largeTilesSpecs
        combine(preferencesInteractor.largeTilesSpecs, currentTilesInteractor.currentTiles) {
                largeTiles,
                currentTiles ->
                if (currentTiles.isEmpty()) {
                    largeTiles
                } else {
                    // Only current tiles can be resized, so observe the current tiles and find the
                    // intersection between them and the large tiles.
                    val newLargeTiles = largeTiles intersect currentTiles.map { it.spec }.toSet()
                    if (newLargeTiles != largeTiles) {
                        preferencesInteractor.setLargeTilesSpecs(newLargeTiles)
                    }
                    newLargeTiles
                }
            }
            .onEach { logChange(it) }
            .stateIn(applicationScope, SharingStarted.Eagerly, repo.defaultLargeTiles)

    fun isIconTile(spec: TileSpec): Boolean = !largeTilesSpecs.value.contains(spec)

    fun resize(spec: TileSpec) {
        if (!isCurrent(spec)) {
            return
        }

        if (largeTilesSpecs.value.contains(spec)) {
            preferencesInteractor.setLargeTilesSpecs(largeTilesSpecs.value - spec)
        } else {
@@ -55,6 +76,10 @@ constructor(
        }
    }

    private fun isCurrent(spec: TileSpec): Boolean {
        return currentTilesInteractor.currentTilesSpecs.contains(spec)
    }

    private fun logChange(specs: Set<TileSpec>) {
        logBuffer.log(
            LOG_BUFFER_LARGE_TILES_SPECS_CHANGE_TAG,
+2 −0
Original line number Diff line number Diff line
@@ -20,11 +20,13 @@ import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.log.core.FakeLogBuffer
import com.android.systemui.qs.panels.data.repository.defaultLargeTilesRepository
import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor

val Kosmos.iconTilesInteractor by
    Kosmos.Fixture {
        IconTilesInteractor(
            defaultLargeTilesRepository,
            currentTilesInteractor,
            qsPreferencesInteractor,
            FakeLogBuffer.Factory.create(),
            applicationCoroutineScope