forked from github/szkolny
[Home] Disable pull to refresh while swiping a card.
This commit is contained in:
parent
35f4a31a76
commit
85fe2636cc
@ -5,6 +5,7 @@
|
|||||||
package pl.szczodrzynski.edziennik.ui.modules.home
|
package pl.szczodrzynski.edziennik.ui.modules.home
|
||||||
|
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper.*
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.Companion.removeCard
|
import pl.szczodrzynski.edziennik.ui.modules.home.HomeFragment.Companion.removeCard
|
||||||
@ -14,8 +15,8 @@ import pl.szczodrzynski.edziennik.utils.SwipeRefreshLayoutNoIndicator
|
|||||||
class CardItemTouchHelperCallback(private val cardAdapter: HomeCardAdapter, private val refreshLayout: SwipeRefreshLayoutNoIndicator?) : ItemTouchHelper.Callback() {
|
class CardItemTouchHelperCallback(private val cardAdapter: HomeCardAdapter, private val refreshLayout: SwipeRefreshLayoutNoIndicator?) : ItemTouchHelper.Callback() {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "CardItemTouchHelperCallback"
|
private const val TAG = "CardItemTouchHelperCallback"
|
||||||
private const val DRAG_FLAGS = ItemTouchHelper.UP or ItemTouchHelper.DOWN
|
private const val DRAG_FLAGS = UP or DOWN
|
||||||
private const val SWIPE_FLAGS = ItemTouchHelper.RIGHT
|
private const val SWIPE_FLAGS = RIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
private var dragCardView: MaterialCardView? = null
|
private var dragCardView: MaterialCardView? = null
|
||||||
@ -40,11 +41,12 @@ class CardItemTouchHelperCallback(private val cardAdapter: HomeCardAdapter, priv
|
|||||||
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
|
||||||
super.onSelectedChanged(viewHolder, actionState)
|
super.onSelectedChanged(viewHolder, actionState)
|
||||||
|
|
||||||
if (actionState == ItemTouchHelper.ACTION_STATE_DRAG && viewHolder != null) {
|
if (viewHolder != null && (actionState == ACTION_STATE_DRAG || actionState == ACTION_STATE_SWIPE)) {
|
||||||
dragCardView = viewHolder.itemView as MaterialCardView
|
dragCardView = viewHolder.itemView as MaterialCardView
|
||||||
dragCardView?.isDragged = true
|
dragCardView?.isDragged = true
|
||||||
refreshLayout?.isEnabled = false
|
refreshLayout?.isEnabled = false
|
||||||
} else if (actionState == ItemTouchHelper.ACTION_STATE_IDLE && dragCardView != null) {
|
}
|
||||||
|
else if (actionState == ACTION_STATE_IDLE && dragCardView != null) {
|
||||||
refreshLayout?.isEnabled = true
|
refreshLayout?.isEnabled = true
|
||||||
dragCardView?.isDragged = false
|
dragCardView?.isDragged = false
|
||||||
dragCardView = null
|
dragCardView = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user