tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 26cd976bff0617e3a86d2615070fae2e4b22d814
parent 0a91e602e37f59e81347d5c6d94e20acdfaa57bf
Author: Gabriel Luong <gabriel.luong@gmail.com>
Date:   Wed, 10 Dec 2025 15:33:06 +0000

Bug 2004511 - Part 6: Migrate DownloadAppDialog to use M3 color tokens r=android-reviewers,007

- The core of this change was simply to migrate `textPrimary` to `onSurface`.
- Improves the preview to help visualize how it would look in a `AlertDialog`.

Differential Revision: https://phabricator.services.mozilla.com/D275383

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/downloads/dialog/DownloadAppDialog.kt | 62+++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/downloads/dialog/DownloadAppDialog.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/downloads/dialog/DownloadAppDialog.kt @@ -8,6 +8,7 @@ import android.content.Context import androidx.appcompat.app.AlertDialog import androidx.compose.foundation.Image import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -16,15 +17,20 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Canvas +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.Paint import androidx.compose.ui.graphics.asImageBitmap -import androidx.compose.ui.graphics.colorspace.ColorSpaces import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.graphics.drawable.toBitmap import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -37,13 +43,13 @@ import org.mozilla.fenix.theme.FirefoxTheme * Creates and configures an [AlertDialog] for allowing the user to choose a third-party * application to handle a download. * - * @param context The Context in which the dialog should be shown. + * @param context The [Context] in which the dialog should be shown. * @param downloaderApps A list of [DownloaderApp] objects representing the available - * applications to choose from. + * applications to choose from. * @param onAppSelected A lambda function that will be invoked when the user selects an - * application. + * application. * @param onDismiss A lambda function that will be invoked when the dialog is dismissed - * for any reason. + * for any reason. * @return The created [AlertDialog] instance, ready to be shown via `dialog.show()`. */ internal fun createDownloadAppDialog( @@ -81,7 +87,7 @@ internal fun createDownloadAppDialog( } @Composable -internal fun DownloaderAppList( +private fun DownloaderAppList( apps: List<DownloaderApp>, onAppSelected: (DownloaderApp) -> Unit, modifier: Modifier = Modifier, @@ -99,7 +105,7 @@ internal fun DownloaderAppList( } @Composable -internal fun DownloaderAppItem( +private fun DownloaderAppItem( iconBitmap: ImageBitmap, appName: String, onAppSelected: () -> Unit, @@ -117,11 +123,13 @@ internal fun DownloaderAppItem( contentDescription = null, modifier = Modifier.size(40.dp), ) + Spacer(Modifier.width(16.dp)) + Text( text = appName, style = FirefoxTheme.typography.subtitle1, - color = FirefoxTheme.colors.textPrimary, + color = MaterialTheme.colorScheme.onSurface, modifier = Modifier.weight(1f), ) } @@ -129,15 +137,39 @@ internal fun DownloaderAppItem( @FlexibleWindowLightDarkPreview @Composable -internal fun DownloaderAppItemPreview() { - val placeholderBitmap = ImageBitmap(width = 40, height = 40, colorSpace = ColorSpaces.Srgb) +private fun DownloaderAppItemPreview() { + val placeholderBitmap = ImageBitmap(width = 40, height = 40).also { + // Draw a 40x40 square for the placeholder bitmap. + val canvas = Canvas(it) + val paint = Paint().apply { color = Color.White } + canvas.drawRect(0f, 0f, 40f, 40f, paint) + } FirefoxTheme { - DownloaderAppItem( - iconBitmap = placeholderBitmap, - appName = "Firefox Nightly Downloader", - onAppSelected = { }, - modifier = Modifier.padding(vertical = 4.dp), + AlertDialog( + title = { + Text( + text = stringResource(R.string.download_app_dialog_title), + style = FirefoxTheme.typography.headline5, + ) + }, + text = { + Column { + DownloaderAppItem( + iconBitmap = placeholderBitmap, + appName = "Firefox Nightly Downloader", + onAppSelected = {}, + ) + + DownloaderAppItem( + iconBitmap = placeholderBitmap, + appName = "Fenix Downloader", + onAppSelected = {}, + ) + } + }, + onDismissRequest = {}, + confirmButton = {}, ) } }