Utilize drawable instead of bitmap for transition.
This commit is contained in:
parent
6aa4ef95b5
commit
417db2341b
9 changed files with 25 additions and 44 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2393,7 +2393,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
mediaThumbnailStub.require().getCorners().getBottomRight(),
|
||||
mediaThumbnailStub.require().getCorners().getBottomLeft()
|
||||
));
|
||||
MediaPreviewCache.INSTANCE.setBitmap(mediaThumbnailStub.require().getBitmap());
|
||||
MediaPreviewCache.INSTANCE.setDrawable(mediaThumbnailStub.require().getDrawable());
|
||||
eventListener.goToMediaPreview(ConversationItem.this, mediaThumbnailStub.require(), args);
|
||||
} else if (slide.getUri() != null) {
|
||||
Log.i(TAG, "Clicked: " + slide.getUri() + " , " + slide.getContentType());
|
||||
|
|
|
@ -347,7 +347,7 @@ final class MediaGalleryAllAdapter extends StickyHeaderGridAdapter {
|
|||
|
||||
thumbnailView.setImageResource(glideRequests, slide, false, false);
|
||||
thumbnailView.setOnClickListener(view -> {
|
||||
MediaPreviewCache.INSTANCE.setBitmap(thumbnailView.getBitmap());
|
||||
MediaPreviewCache.INSTANCE.setDrawable(thumbnailView.getImageDrawable());
|
||||
itemClickListener.onMediaClicked(thumbnailView, mediaRecord);
|
||||
});
|
||||
thumbnailView.setOnLongClickListener(view -> onLongClick());
|
||||
|
@ -598,7 +598,7 @@ final class MediaGalleryAllAdapter extends StickyHeaderGridAdapter {
|
|||
|
||||
@Override
|
||||
protected @NonNull View getTransitionAnchor() {
|
||||
MediaPreviewCache.INSTANCE.setBitmap(null);
|
||||
MediaPreviewCache.INSTANCE.setDrawable(null);
|
||||
return thumbnailView;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.thoughtcrime.securesms.mediapreview
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.drawable.Drawable
|
||||
|
||||
/**
|
||||
* Stores the bitmap for a thumbnail we are animating from via a shared
|
||||
|
@ -8,5 +8,5 @@ import android.graphics.Bitmap
|
|||
* receiving end.
|
||||
*/
|
||||
object MediaPreviewCache {
|
||||
var bitmap: Bitmap? = null
|
||||
var drawable: Drawable? = null
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
|
|||
override fun onCreate(savedInstanceState: Bundle?, ready: Boolean) {
|
||||
val args = MediaIntentFactory.requireArguments(intent.extras!!)
|
||||
|
||||
if (MediaPreviewCache.bitmap != null) {
|
||||
if (MediaPreviewCache.drawable != null) {
|
||||
val originalCorners = ShapeAppearanceModel.Builder()
|
||||
.setTopLeftCornerSize(args.sharedElementArgs.topLeft)
|
||||
.setTopRightCornerSize(args.sharedElementArgs.topRight)
|
||||
|
@ -85,8 +85,8 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
|
|||
setContentView(R.layout.activity_mediapreview_v2)
|
||||
|
||||
transitionImageView = findViewById(R.id.transition_image_view)
|
||||
if (MediaPreviewCache.bitmap != null) {
|
||||
transitionImageView.setImageBitmap(MediaPreviewCache.bitmap)
|
||||
if (MediaPreviewCache.drawable != null) {
|
||||
transitionImageView.setImageDrawable(MediaPreviewCache.drawable)
|
||||
} else {
|
||||
transitionImageView.visibility = View.INVISIBLE
|
||||
viewModel.setIsInSharedAnimation(false)
|
||||
|
@ -119,7 +119,7 @@ class MediaPreviewV2Activity : PassphraseRequiredActivity(), VoiceNoteMediaContr
|
|||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
MediaPreviewCache.bitmap = null
|
||||
MediaPreviewCache.drawable = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -542,7 +542,7 @@ public class AttachmentManager {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (slide.isPresent()) {
|
||||
MediaPreviewCache.INSTANCE.setBitmap(((ThumbnailView) v).getBitmap());
|
||||
MediaPreviewCache.INSTANCE.setDrawable(((ThumbnailView) v).getImageDrawable());
|
||||
previewImageDraft(slide.get());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue