allow reordering favorites by drag and drop
This commit is contained in:
parent
716c527e0f
commit
145d781ecb
|
@ -54,7 +54,7 @@ class ContactsAdapter(
|
|||
highlightText: String = "",
|
||||
private val enableDrag: Boolean = false,
|
||||
itemClick: (Any) -> Unit
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate, ItemTouchHelperContract {
|
||||
) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), RecyclerViewFastScroller.OnPopupTextUpdate, ItemTouchHelperContract {
|
||||
private val NEW_GROUP_ID = -1
|
||||
|
||||
private var config = activity.config
|
||||
|
@ -426,17 +426,23 @@ class ContactsAdapter(
|
|||
}
|
||||
}
|
||||
|
||||
if (enableDrag) {
|
||||
findViewById<ImageView>(R.id.drag_handle_icon).apply {
|
||||
val dragIcon = findViewById<ImageView>(R.id.drag_handle_icon)
|
||||
if (enableDrag && textToHighlight.isEmpty()) {
|
||||
dragIcon.apply {
|
||||
beVisibleIf(selectedKeys.isNotEmpty())
|
||||
applyColorFilter(textColor)
|
||||
setOnTouchListener { v, event ->
|
||||
setOnTouchListener { _, event ->
|
||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
startReorderDragListener?.requestDrag(holder)
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dragIcon.apply {
|
||||
beGone()
|
||||
setOnTouchListener(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,9 +163,15 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
|
||||
private fun sortByCustomOrder(starred: List<Contact>): ArrayList<Contact> {
|
||||
val favoritesOrder = activity!!.config.favoritesContactsOrder
|
||||
|
||||
if (favoritesOrder.isEmpty()) {
|
||||
return ArrayList(starred)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -252,9 +258,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
|
|||
onDragEndListener = {
|
||||
val adapter = fragment_list?.adapter
|
||||
if (adapter is ContactsAdapter) {
|
||||
saveCustomOrderToPrefs(adapter.contactItems)
|
||||
val items = adapter.contactItems
|
||||
saveCustomOrderToPrefs(items)
|
||||
setupLetterFastscroller(items)
|
||||
}
|
||||
refreshContacts(contacts)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue