Skip to content

Commit

Permalink
For mozilla-mobile#12831 - Disable SwipeRefreshLayout while swiping a…
Browse files Browse the repository at this point in the history
… bookmark.
  • Loading branch information
person808 committed Jul 29, 2020
1 parent 6a618aa commit be64727
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit be64727

Please sign in to comment.