mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +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;
|
package org.thoughtcrime.securesms.components;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build.VERSION;
|
||||||
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@ -44,6 +48,11 @@ public class ThumbnailView extends ForegroundImageView {
|
|||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override protected void onDetachedFromWindow() {
|
||||||
|
Glide.clear(this);
|
||||||
|
super.onDetachedFromWindow();
|
||||||
|
}
|
||||||
|
|
||||||
public void setImageResource(@NonNull ListenableFutureTask<SlideDeck> slideDeckFuture,
|
public void setImageResource(@NonNull ListenableFutureTask<SlideDeck> slideDeckFuture,
|
||||||
@Nullable MasterSecret masterSecret)
|
@Nullable MasterSecret masterSecret)
|
||||||
{
|
{
|
||||||
@ -57,12 +66,15 @@ public class ThumbnailView extends ForegroundImageView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setImageResource(@NonNull Slide slide, @Nullable MasterSecret masterSecret) {
|
public void setImageResource(@NonNull Slide slide, @Nullable MasterSecret masterSecret) {
|
||||||
buildGlideRequest(slide, masterSecret).into(ThumbnailView.this);
|
if (isContextValid()) {
|
||||||
setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide));
|
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);
|
setImageResource(slide, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +82,13 @@ public class ThumbnailView extends ForegroundImageView {
|
|||||||
this.thumbnailClickListener = listener;
|
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,
|
private GenericRequestBuilder buildGlideRequest(@NonNull Slide slide,
|
||||||
@Nullable MasterSecret masterSecret)
|
@Nullable MasterSecret masterSecret)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user