Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit c0c0e05a authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #5783 from k9mail/avoid_glide_crashes

Avoid Glide crash
parents e55e92d5 d99c8580
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
package com.fsck.k9.ui.account

import android.app.Activity
import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.fsck.k9.ui.helper.findActivity

/**
 * Load the account image into an [ImageView].
@@ -28,7 +28,7 @@ class AccountImageLoader(private val accountFallbackImageProvider: AccountFallba
    }

    private inline fun Context.ifNotDestroyed(block: (Context) -> Unit) {
        if ((this as? Activity)?.isDestroyed == true) {
        if (findActivity()?.isDestroyed == true) {
            // Do nothing because Glide would throw an exception
        } else {
            block(this)
+11 −0
Original line number Diff line number Diff line
@file:JvmName("ContextHelper")
package com.fsck.k9.ui.helper

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper

// Source: https://stackoverflow.com/a/58249983
tailrec fun Context.findActivity(): Activity? {
    return this as? Activity ?: (this as? ContextWrapper)?.baseContext?.findActivity()
}
+3 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.fsck.k9.K9;
import com.fsck.k9.ui.R;
import com.fsck.k9.ui.helper.ContextHelper;
import com.fsck.k9.ui.helper.SizeFormatter;
import com.fsck.k9.mailstore.AttachmentViewInfo;

@@ -122,7 +123,8 @@ public class AttachmentView extends FrameLayout implements OnClickListener {

    public void refreshThumbnail() {
        Context context = getContext();
        if (context instanceof Activity && ((Activity) context).isDestroyed()) {
        Activity activity = ContextHelper.findActivity(context);
        if (activity != null && activity.isDestroyed()) {
            // Do nothing because Glide would throw an exception
            return;
        }