Updated sortFavourites function
This commit is contained in:
parent
f78edda1c4
commit
66f93e2ad8
|
@ -123,7 +123,13 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
val filtered = when (this) {
|
val filtered = when (this) {
|
||||||
is GroupsFragment -> contacts
|
is GroupsFragment -> contacts
|
||||||
is FavoritesFragment -> {
|
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 -> {
|
else -> {
|
||||||
|
@ -153,16 +159,16 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Contact>.sortFavourites(shouldSort: Boolean = true): List<Contact> {
|
private fun sortFavourites(contacts: List<Contact>): List<Contact> {
|
||||||
val favoritesOrder = activity?.config?.favoritesContactsOrder
|
val favoritesOrder = activity?.config?.favoritesContactsOrder
|
||||||
if (!shouldSort || favoritesOrder.isNullOrEmpty()) {
|
if (favoritesOrder.isNullOrEmpty()) {
|
||||||
return this
|
return contacts
|
||||||
}
|
}
|
||||||
|
|
||||||
val orderList = Converters().jsonToStringList(favoritesOrder)
|
val orderList = Converters().jsonToStringList(favoritesOrder)
|
||||||
val map = orderList.withIndex().associate { it.value to it.index }
|
val map = orderList.withIndex().associate { it.value to it.index }
|
||||||
|
|
||||||
return sortedBy { contact ->
|
return contacts.sortedBy { contact ->
|
||||||
map[contact.id.toString()]
|
map[contact.id.toString()]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue