Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41ff36da authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[tp] More actionable reenablement dialogs for quick affordances." into udc-dev

parents 023656fe e520b083
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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>

    <!--
+1 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ class KeyguardQuickAffordancePickerRepository(
            isEnabled = isEnabled,
            enablementInstructions = enablementInstructions ?: emptyList(),
            enablementActionText = enablementActionText,
            enablementActionComponentName = enablementActionComponentName,
            enablementActionIntent = enablementActionIntent,
            configureIntent = configureIntent,
        )
    }
+3 −3
Original line number Diff line number Diff line
@@ -39,10 +39,10 @@ data class KeyguardQuickAffordancePickerAffordanceModel(
     */
    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?,
)
+11 −31
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ 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.KeyguardPreviewConstants
import com.android.wallpaper.R
@@ -264,8 +263,7 @@ private constructor(
                                        name = affordance.name,
                                        instructions = affordance.enablementInstructions,
                                        actionText = affordance.enablementActionText,
                                        actionComponentName =
                                            affordance.enablementActionComponentName,
                                        actionIntent = affordance.enablementActionIntent,
                                    )
                                }
                            },
@@ -350,7 +348,7 @@ private constructor(
        name: String,
        instructions: List<String>,
        actionText: String?,
        actionComponentName: String?,
        actionIntent: Intent?,
    ) {
        _dialog.value =
            DialogViewModel(
@@ -359,7 +357,14 @@ private constructor(
                        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 @@ private constructor(
                                    ),
                            style = ButtonStyle.Primary,
                            onClicked = {
                                actionComponentName.toIntent()?.let { intent ->
                                    requestActivityStart(intent)
                                }
                                actionIntent?.let { intent -> requestActivityStart(intent) }
                            }
                        ),
                    ),
@@ -425,29 +428,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>,
+4 −3
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
            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 @@ class KeyguardQuickAffordancePickerViewModelTest {
                        isEnabled = false,
                        enablementInstructions = enablementInstructions,
                        enablementActionText = enablementActionText,
                        enablementActionComponentName = enablementActionComponentName,
                        enablementActionIntent = enablementActionIntent,
                    )
                )

@@ -273,7 +273,8 @@ class KeyguardQuickAffordancePickerViewModelTest {
            // 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)