Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28cad9bb authored by moezbhatti's avatar moezbhatti Committed by Moez Bhatti
Browse files

Sort contacts with letter names first

parent fdf2e2db
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -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)
                }
            })
        }
    }

}
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class ContactAdapter @Inject constructor() : QkAdapter<Contact>() {

        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)