-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ceb92cd
commit 6d0b890
Showing
6 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
app/src/main/java/io/github/saeeddev94/xray/ProfileTouchCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.github.saeeddev94.xray | ||
|
||
interface ProfileTouchCallback { | ||
fun onItemMoved(fromPosition: Int, toPosition: Int): Boolean | ||
fun onItemMoveCompleted(startPosition: Int, endPosition: Int) | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/io/github/saeeddev94/xray/ProfileTouchHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.github.saeeddev94.xray | ||
|
||
import androidx.recyclerview.widget.ItemTouchHelper | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
class ProfileTouchHelper(private var adapter: ProfileTouchCallback) : ItemTouchHelper.Callback() { | ||
|
||
private var startPosition: Int = -1 | ||
|
||
override fun getMovementFlags( | ||
recyclerView: RecyclerView, | ||
viewHolder: RecyclerView.ViewHolder | ||
): Int = makeMovementFlags(ItemTouchHelper.UP or ItemTouchHelper.DOWN, 0) | ||
|
||
override fun onMove( | ||
recyclerView: RecyclerView, | ||
source: RecyclerView.ViewHolder, | ||
target: RecyclerView.ViewHolder | ||
): Boolean = adapter.onItemMoved(source.adapterPosition, target.adapterPosition) | ||
|
||
override fun onSwiped( | ||
viewHolder: RecyclerView.ViewHolder, | ||
direction: Int | ||
) { | ||
} | ||
|
||
override fun onSelectedChanged( | ||
viewHolder: RecyclerView.ViewHolder?, | ||
actionState: Int | ||
) { | ||
if (actionState != ItemTouchHelper.ACTION_STATE_DRAG) return | ||
startPosition = viewHolder!!.adapterPosition | ||
} | ||
|
||
override fun clearView( | ||
recyclerView: RecyclerView, | ||
viewHolder: RecyclerView.ViewHolder | ||
) { | ||
val endPosition = viewHolder.adapterPosition | ||
adapter.onItemMoveCompleted(startPosition, endPosition) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters