55package org.mozilla.fenix.home.topsites
66
77import androidx.annotation.DrawableRes
8+ import mozilla.components.feature.top.sites.TopSite
89import org.mozilla.fenix.R
910
1011/* *
1112 * Represents the favicon of a top site.
1213 */
1314sealed 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