diff options
3 files changed, 38 insertions, 47 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettingsShadeOverlay.kt b/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettingsShadeOverlay.kt index afdb3cbba60e..da0b8ac7bda3 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettingsShadeOverlay.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/qs/ui/composable/QuickSettingsShadeOverlay.kt @@ -38,7 +38,6 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.layout.boundsInWindow -import androidx.compose.ui.layout.layoutId import androidx.compose.ui.layout.onPlaced import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.dp @@ -66,7 +65,6 @@ import com.android.systemui.scene.ui.composable.Overlay import com.android.systemui.shade.ui.composable.OverlayShade import com.android.systemui.shade.ui.composable.OverlayShadeHeader import com.android.systemui.shade.ui.composable.QuickSettingsOverlayHeader -import com.android.systemui.shade.ui.composable.SingleShadeMeasurePolicy import com.android.systemui.statusbar.notification.stack.shared.model.ShadeScrimBounds import com.android.systemui.statusbar.notification.stack.shared.model.ShadeScrimShape import com.android.systemui.statusbar.notification.stack.ui.view.NotificationScrollView @@ -108,6 +106,11 @@ constructor( rememberViewModel("QuickSettingsShadeOverlayContainer") { quickSettingsContainerViewModelFactory.create(supportsBrightnessMirroring = true) } + val hunPlaceholderViewModel = + rememberViewModel("QuickSettingsShadeOverlayPlaceholder") { + notificationsPlaceholderViewModelFactory.create() + } + val panelCornerRadius = with(LocalDensity.current) { OverlayShade.Dimensions.PanelCornerRadius.toPx().toInt() } val showBrightnessMirror = @@ -119,13 +122,6 @@ constructor( DisposableEffect(Unit) { onDispose { contentViewModel.onPanelShapeChanged(null) } } Box(modifier = modifier.graphicsLayer { alpha = contentAlphaFromBrightnessMirror }) { - SnoozeableHeadsUpNotificationSpace( - stackScrollView = notificationStackScrollView.get(), - viewModel = - rememberViewModel("QuickSettingsShadeOverlayPlaceholder") { - notificationsPlaceholderViewModelFactory.create() - }, - ) OverlayShade( panelElement = QuickSettingsShade.Elements.Panel, alignmentOnWideScreens = Alignment.TopEnd, @@ -133,50 +129,34 @@ constructor( header = { OverlayShadeHeader( viewModel = quickSettingsContainerViewModel.shadeHeaderViewModel, - modifier = - Modifier.element(QuickSettingsShade.Elements.StatusBar) - .layoutId(SingleShadeMeasurePolicy.LayoutId.ShadeHeader), + modifier = Modifier.element(QuickSettingsShade.Elements.StatusBar), ) }, ) { - ShadeBody( + QuickSettingsContainer( viewModel = quickSettingsContainerViewModel, modifier = Modifier.onPlaced { coordinates -> - val boundsInWindow = coordinates.boundsInWindow() - val shadeScrimBounds = - ShadeScrimBounds( - left = boundsInWindow.left, - top = boundsInWindow.top, - right = boundsInWindow.right, - bottom = boundsInWindow.bottom, - ) val shape = ShadeScrimShape( - bounds = shadeScrimBounds, + bounds = ShadeScrimBounds(coordinates.boundsInWindow()), topRadius = 0, bottomRadius = panelCornerRadius, ) contentViewModel.onPanelShapeChanged(shape) }, - header = { - if (quickSettingsContainerViewModel.showHeader) { - QuickSettingsOverlayHeader( - viewModel = quickSettingsContainerViewModel.shadeHeaderViewModel, - modifier = - Modifier.element(QuickSettingsShade.Elements.Header) - .padding(top = QuickSettingsShade.Dimensions.Padding), - ) - } - }, ) } + SnoozeableHeadsUpNotificationSpace( + stackScrollView = notificationStackScrollView.get(), + viewModel = hunPlaceholderViewModel, + ) } } } -// The possible states of the `ShadeBody`. -sealed interface ShadeBodyState { +/** The possible states of the `ShadeBody`. */ +private sealed interface ShadeBodyState { data object Editing : ShadeBodyState data object TileDetails : ShadeBodyState @@ -185,10 +165,9 @@ sealed interface ShadeBodyState { } @Composable -fun ContentScope.ShadeBody( +fun ContentScope.QuickSettingsContainer( viewModel: QuickSettingsContainerViewModel, modifier: Modifier = Modifier, - header: @Composable () -> Unit, ) { val isEditing by viewModel.editModeViewModel.isEditing.collectAsStateWithLifecycle() val tileDetails = @@ -216,11 +195,10 @@ fun ContentScope.ShadeBody( TileDetails(modifier = modifier, viewModel.detailsViewModel) } - else -> { + ShadeBodyState.Default -> { QuickSettingsLayout( viewModel = viewModel, modifier = modifier.sysuiResTag("quick_settings_panel"), - header = header, ) } } @@ -232,7 +210,6 @@ fun ContentScope.ShadeBody( fun ContentScope.QuickSettingsLayout( viewModel: QuickSettingsContainerViewModel, modifier: Modifier = Modifier, - header: @Composable () -> Unit, ) { Column( verticalArrangement = Arrangement.spacedBy(QuickSettingsShade.Dimensions.Padding), @@ -244,7 +221,14 @@ fun ContentScope.QuickSettingsLayout( bottom = QuickSettingsShade.Dimensions.Padding, ), ) { - header() + if (viewModel.showHeader) { + QuickSettingsOverlayHeader( + viewModel = viewModel.shadeHeaderViewModel, + modifier = + Modifier.element(QuickSettingsShade.Elements.Header) + .padding(top = QuickSettingsShade.Dimensions.Padding), + ) + } Toolbar( modifier = Modifier.fillMaxWidth().requiredHeight(QuickSettingsShade.Dimensions.ToolbarHeight), diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt index 2082423f1fd3..31323c749238 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeViewModel.kt @@ -42,6 +42,8 @@ import javax.inject.Inject import javax.inject.Named import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow @@ -53,6 +55,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch +@OptIn(ExperimentalCoroutinesApi::class) @SysUISingleton class EditModeViewModel @Inject @@ -73,11 +76,9 @@ constructor( private val _isEditing = MutableStateFlow(false) /** - * Whether we should be editing right now. Use [startEditing] and [stopEditing] to change this + * Whether we should be editing right now. Use [startEditing] and [stopEditing] to change this. */ val isEditing = _isEditing.asStateFlow() - private val minimumTiles: Int - get() = minTilesInteractor.minNumberOfTiles val gridLayout: StateFlow<GridLayout> = gridLayoutTypeInteractor.layout @@ -99,7 +100,7 @@ constructor( * * Tiles that are not available will be filtered out. None of them can be current (as they * cannot be created), and they won't be able to be added. */ - val tiles = + val tiles: Flow<List<EditTileViewModel>> = isEditing.flatMapLatest { if (it) { val editTilesData = editTilesListInteractor.getTilesToEdit() @@ -114,10 +115,10 @@ constructor( currentTilesInteractor.currentTiles .map { tiles -> val currentSpecs = tiles.map { it.spec } - val canRemoveTiles = currentSpecs.size > minimumTiles + val canRemoveTiles = currentSpecs.size > minTilesInteractor.minNumberOfTiles val allTiles = editTilesData.stockTiles + editTilesData.customTiles - val allTilesMap = allTiles.associate { it.tileSpec to it } - val currentTiles = currentSpecs.map { allTilesMap.get(it) }.filterNotNull() + val allTilesMap = allTiles.associateBy { it.tileSpec } + val currentTiles = currentSpecs.mapNotNull { allTilesMap[it] } val nonCurrentTiles = allTiles.filter { it.tileSpec !in currentSpecs } (currentTiles + nonCurrentTiles) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/shared/model/ShadeScrimBounds.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/shared/model/ShadeScrimBounds.kt index 832e69080f3c..78ece5336d04 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/shared/model/ShadeScrimBounds.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/shared/model/ShadeScrimBounds.kt @@ -16,6 +16,8 @@ package com.android.systemui.statusbar.notification.stack.shared.model +import androidx.compose.ui.geometry.Rect + /** Models the bounds of the notification stack. */ data class ShadeScrimBounds( /** The position of the left of the stack in its window coordinate system, in pixels. */ @@ -27,6 +29,10 @@ data class ShadeScrimBounds( /** The position of the bottom of the stack in its window coordinate system, in pixels. */ val bottom: Float = 0f, ) { + constructor( + bounds: Rect + ) : this(left = bounds.left, top = bounds.top, right = bounds.right, bottom = bounds.bottom) + /** The current height of the notification container. */ val height: Float = bottom - top |