mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
verify glide isn't loading into destroyed activity
Fixes #3110 Closes #3114 // FREEBIE
This commit is contained in:
parent
cdd7a1042a
commit
8332342d75
@ -1,8 +1,12 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.os.Build.VERSION;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
@ -44,6 +48,11 @@ public class ThumbnailView extends ForegroundImageView {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override protected void onDetachedFromWindow() {
|
||||
Glide.clear(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
public void setImageResource(@NonNull ListenableFutureTask<SlideDeck> slideDeckFuture,
|
||||
@Nullable MasterSecret masterSecret)
|
||||
{
|
||||
@ -57,12 +66,15 @@ public class ThumbnailView extends ForegroundImageView {
|
||||
}
|
||||
|
||||
public void setImageResource(@NonNull Slide slide, @Nullable MasterSecret masterSecret) {
|
||||
if (isContextValid()) {
|
||||
buildGlideRequest(slide, masterSecret).into(ThumbnailView.this);
|
||||
setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide));
|
||||
} else {
|
||||
Log.w(TAG, "Not going to load resource, context is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
public void setImageResource(@NonNull Slide slide)
|
||||
{
|
||||
public void setImageResource(@NonNull Slide slide) {
|
||||
setImageResource(slide, null);
|
||||
}
|
||||
|
||||
@ -70,6 +82,13 @@ public class ThumbnailView extends ForegroundImageView {
|
||||
this.thumbnailClickListener = listener;
|
||||
}
|
||||
|
||||
@TargetApi(VERSION_CODES.JELLY_BEAN_MR1)
|
||||
private boolean isContextValid() {
|
||||
return !(getContext() instanceof Activity) ||
|
||||
VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN_MR1 ||
|
||||
!((Activity)getContext()).isDestroyed();
|
||||
}
|
||||
|
||||
private GenericRequestBuilder buildGlideRequest(@NonNull Slide slide,
|
||||
@Nullable MasterSecret masterSecret)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user