Loading app/ui/legacy/src/main/java/com/fsck/k9/ui/account/AccountImageLoader.kt +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]. Loading @@ -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) Loading app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/ContextExtensions.kt 0 → 100644 +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() } app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/AttachmentView.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading Loading
app/ui/legacy/src/main/java/com/fsck/k9/ui/account/AccountImageLoader.kt +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]. Loading @@ -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) Loading
app/ui/legacy/src/main/java/com/fsck/k9/ui/helper/ContextExtensions.kt 0 → 100644 +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() }
app/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/AttachmentView.java +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; } Loading