commit 45b7b43ae67db7b9fb4da854cdf4520c4bc42944
parent b07347e94d084fb061dc51411e0c7bb8db1bd10d
Author: Gabriel Luong <gabriel.luong@gmail.com>
Date: Fri, 28 Nov 2025 22:14:12 +0000
Bug 2002583 - Use imageUrl for Sponsored Top Sites when loading TopSiteFavicon r=android-reviewers,Roger
Differential Revision: https://phabricator.services.mozilla.com/D274381
Diffstat:
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSites.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSites.kt
@@ -436,19 +436,19 @@ private fun TopSiteFaviconCard(
color = backgroundColor,
shape = RoundedCornerShape(4.dp),
) {
- TopSiteFavicon(url = topSite.url)
+ TopSiteFavicon(topSite = topSite)
}
}
}
}
@Composable
-private fun TopSiteFavicon(url: String) {
- when (val favicon = getTopSitesFavicon(url)) {
+private fun TopSiteFavicon(topSite: TopSite) {
+ when (val favicon = getTopSitesFavicon(topSite)) {
is TopSitesFavicon.ImageUrl -> Favicon(
- url = url,
+ url = topSite.url,
size = TOP_SITES_FAVICON_SIZE.dp,
- imageUrl = favicon.url,
+ imageUrl = favicon.imageUrl,
)
is TopSitesFavicon.Drawable -> Favicon(
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSitesFavicon.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSitesFavicon.kt
@@ -5,6 +5,7 @@
package org.mozilla.fenix.home.topsites
import androidx.annotation.DrawableRes
+import mozilla.components.feature.top.sites.TopSite
import org.mozilla.fenix.R
/**
@@ -12,11 +13,12 @@ import org.mozilla.fenix.R
*/
sealed class TopSitesFavicon {
/**
- * An image URL.
+ * An image URL. Image URL is only available with [TopSite.Provided].
*
- * @property url The URL of the image to use.
+ * @property imageUrl The URL of the image to use. If empty or null, the favicon will be
+ * fetched using the top site URL.
*/
- data class ImageUrl(val url: String?) : TopSitesFavicon()
+ data class ImageUrl(val imageUrl: String?) : TopSitesFavicon()
/**
* A drawable background.
@@ -26,14 +28,21 @@ sealed class TopSitesFavicon {
data class Drawable(@param:DrawableRes val drawableResId: Int) : TopSitesFavicon()
}
-internal fun getTopSitesFavicon(url: String): TopSitesFavicon {
- return when (url) {
- "https://tenki.jp/" -> TopSitesFavicon.ImageUrl(url = "https://tenki.jp/favicon.ico")
- "https://m.yahoo.co.jp/" -> TopSitesFavicon.ImageUrl(url = "https://s.yimg.jp/c/icon/s/bsc/2.0/favicon.ico")
- "https://ameblo.jp/" -> TopSitesFavicon.ImageUrl(url = "https://stat100.ameba.jp/common_style/img/favicon.ico")
+internal fun getTopSitesFavicon(topSite: TopSite): TopSitesFavicon {
+ if (topSite is TopSite.Provided) {
+ return TopSitesFavicon.ImageUrl(imageUrl = topSite.imageUrl)
+ }
+
+ return when (topSite.url) {
+ "https://tenki.jp/" ->
+ TopSitesFavicon.ImageUrl(imageUrl = "https://tenki.jp/favicon.ico")
+ "https://m.yahoo.co.jp/" ->
+ TopSitesFavicon.ImageUrl(imageUrl = "https://s.yimg.jp/c/icon/s/bsc/2.0/favicon.ico")
+ "https://ameblo.jp/" ->
+ TopSitesFavicon.ImageUrl(imageUrl = "https://stat100.ameba.jp/common_style/img/favicon.ico")
"https://blog.mozilla.org/ja/firefox-ja/android-guide/" ->
TopSitesFavicon.Drawable(R.drawable.ic_japan_onboarding_favicon)
- else -> TopSitesFavicon.ImageUrl(url = null)
+ else -> TopSitesFavicon.ImageUrl(imageUrl = null)
}
}