show names at autocomplete suggestions, where available

This commit is contained in:
tibbi 2019-03-14 10:32:13 +01:00
parent a9ff1003fb
commit 236b3ef5ad
3 changed files with 50 additions and 7 deletions

View File

@ -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<Attendee>) : ArrayAdapter<Attendee>(activity, 0, contacts) {
private var resultList = ArrayList<Attendee>()
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]

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_autocomplete_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -8,7 +9,7 @@
android:paddingBottom="@dimen/medium_margin">
<TextView
android:id="@+id/item_autocomplete"
android:id="@+id/item_autocomplete_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
@ -17,6 +18,7 @@
android:maxLines="1"
android:padding="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"/>
android:textSize="@dimen/bigger_text_size"
tools:text="hello@simplemobiletools.com"/>
</RelativeLayout>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_autocomplete_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/medium_margin"
android:paddingBottom="@dimen/medium_margin">
<TextView
android:id="@+id/item_autocomplete_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/activity_margin"
android:lines="1"
android:maxLines="1"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/bigger_text_size"
tools:text="Simple Mobile"/>
<TextView
android:id="@+id/item_autocomplete_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/item_autocomplete_name"
android:layout_marginEnd="@dimen/activity_margin"
android:alpha="0.8"
android:lines="1"
android:maxLines="1"
android:paddingLeft="@dimen/medium_margin"
android:paddingRight="@dimen/medium_margin"
android:singleLine="true"
android:textSize="@dimen/normal_text_size"
tools:text="hello@simplemobiletools.com"/>
</RelativeLayout>