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

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

Add optional labels to icon tiles.

This adds a switch in edit mode. Enabling labels will make the icon tiles taller and add the labels under the icon.

Flag: com.android.systemui.qs_ui_refactor
Test: manually with QSActivity
Fix: 341735914
Change-Id: Ib2639a3fec685360661a1e8c676ef90a76a58b4e
parent 4d3634fd
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.systemui.qs.panels.domain.interactor.InfiniteGridConsistencyI
import com.android.systemui.qs.panels.domain.interactor.NoopGridConsistencyInteractor
import com.android.systemui.qs.panels.shared.model.GridConsistencyLog
import com.android.systemui.qs.panels.shared.model.GridLayoutType
import com.android.systemui.qs.panels.shared.model.IconLabelVisibilityLog
import com.android.systemui.qs.panels.shared.model.InfiniteGridLayoutType
import com.android.systemui.qs.panels.shared.model.PartitionedGridLayoutType
import com.android.systemui.qs.panels.shared.model.StretchedGridLayoutType
@@ -35,6 +36,12 @@ import com.android.systemui.qs.panels.ui.compose.GridLayout
import com.android.systemui.qs.panels.ui.compose.InfiniteGridLayout
import com.android.systemui.qs.panels.ui.compose.PartitionedGridLayout
import com.android.systemui.qs.panels.ui.compose.StretchedGridLayout
import com.android.systemui.qs.panels.ui.viewmodel.IconLabelVisibilityViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconLabelVisibilityViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModelImpl
import com.android.systemui.qs.panels.ui.viewmodel.InfiniteGridSizeViewModel
import com.android.systemui.qs.panels.ui.viewmodel.InfiniteGridSizeViewModelImpl
import dagger.Binds
import dagger.Module
import dagger.Provides
@@ -53,6 +60,15 @@ interface PanelsModule {
        impl: NoopGridConsistencyInteractor
    ): GridTypeConsistencyInteractor

    @Binds fun bindIconTilesViewModel(impl: IconTilesViewModelImpl): IconTilesViewModel

    @Binds fun bindGridSizeViewModel(impl: InfiniteGridSizeViewModelImpl): InfiniteGridSizeViewModel

    @Binds
    fun bindIconLabelVisibilityViewModel(
        impl: IconLabelVisibilityViewModelImpl
    ): IconLabelVisibilityViewModel

    @Binds @Named("Default") fun bindDefaultGridLayout(impl: PartitionedGridLayout): GridLayout

    companion object {
@@ -63,6 +79,13 @@ interface PanelsModule {
            return factory.create("GridConsistencyLog", 50)
        }

        @Provides
        @SysUISingleton
        @IconLabelVisibilityLog
        fun providesIconTileLabelVisibilityLog(factory: LogBufferFactory): LogBuffer {
            return factory.create("IconLabelVisibilityLog", 50)
        }

        @Provides
        @IntoSet
        fun provideGridLayout(gridLayout: InfiniteGridLayout): Pair<GridLayoutType, GridLayout> {
+35 −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 com.android.systemui.dagger.SysUISingleton
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow

/** Repository for whether to show the labels of icon tiles. */
@SysUISingleton
class IconLabelVisibilityRepository @Inject constructor() {
    // TODO(b/341735914): Persist and back up showLabels
    private val _showLabels = MutableStateFlow(false)
    val showLabels: StateFlow<Boolean> = _showLabels.asStateFlow()

    fun setShowLabels(showLabels: Boolean) {
        _showLabels.value = showLabels
    }
}
+61 −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.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.qs.panels.data.repository.IconLabelVisibilityRepository
import com.android.systemui.qs.panels.shared.model.IconLabelVisibilityLog
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

@SysUISingleton
class IconLabelVisibilityInteractor
@Inject
constructor(
    private val repo: IconLabelVisibilityRepository,
    @IconLabelVisibilityLog private val logBuffer: LogBuffer,
    @Application scope: CoroutineScope,
) {
    val showLabels: StateFlow<Boolean> =
        repo.showLabels
            .onEach { logChange(it) }
            .stateIn(scope, SharingStarted.WhileSubscribed(), repo.showLabels.value)

    fun setShowLabels(showLabels: Boolean) {
        repo.setShowLabels(showLabels)
    }

    private fun logChange(showLabels: Boolean) {
        logBuffer.log(
            LOG_BUFFER_ICON_TILE_LABEL_VISIBILITY_CHANGE_TAG,
            LogLevel.DEBUG,
            { bool1 = showLabels },
            { "Icon tile label visibility changed: $bool1" }
        )
    }

    private companion object {
        const val LOG_BUFFER_ICON_TILE_LABEL_VISIBILITY_CHANGE_TAG = "IconLabelVisibilityChange"
    }
}
+24 −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.shared.model

import javax.inject.Qualifier

@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class IconLabelVisibilityLog()
+11 −11
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.qs.panels.domain.interactor.IconTilesInteractor
import com.android.systemui.qs.panels.domain.interactor.InfiniteGridSizeInteractor
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.panels.ui.viewmodel.IconTilesViewModel
import com.android.systemui.qs.panels.ui.viewmodel.InfiniteGridSizeViewModel
import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.res.R
@@ -38,8 +38,8 @@ import javax.inject.Inject
class InfiniteGridLayout
@Inject
constructor(
    private val iconTilesInteractor: IconTilesInteractor,
    private val gridSizeInteractor: InfiniteGridSizeInteractor
    private val iconTilesViewModel: IconTilesViewModel,
    private val gridSizeViewModel: InfiniteGridSizeViewModel,
) : GridLayout {

    @Composable
@@ -52,8 +52,8 @@ constructor(
            tiles.forEach { it.startListening(token) }
            onDispose { tiles.forEach { it.stopListening(token) } }
        }
        val iconTilesSpecs by iconTilesInteractor.iconTilesSpecs.collectAsStateWithLifecycle()
        val columns by gridSizeInteractor.columns.collectAsStateWithLifecycle()
        val iconTilesSpecs by iconTilesViewModel.iconTilesSpecs.collectAsStateWithLifecycle()
        val columns by gridSizeViewModel.columns.collectAsStateWithLifecycle()

        TileLazyGrid(modifier = modifier, columns = GridCells.Fixed(columns)) {
            items(
@@ -68,9 +68,9 @@ constructor(
                }
            ) { index ->
                Tile(
                    tiles[index],
                    iconTilesSpecs.contains(tiles[index].spec),
                    Modifier.height(dimensionResource(id = R.dimen.qs_tile_height))
                    tile = tiles[index],
                    iconOnly = iconTilesSpecs.contains(tiles[index].spec),
                    modifier = Modifier.height(dimensionResource(id = R.dimen.qs_tile_height))
                )
            }
        }
@@ -83,8 +83,8 @@ constructor(
        onAddTile: (TileSpec, Int) -> Unit,
        onRemoveTile: (TileSpec) -> Unit,
    ) {
        val iconOnlySpecs by iconTilesInteractor.iconTilesSpecs.collectAsStateWithLifecycle()
        val columns by gridSizeInteractor.columns.collectAsStateWithLifecycle()
        val iconOnlySpecs by iconTilesViewModel.iconTilesSpecs.collectAsStateWithLifecycle()
        val columns by gridSizeViewModel.columns.collectAsStateWithLifecycle()

        DefaultEditTileGrid(
            tiles = tiles,
Loading