Skip to content

Commit

Permalink
Merge pull request #948 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Nov 18, 2020
2 parents af14b47 + 098afa9 commit fbbe807
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ It's blazingly fast, minimizing the code you need to write, and is easy to exten

## Latest releases 🛠

- Kotlin | [v5.3.0](https://github.com/mikepenz/FastAdapter/tree/v5.3.0)
- Kotlin | [v5.3.1](https://github.com/mikepenz/FastAdapter/tree/v5.3.1)
- Java && AndroidX | [v3.3.1](https://github.com/mikepenz/FastAdapter/tree/v3.3.1)
- Java && AppCompat | [v3.2.9](https://github.com/mikepenz/FastAdapter/tree/v3.2.9)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
.withSwipeLeft(80) // Width of delete button
.withSwipeRight(160) // Width of archive and share buttons
.withSensitivity(10f)
.withSurfaceThreshold(0.3f)

touchHelper = ItemTouchHelper(touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
touchHelper.attachToRecyclerView(rv) // Attach ItemTouchHelper to RecyclerView
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {

ext {
release = [
versionName: "5.3.0",
versionCode: 5030
versionName: "5.3.1",
versionCode: 5031
]

setup = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SimpleSwipeDrawerCallback @JvmOverloads constructor(private val swipeDirs:

// Swipe movement control
private var sensitivityFactor = 1f
private var surfaceThreshold = 0.5f

// "Drawer width" swipe gesture is allowed to reach before blocking
private var swipeWidthLeftDp = 20
Expand Down Expand Up @@ -79,6 +80,15 @@ class SimpleSwipeDrawerCallback @JvmOverloads constructor(private val swipeDirs:
return this
}

/**
* % of the item's width or height needed to confirm the swipe action
* Android default : 0.5
*/
fun withSurfaceThreshold(f: Float): SimpleSwipeDrawerCallback {
surfaceThreshold = f
return this
}

override fun getSwipeDirs(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
val item = FastAdapter.getHolderAdapterItem<IItem<*>>(viewHolder)
return if (item is ISwipeable) {
Expand Down Expand Up @@ -109,6 +119,13 @@ class SimpleSwipeDrawerCallback @JvmOverloads constructor(private val swipeDirs:
return defaultValue * sensitivityFactor
}

override fun getSwipeThreshold(viewHolder: RecyclerView.ViewHolder): Float {
// During the "unswipe" gesture, Android doesn't use the threshold value properly
// => Need to communicate an inverted value for swiped items
return if (swipedStates.containsKey(viewHolder.adapterPosition)) 1f - surfaceThreshold
else surfaceThreshold
}

override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {
val itemView = viewHolder.itemView

Expand Down Expand Up @@ -157,10 +174,10 @@ class SimpleSwipeDrawerCallback @JvmOverloads constructor(private val swipeDirs:
if (childView != null)
when (event.actionMasked) {
MotionEvent.ACTION_DOWN -> {
childView.onTouchEvent(event)
return childView.onTouchEvent(event)
}
MotionEvent.ACTION_UP -> {
childView.onTouchEvent(event)
return childView.onTouchEvent(event)
}
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class SimpleSwipeDrawerDragCallback @JvmOverloads constructor(
return this
}

fun withSurfaceThreshold(f: Float): SimpleSwipeDrawerDragCallback {
simpleSwipeCallback.withSurfaceThreshold(f)
return this
}

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
simpleSwipeCallback.onSwiped(viewHolder, direction)
}
Expand Down

0 comments on commit fbbe807

Please sign in to comment.