allow reordering favorites by drag and drop

This commit is contained in:
Pavel Poley 2022-05-06 15:45:41 +03:00
parent b8113575cb
commit f5a760eb79
3 changed files with 23 additions and 7 deletions

View File

@ -63,7 +63,7 @@ android {
}
dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:1dfdd8d34d'
implementation 'com.github.SimpleMobileTools:Simple-Commons:34fdfce71c'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

View File

@ -22,7 +22,6 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.google.gson.Gson
import com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -55,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
@ -70,6 +69,7 @@ class ContactsAdapter(
private var touchHelper: ItemTouchHelper? = null
private var startReorderDragListener: StartReorderDragListener? = null
var onDragEndListener: (() -> Unit)? = null
init {
setupDragListener(true)
@ -462,8 +462,6 @@ class ContactsAdapter(
}
override fun onRowClear(myViewHolder: ViewHolder?) {
val orderIds = contactItems.map { it.id }
val orderGsonString = Gson().toJson(orderIds)
activity.config.favoritesContactsOrder = orderGsonString
onDragEndListener?.invoke()
}
}

View File

@ -5,6 +5,7 @@ import android.content.Intent
import android.util.AttributeSet
import android.view.ViewGroup
import androidx.coordinatorlayout.widget.CoordinatorLayout
import com.google.gson.Gson
import com.reddit.indicatorfastscroll.FastScrollItemIndicator
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.*
@ -242,11 +243,20 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
location = location,
removeListener = null,
recyclerView = fragment_list,
enableDrag = enableDragReorder
enableDrag = enableDragReorder,
) {
(activity as RefreshContactsListener).contactClicked(it as Contact)
}.apply {
fragment_list.adapter = this
if (enableDragReorder) {
onDragEndListener = {
val adapter = fragment_list?.adapter
if (adapter is ContactsAdapter) {
saveCustomOrderToPrefs(adapter.contactItems)
}
refreshContacts(contacts)
}
}
}
if (context.areSystemAnimationsEnabled) {
@ -262,6 +272,14 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
}
}
private fun saveCustomOrderToPrefs(items: ArrayList<Contact>) {
activity?.apply {
val orderIds = items.map { it.id }
val orderGsonString = Gson().toJson(orderIds)
config.favoritesContactsOrder = orderGsonString
}
}
fun showContactThumbnailsChanged(showThumbnails: Boolean) {
if (this is GroupsFragment) {
(fragment_list.adapter as? GroupsAdapter)?.apply {