Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 18 | package com.android.customization.picker.quickaffordance.ui.viewmodel |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 19 | |
| 20 | import android.annotation.SuppressLint |
| 21 | import android.content.Context |
| 22 | import android.content.Intent |
| 23 | import android.graphics.drawable.Drawable |
Alejandro Nijamkin | b169b2c | 2022-12-22 12:25:23 -0800 | [diff] [blame] | 24 | import android.os.Bundle |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 25 | import androidx.annotation.DrawableRes |
| 26 | import androidx.lifecycle.ViewModel |
| 27 | import androidx.lifecycle.ViewModelProvider |
| 28 | import androidx.lifecycle.viewModelScope |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 29 | import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor |
Alejandro Nijamkin | 6238c2e | 2022-12-24 08:11:52 -0800 | [diff] [blame] | 30 | import com.android.systemui.shared.customization.data.content.CustomizationProviderContract |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 31 | import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots |
Alejandro Nijamkin | b169b2c | 2022-12-22 12:25:23 -0800 | [diff] [blame] | 32 | import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 33 | import com.android.wallpaper.R |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 34 | import com.android.wallpaper.module.CurrentWallpaperInfoFactory |
Alejandro Nijamkin | d42f572 | 2023-01-17 17:58:41 -0800 | [diff] [blame^] | 35 | import com.android.wallpaper.picker.common.button.ui.viewmodel.ButtonStyle |
| 36 | import com.android.wallpaper.picker.common.button.ui.viewmodel.ButtonViewModel |
| 37 | import com.android.wallpaper.picker.common.dialog.ui.viewmodel.DialogViewModel |
| 38 | import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon |
| 39 | import com.android.wallpaper.picker.common.text.ui.viewmodel.Text |
Alejandro Nijamkin | b169b2c | 2022-12-22 12:25:23 -0800 | [diff] [blame] | 40 | import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 41 | import com.android.wallpaper.picker.undo.domain.interactor.UndoInteractor |
| 42 | import com.android.wallpaper.picker.undo.ui.viewmodel.UndoViewModel |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 43 | import com.android.wallpaper.util.PreviewUtils |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 44 | import kotlinx.coroutines.ExperimentalCoroutinesApi |
| 45 | import kotlinx.coroutines.flow.Flow |
| 46 | import kotlinx.coroutines.flow.MutableStateFlow |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 47 | import kotlinx.coroutines.flow.StateFlow |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 48 | import kotlinx.coroutines.flow.asStateFlow |
| 49 | import kotlinx.coroutines.flow.combine |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 50 | import kotlinx.coroutines.flow.map |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 51 | import kotlinx.coroutines.launch |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 52 | import kotlinx.coroutines.suspendCancellableCoroutine |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 53 | |
| 54 | /** Models UI state for a lock screen quick affordance picker experience. */ |
| 55 | @OptIn(ExperimentalCoroutinesApi::class) |
| 56 | class KeyguardQuickAffordancePickerViewModel |
| 57 | private constructor( |
| 58 | context: Context, |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 59 | private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor, |
| 60 | undoInteractor: UndoInteractor, |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 61 | private val wallpaperInfoFactory: CurrentWallpaperInfoFactory, |
Alejandro Nijamkin | 7bda0fd | 2022-12-28 14:14:20 -0800 | [diff] [blame] | 62 | activityStarter: (Intent) -> Unit, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 63 | ) : ViewModel() { |
| 64 | |
| 65 | @SuppressLint("StaticFieldLeak") private val applicationContext = context.applicationContext |
| 66 | |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 67 | val preview = |
| 68 | ScreenPreviewViewModel( |
| 69 | previewUtils = |
| 70 | PreviewUtils( |
| 71 | context = applicationContext, |
| 72 | authority = |
| 73 | applicationContext.getString( |
| 74 | R.string.lock_screen_preview_provider_authority, |
| 75 | ), |
| 76 | ), |
| 77 | initialExtrasProvider = { |
| 78 | Bundle().apply { |
| 79 | putString( |
| 80 | KeyguardQuickAffordancePreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID, |
| 81 | selectedSlotId.value, |
| 82 | ) |
| 83 | } |
| 84 | }, |
| 85 | wallpaperInfoProvider = { |
| 86 | suspendCancellableCoroutine { continuation -> |
| 87 | wallpaperInfoFactory.createCurrentWallpaperInfos( |
| 88 | { homeWallpaper, lockWallpaper, _ -> |
| 89 | continuation.resume(lockWallpaper ?: homeWallpaper, null) |
| 90 | }, |
| 91 | /* forceRefresh= */ true, |
| 92 | ) |
| 93 | } |
| 94 | }, |
| 95 | ) |
Alejandro Nijamkin | b169b2c | 2022-12-22 12:25:23 -0800 | [diff] [blame] | 96 | |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 97 | val undo: UndoViewModel = |
| 98 | UndoViewModel( |
| 99 | interactor = undoInteractor, |
| 100 | ) |
| 101 | |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 102 | private val _selectedSlotId = MutableStateFlow<String?>(null) |
| 103 | val selectedSlotId: StateFlow<String?> = _selectedSlotId.asStateFlow() |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 104 | |
| 105 | /** View-models for each slot, keyed by slot ID. */ |
| 106 | val slots: Flow<Map<String, KeyguardQuickAffordanceSlotViewModel>> = |
| 107 | combine( |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 108 | quickAffordanceInteractor.slots, |
| 109 | quickAffordanceInteractor.affordances, |
| 110 | quickAffordanceInteractor.selections, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 111 | selectedSlotId, |
| 112 | ) { slots, affordances, selections, selectedSlotIdOrNull -> |
| 113 | slots |
| 114 | .mapIndexed { index, slot -> |
| 115 | val selectedAffordanceIds = |
| 116 | selections |
| 117 | .filter { selection -> selection.slotId == slot.id } |
| 118 | .map { selection -> selection.affordanceId } |
| 119 | .toSet() |
| 120 | val selectedAffordances = |
| 121 | affordances.filter { affordance -> |
| 122 | selectedAffordanceIds.contains(affordance.id) |
| 123 | } |
| 124 | val isSelected = |
| 125 | (selectedSlotIdOrNull == null && index == 0) || |
| 126 | selectedSlotIdOrNull == slot.id |
| 127 | slot.id to |
| 128 | KeyguardQuickAffordanceSlotViewModel( |
| 129 | name = getSlotName(slot.id), |
| 130 | isSelected = isSelected, |
| 131 | selectedQuickAffordances = |
| 132 | selectedAffordances.map { affordanceModel -> |
| 133 | KeyguardQuickAffordanceViewModel( |
| 134 | icon = getAffordanceIcon(affordanceModel.iconResourceId), |
| 135 | contentDescription = affordanceModel.name, |
| 136 | isSelected = true, |
| 137 | onClicked = null, |
Alejandro Nijamkin | 7bda0fd | 2022-12-28 14:14:20 -0800 | [diff] [blame] | 138 | onLongClicked = null, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 139 | isEnabled = affordanceModel.isEnabled, |
| 140 | ) |
| 141 | }, |
| 142 | maxSelectedQuickAffordances = slot.maxSelectedQuickAffordances, |
| 143 | onClicked = |
| 144 | if (isSelected) { |
| 145 | null |
| 146 | } else { |
Alejandro Nijamkin | 5ec382d | 2022-12-06 16:43:36 -0800 | [diff] [blame] | 147 | { _selectedSlotId.tryEmit(slot.id) } |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 148 | }, |
| 149 | ) |
| 150 | } |
| 151 | .toMap() |
| 152 | } |
| 153 | |
| 154 | /** The list of all available quick affordances for the selected slot. */ |
| 155 | val quickAffordances: Flow<List<KeyguardQuickAffordanceViewModel>> = |
| 156 | combine( |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 157 | quickAffordanceInteractor.slots, |
| 158 | quickAffordanceInteractor.affordances, |
| 159 | quickAffordanceInteractor.selections, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 160 | selectedSlotId, |
| 161 | ) { slots, affordances, selections, selectedSlotIdOrNull -> |
| 162 | val selectedSlot = |
| 163 | selectedSlotIdOrNull?.let { slots.find { slot -> slot.id == it } } ?: slots.first() |
| 164 | val selectedAffordanceIds = |
| 165 | selections |
| 166 | .filter { selection -> selection.slotId == selectedSlot.id } |
| 167 | .map { selection -> selection.affordanceId } |
| 168 | .toSet() |
| 169 | listOf( |
| 170 | none( |
| 171 | slotId = selectedSlot.id, |
| 172 | isSelected = selectedAffordanceIds.isEmpty(), |
| 173 | ) |
| 174 | ) + |
| 175 | affordances.map { affordance -> |
| 176 | val isSelected = selectedAffordanceIds.contains(affordance.id) |
Alejandro Nijamkin | a547706 | 2022-12-22 16:36:47 -0800 | [diff] [blame] | 177 | val affordanceIcon = getAffordanceIcon(affordance.iconResourceId) |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 178 | KeyguardQuickAffordanceViewModel( |
Alejandro Nijamkin | a547706 | 2022-12-22 16:36:47 -0800 | [diff] [blame] | 179 | icon = affordanceIcon, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 180 | contentDescription = affordance.name, |
| 181 | isSelected = isSelected, |
| 182 | onClicked = |
| 183 | if (affordance.isEnabled) { |
| 184 | { |
| 185 | viewModelScope.launch { |
| 186 | if (isSelected) { |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 187 | quickAffordanceInteractor.unselect( |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 188 | slotId = selectedSlot.id, |
| 189 | affordanceId = affordance.id, |
| 190 | ) |
| 191 | } else { |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 192 | quickAffordanceInteractor.select( |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 193 | slotId = selectedSlot.id, |
| 194 | affordanceId = affordance.id, |
| 195 | ) |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } else { |
| 200 | { |
| 201 | showEnablementDialog( |
Alejandro Nijamkin | a547706 | 2022-12-22 16:36:47 -0800 | [diff] [blame] | 202 | icon = affordanceIcon, |
| 203 | name = affordance.name, |
| 204 | instructions = affordance.enablementInstructions, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 205 | actionText = affordance.enablementActionText, |
| 206 | actionComponentName = |
| 207 | affordance.enablementActionComponentName, |
| 208 | ) |
| 209 | } |
| 210 | }, |
Alejandro Nijamkin | 7bda0fd | 2022-12-28 14:14:20 -0800 | [diff] [blame] | 211 | onLongClicked = |
| 212 | if (affordance.configureIntent != null) { |
| 213 | { activityStarter(affordance.configureIntent) } |
| 214 | } else { |
| 215 | null |
| 216 | }, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 217 | isEnabled = affordance.isEnabled, |
| 218 | ) |
| 219 | } |
| 220 | } |
| 221 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 222 | @SuppressLint("UseCompatLoadingForDrawables") |
| 223 | val summary: Flow<KeyguardQuickAffordanceSummaryViewModel> = |
| 224 | slots.map { slots -> |
| 225 | val icon2 = |
| 226 | slots[KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END] |
| 227 | ?.selectedQuickAffordances |
| 228 | ?.firstOrNull() |
| 229 | ?.icon |
| 230 | val icon1 = |
| 231 | slots[KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START] |
| 232 | ?.selectedQuickAffordances |
| 233 | ?.firstOrNull() |
| 234 | ?.icon |
| 235 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 236 | KeyguardQuickAffordanceSummaryViewModel( |
| 237 | description = toDescriptionText(context, slots), |
| 238 | icon1 = icon1 |
| 239 | ?: if (icon2 == null) { |
| 240 | context.getDrawable(R.drawable.link_off) |
| 241 | } else { |
| 242 | null |
| 243 | }, |
| 244 | icon2 = icon2, |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 245 | ) |
| 246 | } |
| 247 | |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 248 | private val _dialog = MutableStateFlow<DialogViewModel?>(null) |
| 249 | /** |
| 250 | * The current dialog to show. If `null`, no dialog should be shown. |
| 251 | * |
| 252 | * When the dialog is dismissed, [onDialogDismissed] must be called. |
| 253 | */ |
| 254 | val dialog: Flow<DialogViewModel?> = _dialog.asStateFlow() |
| 255 | |
| 256 | /** Notifies that the dialog has been dismissed in the UI. */ |
| 257 | fun onDialogDismissed() { |
| 258 | _dialog.value = null |
| 259 | } |
| 260 | |
| 261 | private fun showEnablementDialog( |
Alejandro Nijamkin | a547706 | 2022-12-22 16:36:47 -0800 | [diff] [blame] | 262 | icon: Drawable, |
| 263 | name: String, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 264 | instructions: List<String>, |
| 265 | actionText: String?, |
| 266 | actionComponentName: String?, |
| 267 | ) { |
| 268 | _dialog.value = |
| 269 | DialogViewModel( |
Alejandro Nijamkin | d42f572 | 2023-01-17 17:58:41 -0800 | [diff] [blame^] | 270 | icon = |
| 271 | Icon.Loaded( |
| 272 | drawable = icon, |
| 273 | contentDescription = null, |
| 274 | ), |
| 275 | title = Text.Loaded(name), |
| 276 | message = |
| 277 | Text.Loaded( |
| 278 | buildString { |
| 279 | instructions.forEachIndexed { index, instruction -> |
| 280 | if (index > 0) { |
| 281 | append('\n') |
| 282 | } |
| 283 | |
| 284 | append(instruction) |
| 285 | } |
| 286 | } |
| 287 | ), |
| 288 | buttons = |
| 289 | listOf( |
| 290 | ButtonViewModel( |
| 291 | text = actionText?.let { Text.Loaded(actionText) } |
| 292 | ?: Text.Resource( |
| 293 | R.string |
| 294 | .keyguard_affordance_enablement_dialog_dismiss_button, |
| 295 | ), |
| 296 | style = ButtonStyle.Primary, |
| 297 | onClicked = { |
| 298 | actionComponentName.toIntent()?.let { intent -> |
| 299 | applicationContext.startActivity(intent) |
| 300 | } |
| 301 | } |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 302 | ), |
Alejandro Nijamkin | d42f572 | 2023-01-17 17:58:41 -0800 | [diff] [blame^] | 303 | ), |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 304 | ) |
| 305 | } |
| 306 | |
| 307 | @SuppressLint("UseCompatLoadingForDrawables") |
| 308 | private fun none( |
| 309 | slotId: String, |
| 310 | isSelected: Boolean, |
| 311 | ): KeyguardQuickAffordanceViewModel { |
| 312 | return KeyguardQuickAffordanceViewModel.none( |
| 313 | context = applicationContext, |
| 314 | isSelected = isSelected, |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 315 | onSelected = { |
| 316 | viewModelScope.launch { quickAffordanceInteractor.unselectAll(slotId) } |
| 317 | }, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 318 | ) |
| 319 | } |
| 320 | |
| 321 | private fun getSlotName(slotId: String): String { |
| 322 | return applicationContext.getString( |
| 323 | when (slotId) { |
| 324 | KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START -> |
| 325 | R.string.keyguard_slot_name_bottom_start |
| 326 | KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END -> |
| 327 | R.string.keyguard_slot_name_bottom_end |
| 328 | else -> error("No name for slot with ID of \"$slotId\"!") |
| 329 | } |
| 330 | ) |
| 331 | } |
| 332 | |
| 333 | private suspend fun getAffordanceIcon(@DrawableRes iconResourceId: Int): Drawable { |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 334 | return quickAffordanceInteractor.getAffordanceIcon(iconResourceId) |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | private fun String?.toIntent(): Intent? { |
| 338 | if (isNullOrEmpty()) { |
| 339 | return null |
| 340 | } |
| 341 | |
Alejandro Nijamkin | 6238c2e | 2022-12-24 08:11:52 -0800 | [diff] [blame] | 342 | val splitUp = |
| 343 | split( |
| 344 | CustomizationProviderContract.LockScreenQuickAffordances.AffordanceTable |
| 345 | .COMPONENT_NAME_SEPARATOR |
| 346 | ) |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 347 | check(splitUp.size == 1 || splitUp.size == 2) { |
| 348 | "Illegal component name \"$this\". Must be either just an action or a package and an" + |
| 349 | " action separated by a" + |
Alejandro Nijamkin | 6238c2e | 2022-12-24 08:11:52 -0800 | [diff] [blame] | 350 | " \"${CustomizationProviderContract.LockScreenQuickAffordances.AffordanceTable.COMPONENT_NAME_SEPARATOR}\"!" |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | return Intent(splitUp.last()).apply { |
| 354 | if (splitUp.size > 1) { |
| 355 | setPackage(splitUp[0]) |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
Alejandro Nijamkin | abda67b | 2022-11-30 14:34:56 -0800 | [diff] [blame] | 360 | private fun toDescriptionText( |
| 361 | context: Context, |
| 362 | slots: Map<String, KeyguardQuickAffordanceSlotViewModel>, |
| 363 | ): String { |
| 364 | val bottomStartAffordanceName = |
| 365 | slots[KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START] |
| 366 | ?.selectedQuickAffordances |
| 367 | ?.firstOrNull() |
| 368 | ?.contentDescription |
| 369 | val bottomEndAffordanceName = |
| 370 | slots[KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END] |
| 371 | ?.selectedQuickAffordances |
| 372 | ?.firstOrNull() |
| 373 | ?.contentDescription |
| 374 | |
| 375 | return when { |
| 376 | !bottomStartAffordanceName.isNullOrEmpty() && |
| 377 | !bottomEndAffordanceName.isNullOrEmpty() -> { |
| 378 | context.getString( |
| 379 | R.string.keyguard_quick_affordance_two_selected_template, |
| 380 | bottomStartAffordanceName, |
| 381 | bottomEndAffordanceName, |
| 382 | ) |
| 383 | } |
| 384 | !bottomStartAffordanceName.isNullOrEmpty() -> bottomStartAffordanceName |
| 385 | !bottomEndAffordanceName.isNullOrEmpty() -> bottomEndAffordanceName |
| 386 | else -> context.getString(R.string.keyguard_quick_affordance_none_selected) |
| 387 | } |
| 388 | } |
| 389 | |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 390 | class Factory( |
| 391 | private val context: Context, |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 392 | private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor, |
| 393 | private val undoInteractor: UndoInteractor, |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 394 | private val wallpaperInfoFactory: CurrentWallpaperInfoFactory, |
Alejandro Nijamkin | 7bda0fd | 2022-12-28 14:14:20 -0800 | [diff] [blame] | 395 | private val activityStarter: (Intent) -> Unit, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 396 | ) : ViewModelProvider.Factory { |
| 397 | override fun <T : ViewModel> create(modelClass: Class<T>): T { |
| 398 | @Suppress("UNCHECKED_CAST") |
| 399 | return KeyguardQuickAffordancePickerViewModel( |
| 400 | context = context, |
Alejandro Nijamkin | c27b1d3 | 2022-12-21 15:27:35 -0800 | [diff] [blame] | 401 | quickAffordanceInteractor = quickAffordanceInteractor, |
| 402 | undoInteractor = undoInteractor, |
Alejandro Nijamkin | 2fe5f2d | 2022-12-22 15:24:22 -0800 | [diff] [blame] | 403 | wallpaperInfoFactory = wallpaperInfoFactory, |
Alejandro Nijamkin | 7bda0fd | 2022-12-28 14:14:20 -0800 | [diff] [blame] | 404 | activityStarter = activityStarter, |
Alejandro Nijamkin | 0f02b08 | 2022-11-24 13:43:43 -0800 | [diff] [blame] | 405 | ) |
| 406 | as T |
| 407 | } |
| 408 | } |
| 409 | } |