mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-16 11:31:37 +01:00
Improved sortFavourites readability
This commit is contained in:
parent
955efe9442
commit
fd24f1ed6c
@ -154,19 +154,16 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
||||
}
|
||||
|
||||
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()) {
|
||||
return this
|
||||
}
|
||||
val orderList = Converters().jsonToStringList(favoritesOrder)
|
||||
val map = orderList.withIndex().associate { it.value to it.index }
|
||||
|
||||
val orderList = Converters().jsonToStringList(favoritesOrder)
|
||||
val map = orderList.withIndex().associate { it.value to it.index }
|
||||
|
||||
return sortedBy { map[it.id.toString()] }
|
||||
} else {
|
||||
this
|
||||
return sortedBy { contact ->
|
||||
map[contact.id.toString()]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user