From 42bcea2f8047cd06453bc3b57befa955635527fc Mon Sep 17 00:00:00 2001 From: Jan Guegel Date: Sat, 7 Mar 2026 01:16:06 +0100 Subject: [PATCH 1/2] add sorting fallbacks --- .../org/fossify/commons/models/contacts/Contact.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt b/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt index 208ed2030..6ad499430 100644 --- a/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt +++ b/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt @@ -137,9 +137,15 @@ data class Contact( return try { var name = when { isABusinessContact() -> getFullCompany() - sorting and SORT_BY_SURNAME != 0 && surname.isNotEmpty() -> surname - sorting and SORT_BY_MIDDLE_NAME != 0 && middleName.isNotEmpty() -> middleName - sorting and SORT_BY_FIRST_NAME != 0 && firstName.isNotEmpty() -> firstName + sorting and SORT_BY_SURNAME != 0 -> { + surname.ifEmpty { firstName } + } + sorting and SORT_BY_MIDDLE_NAME != 0 -> { + middleName.ifEmpty { firstName } + } + sorting and SORT_BY_FIRST_NAME != 0 -> { + firstName.ifEmpty { surname } + } startWithSurname -> surname else -> firstName } From 4a3ca3300ad40e835f8d7e299cd43b27931f6e52 Mon Sep 17 00:00:00 2001 From: Jan Guegel Date: Sat, 7 Mar 2026 12:54:11 +0100 Subject: [PATCH 2/2] adjust sorting for contacts app --- .../commons/models/contacts/Contact.kt | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt b/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt index 6ad499430..822f00777 100644 --- a/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt +++ b/commons/src/main/kotlin/org/fossify/commons/models/contacts/Contact.kt @@ -53,20 +53,20 @@ data class Contact( override fun compareTo(other: Contact): Int { var result = when { sorting and SORT_BY_FIRST_NAME != 0 -> { - val firstString = firstName.normalizeString() - val secondString = other.firstName.normalizeString() + val firstString = firstName.ifEmpty { surname }.normalizeString() + val secondString = other.firstName.ifEmpty { other.surname }.normalizeString() compareUsingStrings(firstString, secondString, other) } sorting and SORT_BY_MIDDLE_NAME != 0 -> { - val firstString = middleName.normalizeString() - val secondString = other.middleName.normalizeString() + val firstString = middleName.ifEmpty { firstName }.normalizeString() + val secondString = other.middleName.ifEmpty { other.firstName }.normalizeString() compareUsingStrings(firstString, secondString, other) } sorting and SORT_BY_SURNAME != 0 -> { - val firstString = surname.normalizeString() - val secondString = other.surname.normalizeString() + val firstString = surname.ifEmpty { firstName }.normalizeString() + val secondString = other.surname.ifEmpty { other.firstName }.normalizeString() compareUsingStrings(firstString, secondString, other) } @@ -137,15 +137,9 @@ data class Contact( return try { var name = when { isABusinessContact() -> getFullCompany() - sorting and SORT_BY_SURNAME != 0 -> { - surname.ifEmpty { firstName } - } - sorting and SORT_BY_MIDDLE_NAME != 0 -> { - middleName.ifEmpty { firstName } - } - sorting and SORT_BY_FIRST_NAME != 0 -> { - firstName.ifEmpty { surname } - } + sorting and SORT_BY_SURNAME != 0 && surname.isNotEmpty() -> surname + sorting and SORT_BY_MIDDLE_NAME != 0 && middleName.isNotEmpty() -> middleName + sorting and SORT_BY_FIRST_NAME != 0 && firstName.isNotEmpty() -> firstName startWithSurname -> surname else -> firstName }