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

Commit d36cc579 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Add screen density as a extra large tiles factor

Current threshold is a screen density of at least 480

Flag: EXEMPT bugfix
Fixes: 441085034
Test: manually - changing display size
Test: LargeTileSpanRepositoryTest.kt
Change-Id: If7676e60e951767bcc4d78844e7033d2170d6a90
parent 0105770f
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class LargeTileSpanRepositoryTest : SysuiTestCase() {
    private val Kosmos.underTest by Kosmos.Fixture { largeTileSpanRepository }

    @Test
    fun useExtraLargeTiles_tracksConfig() =
    fun useExtraLargeTiles_tracksFontScale() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.useExtraLargeTiles)

@@ -65,6 +65,29 @@ class LargeTileSpanRepositoryTest : SysuiTestCase() {
            assertThat(latest).isTrue()
        }

    @Test
    fun useExtraLargeTiles_tracksScreenDensity() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.useExtraLargeTiles)

            val configuration = Configuration().apply { this.densityDpi = 400 }
            context.orCreateTestableResources.overrideConfiguration(configuration)
            fakeConfigurationRepository.onConfigurationChange()
            assertThat(latest).isFalse()

            configuration.densityDpi = 470
            fakeConfigurationRepository.onConfigurationChange()
            assertThat(latest).isFalse()

            configuration.densityDpi = 480
            fakeConfigurationRepository.onConfigurationChange()
            assertThat(latest).isTrue()

            configuration.densityDpi = 600
            fakeConfigurationRepository.onConfigurationChange()
            assertThat(latest).isTrue()
        }

    @Test
    fun tileMaxWidth_tracksConfig() =
        kosmos.runTest {
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.panels.ui.viewmodel

import android.content.res.Configuration
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -70,6 +71,10 @@ class QuickQuickSettingsViewModelTest : SysuiTestCase() {
                R.integer.quick_settings_infinite_grid_num_columns,
                4,
            )
            // Manually set the screen density to avoid triggering extra large tiles
            testCase.context.orCreateTestableResources.overrideConfiguration(
                Configuration().apply { this.densityDpi = 400 }
            )
            fakeConfigurationRepository.onConfigurationChange()
            usingMediaInComposeFragment = true
        }
+7 −3
Original line number Diff line number Diff line
@@ -50,14 +50,18 @@ constructor(

    val defaultTileMaxWidth: Int = DEFAULT_LARGE_TILE_WIDTH

    val currentUseExtraLargeTiles: Boolean
        get() = resources.configuration.fontScale >= FONT_SCALE_THRESHOLD
    /** Use extra large tiles if the font scale or the screen density are past the thresholds. */
    private val currentUseExtraLargeTiles: Boolean
        get() =
            resources.configuration.fontScale >= FONT_SCALE_THRESHOLD ||
                resources.configuration.densityDpi >= DENSITY_THRESHOLD

    val currentTileMaxWidth: Int
    private val currentTileMaxWidth: Int
        get() = resources.getInteger(R.integer.quick_settings_infinite_grid_tile_max_width)

    private companion object {
        const val FONT_SCALE_THRESHOLD = 1.8f
        const val DENSITY_THRESHOLD = 480
        const val DEFAULT_LARGE_TILE_WIDTH = 2
    }
}