UI polish for affordance reenablement dialog.

Does this by using the "fancy dialog" logic in the counterpart CL.

Bug: 265836232
Test: manually tested the affordance reenablement dialog which is what's
shown when the affordance is disabled
Test: unit tests for the undo system still pass

Change-Id: Ic8c18acacba3799f114eba24537865f9e275347f
diff --git a/res/layout/keyguard_quick_affordance_enablement_dialog.xml b/res/layout/keyguard_quick_affordance_enablement_dialog.xml
deleted file mode 100644
index f3d4d8c..0000000
--- a/res/layout/keyguard_quick_affordance_enablement_dialog.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
-  ~ Copyright (C) 2022 The Android Open Source Project
-  ~
-  ~ Licensed under the Apache License, Version 2.0 (the "License");
-  ~ you may not use this file except in compliance with the License.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License.
-  ~
-  -->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="wrap_content"
-    android:layout_height="wrap_content"
-    android:background="@drawable/picker_fragment_background"
-    android:orientation="vertical"
-    android:padding="24dp">
-
-    <ImageView
-        android:id="@+id/icon"
-        android:layout_width="32dp"
-        android:layout_height="32dp"
-        android:tint="@color/color_accent_primary"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginBottom="16dp" />
-
-    <TextView
-        android:id="@+id/title"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:gravity="center"
-        android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginBottom="16dp" />
-
-    <TextView
-        android:id="@+id/message"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginBottom="38dp" />
-
-    <Button
-        android:id="@+id/button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        style="@style/ActionPrimaryButton"
-        android:background="@drawable/button_background"
-        android:layout_gravity="end" />
-
-</LinearLayout>
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordanceEnablementDialogBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordanceEnablementDialogBinder.kt
deleted file mode 100644
index 809e09d..0000000
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordanceEnablementDialogBinder.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.android.customization.picker.quickaffordance.ui.binder
-
-import android.view.View
-import android.widget.ImageView
-import android.widget.TextView
-import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
-import com.android.wallpaper.R
-
-object KeyguardQuickAffordanceEnablementDialogBinder {
-
-    fun bind(
-        view: View,
-        viewModel: KeyguardQuickAffordancePickerViewModel.DialogViewModel,
-        onDismissed: () -> Unit,
-    ) {
-        view.requireViewById<ImageView>(R.id.icon).setImageDrawable(viewModel.icon)
-        view.requireViewById<TextView>(R.id.title).text =
-            view.context.getString(
-                R.string.keyguard_affordance_enablement_dialog_title,
-                viewModel.name
-            )
-        view.requireViewById<TextView>(R.id.message).text = buildString {
-            viewModel.instructions.forEachIndexed { index, instruction ->
-                append(instruction)
-                if (index < viewModel.instructions.size - 1) {
-                    append("\n")
-                }
-            }
-        }
-        view.requireViewById<TextView>(R.id.button).apply {
-            text = viewModel.actionText
-            setOnClickListener {
-                if (viewModel.intent != null) {
-                    view.context.startActivity(viewModel.intent)
-                } else {
-                    onDismissed()
-                }
-            }
-        }
-    }
-}
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 389f8f6..57e9401 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
@@ -17,11 +17,9 @@
 
 package com.android.customization.picker.quickaffordance.ui.binder
 
-import android.app.AlertDialog
 import android.app.Dialog
 import android.content.Context
 import android.graphics.Rect
-import android.view.LayoutInflater
 import android.view.View
 import androidx.core.view.ViewCompat
 import androidx.lifecycle.Lifecycle
@@ -34,6 +32,8 @@
 import com.android.customization.picker.quickaffordance.ui.adapter.SlotTabAdapter
 import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel
 import com.android.wallpaper.R
