show the proper attendee thumbnail image, if available

This commit is contained in:
tibbi 2019-03-14 15:45:08 +01:00
parent 4f0dc2b9c8
commit fa2cf07211
7 changed files with 56 additions and 19 deletions

View File

@ -1125,10 +1125,16 @@ class EventActivity : SimpleActivity() {
val names = getNames() val names = getNames()
mAvailableContacts.forEach { mAvailableContacts.forEach {
val contactId = it.contactId val contactId = it.contactId
val name = names.firstOrNull { it.contactId == contactId }?.name val contact = names.firstOrNull { it.contactId == contactId }
val name = contact?.name
if (name != null) { if (name != null) {
it.name = name it.name = name
} }
val photoUri = contact?.photoUri
if (photoUri != null) {
it.photoUri = photoUri
}
} }
} }
@ -1197,7 +1203,7 @@ class EventActivity : SimpleActivity() {
ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME, ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME,
ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME,
ContactsContract.CommonDataKinds.StructuredName.SUFFIX, ContactsContract.CommonDataKinds.StructuredName.SUFFIX,
ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI)
val selection = "${ContactsContract.Data.MIMETYPE} = ?" val selection = "${ContactsContract.Data.MIMETYPE} = ?"
val selectionArgs = arrayOf(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) val selectionArgs = arrayOf(ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
@ -1213,11 +1219,11 @@ class EventActivity : SimpleActivity() {
val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: "" val middleName = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.MIDDLE_NAME) ?: ""
val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" val surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: ""
val suffix = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.SUFFIX) ?: "" val suffix = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.SUFFIX) ?: ""
val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) ?: "" val photoUri = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) ?: ""
val names = arrayListOf(prefix, firstName, middleName, surname, suffix).filter { it.trim().isNotEmpty() } val names = arrayListOf(prefix, firstName, middleName, surname, suffix).filter { it.trim().isNotEmpty() }
val fullName = TextUtils.join("", names) val fullName = TextUtils.join("", names)
if (fullName.isNotEmpty()) { if (fullName.isNotEmpty() || photoUri.isNotEmpty()) {
val contact = Attendee(id, fullName, "", 0, photoUri) val contact = Attendee(id, fullName, "", 0, photoUri)
contacts.add(contact) contacts.add(contact)
} }

View File

@ -1,18 +1,30 @@
package com.simplemobiletools.calendar.pro.adapters package com.simplemobiletools.calendar.pro.adapters
import android.graphics.drawable.LayerDrawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ArrayAdapter import android.widget.ArrayAdapter
import android.widget.Filter import android.widget.Filter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.R
import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.activities.SimpleActivity
import com.simplemobiletools.calendar.pro.extensions.config
import com.simplemobiletools.calendar.pro.models.Attendee import com.simplemobiletools.calendar.pro.models.Attendee
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.normalizeString import com.simplemobiletools.commons.extensions.normalizeString
import kotlinx.android.synthetic.main.item_autocomplete_email_name.view.* import kotlinx.android.synthetic.main.item_autocomplete_email_name.view.*
class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: ArrayList<Attendee>) : ArrayAdapter<Attendee>(activity, 0, contacts) { class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: ArrayList<Attendee>) : ArrayAdapter<Attendee>(activity, 0, contacts) {
private var resultList = ArrayList<Attendee>() private var resultList = ArrayList<Attendee>()
private var placeholder = activity.resources.getDrawable(R.drawable.attendee_circular_background)
init {
(placeholder as LayerDrawable).findDrawableByLayerId(R.id.attendee_circular_background).applyColorFilter(activity.config.primaryColor)
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val contact = resultList[position] val contact = resultList[position]
@ -25,7 +37,23 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
listItem!!.apply { listItem!!.apply {
tag = contact.name.isNotEmpty() tag = contact.name.isNotEmpty()
item_autocomplete_name?.text = contact.name item_autocomplete_name?.text = contact.name
item_autocomplete_email.text = contact.email item_autocomplete_email?.text = contact.email
if (contact.photoUri.isEmpty()) {
item_autocomplete_image.setImageDrawable(placeholder)
} else {
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.error(placeholder)
.centerCrop()
Glide.with(activity)
.load(contact.photoUri)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.apply(RequestOptions.circleCropTransform())
.into(item_autocomplete_image)
}
} }
return listItem return listItem

View File

@ -1,5 +1,5 @@
package com.simplemobiletools.calendar.pro.models package com.simplemobiletools.calendar.pro.models
data class Attendee(val contactId: Int, var name: String, val email: String, val status: Int, val photoUri: String) { data class Attendee(val contactId: Int, var name: String, val email: String, val status: Int, var photoUri: String) {
fun getPublicName() = if (name.isNotEmpty()) name else email fun getPublicName() = if (name.isNotEmpty()) name else email
} }

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/color_primary"/>
</shape>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/attendee_circular_background">
<shape android:shape="oval">
<solid android:color="@color/color_primary"/>
</shape>
</item>
<item
android:bottom="@dimen/medium_margin"
android:drawable="@drawable/ic_person"
android:left="@dimen/medium_margin"
android:right="@dimen/medium_margin"
android:top="@dimen/medium_margin"/>
</layer-list>

View File

@ -16,9 +16,6 @@
android:layout_width="@dimen/avatar_size" android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" android:layout_height="@dimen/avatar_size"
android:layout_margin="@dimen/tiny_margin" android:layout_margin="@dimen/tiny_margin"
android:background="@drawable/attendee_circular_background"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_person"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>

View File

@ -16,9 +16,6 @@
android:layout_width="@dimen/avatar_size" android:layout_width="@dimen/avatar_size"
android:layout_height="@dimen/avatar_size" android:layout_height="@dimen/avatar_size"
android:layout_margin="@dimen/tiny_margin" android:layout_margin="@dimen/tiny_margin"
android:background="@drawable/attendee_circular_background"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_person"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>