fix #268, use a different image placeholder for business contacts

This commit is contained in:
tibbi 2018-10-28 11:36:19 +01:00
parent 6de4f09319
commit 09b3f7f2f7
3 changed files with 9 additions and 3 deletions

View File

@ -36,6 +36,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
MyRecyclerViewAdapter(activity, recyclerView, fastScroller, itemClick) {
private lateinit var contactDrawable: Drawable
private lateinit var businessContactDrawable: Drawable
private var config = activity.config
private var textToHighlight = highlightText
@ -121,6 +122,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
fun initDrawables() {
contactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_person, textColor)
businessContactDrawable = activity.resources.getColoredDrawableWithColor(R.drawable.ic_business, textColor)
}
fun updateItems(newItems: ArrayList<Contact>, highlightText: String = "") {
@ -265,12 +267,13 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
contact_tmb.beVisibleIf(showContactThumbnails)
if (showContactThumbnails) {
val placeholderImage = if (contact.isABusinessContact()) businessContactDrawable else contactDrawable
when {
contact.photoUri.isNotEmpty() -> {
val options = RequestOptions()
.signature(ObjectKey(contact.photoUri))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(contactDrawable)
.error(placeholderImage)
.centerCrop()
Glide.with(activity).load(contact.photoUri).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
@ -279,12 +282,12 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
val options = RequestOptions()
.signature(ObjectKey(contact.photo!!))
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(contactDrawable)
.error(placeholderImage)
.centerCrop()
Glide.with(activity).load(contact.photo).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(contact_tmb)
}
else -> contact_tmb.setImageDrawable(contactDrawable)
else -> contact_tmb.setImageDrawable(placeholderImage)
}
}
}

View File

@ -118,6 +118,8 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
fun getHashToCompare() = getStringToCompare().hashCode()
fun isABusinessContact() = prefix.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && suffix.isEmpty() && organization.isNotEmpty()
// do a more advanced phone number check here, compare numbers and and search query with dashes, spaces and everything but numbers removed
fun doesContainPhoneNumber(text: String): Boolean {
if (text.isNotEmpty()) {

View File

@ -20,6 +20,7 @@
android:id="@+id/contact_tmb"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_marginTop="@dimen/tiny_margin"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_person"/>