mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-06-05 21:59:27 +02:00
Improved sortFavourites readability
This commit is contained in:
@ -154,19 +154,16 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun List<Contact>.sortFavourites(shouldSort: Boolean = true): List<Contact> {
|
private fun List<Contact>.sortFavourites(shouldSort: Boolean = true): List<Contact> {
|
||||||
return if (shouldSort) {
|
val favoritesOrder = activity?.config?.favoritesContactsOrder
|
||||||
val favoritesOrder = activity!!.config.favoritesContactsOrder
|
if (!shouldSort || favoritesOrder.isNullOrEmpty()) {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
if (favoritesOrder.isEmpty()) {
|
val orderList = Converters().jsonToStringList(favoritesOrder)
|
||||||
return this
|
val map = orderList.withIndex().associate { it.value to it.index }
|
||||||
}
|
|
||||||
|
|
||||||
val orderList = Converters().jsonToStringList(favoritesOrder)
|
return sortedBy { contact ->
|
||||||
val map = orderList.withIndex().associate { it.value to it.index }
|
map[contact.id.toString()]
|
||||||
|
|
||||||
return sortedBy { map[it.id.toString()] }
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user