From 66f93e2ad84e455051f76fc7488d2b9c1c18fe42 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 24 Jul 2023 13:15:13 +1000 Subject: [PATCH] Updated sortFavourites function --- .../pro/fragments/MyViewPagerFragment.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt index 66b60b8a..990a9686 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt @@ -123,7 +123,13 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) val filtered = when (this) { is GroupsFragment -> contacts is FavoritesFragment -> { - contacts.filter { it.starred == 1 }.sortFavourites(activity!!.config.isCustomOrderSelected) + val favouriteContacts = contacts.filter { it.starred == 1 } + + if (activity!!.config.isCustomOrderSelected) { + sortFavourites(favouriteContacts) + } else { + favouriteContacts + } } else -> { @@ -153,16 +159,16 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) } } - private fun List.sortFavourites(shouldSort: Boolean = true): List { + private fun sortFavourites(contacts: List): List { val favoritesOrder = activity?.config?.favoritesContactsOrder - if (!shouldSort || favoritesOrder.isNullOrEmpty()) { - return this + if (favoritesOrder.isNullOrEmpty()) { + return contacts } val orderList = Converters().jsonToStringList(favoritesOrder) val map = orderList.withIndex().associate { it.value to it.index } - return sortedBy { contact -> + return contacts.sortedBy { contact -> map[contact.id.toString()] } }