Loading legacy/ui/account/build.gradle.kts +7 −0 Original line number Diff line number Diff line Loading @@ -7,7 +7,14 @@ android { } dependencies { api(projects.legacy.account) implementation(projects.core.android.common) implementation(projects.core.ui.legacy.designsystem) implementation(projects.legacy.mailstore) implementation(projects.legacy.message) implementation(libs.androidx.lifecycle.livedata.ktx) implementation(libs.glide) } legacy/ui/account/src/main/java/app/k9mail/legacy/ui/account/AccountImageLoader.kt 0 → 100644 +37 −0 Original line number Diff line number Diff line package app.k9mail.legacy.ui.account import android.content.Context import android.widget.ImageView import app.k9mail.core.android.common.activity.findActivity import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy /** * Load the account image into an [ImageView]. */ class AccountImageLoader(private val accountFallbackImageProvider: AccountFallbackImageProvider) { fun setAccountImage(imageView: ImageView, email: String, color: Int) { imageView.context.ifNotDestroyed { context -> Glide.with(context) .load(AccountImage(email, color)) .placeholder(accountFallbackImageProvider.getDrawable(color)) .diskCacheStrategy(DiskCacheStrategy.NONE) .dontAnimate() .into(imageView) } } fun cancel(imageView: ImageView) { imageView.context.ifNotDestroyed { context -> Glide.with(context).clear(imageView) } } private inline fun Context.ifNotDestroyed(block: (Context) -> Unit) { if (findActivity()?.isDestroyed == true) { // Do nothing because Glide would throw an exception } else { block(this) } } } legacy/ui/legacy/src/main/java/com/fsck/k9/ui/account/KoinModule.kt +2 −0 Original line number Diff line number Diff line package com.fsck.k9.ui.account import app.k9mail.legacy.ui.account.AccountFallbackImageProvider import app.k9mail.legacy.ui.account.AccountImageLoader import org.koin.dsl.module val accountUiModule = module { factory { AccountImageLoader(accountFallbackImageProvider = get()) } factory { AccountFallbackImageProvider(context = get()) } factory { AccountImageModelLoaderFactory(contactPhotoLoader = get(), accountFallbackImageProvider = get()) } } Loading
legacy/ui/account/build.gradle.kts +7 −0 Original line number Diff line number Diff line Loading @@ -7,7 +7,14 @@ android { } dependencies { api(projects.legacy.account) implementation(projects.core.android.common) implementation(projects.core.ui.legacy.designsystem) implementation(projects.legacy.mailstore) implementation(projects.legacy.message) implementation(libs.androidx.lifecycle.livedata.ktx) implementation(libs.glide) }
legacy/ui/account/src/main/java/app/k9mail/legacy/ui/account/AccountImageLoader.kt 0 → 100644 +37 −0 Original line number Diff line number Diff line package app.k9mail.legacy.ui.account import android.content.Context import android.widget.ImageView import app.k9mail.core.android.common.activity.findActivity import com.bumptech.glide.Glide import com.bumptech.glide.load.engine.DiskCacheStrategy /** * Load the account image into an [ImageView]. */ class AccountImageLoader(private val accountFallbackImageProvider: AccountFallbackImageProvider) { fun setAccountImage(imageView: ImageView, email: String, color: Int) { imageView.context.ifNotDestroyed { context -> Glide.with(context) .load(AccountImage(email, color)) .placeholder(accountFallbackImageProvider.getDrawable(color)) .diskCacheStrategy(DiskCacheStrategy.NONE) .dontAnimate() .into(imageView) } } fun cancel(imageView: ImageView) { imageView.context.ifNotDestroyed { context -> Glide.with(context).clear(imageView) } } private inline fun Context.ifNotDestroyed(block: (Context) -> Unit) { if (findActivity()?.isDestroyed == true) { // Do nothing because Glide would throw an exception } else { block(this) } } }
legacy/ui/legacy/src/main/java/com/fsck/k9/ui/account/KoinModule.kt +2 −0 Original line number Diff line number Diff line package com.fsck.k9.ui.account import app.k9mail.legacy.ui.account.AccountFallbackImageProvider import app.k9mail.legacy.ui.account.AccountImageLoader import org.koin.dsl.module val accountUiModule = module { factory { AccountImageLoader(accountFallbackImageProvider = get()) } factory { AccountFallbackImageProvider(context = get()) } factory { AccountImageModelLoaderFactory(contactPhotoLoader = get(), accountFallbackImageProvider = get()) } }