1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.qs.panels.ui.viewmodel 18 19 import android.content.Context 20 import androidx.compose.runtime.Immutable 21 import androidx.compose.ui.text.AnnotatedString 22 import com.android.systemui.common.shared.model.Icon 23 import com.android.systemui.common.shared.model.Text 24 import com.android.systemui.common.ui.compose.toAnnotatedString 25 import com.android.systemui.qs.pipeline.shared.TileSpec 26 import com.android.systemui.qs.shared.model.CategoryAndName 27 import com.android.systemui.qs.shared.model.TileCategory 28 29 /** 30 * View model for each tile that is available to be added/removed/moved in Edit mode. 31 * 32 * [isCurrent] indicates whether this tile is part of the current set of tiles that the user sees in 33 * Quick Settings. 34 */ 35 data class UnloadedEditTileViewModel( 36 val tileSpec: TileSpec, 37 val icon: Icon, 38 val label: Text, 39 val appName: Text?, 40 val isCurrent: Boolean, 41 val availableEditActions: Set<AvailableEditActions>, 42 val category: TileCategory, 43 ) { loadnull44 fun load(context: Context): EditTileViewModel { 45 return EditTileViewModel( 46 tileSpec = tileSpec, 47 icon = icon, 48 label = label.toAnnotatedString(context) ?: AnnotatedString(tileSpec.spec), 49 appName = appName?.toAnnotatedString(context), 50 isCurrent = isCurrent, 51 availableEditActions = availableEditActions, 52 category = category, 53 ) 54 } 55 } 56 57 @Immutable 58 data class EditTileViewModel( 59 val tileSpec: TileSpec, 60 val icon: Icon, 61 val label: AnnotatedString, 62 val appName: AnnotatedString?, 63 val isCurrent: Boolean, 64 val availableEditActions: Set<AvailableEditActions>, 65 override val category: TileCategory, 66 ) : CategoryAndName { 67 override val name 68 get() = label.text 69 70 val isRemovable 71 get() = availableEditActions.contains(AvailableEditActions.REMOVE) 72 } 73 74 enum class AvailableEditActions { 75 ADD, 76 REMOVE, 77 MOVE, 78 } 79