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

Commit 500d5073 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Add paging to modes dialog

Bug: 376450983
Test: manually scroll through pages and see that things look good
Flag: com.android.systemui.modes_ui_dialog_paging

Change-Id: I475e50e15725c844975768c0f041663948f7bc4f
parent 451010f9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,13 @@ flag {
   }
}

flag {
   name: "modes_ui_dialog_paging"
   namespace: "systemui"
   description: "Add pagination to the Modes dialog in quick settings."
   bug: "376450983"
}

flag {
   name: "priority_people_section"
   namespace: "systemui"
+2 −2
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ import com.android.systemui.common.ui.compose.Icon
import com.android.systemui.statusbar.policy.ui.dialog.viewmodel.ModeTileViewModel

@Composable
fun ModeTile(viewModel: ModeTileViewModel) {
fun ModeTile(viewModel: ModeTileViewModel, modifier: Modifier = Modifier) {
    val tileColor: Color by
        animateColorAsState(
            if (viewModel.enabled) MaterialTheme.colorScheme.primary
@@ -59,7 +59,7 @@ fun ModeTile(viewModel: ModeTileViewModel) {
        )

    CompositionLocalProvider(LocalContentColor provides contentColor) {
        Surface(color = tileColor, shape = RoundedCornerShape(16.dp)) {
        Surface(color = tileColor, shape = RoundedCornerShape(16.dp), modifier = modifier) {
            Row(
                modifier =
                    Modifier.combinedClickable(
+53 −8
Original line number Diff line number Diff line
@@ -17,21 +17,65 @@
package com.android.systemui.statusbar.policy.ui.dialog.composable

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.systemui.Flags
import com.android.systemui.qs.panels.ui.compose.PagerDots
import com.android.systemui.statusbar.policy.ui.dialog.viewmodel.ModesDialogViewModel

@Composable
fun ModeTileGrid(viewModel: ModesDialogViewModel) {
    val tiles by viewModel.tiles.collectAsStateWithLifecycle(initialValue = emptyList())

    if (Flags.modesUiDialogPaging()) {
        val tilesPerPage = 3
        val totalPages = { (tiles.size + tilesPerPage - 1) / tilesPerPage }
        val pagerState = rememberPagerState(initialPage = 0, pageCount = totalPages)

        Column {
            HorizontalPager(
                state = pagerState,
                modifier = Modifier.fillMaxWidth(),
                pageSpacing = 16.dp,
                verticalAlignment = Alignment.Top,
                // Pre-emptively layout and compose the next page, to make sure the height stays
                // the same even if we have fewer than [tilesPerPage] tiles on the last page.
                beyondViewportPageCount = 1,
            ) { page ->
                Column(
                    modifier = Modifier.fillMaxWidth().fillMaxHeight(),
                    verticalArrangement = Arrangement.spacedBy(8.dp, alignment = Alignment.Top),
                ) {
                    val startIndex = page * tilesPerPage
                    val endIndex = minOf((page + 1) * tilesPerPage, tiles.size)
                    for (index in startIndex until endIndex) {
                        ModeTile(viewModel = tiles[index], modifier = Modifier.fillMaxWidth())
                    }
                }
            }

            PagerDots(
                pagerState = pagerState,
                activeColor = MaterialTheme.colorScheme.primary,
                nonActiveColor = MaterialTheme.colorScheme.onSurfaceVariant,
                modifier = Modifier.align(Alignment.CenterHorizontally).padding(top = 8.dp),
            )
        }
    } else {
        LazyVerticalGrid(
            columns = GridCells.Fixed(1),
            modifier = Modifier.fillMaxWidth().heightIn(max = 280.dp),
@@ -43,3 +87,4 @@ fun ModeTileGrid(viewModel: ModesDialogViewModel) {
            }
        }
    }
}