diff --git a/data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt b/data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt index 848e7d38..45248ff9 100644 --- a/data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt +++ b/data/src/main/java/com/moez/QKSMS/repository/ContactRepositoryImpl.kt @@ -77,10 +77,9 @@ class ContactRepositoryImpl @Inject constructor( Phone.getTypeLabel(context.resources, Phone.TYPE_MOBILE, "Mobile").toString() } - return when (prefs.mobileOnly.get()) { + val contactsFlowable = when (prefs.mobileOnly.get()) { true -> realm.where(Contact::class.java) .contains("numbers.type", mobileLabel) - .sort("name") .findAllAsync() .asFlowable() .filter { it.isLoaded } @@ -98,7 +97,6 @@ class ContactRepositoryImpl @Inject constructor( } false -> realm.where(Contact::class.java) - .sort("name") .findAllAsync() .asFlowable() .filter { it.isLoaded } @@ -107,6 +105,20 @@ class ContactRepositoryImpl @Inject constructor( .subscribeOn(AndroidSchedulers.mainThread()) .observeOn(Schedulers.io()) } + + return contactsFlowable.map { contacts -> + contacts.sortedWith(Comparator { c1, c2 -> + val initial = c1.name.firstOrNull() + val other = c2.name.firstOrNull() + if (initial?.isLetter() == true && other?.isLetter() != true) { + -1 + } else if (initial?.isLetter() != true && other?.isLetter() == true) { + 1 + } else { + c1.name.compareTo(c2.name, ignoreCase = true) + } + }) + } } -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt index a7cb4ce4..595f6918 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/ContactAdapter.kt @@ -62,7 +62,7 @@ class ContactAdapter @Inject constructor() : QkAdapter() { view.index.text = if (contact.name.getOrNull(0)?.isLetter() == true) contact.name[0].toString() else "#" view.index.isVisible = prevContact == null || - (contact.name[0].isLetter() && contact.name[0] != prevContact.name[0]) || + (contact.name[0].isLetter() && !contact.name[0].equals(prevContact.name[0], ignoreCase = true)) || (!contact.name[0].isLetter() && prevContact.name[0].isLetter()) view.avatar.setContact(contact)