From b8113575cb8b311d4efd1ce2a434833aba2df48b Mon Sep 17 00:00:00 2001 From: Pavel Poley Date: Fri, 6 May 2022 12:13:04 +0300 Subject: [PATCH] allow reordering favorites by drag and drop --- app/build.gradle | 2 +- .../contacts/pro/adapters/ContactsAdapter.kt | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8b4089a8..0abf9e7d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:b264da6cff' + implementation 'com.github.SimpleMobileTools:Simple-Commons:1dfdd8d34d' implementation 'com.googlecode.ez-vcard:ez-vcard:0.11.3' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ContactsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ContactsAdapter.kt index bdddaf79..fc2d4b0b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ContactsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/ContactsAdapter.kt @@ -8,7 +8,6 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.graphics.drawable.Icon import android.graphics.drawable.LayerDrawable -import android.util.Log import android.util.TypedValue import android.view.Menu import android.view.MotionEvent @@ -136,9 +135,13 @@ class ContactsAdapter( override fun getItemKeyPosition(key: Int) = contactItems.indexOfFirst { it.id == key } - override fun onActionModeCreated() {} + override fun onActionModeCreated() { + notifyDataSetChanged() + } - override fun onActionModeDestroyed() {} + override fun onActionModeDestroyed() { + notifyDataSetChanged() + } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(itemLayout, parent) @@ -423,15 +426,17 @@ class ContactsAdapter( } } - // TODO: if (enableDrag) { - - } - findViewById(R.id.item_contact_image).setOnTouchListener { v, event -> - if (event.action == MotionEvent.ACTION_DOWN) { - startReorderDragListener?.requestDrag(holder) + findViewById(R.id.drag_handle_icon).apply { + beVisibleIf(selectedKeys.isNotEmpty()) + applyColorFilter(textColor) + setOnTouchListener { v, event -> + if (event.action == MotionEvent.ACTION_DOWN) { + startReorderDragListener?.requestDrag(holder) + } + false + } } - false } } } @@ -439,7 +444,7 @@ class ContactsAdapter( override fun onChange(position: Int) = contactItems.getOrNull(position)?.getBubbleText() ?: "" override fun onRowMoved(fromPosition: Int, toPosition: Int) { - activity.config.sorting = SORT_BY_CUSTOM // TODO: check if i can use this constant + activity.config.sorting = SORT_BY_CUSTOM if (fromPosition < toPosition) { for (i in fromPosition until toPosition) { Collections.swap(contactItems, i, i + 1) @@ -457,12 +462,8 @@ class ContactsAdapter( } override fun onRowClear(myViewHolder: ViewHolder?) { - for (contact in contactItems) { - Log.d("test", "onRowClear: ${contact.getNameToDisplay()} ${contact.id} ${contact.contactId}") - } val orderIds = contactItems.map { it.id } val orderGsonString = Gson().toJson(orderIds) - Log.d("test", "onRowClear: $orderGsonString") activity.config.favoritesContactsOrder = orderGsonString } }