diff --git a/packages/SystemUI/compose/gallery/src/com/android/systemui/qs/footer/Fakes.kt b/packages/SystemUI/compose/gallery/src/com/android/systemui/qs/footer/Fakes.kt new file mode 100644 index 0000000000000..11477f9d833bb --- /dev/null +++ b/packages/SystemUI/compose/gallery/src/com/android/systemui/qs/footer/Fakes.kt @@ -0,0 +1,160 @@ +/* + * Copyright (C) 2022 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.footer + +import android.content.Context +import android.os.UserHandle +import android.view.View +import com.android.internal.util.UserIcons +import com.android.systemui.R +import com.android.systemui.animation.Expandable +import com.android.systemui.classifier.FalsingManagerFake +import com.android.systemui.common.shared.model.Icon +import com.android.systemui.dagger.qualifiers.Application +import com.android.systemui.globalactions.GlobalActionsDialogLite +import com.android.systemui.qs.footer.data.model.UserSwitcherStatusModel +import com.android.systemui.qs.footer.domain.interactor.FooterActionsInteractor +import com.android.systemui.qs.footer.domain.model.SecurityButtonConfig +import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel +import com.android.systemui.util.mockito.mock +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf + +/** A list of fake [FooterActionsViewModel] to be used in screenshot tests and the gallery. */ +fun fakeFooterActionsViewModels( + @Application context: Context, +): List { + return listOf( + fakeFooterActionsViewModel(context), + fakeFooterActionsViewModel(context, showPowerButton = false, isGuestUser = true), + fakeFooterActionsViewModel(context, showUserSwitcher = false), + fakeFooterActionsViewModel(context, showUserSwitcher = false, foregroundServices = 4), + fakeFooterActionsViewModel( + context, + foregroundServices = 4, + hasNewForegroundServices = true, + userId = 1, + ), + fakeFooterActionsViewModel( + context, + securityText = "Security", + foregroundServices = 4, + showUserSwitcher = false, + ), + fakeFooterActionsViewModel( + context, + securityText = "Security (not clickable)", + securityClickable = false, + foregroundServices = 4, + hasNewForegroundServices = true, + userId = 2, + ), + ) +} + +private fun fakeFooterActionsViewModel( + @Application context: Context, + securityText: String? = null, + securityClickable: Boolean = true, + foregroundServices: Int = 0, + hasNewForegroundServices: Boolean = false, + showUserSwitcher: Boolean = true, + showPowerButton: Boolean = true, + userId: Int = UserHandle.USER_OWNER, + isGuestUser: Boolean = false, +): FooterActionsViewModel { + val interactor = + FakeFooterActionsInteractor( + securityButtonConfig = + flowOf( + securityText?.let { text -> + SecurityButtonConfig( + icon = Icon.Resource(R.drawable.ic_info_outline), + text = text, + isClickable = securityClickable, + ) + } + ), + foregroundServicesCount = flowOf(foregroundServices), + hasNewForegroundServices = flowOf(hasNewForegroundServices), + userSwitcherStatus = + flowOf( + if (showUserSwitcher) { + UserSwitcherStatusModel.Enabled( + currentUserName = "foo", + currentUserImage = + UserIcons.getDefaultUserIcon( + context.resources, + userId, + /* light= */ false, + ), + isGuestUser = isGuestUser, + ) + } else { + UserSwitcherStatusModel.Disabled + } + ), + deviceMonitoringDialogRequests = flowOf(), + ) + + return FooterActionsViewModel( + context, + interactor, + FalsingManagerFake(), + globalActionsDialogLite = mock(), + showPowerButton = showPowerButton, + ) +} + +private class FakeFooterActionsInteractor( + override val securityButtonConfig: Flow = flowOf(null), + override val foregroundServicesCount: Flow = flowOf(0), + override val hasNewForegroundServices: Flow = flowOf(false), + override val userSwitcherStatus: Flow = + flowOf(UserSwitcherStatusModel.Disabled), + override val deviceMonitoringDialogRequests: Flow = flowOf(), + private val onShowDeviceMonitoringDialogFromView: (View) -> Unit = {}, + private val onShowDeviceMonitoringDialog: (Context) -> Unit = {}, + private val onShowForegroundServicesDialog: (View) -> Unit = {}, + private val onShowPowerMenuDialog: (GlobalActionsDialogLite, View) -> Unit = { _, _ -> }, + private val onShowSettings: (Expandable) -> Unit = {}, + private val onShowUserSwitcher: (View) -> Unit = {}, +) : FooterActionsInteractor { + override fun showDeviceMonitoringDialog(view: View) { + onShowDeviceMonitoringDialogFromView(view) + } + + override fun showDeviceMonitoringDialog(quickSettingsContext: Context) { + onShowDeviceMonitoringDialog(quickSettingsContext) + } + + override fun showForegroundServicesDialog(view: View) { + onShowForegroundServicesDialog(view) + } + + override fun showPowerMenuDialog(globalActionsDialogLite: GlobalActionsDialogLite, view: View) { + onShowPowerMenuDialog(globalActionsDialogLite, view) + } + + override fun showSettings(expandable: Expandable) { + onShowSettings(expandable) + } + + override fun showUserSwitcher(view: View) { + onShowUserSwitcher(view) + } +} diff --git a/packages/SystemUI/res-keyguard/layout/footer_actions.xml b/packages/SystemUI/res-keyguard/layout/footer_actions.xml index 0a6a68733b115..1ce106ed2156d 100644 --- a/packages/SystemUI/res-keyguard/layout/footer_actions.xml +++ b/packages/SystemUI/res-keyguard/layout/footer_actions.xml @@ -23,7 +23,7 @@ android:layout_width="match_parent" android:layout_height="@dimen/footer_actions_height" android:elevation="@dimen/qs_panel_elevation" - android:paddingTop="8dp" + android:paddingTop="@dimen/qs_footer_actions_top_padding" android:paddingBottom="@dimen/qs_footer_actions_bottom_padding" android:background="@drawable/qs_footer_actions_background" android:gravity="center_vertical|end" diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index f34472158d1bd..a2145fd50c78f 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -380,6 +380,7 @@ 4dp + 8dp 4dp -4dp