From 4904d46cb27b019d08a2be8c9eb3f64c6bc98afe Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 19 Nov 2020 19:25:25 +0800 Subject: Fix crash in GlideImageGetter. --- .../infinityforreddit/utils/GlideImageGetter.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/GlideImageGetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/GlideImageGetter.java index ee729d96..28ba6dce 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/GlideImageGetter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/GlideImageGetter.java @@ -58,13 +58,18 @@ public class GlideImageGetter implements Html.ImageGetter { BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize); - Context context = container.get().getContext(); - if (!(context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) { - container.get().post(() -> Glide.with(context) - .asBitmap() - .load(source) - .into(drawable)); - } + container.get().post(() -> { + TextView textView = container.get(); + if (textView != null) { + Context context = textView.getContext(); + if (!(context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) { + Glide.with(context) + .asBitmap() + .load(source) + .into(drawable); + } + } + }); return drawable; } -- cgit v1.2.3