From 9c0ef0fbe9cc7dff5b440aa3455134dbed2b2ee6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 23 May 2021 17:37:35 +0200 Subject: [PATCH] adding some null checks at autocomplete textview adapter --- .../adapters/AutoCompleteTextViewAdapter.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/AutoCompleteTextViewAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/AutoCompleteTextViewAdapter.kt index 1f9c20de..13199da6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/AutoCompleteTextViewAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/adapters/AutoCompleteTextViewAdapter.kt @@ -20,14 +20,14 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar var resultList = ArrayList() override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val contact = resultList[position] + val contact = resultList.getOrNull(position) var listItem = convertView - if (listItem == null || listItem.tag != contact.name.isNotEmpty()) { + if (listItem == null || listItem.tag != contact?.name?.isNotEmpty()) { listItem = LayoutInflater.from(activity).inflate(R.layout.item_contact_with_number, parent, false) } listItem!!.apply { - tag = contact.name.isNotEmpty() + tag = contact?.name?.isNotEmpty() // clickable and focusable properties seem to break Autocomplete clicking, so remove them findViewById(R.id.item_contact_frame).apply { isClickable = false @@ -35,14 +35,16 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar } val backgroundColor = activity.config.backgroundColor - findViewById(R.id.item_contact_name).text = contact.name - findViewById(R.id.item_contact_number).text = contact.phoneNumbers.first() findViewById(R.id.item_contact_holder).setBackgroundColor(backgroundColor.darkenColor()) findViewById(R.id.item_contact_name).setTextColor(backgroundColor.getContrastColor()) findViewById(R.id.item_contact_number).setTextColor(backgroundColor.getContrastColor()) - SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name) + if (contact != null) { + findViewById(R.id.item_contact_name).text = contact.name + findViewById(R.id.item_contact_number).text = contact.phoneNumbers.first() + SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name) + } } return listItem