Fix missing thumbnail background color.

This commit is contained in:
Cody Henthorne
2025-03-26 12:33:12 -04:00
parent c0113436a2
commit 03614b32e4
4 changed files with 19 additions and 11 deletions

View File

@@ -6,6 +6,7 @@ import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -53,15 +54,15 @@ public class BorderlessImageView extends FrameLayout {
image.setOnLongClickListener(l);
}
public void setSlide(@NonNull RequestManager requestManager, @NonNull Slide slide) {
public void setSlide(@NonNull RequestManager requestManager, @NonNull Slide slide, @ColorInt int missingBackgroundColor) {
boolean showControls = slide.asAttachment().getUri() == null;
if (slide.hasSticker()) {
image.setScaleType(ImageView.ScaleType.FIT_CENTER);
image.setImageResource(requestManager, slide, showControls, false);
image.setImageResource(requestManager, slide, showControls, false, 0, 0, missingBackgroundColor);
} else {
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
image.setImageResource(requestManager, slide, showControls, false, slide.asAttachment().width, slide.asAttachment().height);
image.setImageResource(requestManager, slide, showControls, false, slide.asAttachment().width, slide.asAttachment().height, missingBackgroundColor);
}
missingShade.setVisibility(showControls ? View.VISIBLE : View.GONE);

View File

@@ -195,7 +195,8 @@ class ConversationItemThumbnail @JvmOverloads constructor(
requestManager: RequestManager,
slides: List<Slide>,
showControls: Boolean,
isPreview: Boolean
isPreview: Boolean,
@ColorInt missingThumbnailBackgroundColor: Int
) {
if (slides.size == 1) {
val slide = slides[0]
@@ -223,7 +224,7 @@ class ConversationItemThumbnail @JvmOverloads constructor(
val attachment = slides[0].asAttachment()
thumbnail.get().setImageResource(requestManager, slides[0], showControls, isPreview, attachment.width, attachment.height)
thumbnail.get().setImageResource(requestManager, slides[0], showControls, isPreview, attachment.width, attachment.height, missingThumbnailBackgroundColor)
touchDelegate = thumbnail.get().touchDelegate
} else {
state = state.copy(

View File

@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
@@ -20,6 +21,7 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
@@ -328,13 +330,13 @@ public class ThumbnailView extends FrameLayout {
public ListenableFuture<Boolean> setImageResource(@NonNull RequestManager requestManager, @NonNull Slide slide,
boolean showControls, boolean isPreview)
{
return setImageResource(requestManager, slide, showControls, isPreview, 0, 0);
return setImageResource(requestManager, slide, showControls, isPreview, 0, 0, Color.TRANSPARENT);
}
@UiThread
public ListenableFuture<Boolean> setImageResource(@NonNull RequestManager requestManager, @NonNull Slide slide,
boolean showControls, boolean isPreview,
int naturalWidth, int naturalHeight)
int naturalWidth, int naturalHeight, @ColorInt int missingBackgroundColor)
{
if (slide.asAttachment().isPermanentlyFailed()) {
this.slide = slide;
@@ -347,6 +349,7 @@ public class ThumbnailView extends FrameLayout {
requestManager.clear(image);
image.setImageDrawable(null);
image.setBackgroundColor(Color.TRANSPARENT);
int errorImageResource;
if (slide instanceof ImageSlide) {
@@ -359,6 +362,8 @@ public class ThumbnailView extends FrameLayout {
errorImage.setImageResource(errorImageResource);
errorImage.setVisibility(View.VISIBLE);
image.setBackgroundColor(missingBackgroundColor);
return new SettableFuture<>(true);
} else {
errorImage.setVisibility(View.GONE);