summaryrefslogtreecommitdiff
path: root/src/com/android/customization/picker/quickaffordance
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-10 23:17:19 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-10-10 23:17:19 +0000
commit3cc68260bf5367ff502c46322e5673e4b3ad84be (patch)
treebba514fb9c0823137d44bcafd1c628b0ad0fe18b /src/com/android/customization/picker/quickaffordance
parent2b928f6a737cd73c67b809125040c5e4e1a5ab23 (diff)
parent2585ebb7fa1f2fb73dfe2970311b5335311d14d1 (diff)
downloadThemePicker-3cc68260bf5367ff502c46322e5673e4b3ad84be.tar.gz
Snap for 10929834 from 2585ebb7fa1f2fb73dfe2970311b5335311d14d1 to sdk-release
Change-Id: I1035e5616f20b1a338f99eeac0a354c1d286c0fc
Diffstat (limited to 'src/com/android/customization/picker/quickaffordance')
-rw-r--r--src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt4
-rw-r--r--src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt10
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/adapter/SlotTabAdapter.kt2
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt9
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePreviewBinder.kt9
-rw-r--r--src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt136
6 files changed, 92 insertions, 78 deletions
diff --git a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
index c432bd9a..b17af80d 100644
--- a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
+++ b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
@@ -80,9 +80,9 @@ class KeyguardQuickAffordancePickerRepository(
name = name,
iconResourceId = iconResourceId,
isEnabled = isEnabled,
- enablementInstructions = enablementInstructions ?: emptyList(),
+ enablementExplanation = enablementExplanation ?: "",
enablementActionText = enablementActionText,
- enablementActionComponentName = enablementActionComponentName,
+ enablementActionIntent = enablementActionIntent,
configureIntent = configureIntent,
)
}
diff --git a/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt b/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
index 7b04ff18..e53f7901 100644
--- a/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
@@ -31,18 +31,18 @@ data class KeyguardQuickAffordancePickerAffordanceModel(
@DrawableRes val iconResourceId: Int,
/** Whether this quick affordance is enabled. */
val isEnabled: Boolean,
- /** If not enabled, the list of user-visible steps to re-enable it. */
- val enablementInstructions: List<String>,
+ /** If not enabled, the user-visible message explaining why. */
+ val enablementExplanation: String,
/**
* If not enabled, an optional label for a button that takes the user to a destination where
* they can re-enable it.
*/
val enablementActionText: String?,
/**
- * If not enabled, an optional component name (package and action) for a button that takes the
- * user to a destination where they can re-enable it.
+ * If not enabled, an optional [Intent] for a button that takes the user to a destination where
+ * they can re-enable it.
*/
- val enablementActionComponentName: String?,
+ val enablementActionIntent: Intent?,
/** Optional [Intent] to use to start an activity to configure this affordance. */
val configureIntent: Intent?,
)
diff --git a/src/com/android/customization/picker/quickaffordance/ui/adapter/SlotTabAdapter.kt b/src/com/android/customization/picker/quickaffordance/ui/adapter/SlotTabAdapter.kt
index 5203ed32..6879ffc8 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/adapter/SlotTabAdapter.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/adapter/SlotTabAdapter.kt
@@ -55,7 +55,7 @@ class SlotTabAdapter : RecyclerView.Adapter<SlotTabAdapter.ViewHolder>() {
val item = items[position]
holder.itemView.isSelected = item.isSelected
holder.textView.text = item.name
- holder.textView.setOnClickListener(
+ holder.itemView.setOnClickListener(
if (item.onClicked != null) {
View.OnClickListener { item.onClicked.invoke() }
} else {
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
index 4395f5e0..68367c8b 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
@@ -126,6 +126,15 @@ object KeyguardQuickAffordancePickerBinder {
}
}
}
+
+ launch {
+ viewModel.activityStartRequests.collect { intent ->
+ if (intent != null) {
+ view.context.startActivity(intent)
+ viewModel.onActivityStarted()
+ }
+ }
+ }
}
}
}
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePreviewBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePreviewBinder.kt
index 58a082dd..5b6d3533 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePreviewBinder.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePreviewBinder.kt
@@ -25,7 +25,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
-import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants
import com.android.wallpaper.R
import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder
import kotlinx.coroutines.launch
@@ -49,6 +49,7 @@ object KeyguardQuickAffordancePreviewBinder {
lifecycleOwner = lifecycleOwner,
offsetToStart = offsetToStart,
dimWallpaper = true,
+ onWallpaperPreviewDirty = { activity.recreate() },
)
previewView.contentDescription =
@@ -61,10 +62,8 @@ object KeyguardQuickAffordancePreviewBinder {
.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
.collect { slotId ->
binding.sendMessage(
- KeyguardQuickAffordancePreviewConstants.MESSAGE_ID_SLOT_SELECTED,
- Bundle().apply {
- putString(KeyguardQuickAffordancePreviewConstants.KEY_SLOT_ID, slotId)
- },
+ KeyguardPreviewConstants.MESSAGE_ID_SLOT_SELECTED,
+ Bundle().apply { putString(KeyguardPreviewConstants.KEY_SLOT_ID, slotId) },
)
}
}
diff --git a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 14b6acca..f832cdeb 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -27,16 +27,17 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor
-import com.android.systemui.shared.customization.data.content.CustomizationProviderContract
import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots
-import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants
import com.android.wallpaper.R
import com.android.wallpaper.module.CurrentWallpaperInfoFactory
+import com.android.wallpaper.module.CustomizationSections
import com.android.wallpaper.picker.common.button.ui.viewmodel.ButtonStyle
import com.android.wallpaper.picker.common.button.ui.viewmodel.ButtonViewModel
import com.android.wallpaper.picker.common.dialog.ui.viewmodel.DialogViewModel
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
+import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel
import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel
import com.android.wallpaper.util.PreviewUtils
@@ -60,8 +61,8 @@ class KeyguardQuickAffordancePickerViewModel
private constructor(
context: Context,
private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor,
+ private val wallpaperInteractor: WallpaperInteractor,
private val wallpaperInfoFactory: CurrentWallpaperInfoFactory,
- activityStarter: (Intent) -> Unit,
) : ViewModel() {
@SuppressLint("StaticFieldLeak") private val applicationContext = context.applicationContext
@@ -79,25 +80,27 @@ private constructor(
initialExtrasProvider = {
Bundle().apply {
putString(
- KeyguardQuickAffordancePreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID,
+ KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID,
selectedSlotId.value,
)
putBoolean(
- KeyguardQuickAffordancePreviewConstants.KEY_HIGHLIGHT_QUICK_AFFORDANCES,
+ KeyguardPreviewConstants.KEY_HIGHLIGHT_QUICK_AFFORDANCES,
true,
)
}
},
- wallpaperInfoProvider = {
+ wallpaperInfoProvider = { forceReload ->
suspendCancellableCoroutine { continuation ->
wallpaperInfoFactory.createCurrentWallpaperInfos(
{ homeWallpaper, lockWallpaper, _ ->
continuation.resume(lockWallpaper ?: homeWallpaper, null)
},
- /* forceRefresh= */ true,
+ forceReload,
)
}
},
+ wallpaperInteractor = wallpaperInteractor,
+ screen = CustomizationSections.Screen.LOCK_SCREEN,
)
/** A locally-selected slot, if the user ever switched from the original one. */
@@ -258,16 +261,15 @@ private constructor(
showEnablementDialog(
icon = affordanceIcon,
name = affordance.name,
- instructions = affordance.enablementInstructions,
+ explanation = affordance.enablementExplanation,
actionText = affordance.enablementActionText,
- actionComponentName =
- affordance.enablementActionComponentName,
+ actionIntent = affordance.enablementActionIntent,
)
}
},
onLongClicked =
if (affordance.configureIntent != null) {
- { activityStarter(affordance.configureIntent) }
+ { requestActivityStart(affordance.configureIntent) }
} else {
null
},
@@ -313,17 +315,40 @@ private constructor(
*/
val dialog: Flow<DialogViewModel?> = _dialog.asStateFlow()
+ private val _activityStartRequests = MutableStateFlow<Intent?>(null)
+ /**
+ * Requests to start an activity with the given [Intent].
+ *
+ * Important: once the activity is started, the [Intent] should be consumed by calling
+ * [onActivityStarted].
+ */
+ val activityStartRequests: StateFlow<Intent?> = _activityStartRequests.asStateFlow()
+
/** Notifies that the dialog has been dismissed in the UI. */
fun onDialogDismissed() {
_dialog.value = null
}
+ /**
+ * Notifies that an activity request from [activityStartRequests] has been fulfilled (e.g. the
+ * activity was started and the view-model can forget needing to start this activity).
+ */
+ fun onActivityStarted() {
+ _activityStartRequests.value = null
+ }
+
+ private fun requestActivityStart(
+ intent: Intent,
+ ) {
+ _activityStartRequests.value = intent
+ }
+
private fun showEnablementDialog(
icon: Drawable,
name: String,
- instructions: List<String>,
+ explanation: String,
actionText: String?,
- actionComponentName: String?,
+ actionIntent: Intent?,
) {
_dialog.value =
DialogViewModel(
@@ -332,35 +357,39 @@ private constructor(
drawable = icon,
contentDescription = null,
),
- title = Text.Loaded(name),
- message =
- Text.Loaded(
- buildString {
- instructions.forEachIndexed { index, instruction ->
- if (index > 0) {
- append('\n')
- }
-
- append(instruction)
- }
- }
- ),
+ headline = Text.Resource(R.string.keyguard_affordance_enablement_dialog_headline),
+ message = Text.Loaded(explanation),
buttons =
- listOf(
- ButtonViewModel(
- text = actionText?.let { Text.Loaded(actionText) }
- ?: Text.Resource(
- R.string
- .keyguard_affordance_enablement_dialog_dismiss_button,
+ buildList {
+ add(
+ ButtonViewModel(
+ text =
+ Text.Resource(
+ if (actionText != null) {
+ // This is not the only button on the dialog.
+ R.string.cancel
+ } else {
+ // This is the only button on the dialog.
+ R.string
+ .keyguard_affordance_enablement_dialog_dismiss_button
+ }
),
- style = ButtonStyle.Primary,
- onClicked = {
- actionComponentName.toIntent()?.let { intent ->
- applicationContext.startActivity(intent)
- }
- }
- ),
- ),
+ style = ButtonStyle.Secondary,
+ ),
+ )
+
+ if (actionText != null) {
+ add(
+ ButtonViewModel(
+ text = Text.Loaded(actionText),
+ style = ButtonStyle.Primary,
+ onClicked = {
+ actionIntent?.let { intent -> requestActivityStart(intent) }
+ }
+ ),
+ )
+ }
+ },
)
}
@@ -398,29 +427,6 @@ private constructor(
return quickAffordanceInteractor.getAffordanceIcon(iconResourceId)
}
- private fun String?.toIntent(): Intent? {
- if (isNullOrEmpty()) {
- return null
- }
-
- val splitUp =
- split(
- CustomizationProviderContract.LockScreenQuickAffordances.AffordanceTable
- .COMPONENT_NAME_SEPARATOR
- )
- check(splitUp.size == 1 || splitUp.size == 2) {
- "Illegal component name \"$this\". Must be either just an action or a package and an" +
- " action separated by a" +
- " \"${CustomizationProviderContract.LockScreenQuickAffordances.AffordanceTable.COMPONENT_NAME_SEPARATOR}\"!"
- }
-
- return Intent(splitUp.last()).apply {
- if (splitUp.size > 1) {
- setPackage(splitUp[0])
- }
- }
- }
-
private fun toDescriptionText(
context: Context,
slots: Map<String, KeyguardQuickAffordanceSlotViewModel>,
@@ -455,16 +461,16 @@ private constructor(
class Factory(
private val context: Context,
private val quickAffordanceInteractor: KeyguardQuickAffordancePickerInteractor,
+ private val wallpaperInteractor: WallpaperInteractor,
private val wallpaperInfoFactory: CurrentWallpaperInfoFactory,
- private val activityStarter: (Intent) -> Unit,
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return KeyguardQuickAffordancePickerViewModel(
context = context,
quickAffordanceInteractor = quickAffordanceInteractor,
+ wallpaperInteractor = wallpaperInteractor,
wallpaperInfoFactory = wallpaperInfoFactory,
- activityStarter = activityStarter,
)
as T
}