mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-12 09:30:39 +01:00
removing some duplication at avatar loading
This commit is contained in:
parent
c7fda28544
commit
a84aa91e28
@ -7,7 +7,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||||
@ -291,39 +290,33 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
|
|||||||
contact_tmb.beVisibleIf(showContactThumbnails)
|
contact_tmb.beVisibleIf(showContactThumbnails)
|
||||||
|
|
||||||
if (showContactThumbnails) {
|
if (showContactThumbnails) {
|
||||||
val placeholderImage = BitmapDrawable(resources, context.getContactLetterIcon(fullName))
|
val avatarName = when {
|
||||||
when {
|
contact.isABusinessContact() -> contact.getFullCompany()
|
||||||
contact.photoUri.isNotEmpty() -> {
|
config.startNameWithSurname -> contact.surname
|
||||||
val options = RequestOptions()
|
else -> contact.firstName
|
||||||
.signature(ObjectKey(contact.photoUri))
|
}
|
||||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
|
||||||
.error(placeholderImage)
|
|
||||||
.centerCrop()
|
|
||||||
|
|
||||||
Glide.with(activity)
|
val placeholderImage = BitmapDrawable(resources, context.getContactLetterIcon(avatarName))
|
||||||
.load(contact.photoUri)
|
if (contact.photoUri.isEmpty() && contact.photo == null) {
|
||||||
.transition(DrawableTransitionOptions.withCrossFade())
|
contact_tmb.setImageDrawable(placeholderImage)
|
||||||
.apply(options)
|
} else {
|
||||||
.apply(RequestOptions.circleCropTransform())
|
val options = RequestOptions()
|
||||||
.into(contact_tmb)
|
.signature(ObjectKey(contact.getSignatureKey()))
|
||||||
}
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||||
contact.photo != null -> {
|
.error(placeholderImage)
|
||||||
val options = RequestOptions()
|
.centerCrop()
|
||||||
.signature(ObjectKey(contact.hashCode()))
|
|
||||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
|
||||||
.error(placeholderImage)
|
|
||||||
.centerCrop()
|
|
||||||
|
|
||||||
Glide.with(activity)
|
val itemToLoad: Any? = if (contact.photoUri.isNotEmpty()) {
|
||||||
.load(contact.photo)
|
contact.photoUri
|
||||||
.transition(DrawableTransitionOptions.withCrossFade())
|
} else {
|
||||||
.apply(options)
|
contact.photo
|
||||||
.apply(RequestOptions.circleCropTransform())
|
|
||||||
.into(contact_tmb)
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
contact_tmb.setImageDrawable(placeholderImage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Glide.with(activity)
|
||||||
|
.load(itemToLoad)
|
||||||
|
.apply(options)
|
||||||
|
.apply(RequestOptions.circleCropTransform())
|
||||||
|
.into(contact_tmb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,4 +138,6 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isPrivate() = source == SMT_PRIVATE
|
fun isPrivate() = source == SMT_PRIVATE
|
||||||
|
|
||||||
|
fun getSignatureKey() = if (photoUri.isNotEmpty()) photoUri else hashCode()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user