diff --git a/app/src/main/java/org/mozilla/fenix/ext/Session.kt b/app/src/main/java/org/mozilla/fenix/ext/Session.kt index 977a88283..9b086637a 100644 --- a/app/src/main/java/org/mozilla/fenix/ext/Session.kt +++ b/app/src/main/java/org/mozilla/fenix/ext/Session.kt @@ -16,6 +16,7 @@ fun Session.toTab(context: Context, selected: Boolean? = null, mediaState: Media this.url.urlToTrimmedHost(context), this.title, selected, - mediaState + mediaState, + this.icon ) } diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt index b35541fd6..230cdd609 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlAdapter.kt @@ -45,7 +45,8 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) { // Tell the adapter exactly what values have changed so it only has to draw those override fun getChangePayload(newItem: AdapterItem): Any? { (newItem as TabItem).let { - val shouldUpdateUrl = newItem.tab.url != this.tab.url + val shouldUpdateFavicon = + newItem.tab.url != this.tab.url || newItem.tab.icon != this.tab.icon val shouldUpdateHostname = newItem.tab.hostname != this.tab.hostname val shouldUpdateTitle = newItem.tab.title != this.tab.title val shouldUpdateSelected = newItem.tab.selected != this.tab.selected @@ -53,7 +54,7 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) { return AdapterItemDiffCallback.TabChangePayload( tab = newItem.tab, - shouldUpdateUrl = shouldUpdateUrl, + shouldUpdateFavicon = shouldUpdateFavicon, shouldUpdateHostname = shouldUpdateHostname, shouldUpdateTitle = shouldUpdateTitle, shouldUpdateSelected = shouldUpdateSelected, @@ -129,7 +130,7 @@ class AdapterItemDiffCallback : DiffUtil.ItemCallback() { data class TabChangePayload( val tab: Tab, - val shouldUpdateUrl: Boolean, + val shouldUpdateFavicon: Boolean, val shouldUpdateHostname: Boolean, val shouldUpdateTitle: Boolean, val shouldUpdateSelected: Boolean, @@ -220,7 +221,9 @@ class SessionControlAdapter( if (it.shouldUpdateHostname) { holder.updateHostname(it.tab.hostname) } if (it.shouldUpdateTitle) { holder.updateTitle(it.tab.title) } - if (it.shouldUpdateUrl) { holder.updateFavIcon(it.tab.url, it.tab.sessionId) } + if (it.shouldUpdateFavicon) { + holder.updateFavIcon(it.tab.url, it.tab.icon) + } if (it.shouldUpdateSelected) { holder.updateSelected(it.tab.selected ?: false) } if (it.shouldUpdateMediaState) { holder.updatePlayPauseButton(it.tab.mediaState ?: MediaState.None) diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlComponent.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlComponent.kt index 6fc8720d6..e5e59dd8b 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/SessionControlComponent.kt @@ -5,6 +5,7 @@ package org.mozilla.fenix.home.sessioncontrol import android.content.Context +import android.graphics.Bitmap import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView @@ -50,7 +51,8 @@ data class Tab( val hostname: String, val title: String, val selected: Boolean? = null, - var mediaState: MediaState? = null + var mediaState: MediaState? = null, + val icon: Bitmap? = null ) fun List.toSessionBundle(context: Context): MutableList { diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt index ab99a27e8..bd483ad6a 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/TabViewHolder.kt @@ -5,6 +5,7 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders import android.content.Context +import android.graphics.Bitmap import android.graphics.Outline import android.view.View import android.view.ViewOutlineProvider @@ -93,7 +94,7 @@ class TabViewHolder( updateTab(tab) updateTitle(tab.title) updateHostname(tab.hostname) - updateFavIcon(tab.url, tab.sessionId) + updateFavIcon(tab.url, tab.icon) updateSelected(tab.selected ?: false) updatePlayPauseButton(tab.mediaState ?: MediaState.None) item_tab.transitionName = "$TAB_ITEM_TRANSITION_NAME${tab.sessionId}" @@ -130,11 +131,7 @@ class TabViewHolder( hostname.text = text } - internal fun updateFavIcon(url: String, sessionId: String) { - val icon = favicon_image.context.components.core - .sessionManager - .findSessionById(sessionId)?.icon - + internal fun updateFavIcon(url: String, icon: Bitmap?) { if (icon == null) { favicon_image.context.components.core.icons.loadIntoView(favicon_image, url) } else {