From 16ed7a2a093a4192b757efceed97e64cba856141 Mon Sep 17 00:00:00 2001 From: Fabián Kozynski Date: Wed, 27 Nov 2024 14:34:56 -0500 Subject: Add a toolbar for dual shade QS actions This adds a toolbar for dual shade QS containing: * Edit mode button * User switcher button * Settings button * Power menu button It leverages the FooterActionsInteractor as well as the individual view models that FooterActions uses. This means that it uses the same color tokens. In the future, we'll need to use material color tokens. It does not include security "footer", as that will be done later. Test: manual, test buttons in QS shade Bug: 381279450 Flag: com.android.systemui.dual_shade Change-Id: I0ef0ecaa76c1058cff443b5e93f71d9edaf0654a --- .../systemui/qs/footer/ui/compose/FooterActions.kt | 2 +- .../qs/ui/composable/QuickSettingsShadeOverlay.kt | 2 + .../ui/viewmodel/EditModeButtonViewModelTest.kt | 63 ------------ .../toolbar/EditModeButtonViewModelTest.kt | 64 ++++++++++++ .../domain/interactor/FalsingInteractor.kt | 9 ++ .../footer/ui/viewmodel/FooterActionsViewModel.kt | 78 ++++++++------- .../qs/panels/ui/compose/EditModeButton.kt | 61 ----------- .../qs/panels/ui/compose/PaginatedGridLayout.kt | 3 +- .../qs/panels/ui/compose/toolbar/EditModeButton.kt | 61 +++++++++++ .../qs/panels/ui/compose/toolbar/Toolbar.kt | 54 ++++++++++ .../panels/ui/viewmodel/EditModeButtonViewModel.kt | 41 -------- .../panels/ui/viewmodel/PaginatedGridViewModel.kt | 1 + .../viewmodel/toolbar/EditModeButtonViewModel.kt | 42 ++++++++ .../ui/viewmodel/toolbar/ToolbarViewModel.kt | 111 +++++++++++++++++++++ .../viewmodel/QuickSettingsContainerViewModel.kt | 2 + .../globalactions/GlobalActionsDialogLiteKosmos.kt | 23 +++++ .../ui/viewmodel/EditModeButtonViewModelKosmos.kt | 29 ------ .../ui/viewmodel/PaginatedGridViewModelKosmos.kt | 1 + .../toolbar/EditModeButtonViewModelKosmos.kt | 30 ++++++ .../ui/viewmodel/toolbar/ToolbarViewModelKosmos.kt | 38 +++++++ .../QuickSettingsContainerViewModelKosmos.kt | 2 + 21 files changed, 484 insertions(+), 233 deletions(-) delete mode 100644 packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelTest.kt create mode 100644 packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelTest.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditModeButton.kt create mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/EditModeButton.kt create mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/Toolbar.kt delete mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModel.kt create mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModel.kt create mode 100644 packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModel.kt create mode 100644 packages/SystemUI/tests/utils/src/com/android/systemui/globalactions/GlobalActionsDialogLiteKosmos.kt delete mode 100644 packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelKosmos.kt create mode 100644 packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelKosmos.kt create mode 100644 packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModelKosmos.kt diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt index 2d32fd768eaa..f7ce2153b0ec 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt @@ -261,7 +261,7 @@ private fun RowScope.ForegroundServicesButton( /** A button with an icon. */ @Composable -private fun IconButton(model: FooterActionsButtonViewModel, modifier: Modifier = Modifier) { +fun IconButton(model: FooterActionsButtonViewModel, modifier: Modifier = Modifier) { Expandable( color = colorAttr(model.backgroundColor), shape = CircleShape, 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 b0b1288a7cbd..b1a19456ab7d 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 @@ -52,6 +52,7 @@ import com.android.systemui.qs.flags.QsDetailedView import com.android.systemui.qs.panels.ui.compose.EditMode import com.android.systemui.qs.panels.ui.compose.TileDetails import com.android.systemui.qs.panels.ui.compose.TileGrid +import com.android.systemui.qs.panels.ui.compose.toolbar.Toolbar import com.android.systemui.qs.ui.composable.QuickSettingsShade.Dimensions.GridMaxHeight import com.android.systemui.qs.ui.viewmodel.QuickSettingsContainerViewModel import com.android.systemui.qs.ui.viewmodel.QuickSettingsShadeOverlayActionsViewModel @@ -189,6 +190,7 @@ fun SceneScope.QuickSettingsLayout( bottom = QuickSettingsShade.Dimensions.Padding / 2, ), ) { + Toolbar(viewModel.toolbarViewModelFactory) BrightnessSliderContainer( viewModel = viewModel.brightnessSliderViewModel, modifier = diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelTest.kt deleted file mode 100644 index f2bfd729f74a..000000000000 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelTest.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.ui.viewmodel - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import com.android.systemui.SysuiTestCase -import com.android.systemui.classifier.fakeFalsingManager -import com.android.systemui.kosmos.collectLastValue -import com.android.systemui.kosmos.runCurrent -import com.android.systemui.kosmos.runTest -import com.android.systemui.testKosmos -import com.google.common.truth.Truth.assertThat -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -@SmallTest -class EditModeButtonViewModelTest : SysuiTestCase() { - val kosmos = testKosmos() - - val underTest = kosmos.editModeButtonViewModelFactory.create() - - @Test - fun falsingFalseTap_editModeDoesntStart() = - kosmos.runTest { - val isEditing by collectLastValue(editModeViewModel.isEditing) - - fakeFalsingManager.setFalseTap(true) - - underTest.onButtonClick() - runCurrent() - - assertThat(isEditing).isFalse() - } - - @Test - fun falsingNotFalseTap_editModeStarted() = - kosmos.runTest { - val isEditing by collectLastValue(editModeViewModel.isEditing) - - fakeFalsingManager.setFalseTap(false) - - underTest.onButtonClick() - runCurrent() - - assertThat(isEditing).isTrue() - } -} diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelTest.kt new file mode 100644 index 000000000000..a8e390c25a4d --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelTest.kt @@ -0,0 +1,64 @@ +/* + * 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.ui.viewmodel + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.classifier.fakeFalsingManager +import com.android.systemui.kosmos.collectLastValue +import com.android.systemui.kosmos.runCurrent +import com.android.systemui.kosmos.runTest +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.editModeButtonViewModelFactory +import com.android.systemui.testKosmos +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +@SmallTest +class EditModeButtonViewModelTest : SysuiTestCase() { + val kosmos = testKosmos() + + val underTest = kosmos.editModeButtonViewModelFactory.create() + + @Test + fun falsingFalseTap_editModeDoesntStart() = + kosmos.runTest { + val isEditing by collectLastValue(editModeViewModel.isEditing) + + fakeFalsingManager.setFalseTap(true) + + underTest.onButtonClick() + runCurrent() + + assertThat(isEditing).isFalse() + } + + @Test + fun falsingNotFalseTap_editModeStarted() = + kosmos.runTest { + val isEditing by collectLastValue(editModeViewModel.isEditing) + + fakeFalsingManager.setFalseTap(false) + + underTest.onButtonClick() + runCurrent() + + assertThat(isEditing).isTrue() + } +} diff --git a/packages/SystemUI/src/com/android/systemui/classifier/domain/interactor/FalsingInteractor.kt b/packages/SystemUI/src/com/android/systemui/classifier/domain/interactor/FalsingInteractor.kt index 074b64e0fab0..69f4f6d30f5d 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/domain/interactor/FalsingInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/classifier/domain/interactor/FalsingInteractor.kt @@ -74,3 +74,12 @@ constructor( /** Returns `true` if the tap gesture should be rejected */ fun isFalseTap(@Penalty penalty: Int): Boolean = manager.isFalseTap(penalty) } + +inline fun FalsingInteractor.runIfNotFalseTap( + penalty: Int = FalsingManager.LOW_PENALTY, + action: () -> Unit, +) { + if (!isFalseTap(penalty)) { + action() + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModel.kt index 8ef637545e69..cc872060b827 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/footer/ui/viewmodel/FooterActionsViewModel.kt @@ -23,12 +23,12 @@ import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleCoroutineScope import androidx.lifecycle.LifecycleOwner +import com.android.app.tracing.coroutines.launchTraced as launch import com.android.settingslib.Utils import com.android.systemui.animation.Expandable import com.android.systemui.common.shared.model.ContentDescription import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.globalactions.GlobalActionsDialogLite import com.android.systemui.plugins.ActivityStarter import com.android.systemui.plugins.FalsingManager @@ -38,6 +38,7 @@ import com.android.systemui.qs.footer.domain.interactor.FooterActionsInteractor import com.android.systemui.qs.footer.domain.model.SecurityButtonConfig import com.android.systemui.res.R import com.android.systemui.shade.ShadeDisplayAware +import com.android.systemui.shade.shared.flag.DualShade import com.android.systemui.util.icuMessageFormat import javax.inject.Inject import javax.inject.Named @@ -54,7 +55,6 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map import kotlinx.coroutines.isActive -import com.android.app.tracing.coroutines.launchTraced as launch private const val TAG = "FooterActionsViewModel" @@ -113,7 +113,7 @@ class FooterActionsViewModel( class Factory @Inject constructor( - @ShadeDisplayAware private val context: Context, + @ShadeDisplayAware private val context: Context, private val falsingManager: FalsingManager, private val footerActionsInteractor: FooterActionsInteractor, private val globalActionsDialogLiteProvider: Provider, @@ -211,7 +211,7 @@ fun FooterActionsViewModel( false /* if the dismiss should be deferred */ }, null /* cancelAction */, - true /* afterKeyguardGone */ + true, /* afterKeyguardGone */ ) } @@ -269,29 +269,7 @@ fun FooterActionsViewModel( .distinctUntilChanged() val userSwitcher = - footerActionsInteractor.userSwitcherStatus - .map { userSwitcherStatus -> - when (userSwitcherStatus) { - UserSwitcherStatusModel.Disabled -> null - is UserSwitcherStatusModel.Enabled -> { - if (userSwitcherStatus.currentUserImage == null) { - Log.e( - TAG, - "Skipped the addition of user switcher button because " + - "currentUserImage is missing", - ) - return@map null - } - - userSwitcherButtonViewModel( - qsThemedContext, - userSwitcherStatus, - ::onUserSwitcherClicked - ) - } - } - } - .distinctUntilChanged() + userSwitcherViewModel(qsThemedContext, footerActionsInteractor, ::onUserSwitcherClicked) val settings = settingsButtonViewModel(qsThemedContext, ::onSettingsButtonClicked) val power = @@ -311,6 +289,36 @@ fun FooterActionsViewModel( ) } +fun userSwitcherViewModel( + themedContext: Context, + footerActionsInteractor: FooterActionsInteractor, + onUserSwitcherClicked: (Expandable) -> Unit, +): Flow { + return footerActionsInteractor.userSwitcherStatus + .map { userSwitcherStatus -> + when (userSwitcherStatus) { + UserSwitcherStatusModel.Disabled -> null + is UserSwitcherStatusModel.Enabled -> { + if (userSwitcherStatus.currentUserImage == null) { + Log.e( + TAG, + "Skipped the addition of user switcher button because " + + "currentUserImage is missing", + ) + return@map null + } + + userSwitcherButtonViewModel( + themedContext, + userSwitcherStatus, + onUserSwitcherClicked, + ) + } + } + } + .distinctUntilChanged() +} + fun securityButtonViewModel( config: SecurityButtonConfig, onSecurityButtonClicked: (Context, Expandable) -> Unit, @@ -369,7 +377,7 @@ fun userSwitcherButtonViewModel( private fun userSwitcherContentDescription( qsThemedContext: Context, - currentUser: String? + currentUser: String?, ): String? { return currentUser?.let { user -> qsThemedContext.getString(R.string.accessibility_quick_settings_user, user) @@ -384,13 +392,9 @@ fun settingsButtonViewModel( id = R.id.settings_button_container, Icon.Resource( R.drawable.ic_settings, - ContentDescription.Resource(R.string.accessibility_quick_settings_settings) + ContentDescription.Resource(R.string.accessibility_quick_settings_settings), ), - iconTint = - Utils.getColorAttrDefaultColor( - qsThemedContext, - R.attr.onShadeInactiveVariant, - ), + iconTint = Utils.getColorAttrDefaultColor(qsThemedContext, R.attr.onShadeInactiveVariant), backgroundColor = R.attr.shadeInactive, onSettingsButtonClicked, ) @@ -404,14 +408,14 @@ fun powerButtonViewModel( id = R.id.pm_lite, Icon.Resource( android.R.drawable.ic_lock_power_off, - ContentDescription.Resource(R.string.accessibility_quick_settings_power_menu) + ContentDescription.Resource(R.string.accessibility_quick_settings_power_menu), ), iconTint = Utils.getColorAttrDefaultColor( qsThemedContext, - R.attr.onShadeActive, + if (DualShade.isEnabled) R.attr.onShadeInactiveVariant else R.attr.onShadeActive, ), - backgroundColor = R.attr.shadeActive, + backgroundColor = if (DualShade.isEnabled) R.attr.shadeInactive else R.attr.shadeActive, onPowerButtonClicked, ) } diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditModeButton.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditModeButton.kt deleted file mode 100644 index c2764f9f338b..000000000000 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/EditModeButton.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.ui.compose - -import androidx.compose.foundation.shape.CornerSize -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Edit -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton -import androidx.compose.material3.LocalContentColor -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.runtime.CompositionLocalProvider -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.unit.dp -import com.android.systemui.lifecycle.rememberViewModel -import com.android.systemui.qs.panels.ui.viewmodel.EditModeButtonViewModel -import com.android.systemui.qs.ui.compose.borderOnFocus -import com.android.systemui.res.R - -@Composable -fun EditModeButton( - viewModelFactory: EditModeButtonViewModel.Factory, - modifier: Modifier = Modifier, -) { - val viewModel = rememberViewModel(traceName = "EditModeButton") { viewModelFactory.create() } - CompositionLocalProvider( - value = LocalContentColor provides MaterialTheme.colorScheme.onSurface - ) { - IconButton( - onClick = viewModel::onButtonClick, - shape = RoundedCornerShape(CornerSize(28.dp)), - modifier = - modifier.borderOnFocus( - color = MaterialTheme.colorScheme.secondary, - cornerSize = CornerSize(24.dp), - ), - ) { - Icon( - imageVector = Icons.Default.Edit, - contentDescription = stringResource(id = R.string.qs_edit), - ) - } - } -} diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PaginatedGridLayout.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PaginatedGridLayout.kt index b6dbf4db57a4..39408d3dee72 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PaginatedGridLayout.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/PaginatedGridLayout.kt @@ -49,9 +49,10 @@ import com.android.systemui.lifecycle.rememberViewModel import com.android.systemui.qs.panels.dagger.PaginatedBaseLayoutType import com.android.systemui.qs.panels.ui.compose.Dimensions.FooterHeight import com.android.systemui.qs.panels.ui.compose.Dimensions.InterPageSpacing -import com.android.systemui.qs.panels.ui.viewmodel.EditModeButtonViewModel +import com.android.systemui.qs.panels.ui.compose.toolbar.EditModeButton 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 javax.inject.Inject diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/EditModeButton.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/EditModeButton.kt new file mode 100644 index 000000000000..85db95203b45 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/EditModeButton.kt @@ -0,0 +1,61 @@ +/* + * 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.ui.compose.toolbar + +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import com.android.systemui.lifecycle.rememberViewModel +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.EditModeButtonViewModel +import com.android.systemui.qs.ui.compose.borderOnFocus +import com.android.systemui.res.R + +@Composable +fun EditModeButton( + viewModelFactory: EditModeButtonViewModel.Factory, + modifier: Modifier = Modifier, +) { + val viewModel = rememberViewModel(traceName = "EditModeButton") { viewModelFactory.create() } + CompositionLocalProvider( + value = LocalContentColor provides MaterialTheme.colorScheme.onSurface + ) { + IconButton( + onClick = viewModel::onButtonClick, + shape = RoundedCornerShape(CornerSize(28.dp)), + modifier = + modifier.borderOnFocus( + color = MaterialTheme.colorScheme.secondary, + cornerSize = CornerSize(24.dp), + ), + ) { + Icon( + imageVector = Icons.Default.Edit, + contentDescription = stringResource(id = R.string.qs_edit), + ) + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/Toolbar.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/Toolbar.kt new file mode 100644 index 000000000000..37fa9e799521 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/compose/toolbar/Toolbar.kt @@ -0,0 +1,54 @@ +/* + * 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.ui.compose.toolbar + +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.requiredHeight +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.android.systemui.compose.modifiers.sysuiResTag +import com.android.systemui.lifecycle.rememberViewModel +import com.android.systemui.qs.footer.ui.compose.IconButton +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.ToolbarViewModel + +@Composable +fun Toolbar(toolbarViewModelFactory: ToolbarViewModel.Factory, modifier: Modifier = Modifier) { + val viewModel = rememberViewModel("Toolbar") { toolbarViewModelFactory.create() } + + Row( + modifier = modifier.fillMaxWidth().requiredHeight(48.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + viewModel.userSwitcherViewModel?.let { + IconButton(it, Modifier.sysuiResTag("multi_user_switch")) + } + + EditModeButton(viewModel.editModeButtonViewModelFactory) + + IconButton( + viewModel.settingsButtonViewModel, + Modifier.sysuiResTag("settings_button_container"), + ) + + Spacer(modifier = Modifier.weight(1f)) + IconButton(viewModel.powerButtonViewModel, Modifier.sysuiResTag("pm_lite")) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModel.kt deleted file mode 100644 index b033473a91e5..000000000000 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModel.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.ui.viewmodel - -import com.android.systemui.classifier.domain.interactor.FalsingInteractor -import com.android.systemui.plugins.FalsingManager -import dagger.assisted.AssistedFactory -import dagger.assisted.AssistedInject - -class EditModeButtonViewModel -@AssistedInject -constructor( - private val editModeViewModel: EditModeViewModel, - private val falsingInteractor: FalsingInteractor, -) { - - fun onButtonClick() { - if (!falsingInteractor.isFalseTap(FalsingManager.LOW_PENALTY)) { - editModeViewModel.startEditing() - } - } - - @AssistedFactory - interface Factory { - fun create(): EditModeButtonViewModel - } -} diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModel.kt index 4a18872ad6f6..3fcb2ab37b0f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModel.kt @@ -24,6 +24,7 @@ import com.android.systemui.lifecycle.ExclusiveActivatable import com.android.systemui.lifecycle.Hydrator import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager.Companion.LOCATION_QS import com.android.systemui.qs.panels.domain.interactor.PaginatedGridInteractor +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.EditModeButtonViewModel import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.awaitCancellation diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModel.kt new file mode 100644 index 000000000000..f60621882ac0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModel.kt @@ -0,0 +1,42 @@ +/* + * 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.ui.viewmodel.toolbar + +import com.android.systemui.classifier.domain.interactor.FalsingInteractor +import com.android.systemui.plugins.FalsingManager +import com.android.systemui.qs.panels.ui.viewmodel.EditModeViewModel +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject + +class EditModeButtonViewModel +@AssistedInject +constructor( + private val editModeViewModel: EditModeViewModel, + private val falsingInteractor: FalsingInteractor, +) { + + fun onButtonClick() { + if (!falsingInteractor.isFalseTap(FalsingManager.LOW_PENALTY)) { + editModeViewModel.startEditing() + } + } + + @AssistedFactory + interface Factory { + fun create(): EditModeButtonViewModel + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModel.kt new file mode 100644 index 000000000000..0fde855f576f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModel.kt @@ -0,0 +1,111 @@ +/* + * 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.ui.viewmodel.toolbar + +import android.content.Context +import android.view.ContextThemeWrapper +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import com.android.systemui.animation.Expandable +import com.android.systemui.classifier.domain.interactor.FalsingInteractor +import com.android.systemui.classifier.domain.interactor.runIfNotFalseTap +import com.android.systemui.globalactions.GlobalActionsDialogLite +import com.android.systemui.lifecycle.ExclusiveActivatable +import com.android.systemui.lifecycle.Hydrator +import com.android.systemui.qs.footer.domain.interactor.FooterActionsInteractor +import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsButtonViewModel +import com.android.systemui.qs.footer.ui.viewmodel.powerButtonViewModel +import com.android.systemui.qs.footer.ui.viewmodel.settingsButtonViewModel +import com.android.systemui.qs.footer.ui.viewmodel.userSwitcherViewModel +import com.android.systemui.res.R +import com.android.systemui.shade.ShadeDisplayAware +import dagger.assisted.AssistedFactory +import dagger.assisted.AssistedInject +import javax.inject.Provider +import kotlinx.coroutines.awaitCancellation +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch + +class ToolbarViewModel +@AssistedInject +constructor( + val editModeButtonViewModelFactory: EditModeButtonViewModel.Factory, + private val footerActionsInteractor: FooterActionsInteractor, + private val globalActionsDialogLiteProvider: Provider, + private val falsingInteractor: FalsingInteractor, + @ShadeDisplayAware appContext: Context, +) : ExclusiveActivatable() { + private val qsThemedContext = + ContextThemeWrapper(appContext, R.style.Theme_SystemUI_QuickSettings) + private val hydrator = Hydrator("ToolbarViewModel.hydrator") + + val powerButtonViewModel = powerButtonViewModel(qsThemedContext, ::onPowerButtonClicked) + + val settingsButtonViewModel = + settingsButtonViewModel(qsThemedContext, ::onSettingsButtonClicked) + + val userSwitcherViewModel: FooterActionsButtonViewModel? by + hydrator.hydratedStateOf( + traceName = "userSwitcherViewModel", + initialValue = null, + source = + userSwitcherViewModel( + qsThemedContext, + footerActionsInteractor, + ::onUserSwitcherClicked, + ), + ) + + override suspend fun onActivated(): Nothing { + coroutineScope { + launch { + try { + globalActionsDialogLite = globalActionsDialogLiteProvider.get() + awaitCancellation() + } finally { + globalActionsDialogLite?.destroy() + } + } + launch { hydrator.activate() } + awaitCancellation() + } + } + + private var globalActionsDialogLite: GlobalActionsDialogLite? by mutableStateOf(null) + + private fun onPowerButtonClicked(expandable: Expandable) { + falsingInteractor.runIfNotFalseTap { + globalActionsDialogLite?.let { + footerActionsInteractor.showPowerMenuDialog(it, expandable) + } + } + } + + private fun onUserSwitcherClicked(expandable: Expandable) { + falsingInteractor.runIfNotFalseTap { footerActionsInteractor.showUserSwitcher(expandable) } + } + + private fun onSettingsButtonClicked(expandable: Expandable) { + falsingInteractor.runIfNotFalseTap { footerActionsInteractor.showSettings(expandable) } + } + + @AssistedFactory + interface Factory { + fun create(): ToolbarViewModel + } +} diff --git a/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModel.kt index 62b120332289..91d907952bc6 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModel.kt @@ -22,6 +22,7 @@ import com.android.systemui.qs.panels.ui.viewmodel.DetailsViewModel import com.android.systemui.qs.panels.ui.viewmodel.EditModeViewModel import com.android.systemui.qs.panels.ui.viewmodel.QuickQuickSettingsViewModel import com.android.systemui.qs.panels.ui.viewmodel.TileGridViewModel +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.ToolbarViewModel import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -38,6 +39,7 @@ constructor( val tileGridViewModel: TileGridViewModel, val editModeViewModel: EditModeViewModel, val detailsViewModel: DetailsViewModel, + val toolbarViewModelFactory: ToolbarViewModel.Factory, ) : ExclusiveActivatable() { val brightnessSliderViewModel = diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/globalactions/GlobalActionsDialogLiteKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/globalactions/GlobalActionsDialogLiteKosmos.kt new file mode 100644 index 000000000000..63bfa52e9720 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/globalactions/GlobalActionsDialogLiteKosmos.kt @@ -0,0 +1,23 @@ +/* + * 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.globalactions + +import com.android.systemui.kosmos.Kosmos +import org.mockito.kotlin.mock + +/** Provides a mock */ +val Kosmos.globalActionsDialogLite: GlobalActionsDialogLite by Kosmos.Fixture { mock() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelKosmos.kt deleted file mode 100644 index b8d3ff425f20..000000000000 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/EditModeButtonViewModelKosmos.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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.ui.viewmodel - -import com.android.systemui.classifier.domain.interactor.falsingInteractor -import com.android.systemui.kosmos.Kosmos - -val Kosmos.editModeButtonViewModelFactory by - Kosmos.Fixture { - object : EditModeButtonViewModel.Factory { - override fun create(): EditModeButtonViewModel { - return EditModeButtonViewModel(editModeViewModel, falsingInteractor) - } - } - } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModelKosmos.kt index eea797a40905..128cfcad5c45 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/PaginatedGridViewModelKosmos.kt @@ -20,6 +20,7 @@ import com.android.systemui.classifier.domain.interactor.falsingInteractor import com.android.systemui.development.ui.viewmodel.buildNumberViewModelFactory import com.android.systemui.kosmos.Kosmos import com.android.systemui.qs.panels.domain.interactor.paginatedGridInteractor +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.editModeButtonViewModelFactory val Kosmos.paginatedGridViewModel by Kosmos.Fixture { diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelKosmos.kt new file mode 100644 index 000000000000..8ae1332c387a --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/EditModeButtonViewModelKosmos.kt @@ -0,0 +1,30 @@ +/* + * 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.ui.viewmodel.toolbar + +import com.android.systemui.classifier.domain.interactor.falsingInteractor +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.qs.panels.ui.viewmodel.editModeViewModel + +val Kosmos.editModeButtonViewModelFactory by + Kosmos.Fixture { + object : EditModeButtonViewModel.Factory { + override fun create(): EditModeButtonViewModel { + return EditModeButtonViewModel(editModeViewModel, falsingInteractor) + } + } + } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModelKosmos.kt new file mode 100644 index 000000000000..52d8a3aac836 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/panels/ui/viewmodel/toolbar/ToolbarViewModelKosmos.kt @@ -0,0 +1,38 @@ +/* + * 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.ui.viewmodel.toolbar + +import android.content.applicationContext +import com.android.systemui.classifier.domain.interactor.falsingInteractor +import com.android.systemui.globalactions.globalActionsDialogLite +import com.android.systemui.kosmos.Kosmos +import com.android.systemui.qs.footerActionsInteractor + +val Kosmos.toolbarViewModelFactory by + Kosmos.Fixture { + object : ToolbarViewModel.Factory { + override fun create(): ToolbarViewModel { + return ToolbarViewModel( + editModeButtonViewModelFactory, + footerActionsInteractor, + { globalActionsDialogLite }, + falsingInteractor, + applicationContext, + ) + } + } + } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModelKosmos.kt index 6afc0d803f8d..aa6ce9a433df 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModelKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsContainerViewModelKosmos.kt @@ -22,6 +22,7 @@ import com.android.systemui.qs.panels.ui.viewmodel.detailsViewModel import com.android.systemui.qs.panels.ui.viewmodel.editModeViewModel import com.android.systemui.qs.panels.ui.viewmodel.quickQuickSettingsViewModelFactory import com.android.systemui.qs.panels.ui.viewmodel.tileGridViewModel +import com.android.systemui.qs.panels.ui.viewmodel.toolbar.toolbarViewModelFactory val Kosmos.quickSettingsContainerViewModelFactory by Kosmos.Fixture { @@ -36,6 +37,7 @@ val Kosmos.quickSettingsContainerViewModelFactory by tileGridViewModel, editModeViewModel, detailsViewModel, + toolbarViewModelFactory, ) } } -- cgit v1.2.3-59-g8ed1b