Fix crash in GlideImageGetter.

This commit is contained in:
Alex Ning 2020-11-19 19:25:25 +08:00
parent c21d59e979
commit 4904d46cb2

View File

@ -58,13 +58,18 @@ public class GlideImageGetter implements Html.ImageGetter {
BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize); BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize);
Context context = container.get().getContext(); container.get().post(() -> {
TextView textView = container.get();
if (textView != null) {
Context context = textView.getContext();
if (!(context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) { if (!(context instanceof Activity && (((Activity) context).isFinishing() || ((Activity) context).isDestroyed()))) {
container.get().post(() -> Glide.with(context) Glide.with(context)
.asBitmap() .asBitmap()
.load(source) .load(source)
.into(drawable)); .into(drawable);
} }
}
});
return drawable; return drawable;
} }