Skip to content

Commit ea5adfc

Browse files
committed
Always use Contact.getNameToDisplay()
Because Contact.name is empty on some android versions
1 parent 01c771d commit ea5adfc

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/EditContactActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ class EditContactActivity : ContactActivity() {
15361536
}
15371537

15381538
private fun setupAutofill(nameTextViews: List<MyAutoCompleteTextView>) {
1539-
ContactsHelper(this).getContacts { contacts ->
1539+
ContactsHelper(this).getContacts(getAll = true) { contacts ->
15401540
val adapter = AutoCompleteTextViewAdapter(this, contacts)
15411541
val handler = Handler(mainLooper)
15421542
nameTextViews.forEach { view ->

app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/AutoCompleteTextViewAdapter.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,29 @@ import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_au
2121
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_name
2222
import kotlinx.android.synthetic.main.item_autocomplete_name_number.view.item_autocomplete_number
2323

24-
class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: ArrayList<Contact>, var enableAutoFill: Boolean = false) : ArrayAdapter<Contact>(activity, 0, contacts) {
24+
class AutoCompleteTextViewAdapter(
25+
val activity: SimpleActivity,
26+
val contacts: ArrayList<Contact>,
27+
var enableAutoFill: Boolean = false
28+
) : ArrayAdapter<Contact>(activity, 0, contacts) {
2529
var resultList = ArrayList<Contact>()
2630

2731
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
2832
val contact = resultList[position]
2933
var listItem = convertView
30-
if (listItem == null || listItem.tag != contact.name.isNotEmpty()) {
34+
val nameToUse = contact.getNameToDisplay()
35+
if (listItem == null || listItem.tag != nameToUse.isNotEmpty()) {
3136
listItem = LayoutInflater.from(activity).inflate(R.layout.item_autocomplete_name_number, parent, false)
3237
}
3338

34-
val nameToUse = contact.name
35-
3639
val placeholder = BitmapDrawable(activity.resources, SimpleContactsHelper(context).getContactLetterIcon(nameToUse))
3740
listItem!!.apply {
3841
setBackgroundColor(context.getProperBackgroundColor())
3942
item_autocomplete_name.setTextColor(context.getProperTextColor())
4043
item_autocomplete_number.setTextColor(context.getProperTextColor())
4144

42-
tag = contact.name.isNotEmpty()
43-
item_autocomplete_name.text = contact.name
45+
tag = nameToUse.isNotEmpty()
46+
item_autocomplete_name.text = nameToUse
4447
item_autocomplete_number.text = contact.phoneNumbers.run {
4548
firstOrNull { it.isPrimary }?.normalizedNumber ?: firstOrNull()?.normalizedNumber
4649
}
@@ -70,7 +73,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
7073
if (enableAutoFill) {
7174
val searchString = constraint.toString().normalizeString()
7275
contacts.forEach {
73-
if (it.name.contains(searchString, true)) {
76+
if (it.getNameToDisplay().contains(searchString, true)) {
7477
resultList.add(it)
7578
}
7679
}

0 commit comments

Comments
 (0)