mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Utilize drawable instead of bitmap for transition.
This commit is contained in:
committed by
Greyson Parrelli
parent
6aa4ef95b5
commit
417db2341b
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -30,11 +31,11 @@ public class AlbumThumbnailView extends FrameLayout {
|
||||
|
||||
private ViewGroup albumCellContainer;
|
||||
private Stub<TransferControlView> transferControls;
|
||||
private Bitmap bitmap;
|
||||
private Drawable imageDrawable;
|
||||
|
||||
private final SlideClickListener defaultThumbnailClickListener = (v, slide) -> {
|
||||
if (thumbnailClickListener != null) {
|
||||
bitmap = ((ThumbnailView) v).getBitmap();
|
||||
imageDrawable = ((ThumbnailView) v).getImageDrawable();
|
||||
thumbnailClickListener.onClick(v, slide);
|
||||
}
|
||||
};
|
||||
@@ -87,8 +88,8 @@ public class AlbumThumbnailView extends FrameLayout {
|
||||
showSlides(glideRequests, slides);
|
||||
}
|
||||
|
||||
public @Nullable Bitmap getBitmap() {
|
||||
return bitmap;
|
||||
public @Nullable Drawable getDrawable() {
|
||||
return imageDrawable;
|
||||
}
|
||||
|
||||
public void setCellBackgroundColor(@ColorInt int color) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.thoughtcrime.securesms.components
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import android.util.AttributeSet
|
||||
@@ -131,11 +131,11 @@ class ConversationItemThumbnail @JvmOverloads constructor(
|
||||
state.applyState(thumbnail, album)
|
||||
}
|
||||
|
||||
fun getBitmap(): Bitmap? {
|
||||
fun getDrawable(): Drawable? {
|
||||
return if (thumbnail.resolved()) {
|
||||
thumbnail.get().bitmap
|
||||
thumbnail.get().imageDrawable
|
||||
} else {
|
||||
album.get().bitmap
|
||||
album.get().drawable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ public class ThreadPhotoRailView extends FrameLayout {
|
||||
}
|
||||
|
||||
imageView.setOnClickListener(v -> {
|
||||
MediaPreviewCache.INSTANCE.setBitmap(imageView.getBitmap());
|
||||
MediaPreviewCache.INSTANCE.setDrawable(imageView.getImageDrawable());
|
||||
if (clickedListener != null) clickedListener.onItemClicked(imageView, mediaRecord);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
@@ -66,7 +65,6 @@ public class ThumbnailView extends FrameLayout {
|
||||
private static final int MIN_HEIGHT = 2;
|
||||
private static final int MAX_HEIGHT = 3;
|
||||
|
||||
private Bitmap imageBitmap;
|
||||
private final ImageView image;
|
||||
private final ImageView blurHash;
|
||||
private final View playOverlay;
|
||||
@@ -286,8 +284,8 @@ public class ThumbnailView extends FrameLayout {
|
||||
transferControls.ifPresent(transferControlView -> transferControlView.setClickable(clickable));
|
||||
}
|
||||
|
||||
public @Nullable Bitmap getBitmap() {
|
||||
return imageBitmap;
|
||||
public @Nullable Drawable getImageDrawable() {
|
||||
return image.getDrawable();
|
||||
}
|
||||
|
||||
private TransferControlView getTransferControls() {
|
||||
@@ -416,7 +414,7 @@ public class ThumbnailView extends FrameLayout {
|
||||
thumbnailFuture.addListener(new BlurHashClearListener(glideRequests, blurHash));
|
||||
}
|
||||
|
||||
buildThumbnailGlideRequest(glideRequests, slide).into(new BitmapCaptor(image, result));
|
||||
buildThumbnailGlideRequest(glideRequests, slide).into(new GlideDrawableListeningTarget(image, result));
|
||||
|
||||
resultHandled = true;
|
||||
} else {
|
||||
@@ -456,7 +454,7 @@ public class ThumbnailView extends FrameLayout {
|
||||
request = request.override(width, height);
|
||||
}
|
||||
|
||||
GlideDrawableListeningTarget target = new BitmapCaptor(image, future);
|
||||
GlideDrawableListeningTarget target = new GlideDrawableListeningTarget(image, future);
|
||||
Request previousRequest = target.getRequest();
|
||||
boolean previousRequestRunning = previousRequest != null && previousRequest.isRunning();
|
||||
request.into(target);
|
||||
@@ -486,7 +484,7 @@ public class ThumbnailView extends FrameLayout {
|
||||
request = request.override(width, height);
|
||||
}
|
||||
|
||||
request.into(new BitmapCaptor(image, future));
|
||||
request.into(new GlideDrawableListeningTarget(image, future));
|
||||
blurHash.setImageDrawable(null);
|
||||
|
||||
return future;
|
||||
@@ -642,22 +640,4 @@ public class ThumbnailView extends FrameLayout {
|
||||
blurHash.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
public class BitmapCaptor extends GlideDrawableListeningTarget {
|
||||
|
||||
public BitmapCaptor(@NonNull ImageView view, @NonNull SettableFuture<Boolean> loaded) {
|
||||
super(view, loaded);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
||||
imageBitmap = ((BitmapDrawable) resource).getBitmap();
|
||||
super.onResourceReady(resource, transition);
|
||||
}
|
||||
|
||||
@Override public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||
imageBitmap = null;
|
||||
super.onLoadCleared(placeholder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user