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

Commit da9cb4a0 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

Revert "Remove AccountImageLoader"

This reverts commit f16e6802.
parent eb40fd6c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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)
}
+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)
        }
    }
}
+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()) }
}