From 236b3ef5ad719174c369610ec14a526125b0847b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 14 Mar 2019 10:32:13 +0100 Subject: [PATCH] show names at autocomplete suggestions, where available --- .../adapters/AutoCompleteTextViewAdapter.kt | 12 +++--- .../res/layout/item_autocomplete_email.xml | 6 ++- .../layout/item_autocomplete_email_name.xml | 39 +++++++++++++++++++ 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/layout/item_autocomplete_email_name.xml 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 f71e9d78f..ac6aabdcd 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 @@ -9,19 +9,21 @@ import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.activities.SimpleActivity import com.simplemobiletools.calendar.pro.models.Attendee import com.simplemobiletools.commons.extensions.normalizeString -import kotlinx.android.synthetic.main.item_autocomplete_email.view.* +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() override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { + val contact = resultList[position] var listItem = convertView if (listItem == null) { - listItem = LayoutInflater.from(activity).inflate(R.layout.item_autocomplete_email, parent, false) + val layout = if (contact.name.isNotEmpty()) R.layout.item_autocomplete_email_name else R.layout.item_autocomplete_email + listItem = LayoutInflater.from(activity).inflate(layout, parent, false) } - val contact = resultList[position] - listItem!!.item_autocomplete.text = contact.email + listItem!!.item_autocomplete_name?.text = contact.name + listItem.item_autocomplete_email.text = contact.email return listItem } @@ -59,7 +61,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar } } - override fun convertResultToString(resultValue: Any?) = (resultValue as? Attendee)?.email + override fun convertResultToString(resultValue: Any?) = (resultValue as? Attendee)?.getPublicName() } override fun getItem(index: Int) = resultList[index] diff --git a/app/src/main/res/layout/item_autocomplete_email.xml b/app/src/main/res/layout/item_autocomplete_email.xml index ce4b4edf9..bc48edf72 100644 --- a/app/src/main/res/layout/item_autocomplete_email.xml +++ b/app/src/main/res/layout/item_autocomplete_email.xml @@ -1,6 +1,7 @@ + android:textSize="@dimen/bigger_text_size" + tools:text="hello@simplemobiletools.com"/> diff --git a/app/src/main/res/layout/item_autocomplete_email_name.xml b/app/src/main/res/layout/item_autocomplete_email_name.xml new file mode 100644 index 000000000..d99035825 --- /dev/null +++ b/app/src/main/res/layout/item_autocomplete_email_name.xml @@ -0,0 +1,39 @@ + + + + + + + +