diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 0c2ef1cf5..bfba5d654 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -1125,10 +1125,16 @@ class EventActivity : SimpleActivity() { val names = getNames() mAvailableContacts.forEach { 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) { 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.FAMILY_NAME, ContactsContract.CommonDataKinds.StructuredName.SUFFIX, - ContactsContract.CommonDataKinds.StructuredName.PHOTO_URI) + ContactsContract.CommonDataKinds.StructuredName.PHOTO_THUMBNAIL_URI) val selection = "${ContactsContract.Data.MIMETYPE} = ?" 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 surname = cursor.getStringValue(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME) ?: "" 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 fullName = TextUtils.join("", names) - if (fullName.isNotEmpty()) { + if (fullName.isNotEmpty() || photoUri.isNotEmpty()) { val contact = Attendee(id, fullName, "", 0, photoUri) contacts.add(contact) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/AutoCompleteTextViewAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/AutoCompleteTextViewAdapter.kt index 4654612ce..5205d11ea 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/AutoCompleteTextViewAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/adapters/AutoCompleteTextViewAdapter.kt @@ -1,18 +1,30 @@ package com.simplemobiletools.calendar.pro.adapters +import android.graphics.drawable.LayerDrawable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter 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.activities.SimpleActivity +import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.models.Attendee +import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.normalizeString import kotlinx.android.synthetic.main.item_autocomplete_email_name.view.* class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: ArrayList) : ArrayAdapter(activity, 0, contacts) { private var resultList = ArrayList() + 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 { val contact = resultList[position] @@ -25,7 +37,23 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar listItem!!.apply { tag = contact.name.isNotEmpty() 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Attendee.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Attendee.kt index 29d69f1cc..74ebfa8d7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Attendee.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/models/Attendee.kt @@ -1,5 +1,5 @@ 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 } diff --git a/app/src/main/res/drawable-xhdpi/attendee_circular_background.xml b/app/src/main/res/drawable-xhdpi/attendee_circular_background.xml deleted file mode 100644 index bd3dc800d..000000000 --- a/app/src/main/res/drawable-xhdpi/attendee_circular_background.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/app/src/main/res/drawable/attendee_circular_background.xml b/app/src/main/res/drawable/attendee_circular_background.xml new file mode 100644 index 000000000..4b622c6eb --- /dev/null +++ b/app/src/main/res/drawable/attendee_circular_background.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/item_autocomplete_email.xml b/app/src/main/res/layout/item_autocomplete_email.xml index c066f4b4e..56fd8b08f 100644 --- a/app/src/main/res/layout/item_autocomplete_email.xml +++ b/app/src/main/res/layout/item_autocomplete_email.xml @@ -16,9 +16,6 @@ android:layout_width="@dimen/avatar_size" android:layout_height="@dimen/avatar_size" 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_constraintTop_toTopOf="parent"/> diff --git a/app/src/main/res/layout/item_autocomplete_email_name.xml b/app/src/main/res/layout/item_autocomplete_email_name.xml index 2439d5f6a..c11ab5886 100644 --- a/app/src/main/res/layout/item_autocomplete_email_name.xml +++ b/app/src/main/res/layout/item_autocomplete_email_name.xml @@ -16,9 +16,6 @@ android:layout_width="@dimen/avatar_size" android:layout_height="@dimen/avatar_size" 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_constraintTop_toTopOf="parent"/>