Skip to content

Commit 45b7b43

Browse files
committed
Bug 2002583 - Use imageUrl for Sponsored Top Sites when loading TopSiteFavicon r=android-reviewers,Roger
Differential Revision: https://phabricator.services.mozilla.com/D274381
1 parent b07347e commit 45b7b43

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSites.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,19 @@ private fun TopSiteFaviconCard(
436436
color = backgroundColor,
437437
shape = RoundedCornerShape(4.dp),
438438
) {
439-
TopSiteFavicon(url = topSite.url)
439+
TopSiteFavicon(topSite = topSite)
440440
}
441441
}
442442
}
443443
}
444444

445445
@Composable
446-
private fun TopSiteFavicon(url: String) {
447-
when (val favicon = getTopSitesFavicon(url)) {
446+
private fun TopSiteFavicon(topSite: TopSite) {
447+
when (val favicon = getTopSitesFavicon(topSite)) {
448448
is TopSitesFavicon.ImageUrl -> Favicon(
449-
url = url,
449+
url = topSite.url,
450450
size = TOP_SITES_FAVICON_SIZE.dp,
451-
imageUrl = favicon.url,
451+
imageUrl = favicon.imageUrl,
452452
)
453453

454454
is TopSitesFavicon.Drawable -> Favicon(

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/topsites/TopSitesFavicon.kt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
package org.mozilla.fenix.home.topsites
66

77
import androidx.annotation.DrawableRes
8+
import mozilla.components.feature.top.sites.TopSite
89
import org.mozilla.fenix.R
910

1011
/**
1112
* Represents the favicon of a top site.
1213
*/
1314
sealed class TopSitesFavicon {
1415
/**
15-
* An image URL.
16+
* An image URL. Image URL is only available with [TopSite.Provided].
1617
*
17-
* @property url The URL of the image to use.
18+
* @property imageUrl The URL of the image to use. If empty or null, the favicon will be
19+
* fetched using the top site URL.
1820
*/
19-
data class ImageUrl(val url: String?) : TopSitesFavicon()
21+
data class ImageUrl(val imageUrl: String?) : TopSitesFavicon()
2022

2123
/**
2224
* A drawable background.
@@ -26,14 +28,21 @@ sealed class TopSitesFavicon {
2628
data class Drawable(@param:DrawableRes val drawableResId: Int) : TopSitesFavicon()
2729
}
2830

29-
internal fun getTopSitesFavicon(url: String): TopSitesFavicon {
30-
return when (url) {
31-
"https://tenki.jp/" -> TopSitesFavicon.ImageUrl(url = "https://tenki.jp/favicon.ico")
32-
"https://m.yahoo.co.jp/" -> TopSitesFavicon.ImageUrl(url = "https://s.yimg.jp/c/icon/s/bsc/2.0/favicon.ico")
33-
"https://ameblo.jp/" -> TopSitesFavicon.ImageUrl(url = "https://stat100.ameba.jp/common_style/img/favicon.ico")
31+
internal fun getTopSitesFavicon(topSite: TopSite): TopSitesFavicon {
32+
if (topSite is TopSite.Provided) {
33+
return TopSitesFavicon.ImageUrl(imageUrl = topSite.imageUrl)
34+
}
35+
36+
return when (topSite.url) {
37+
"https://tenki.jp/" ->
38+
TopSitesFavicon.ImageUrl(imageUrl = "https://tenki.jp/favicon.ico")
39+
"https://m.yahoo.co.jp/" ->
40+
TopSitesFavicon.ImageUrl(imageUrl = "https://s.yimg.jp/c/icon/s/bsc/2.0/favicon.ico")
41+
"https://ameblo.jp/" ->
42+
TopSitesFavicon.ImageUrl(imageUrl = "https://stat100.ameba.jp/common_style/img/favicon.ico")
3443
"https://blog.mozilla.org/ja/firefox-ja/android-guide/" ->
3544
TopSitesFavicon.Drawable(R.drawable.ic_japan_onboarding_favicon)
3645

37-
else -> TopSitesFavicon.ImageUrl(url = null)
46+
else -> TopSitesFavicon.ImageUrl(imageUrl = null)
3847
}
3948
}

0 commit comments

Comments
 (0)