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

Commit 75311b0a authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Remove empty default for tile list

This was causing a frame of empty list of tiles when expanding to QS,
which translated to big recomposition on the second frame.

Test: manual, perfetto
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Bug: 389985793
Change-Id: I2838341c3ff4f8f49fbff2f3ef7d21fba4736fb9
parent 3a3c73d6
Loading
Loading
Loading
Loading
+0 −62
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 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.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class PaginatedGridRepositoryTest : SysuiTestCase() {
    private val kosmos = testKosmos()

    val underTest = kosmos.paginatedGridRepository

    @Test
    fun rows_followsConfig() =
        with(kosmos) {
            testScope.runTest {
                val rows by collectLastValue(underTest.rows)

                setRowsInConfig(3)
                assertThat(rows).isEqualTo(3)

                setRowsInConfig(6)
                assertThat(rows).isEqualTo(6)
            }
        }

    private fun setRowsInConfig(rows: Int) =
        with(kosmos) {
            testCase.context.orCreateTestableResources.addOverride(
                R.integer.quick_settings_paginated_grid_num_rows,
                rows,
            )
            fakeConfigurationRepository.onConfigurationChange()
        }
}
+0 −43
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.content.res.Resources
import com.android.systemui.common.ui.data.repository.ConfigurationRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.res.R
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.util.kotlin.emitOnStart
import javax.inject.Inject
import kotlinx.coroutines.flow.map

/**
 * Provides the number of [rows] to use with a paginated grid, by tracking the resource
 * [R.integer.quick_settings_max_rows].
 */
@SysUISingleton
class PaginatedGridRepository
@Inject
constructor(
    @ShadeDisplayAware private val resources: Resources,
    @ShadeDisplayAware configurationRepository: ConfigurationRepository,
) {
    val rows =
        configurationRepository.onConfigurationChange.emitOnStart().map {
            resources.getInteger(R.integer.quick_settings_paginated_grid_num_rows)
        }
}
+0 −30
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.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.qs.panels.data.repository.PaginatedGridRepository
import javax.inject.Inject

@SysUISingleton
class PaginatedGridInteractor
@Inject
constructor(paginatedGridRepository: PaginatedGridRepository) {
    val rows = paginatedGridRepository.rows

    val defaultRows = 4
}
+3 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.res.integerResource
import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.ContentScope
import com.android.compose.modifiers.padding
@@ -54,6 +55,7 @@ import com.android.systemui.qs.panels.ui.viewmodel.PaginatedGridViewModel
import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.toolbar.EditModeButtonViewModel
import com.android.systemui.qs.ui.compose.borderOnFocus
import com.android.systemui.res.R
import javax.inject.Inject

class PaginatedGridLayout
@@ -75,7 +77,7 @@ constructor(
            onDispose { tiles.forEach { it.stopListening(token) } }
        }
        val columns = viewModel.columns
        val rows = viewModel.rows
        val rows = integerResource(R.integer.quick_settings_paginated_grid_num_rows)

        val pages =
            remember(tiles, columns, rows) {
+2 −4
Original line number Diff line number Diff line
@@ -17,16 +17,14 @@
package com.android.systemui.qs.panels.ui.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.animation.scene.ContentScope
import com.android.systemui.qs.panels.ui.viewmodel.TileGridViewModel

@Composable
fun ContentScope.TileGrid(viewModel: TileGridViewModel, modifier: Modifier = Modifier) {
    val gridLayout by viewModel.gridLayout.collectAsStateWithLifecycle()
    val tiles by viewModel.tileViewModels.collectAsStateWithLifecycle(emptyList())
    val gridLayout = viewModel.gridLayout
    val tiles = viewModel.tileViewModels

    with(gridLayout) { TileGrid(tiles, modifier) }
}
Loading