From 23d6e5471855d971bc8f5278f5e42c151aad951f Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 2 Aug 2018 22:02:10 +0200 Subject: [PATCH] fix the sorting of organization contacts --- .../com/simplemobiletools/contacts/models/Contact.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt index b35c5130..dd5f3250 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt @@ -16,8 +16,8 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m } override fun compareTo(other: Contact): Int { - val firstString: String - val secondString: String + var firstString: String + var secondString: String when { sorting and SORT_BY_FIRST_NAME != 0 -> { @@ -34,6 +34,14 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m } } + if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && organization.company.isNotEmpty()) { + firstString = organization.company + } + + if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty() && other.organization.company.isNotEmpty()) { + secondString = other.organization.company + } + var result = if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) { -1 } else if (firstString.firstOrNull()?.isLetter() == false && secondString.firstOrNull()?.isLetter() == true) {