-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathDragAndDropHandleItemActivity.kt
61 lines (50 loc) · 2.12 KB
/
DragAndDropHandleItemActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package smartrecycleradapter.feature
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.ItemTouchHelper
import kotlinx.android.synthetic.main.activity_simple_item.recyclerView
import smartadapter.SmartRecyclerAdapter
import smartadapter.viewevent.dragdrop.AutoDragAndDropBinder
import smartadapter.viewevent.listener.OnClickEventListener
import smartadapter.viewevent.listener.OnLongClickEventListener
import smartadapter.viewholder.DraggableViewHolder
import smartadapter.viewholder.SmartViewHolder
import smartrecycleradapter.R
import smartrecycleradapter.utils.showToast
/*
* Created by Manne Öhlund on 2019-08-11.
* Copyright (c) All rights reserved.
*/
class DragAndDropHandleItemActivity : BaseSampleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.title = "Drag & Drop handle"
val items = (0..50).toMutableList()
SmartRecyclerAdapter
.items(items)
.map(Integer::class, SimpleDragHandleItemViewHolder::class)
.add(OnClickEventListener {
showToast("onClick ${it.position}")
})
.add(OnLongClickEventListener {
showToast("onLongClick ${it.position}")
})
.add(AutoDragAndDropBinder(ItemTouchHelper.UP or ItemTouchHelper.DOWN) {
supportActionBar?.subtitle =
"onItemMoved from ${it.viewHolder.adapterPosition} to ${it.targetViewHolder.adapterPosition}"
})
.into<SmartRecyclerAdapter>(recyclerView)
}
class SimpleDragHandleItemViewHolder(parentView: ViewGroup) :
SmartViewHolder<Int>(parentView, R.layout.simple_drag_handle_item),
DraggableViewHolder {
private var textView: TextView = itemView.findViewById(R.id.textView)
private val dragHandle: View = itemView.findViewById(R.id.dragHandle)
override var draggableView = dragHandle
override fun bind(item: Int) {
textView.text = "Item $item"
}
}
}