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

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

Reapply "Implement QS columns for different configurations"

This reverts commit 0bc4cf30.

Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Bug: 366426898
Test: manually rotating the device and opening QS
Test: QSColumnsRepositoryTest.kt
Test: QuickQuickSettingsViewModel.kt
Change-Id: I1cb61685b57523edfb356c3796484543899ce9d5
parent 3e806614
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.panels.data.repository

import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testCase
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.shade.shared.flag.DualShade
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class QSColumnsRepositoryTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private lateinit var underTest: QSColumnsRepository

    @Before
    fun setUp() {
        underTest = with(kosmos) { qsColumnsRepository }
    }

    @Test
    fun configChanges_triggerColumnsUpdate() =
        with(kosmos) {
            testScope.runTest {
                val latest by collectLastValue(underTest.columns)

                setColumnsInConfig(4)
                assertThat(latest).isEqualTo(4)

                setColumnsInConfig(8)
                assertThat(latest).isEqualTo(8)
            }
        }

    @Test
    @EnableFlags(DualShade.FLAG_NAME)
    fun withDualShade_returnsCorrectValue() =
        with(kosmos) {
            testScope.runTest {
                val latest by collectLastValue(underTest.columns)
                assertThat(latest).isEqualTo(4)

                setColumnsInConfig(8, id = R.integer.quick_settings_dual_shade_num_columns)
                // Asserts config changes are ignored
                assertThat(latest).isEqualTo(4)
            }
        }

    private fun setColumnsInConfig(
        columns: Int,
        id: Int = R.integer.quick_settings_infinite_grid_num_columns,
    ) =
        with(kosmos) {
            testCase.context.orCreateTestableResources.addOverride(id, columns)
            fakeConfigurationRepository.onConfigurationChange()
        }
}
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,11 @@ class QuickQuickSettingsViewModelTest : SysuiTestCase() {
            qsPreferencesInteractor.setLargeTilesSpecs(
                tiles.filter { it.spec.startsWith(PREFIX_LARGE) }.toSet()
            )
            testCase.context.orCreateTestableResources.addOverride(
                R.integer.quick_settings_infinite_grid_num_columns,
                4,
            )
            fakeConfigurationRepository.onConfigurationChange()
        }

    private val underTest = kosmos.quickQuickSettingsViewModel
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@

    <integer name="quick_settings_num_columns">4</integer>

    <!-- The number of columns in the infinite grid QuickSettings -->
    <integer name="quick_settings_infinite_grid_num_columns">8</integer>

    <!-- The number of columns that the top level tiles span in the QuickSettings -->
    <integer name="quick_settings_user_time_settings_tile_span">2</integer>

+3 −0
Original line number Diff line number Diff line
@@ -24,6 +24,9 @@
    <!-- The number of columns in the QuickSettings -->
    <integer name="quick_settings_num_columns">3</integer>

    <!-- The number of columns in the infinite grid QuickSettings -->
    <integer name="quick_settings_infinite_grid_num_columns">6</integer>

    <integer name="power_menu_lite_max_columns">2</integer>
    <integer name="power_menu_lite_max_rows">3</integer>

+3 −0
Original line number Diff line number Diff line
@@ -73,6 +73,9 @@
    <!-- The number of columns in the infinite grid QuickSettings -->
    <integer name="quick_settings_infinite_grid_num_columns">4</integer>

    <!-- The number of columns in the Dual Shade QuickSettings -->
    <integer name="quick_settings_dual_shade_num_columns">4</integer>

    <!-- Override column number for quick settings.
    For now, this value has effect only when flag lockscreen.enable_landscape is enabled.
    TODO (b/293252410) - change this comment/resource when flag is enabled -->
Loading