diff --git a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt index af728d664e..a94b08eddf 100644 --- a/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/tabtray/TabTrayViewHolder.kt @@ -7,11 +7,11 @@ package org.mozilla.fenix.tabtray import android.view.View import android.view.accessibility.AccessibilityNodeInfo import android.widget.ImageButton +import android.widget.ImageView import android.widget.TextView import androidx.annotation.VisibleForTesting import androidx.appcompat.widget.AppCompatImageButton import androidx.core.content.ContextCompat -import androidx.core.view.doOnNextLayout import mozilla.components.browser.state.state.MediaState import mozilla.components.browser.tabstray.TabViewHolder import mozilla.components.browser.tabstray.thumbnail.TabThumbnailView @@ -21,7 +21,7 @@ import mozilla.components.concept.tabstray.TabsTray import mozilla.components.feature.media.ext.pauseIfPlaying import mozilla.components.feature.media.ext.playIfPaused import mozilla.components.support.base.observer.Observable -import mozilla.components.support.images.ext.loadIntoView +import mozilla.components.support.images.ImageLoadRequest import mozilla.components.support.images.loader.ImageLoader import mozilla.components.support.ktx.kotlin.tryGetHostFromUrl import org.mozilla.fenix.R @@ -32,6 +32,7 @@ import org.mozilla.fenix.ext.removeAndDisable import org.mozilla.fenix.ext.removeTouchDelegate import org.mozilla.fenix.ext.showAndEnable import org.mozilla.fenix.ext.toTab +import kotlin.math.max /** * A RecyclerView ViewHolder implementation for "tab" items. @@ -73,10 +74,7 @@ class TabTrayViewHolder( if (tab.thumbnail != null) { thumbnailView.setImageBitmap(tab.thumbnail) } else { - // Make sure we have the view's dimensions so we can load the image at the correct size - thumbnailView.doOnNextLayout { - imageLoader.loadIntoView(thumbnailView, tab.id) - } + loadIntoThumbnailView(thumbnailView, tab.id) } // Media state @@ -182,6 +180,14 @@ class TabTrayViewHolder( closeView.context.getString(R.string.close_tab_title, title) } + private fun loadIntoThumbnailView(thumbnailView: ImageView, id: String) { + val thumbnailSize = max( + itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_thumbnail_height), + itemView.resources.getDimensionPixelSize(R.dimen.tab_tray_thumbnail_width) + ) + imageLoader.loadIntoView(thumbnailView, ImageLoadRequest(id, thumbnailSize)) + } + internal fun updateAccessibilityRowIndex(item: View, newIndex: Int) { item.setAccessibilityDelegate(object : View.AccessibilityDelegate() { override fun onInitializeAccessibilityNodeInfo( diff --git a/app/src/main/res/layout/tab_tray_item.xml b/app/src/main/res/layout/tab_tray_item.xml index 0a465794e9..1bcd76021e 100644 --- a/app/src/main/res/layout/tab_tray_item.xml +++ b/app/src/main/res/layout/tab_tray_item.xml @@ -25,8 +25,8 @@ 40dp + 92dp + 69dp 10dp