Merge "[tp] More actionable reenablement dialogs for quick affordances." into udc-dev am: 41ff36da3d
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ThemePicker/+/23566552
Change-Id: I3311d593dd40697191a53c780ca1f7b5418ee01c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 96ff1bf..c023924 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -360,6 +360,13 @@
enabled. The dialog contains a list of instructions that the user needs to take in order to
enable the option before it can be selected again. [CHAR LIMIT=NONE].
-->
+ <string name="keyguard_affordance_enablement_dialog_headline">Shortcut unavailable</string>
+
+ <!--
+ Supporting text for a popup dialog shown when the user attempts to select an option that is not
+ currently enabled. The dialog contains a list of instructions that the user needs to take in
+ order to enable the option before it can be selected again. [CHAR LIMIT=NONE].
+ -->
<string name="keyguard_affordance_enablement_dialog_title">To select `<xliff:g id="appName" example="Wallet">%1$s</xliff:g>` check the following</string>
<!--
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 c432bd9..9729661 100644
--- a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
+++ b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt
@@ -82,7 +82,7 @@
isEnabled = isEnabled,
enablementInstructions = enablementInstructions ?: emptyList(),
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 7b04ff1..5ca7d56 100644
--- a/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/shared/model/KeyguardQuickAffordancePickerAffordanceModel.kt
@@ -39,10 +39,10 @@
*/
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/viewmodel/KeyguardQuickAffordancePickerViewModel.kt b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
index 525c657..08cb756 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -27,7 +27,6 @@
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.KeyguardPreviewConstants
import com.android.wallpaper.R
@@ -264,8 +263,7 @@
name = affordance.name,
instructions = affordance.enablementInstructions,
actionText = affordance.enablementActionText,
- actionComponentName =
- affordance.enablementActionComponentName,
+ actionIntent = affordance.enablementActionIntent,
)
}
},
@@ -350,7 +348,7 @@
name: String,
instructions: List<String>,
actionText: String?,
- actionComponentName: String?,
+ actionIntent: Intent?,
) {
_dialog.value =
DialogViewModel(
@@ -359,7 +357,14 @@
drawable = icon,
contentDescription = null,
),
- title = Text.Loaded(name),
+ headline = Text.Resource(R.string.keyguard_affordance_enablement_dialog_headline),
+ supportingText =
+ Text.Loaded(
+ applicationContext.getString(
+ R.string.keyguard_affordance_enablement_dialog_title,
+ name
+ )
+ ),
message =
Text.Loaded(
buildString {
@@ -382,9 +387,7 @@
),
style = ButtonStyle.Primary,
onClicked = {
- actionComponentName.toIntent()?.let { intent ->
- requestActivityStart(intent)
- }
+ actionIntent?.let { intent -> requestActivityStart(intent) }
}
),
),
@@ -425,29 +428,6 @@
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>,
diff --git a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
index 43ca2ab..d51f411 100644
--- a/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
+++ b/tests/src/com/android/customization/model/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModelTest.kt
@@ -252,7 +252,7 @@
val enablementActionText = "enablementActionText"
val packageName = "packageName"
val action = "action"
- val enablementActionComponentName = "$packageName/$action"
+ val enablementActionIntent = Intent(action).apply { `package` = packageName }
// Lets add a disabled affordance to the picker:
val affordanceIndex =
client.addAffordance(
@@ -263,7 +263,7 @@
isEnabled = false,
enablementInstructions = enablementInstructions,
enablementActionText = enablementActionText,
- enablementActionComponentName = enablementActionComponentName,
+ enablementActionIntent = enablementActionIntent,
)
)
@@ -273,7 +273,8 @@
// We expect there to be a dialog that should be shown:
assertThat(dialog()?.icon)
.isEqualTo(Icon.Loaded(FakeCustomizationProviderClient.ICON_1, null))
- assertThat(dialog()?.title).isEqualTo(Text.Loaded("disabled"))
+ assertThat(dialog()?.headline)
+ .isEqualTo(Text.Resource(R.string.keyguard_affordance_enablement_dialog_headline))
assertThat(dialog()?.message)
.isEqualTo(Text.Loaded(enablementInstructions.joinToString("\n")))
assertThat(dialog()?.buttons?.size).isEqualTo(1)