From be64727ff7f0af9403a6094939fa0700b8afd80b Mon Sep 17 00:00:00 2001 From: Kainalu Hagiwara Date: Tue, 28 Jul 2020 16:57:43 -0700 Subject: [PATCH] For #12831 - Disable SwipeRefreshLayout while swiping a bookmark. --- .../library/bookmarks/BookmarkTouchHelper.kt | 28 ++++++++++++++++--- .../fenix/library/bookmarks/BookmarkView.kt | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkTouchHelper.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkTouchHelper.kt index 69c0186ed6f7..666152e13101 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkTouchHelper.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkTouchHelper.kt @@ -10,6 +10,7 @@ import android.graphics.drawable.Drawable import androidx.appcompat.content.res.AppCompatResources import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.RecyclerView +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import mozilla.components.support.ktx.android.content.getColorFromAttr import mozilla.components.support.ktx.android.content.getDrawableWithTint import mozilla.components.support.ktx.android.util.dpToPx @@ -18,11 +19,18 @@ import org.mozilla.fenix.home.sessioncontrol.SwipeToDeleteCallback import org.mozilla.fenix.library.bookmarks.viewholders.BookmarkNodeViewHolder import org.mozilla.fenix.library.bookmarks.viewholders.BookmarkSeparatorViewHolder -class BookmarkTouchHelper(interactor: BookmarkViewInteractor) : - ItemTouchHelper(BookmarkTouchCallback(interactor)) +class BookmarkTouchHelper( + interactor: BookmarkViewInteractor, + swipeRefreshLayout: SwipeRefreshLayout +) : + ItemTouchHelper(BookmarkTouchCallback(interactor, swipeRefreshLayout)) -class BookmarkTouchCallback(private val interactor: BookmarkViewInteractor) : - ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { +class BookmarkTouchCallback( + private val interactor: BookmarkViewInteractor, + private val swipeRefreshLayout: SwipeRefreshLayout +) : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) { + + private var previousSwipeRefreshEnabledState = false override fun getSwipeDirs( recyclerView: RecyclerView, @@ -107,6 +115,18 @@ class BookmarkTouchCallback(private val interactor: BookmarkViewInteractor) : target: RecyclerView.ViewHolder ): Boolean = false + override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { + super.onSelectedChanged(viewHolder, actionState) + if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { + // We don't always have swipe to refresh enabled (ie in multi-select mode) so + // we need to store the layout's previous state + previousSwipeRefreshEnabledState = swipeRefreshLayout.isEnabled + swipeRefreshLayout.isEnabled = false + } else { + swipeRefreshLayout.isEnabled = previousSwipeRefreshEnabledState + } + } + private fun setBounds( background: Drawable, backgroundBounds: Rect, diff --git a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt index 10d91822b922..4a711d2097dc 100644 --- a/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt +++ b/app/src/main/java/org/mozilla/fenix/library/bookmarks/BookmarkView.kt @@ -126,7 +126,7 @@ class BookmarkView( interactor.onRequestSync() } - BookmarkTouchHelper(interactor).attachToRecyclerView(view.bookmark_list) + BookmarkTouchHelper(interactor, view.swipe_refresh).attachToRecyclerView(view.bookmark_list) } fun update(state: BookmarkFragmentState) {