+import com.android.wallpaper.picker.common.dialog.ui.viewbinder.DialogViewBinder
+import com.android.wallpaper.picker.common.dialog.ui.viewmodel.DialogViewModel
 import kotlinx.coroutines.flow.distinctUntilChanged
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.launch
@@ -98,25 +98,14 @@
 
     private fun showDialog(
         context: Context,
-        request: KeyguardQuickAffordancePickerViewModel.DialogViewModel,
+        request: DialogViewModel,
         onDismissed: () -> Unit,
     ): Dialog {
-        val view: View =
-            LayoutInflater.from(context)
-                .inflate(
-                    R.layout.keyguard_quick_affordance_enablement_dialog,
-                    null,
-                )
-        KeyguardQuickAffordanceEnablementDialogBinder.bind(
-            view = view,
+        return DialogViewBinder.show(
+            context = context,
             viewModel = request,
             onDismissed = onDismissed,
         )
-
-        return AlertDialog.Builder(context, R.style.LightDialogTheme)
-            .setView(view)
-            .setOnDismissListener { onDismissed() }
-            .show()
     }
 
     private class ItemSpacing : RecyclerView.ItemDecoration() {
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 1b3dbe3..b5954e5 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/viewmodel/KeyguardQuickAffordancePickerViewModel.kt
@@ -32,6 +32,11 @@
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardQuickAffordancePreviewConstants
 import com.android.wallpaper.R
 import com.android.wallpaper.module.CurrentWallpaperInfoFactory
+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.ui.viewmodel.ScreenPreviewViewModel
 import com.android.wallpaper.picker.undo.domain.interactor.UndoInteractor
 import com.android.wallpaper.picker.undo.ui.viewmodel.UndoViewModel
@@ -262,14 +267,40 @@
     ) {
         _dialog.value =
             DialogViewModel(
-                icon = icon,
-                name = name,
-                instructions = instructions,
-                actionText = actionText
-                        ?: applicationContext.getString(
-                            R.string.keyguard_affordance_enablement_dialog_dismiss_button
+                icon =
+                    Icon.Loaded(
+                        drawable = icon,
+                        contentDescription = null,
+                    ),
+                title = Text.Loaded(name),
+                message =
+                    Text.Loaded(
+                        buildString {
+                            instructions.forEachIndexed { index, instruction ->
+                                if (index > 0) {
+                                    append('\n')
+                                }
+
+                                append(instruction)
+                            }
+                        }
+                    ),
+                buttons =
+                    listOf(
+                        ButtonViewModel(
+                            text = actionText?.let { Text.Loaded(actionText) }
+                                    ?: Text.Resource(
+                                        R.string
+                                            .keyguard_affordance_enablement_dialog_dismiss_button,
+                                    ),
+                            style = ButtonStyle.Primary,
+                            onClicked = {
+                                actionComponentName.toIntent()?.let { intent ->
+                                    applicationContext.startActivity(intent)
+                                }
+                            }
                         ),
-                intent = actionComponentName.toIntent(),
+                    ),
             )
     }
 
@@ -326,27 +357,6 @@
         }
     }
 
-    /** Encapsulates a request to show a dialog. */
-    data class DialogViewModel(
-        /** An icon to show. */
-        val icon: Drawable,
-
-        /** Name of the affordance. */
-        val name: String,
-
-        /** The set of instructions to show below the header. */
-        val instructions: List<String>,
-
-        /** Label for the dialog button. */
-        val actionText: String,
-
-        /**
-         * Optional [Intent] to use to start an activity when the dialog button is clicked. If
-         * `null`, the dialog should be dismissed.
-         */
-        val intent: Intent?,
-    )
-
     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 be118ee..85d5e3b 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
@@ -32,6 +32,8 @@
 import com.android.systemui.shared.customization.data.content.FakeCustomizationProviderClient
 import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots
 import com.android.wallpaper.module.InjectorProvider
+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.undo.data.repository.UndoRepository
 import com.android.wallpaper.picker.undo.domain.interactor.UndoInteractor
 import com.android.wallpaper.testing.FAKE_RESTORERS
@@ -264,11 +266,14 @@
             quickAffordances()?.get(affordanceIndex + 1)?.onClicked?.invoke()
 
             // We expect there to be a dialog that should be shown:
-            assertThat(dialog()?.icon).isEqualTo(FakeCustomizationProviderClient.ICON_1)
-            assertThat(dialog()?.instructions).isEqualTo(enablementInstructions)
-            assertThat(dialog()?.actionText).isEqualTo(enablementActionText)
-            assertThat(dialog()?.intent?.`package`).isEqualTo(packageName)
-            assertThat(dialog()?.intent?.action).isEqualTo(action)
+            assertThat(dialog()?.icon)
+                .isEqualTo(Icon.Loaded(FakeCustomizationProviderClient.ICON_1, null))
+            assertThat(dialog()?.title).isEqualTo(Text.Loaded("disabled"))
+            assertThat(dialog()?.message)
+                .isEqualTo(Text.Loaded(enablementInstructions.joinToString("\n")))
+            assertThat(dialog()?.buttons?.size).isEqualTo(1)
+            assertThat(dialog()?.buttons?.first()?.text)
+                .isEqualTo(Text.Loaded(enablementActionText))
 
             // Once we report that the dialog has been dismissed by the user, we expect there to be
             // no