Skip to content

Commit d08dc83

Browse files
iorgamgabrielgiorga-jpg
authored andcommitted
Bug 1974873 - Migrate the AlertDialogs in Fenix to use the Material component. r=android-reviewers,tthibaud
Differential Revision: https://phabricator.services.mozilla.com/D262756
1 parent 6200862 commit d08dc83

File tree

80 files changed

+229
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+229
-181
lines changed

mobile/android/android-components/components/feature/addons/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ dependencies {
6161
implementation libs.androidx.core.ktx
6262
implementation libs.androidx.recyclerview
6363
implementation libs.androidx.room.runtime
64+
implementation libs.google.material
6465
ksp libs.androidx.room.compiler
6566
implementation libs.androidx.work.runtime
6667
implementation libs.kotlinx.coroutines

mobile/android/android-components/components/feature/addons/src/main/java/mozilla/components/feature/addons/ui/Extensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ package mozilla.components.feature.addons.ui
66

77
import android.content.Context
88
import android.widget.ImageView
9-
import androidx.appcompat.app.AlertDialog
109
import androidx.appcompat.content.res.AppCompatResources
1110
import androidx.core.content.ContextCompat
1211
import androidx.core.graphics.drawable.toDrawable
12+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1313
import mozilla.components.feature.addons.Addon
1414
import mozilla.components.feature.addons.R
1515
import mozilla.components.feature.addons.update.AddonUpdater
@@ -120,7 +120,7 @@ fun AddonUpdater.Status?.toLocalizedString(context: Context): String {
120120
* Shows a dialog containing all the information related to the given [AddonUpdater.UpdateAttempt].
121121
*/
122122
fun AddonUpdater.UpdateAttempt.showInformationDialog(context: Context) {
123-
AlertDialog.Builder(context)
123+
MaterialAlertDialogBuilder(context)
124124
.setTitle(R.string.mozac_feature_addons_updater_dialog_title)
125125
.setMessage(getDialogMessage(context))
126126
.show()

mobile/android/android-components/components/feature/app-links/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation project(':components:ui-widgets')
3737

3838
implementation libs.kotlinx.coroutines
39+
implementation libs.google.material
3940

4041
testImplementation project(':components:support-test')
4142
testImplementation project(':components:support-test-libstate')

mobile/android/android-components/components/feature/app-links/src/main/java/mozilla/components/feature/app/links/SimpleRedirectDialogFragment.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import androidx.annotation.StringRes
1515
import androidx.annotation.StyleRes
1616
import androidx.annotation.VisibleForTesting
1717
import androidx.appcompat.app.AlertDialog
18+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1819
import mozilla.components.support.ktx.util.PromptAbuserDetector
1920
import mozilla.components.ui.widgets.withCenterAlignedButtons
2021

2122
/**
2223
* This is the default implementation of the [RedirectDialogFragment].
2324
*
24-
* It provides an [AlertDialog] giving the user the choice to allow or deny the opening of a
25+
* It provides an [MaterialAlertDialogBuilder] giving the user the choice to allow or deny the opening of a
2526
* third party app.
2627
*
2728
* Intents passed are guaranteed to be openable by a non-browser app.
@@ -38,9 +39,13 @@ class SimpleRedirectDialogFragment(
3839
internal var testingContext: Context? = null
3940

4041
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
41-
fun getBuilder(themeID: Int): AlertDialog.Builder {
42+
fun getBuilder(themeID: Int): MaterialAlertDialogBuilder {
4243
val context = testingContext ?: requireContext()
43-
return if (themeID == 0) AlertDialog.Builder(context) else AlertDialog.Builder(context, themeID)
44+
return if (themeID == 0) {
45+
MaterialAlertDialogBuilder(context)
46+
} else {
47+
MaterialAlertDialogBuilder(context, themeID)
48+
}
4449
}
4550

4651
promptAbuserDetector.updateJSDialogAbusedState()

mobile/android/android-components/components/feature/app-links/src/test/java/mozilla/components/feature/app/links/SimpleRedirectDialogFragmentTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ import org.mockito.Mockito.doNothing
2424
import org.mockito.Mockito.doReturn
2525
import org.mockito.Mockito.spy
2626
import org.robolectric.Shadows.shadowOf
27-
import androidx.appcompat.R as appcompatR
2827

2928
@RunWith(AndroidJUnit4::class)
3029
class SimpleRedirectDialogFragmentTest {
31-
private val themeResId = appcompatR.style.Theme_AppCompat_Light
30+
private val themeResId = com.google.android.material.R.style.Theme_MaterialComponents_Light
3231

3332
@Before
3433
fun setUp() {

mobile/android/android-components/components/feature/autofill/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies {
4242
implementation libs.androidx.preferences
4343
implementation libs.androidx.recyclerview
4444
implementation libs.kotlinx.coroutines
45+
implementation libs.google.material
4546

4647
testImplementation project(':components:lib-fetch-okhttp')
4748
testImplementation project(':components:support-test')

mobile/android/android-components/components/feature/autofill/src/main/java/mozilla/components/feature/autofill/ui/AbstractAutofillConfirmActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import android.content.Intent
1111
import android.os.Bundle
1212
import android.service.autofill.Dataset
1313
import android.view.autofill.AutofillManager
14-
import androidx.appcompat.app.AlertDialog
1514
import androidx.fragment.app.DialogFragment
1615
import androidx.fragment.app.FragmentActivity
1716
import androidx.lifecycle.lifecycleScope
17+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1818
import kotlinx.coroutines.Deferred
1919
import kotlinx.coroutines.Dispatchers
2020
import kotlinx.coroutines.async
@@ -101,7 +101,7 @@ internal class AutofillConfirmFragment : DialogFragment() {
101101
get() = getConfirmActivity().configuration
102102

103103
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
104-
return AlertDialog.Builder(requireContext())
104+
return MaterialAlertDialogBuilder(requireContext())
105105
.setTitle(
106106
getString(R.string.mozac_feature_autofill_confirmation_title),
107107
)

mobile/android/android-components/components/feature/contextmenu/src/main/java/mozilla/components/feature/contextmenu/ContextMenuFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import android.view.View
1414
import android.view.ViewGroup
1515
import android.widget.TextView
1616
import androidx.annotation.VisibleForTesting
17-
import androidx.appcompat.app.AlertDialog
1817
import androidx.appcompat.widget.AppCompatTextView
1918
import androidx.core.text.HtmlCompat
2019
import androidx.fragment.app.DialogFragment
2120
import androidx.recyclerview.widget.LinearLayoutManager
2221
import androidx.recyclerview.widget.RecyclerView
22+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
2323
import com.google.android.material.textview.MaterialTextView
2424
import mozilla.components.browser.state.state.SessionState
2525

@@ -60,7 +60,7 @@ class ContextMenuFragment : DialogFragment() {
6060
@SuppressLint("UseGetLayoutInflater")
6161
val inflater = LayoutInflater.from(requireContext())
6262

63-
val builder = AlertDialog.Builder(requireContext())
63+
val builder = MaterialAlertDialogBuilder(requireContext())
6464
.setCustomTitle(createDialogTitleView(inflater))
6565
.setView(createDialogContentView(inflater))
6666

mobile/android/android-components/components/feature/contextmenu/src/test/java/mozilla/components/feature/contextmenu/ContextMenuFragmentTest.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import mozilla.components.support.test.mock
1616
import mozilla.components.support.test.robolectric.testContext
1717
import org.junit.Assert.assertEquals
1818
import org.junit.Assert.assertNotNull
19+
import org.junit.Before
1920
import org.junit.Test
2021
import org.junit.runner.RunWith
2122
import org.mockito.Mockito.doNothing
@@ -25,6 +26,12 @@ import org.mockito.Mockito.verify
2526

2627
@RunWith(AndroidJUnit4::class)
2728
class ContextMenuFragmentTest {
29+
30+
@Before
31+
fun setup() {
32+
testContext.setTheme(com.google.android.material.R.style.Theme_MaterialComponents_Light)
33+
}
34+
2835
@Test
2936
fun `Build dialog`() {
3037
val ids = listOf("A", "B", "C")

mobile/android/android-components/components/feature/downloads/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class FocusDialogDownloadFragment : DownloadDialogFragment() {
7474
val url = arguments?.getString(KEY_URL)
7575
val contentLength = arguments?.getString(KEY_CONTENT_LENGTH)
7676

77-
val builder = AlertDialog.Builder(requireContext())
77+
val builder = MaterialAlertDialogBuilder(requireContext())
7878
builder.setCancelable(true)
7979
builder.setTitle(getString(R.string.download_dialog_title))
8080

0 commit comments

Comments
 (0)