allow reordering favorites by drag and drop

This commit is contained in:
Pavel Poley
2022-05-05 18:03:58 +03:00
parent 307ce40e19
commit f807961768
6 changed files with 60 additions and 6 deletions

View File

@ -124,7 +124,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
val filtered = when {
this is GroupsFragment -> contacts
this is FavoritesFragment -> contacts.filter { it.starred == 1 } as ArrayList<Contact>
this is FavoritesFragment -> {
val favorites = contacts.filter { it.starred == 1 } as ArrayList<Contact>
if (activity!!.config.sorting == SORT_BY_CUSTOM) {
sortByCustomOrder(favorites)
} else {
favorites
}
}
else -> {
val contactSources = activity!!.getVisibleContactSources()
contacts.filter { contactSources.contains(it.source) } as ArrayList<Contact>
@ -152,6 +160,14 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
private fun sortByCustomOrder(starred: List<Contact>): ArrayList<Contact> {
val favoritesOrder = activity!!.config.favoritesContactsOrder
val orderList = Converters().jsonToStringList(favoritesOrder)
val map = orderList.withIndex().associate { it.value to it.index }
val sorted = starred.sortedBy { map[it.id.toString()] }
return ArrayList(sorted)
}
private fun setupContacts(contacts: ArrayList<Contact>) {
if (this is GroupsFragment) {
setupGroupsAdapter(contacts) {