1
0
Fork 0

For #3846 - Pass in updated session icon to tabs

master
ekager 2019-10-06 11:02:37 -07:00 committed by Emily Kager
parent d028c97112
commit f6285ad5f8
4 changed files with 15 additions and 12 deletions

View File

@ -16,6 +16,7 @@ fun Session.toTab(context: Context, selected: Boolean? = null, mediaState: Media
this.url.urlToTrimmedHost(context), this.url.urlToTrimmedHost(context),
this.title, this.title,
selected, selected,
mediaState mediaState,
this.icon
) )
} }

View File

@ -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 // Tell the adapter exactly what values have changed so it only has to draw those
override fun getChangePayload(newItem: AdapterItem): Any? { override fun getChangePayload(newItem: AdapterItem): Any? {
(newItem as TabItem).let { (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 shouldUpdateHostname = newItem.tab.hostname != this.tab.hostname
val shouldUpdateTitle = newItem.tab.title != this.tab.title val shouldUpdateTitle = newItem.tab.title != this.tab.title
val shouldUpdateSelected = newItem.tab.selected != this.tab.selected val shouldUpdateSelected = newItem.tab.selected != this.tab.selected
@ -53,7 +54,7 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) {
return AdapterItemDiffCallback.TabChangePayload( return AdapterItemDiffCallback.TabChangePayload(
tab = newItem.tab, tab = newItem.tab,
shouldUpdateUrl = shouldUpdateUrl, shouldUpdateFavicon = shouldUpdateFavicon,
shouldUpdateHostname = shouldUpdateHostname, shouldUpdateHostname = shouldUpdateHostname,
shouldUpdateTitle = shouldUpdateTitle, shouldUpdateTitle = shouldUpdateTitle,
shouldUpdateSelected = shouldUpdateSelected, shouldUpdateSelected = shouldUpdateSelected,
@ -129,7 +130,7 @@ class AdapterItemDiffCallback : DiffUtil.ItemCallback<AdapterItem>() {
data class TabChangePayload( data class TabChangePayload(
val tab: Tab, val tab: Tab,
val shouldUpdateUrl: Boolean, val shouldUpdateFavicon: Boolean,
val shouldUpdateHostname: Boolean, val shouldUpdateHostname: Boolean,
val shouldUpdateTitle: Boolean, val shouldUpdateTitle: Boolean,
val shouldUpdateSelected: Boolean, val shouldUpdateSelected: Boolean,
@ -220,7 +221,9 @@ class SessionControlAdapter(
if (it.shouldUpdateHostname) { holder.updateHostname(it.tab.hostname) } if (it.shouldUpdateHostname) { holder.updateHostname(it.tab.hostname) }
if (it.shouldUpdateTitle) { holder.updateTitle(it.tab.title) } 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.shouldUpdateSelected) { holder.updateSelected(it.tab.selected ?: false) }
if (it.shouldUpdateMediaState) { if (it.shouldUpdateMediaState) {
holder.updatePlayPauseButton(it.tab.mediaState ?: MediaState.None) holder.updatePlayPauseButton(it.tab.mediaState ?: MediaState.None)

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.home.sessioncontrol package org.mozilla.fenix.home.sessioncontrol
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -50,7 +51,8 @@ data class Tab(
val hostname: String, val hostname: String,
val title: String, val title: String,
val selected: Boolean? = null, val selected: Boolean? = null,
var mediaState: MediaState? = null var mediaState: MediaState? = null,
val icon: Bitmap? = null
) )
fun List<Tab>.toSessionBundle(context: Context): MutableList<Session> { fun List<Tab>.toSessionBundle(context: Context): MutableList<Session> {

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.home.sessioncontrol.viewholders package org.mozilla.fenix.home.sessioncontrol.viewholders
import android.content.Context import android.content.Context
import android.graphics.Bitmap
import android.graphics.Outline import android.graphics.Outline
import android.view.View import android.view.View
import android.view.ViewOutlineProvider import android.view.ViewOutlineProvider
@ -93,7 +94,7 @@ class TabViewHolder(
updateTab(tab) updateTab(tab)
updateTitle(tab.title) updateTitle(tab.title)
updateHostname(tab.hostname) updateHostname(tab.hostname)
updateFavIcon(tab.url, tab.sessionId) updateFavIcon(tab.url, tab.icon)
updateSelected(tab.selected ?: false) updateSelected(tab.selected ?: false)
updatePlayPauseButton(tab.mediaState ?: MediaState.None) updatePlayPauseButton(tab.mediaState ?: MediaState.None)
item_tab.transitionName = "$TAB_ITEM_TRANSITION_NAME${tab.sessionId}" item_tab.transitionName = "$TAB_ITEM_TRANSITION_NAME${tab.sessionId}"
@ -130,11 +131,7 @@ class TabViewHolder(
hostname.text = text hostname.text = text
} }
internal fun updateFavIcon(url: String, sessionId: String) { internal fun updateFavIcon(url: String, icon: Bitmap?) {
val icon = favicon_image.context.components.core
.sessionManager
.findSessionById(sessionId)?.icon
if (icon == null) { if (icon == null) {
favicon_image.context.components.core.icons.loadIntoView(favicon_image, url) favicon_image.context.components.core.icons.loadIntoView(favicon_image, url)
} else { } else {