@@ -5,13 +5,15 @@ import android.os.Bundle
5
5
import android.text.TextUtils
6
6
import android.view.Menu
7
7
import android.view.MenuItem
8
+ import android.view.View
8
9
import android.widget.Toast
9
10
import androidx.appcompat.app.AppCompatActivity
10
11
import androidx.appcompat.widget.SearchView
11
12
import androidx.recyclerview.widget.DefaultItemAnimator
12
13
import androidx.recyclerview.widget.ItemTouchHelper
13
14
import androidx.recyclerview.widget.LinearLayoutManager
14
15
import androidx.recyclerview.widget.RecyclerView
16
+ import com.mikepenz.fastadapter.IAdapter
15
17
import com.mikepenz.fastadapter.adapters.FastItemAdapter
16
18
import com.mikepenz.fastadapter.app.adapters.IDraggableViewHolder
17
19
import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding
@@ -28,7 +30,8 @@ import com.mikepenz.iconics.utils.colorInt
28
30
import io.reactivex.functions.Consumer
29
31
import java.util.*
30
32
31
- class SwipeDrawerListActivity : AppCompatActivity (), ItemTouchCallback, SimpleSwipeDrawerCallback.ItemSwipeCallback {
33
+ class SwipeDrawerListActivity : AppCompatActivity (), ItemTouchCallback,
34
+ SimpleSwipeDrawerCallback .ItemSwipeCallback {
32
35
private lateinit var binding: ActivitySampleBinding
33
36
34
37
// save our FastAdapter
@@ -78,9 +81,20 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
78
81
// create our FastAdapter which will manage everything
79
82
fastItemDrawerAdapter = FastItemAdapter ()
80
83
// configure the itemAdapter
81
- fastItemDrawerAdapter.itemFilter.filterPredicate = { item: SwipeableDrawerItem , constraint: CharSequence? ->
82
- item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true )
83
- }
84
+ fastItemDrawerAdapter.itemFilter.filterPredicate =
85
+ { item: SwipeableDrawerItem , constraint: CharSequence? ->
86
+ item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true )
87
+ }
88
+
89
+
90
+ // Item click listener
91
+ fastItemDrawerAdapter.onClickListener =
92
+ { _: View ? , _: IAdapter <SwipeableDrawerItem >, _: SwipeableDrawerItem , pos: Int ->
93
+ run {
94
+ println (" click! $pos " )
95
+ true
96
+ }
97
+ }
84
98
85
99
// get our recyclerView and do basic setup
86
100
binding.rv.layoutManager = LinearLayoutManager (this )
@@ -110,16 +124,18 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
110
124
// add drag and drop for item
111
125
// and add swipe as well
112
126
touchCallback = SimpleSwipeDrawerDragCallback (
113
- this ,
114
- ItemTouchHelper .LEFT ,
115
- this )
116
- .withNotifyAllDrops(true )
117
- .withSwipeLeft(80 ) // Width of delete button
118
- .withSwipeRight(160 ) // Width of archive and share buttons
119
- .withSensitivity(10f )
120
- .withSurfaceThreshold(0.3f )
121
-
122
- touchHelper = ItemTouchHelper (touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
127
+ this ,
128
+ ItemTouchHelper .LEFT ,
129
+ this
130
+ )
131
+ .withNotifyAllDrops(true )
132
+ .withSwipeLeft(80 ) // Width of delete button
133
+ .withSwipeRight(160 ) // Width of archive and share buttons
134
+ .withSensitivity(10f )
135
+ .withSurfaceThreshold(0.3f )
136
+
137
+ touchHelper =
138
+ ItemTouchHelper (touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
123
139
touchHelper.attachToRecyclerView(binding.rv) // Attach ItemTouchHelper to RecyclerView
124
140
125
141
// restore selections (this has to be done after the items were added)
@@ -155,7 +171,10 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
155
171
inflater.inflate(R .menu.search, menu)
156
172
157
173
// search icon
158
- menu.findItem(R .id.search).icon = IconicsDrawable (this , MaterialDesignIconic .Icon .gmi_search).apply { colorInt = Color .BLACK ; actionBar() }
174
+ menu.findItem(R .id.search).icon =
175
+ IconicsDrawable (this , MaterialDesignIconic .Icon .gmi_search).apply {
176
+ colorInt = Color .BLACK ; actionBar()
177
+ }
159
178
160
179
val searchView = menu.findItem(R .id.search).actionView as SearchView
161
180
searchView.setOnQueryTextListener(object : SearchView .OnQueryTextListener {
@@ -177,7 +196,11 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
177
196
}
178
197
179
198
override fun itemTouchOnMove (oldPosition : Int , newPosition : Int ): Boolean {
180
- DragDropUtil .onMove(fastItemDrawerAdapter.itemAdapter, oldPosition, newPosition) // change position
199
+ DragDropUtil .onMove(
200
+ fastItemDrawerAdapter.itemAdapter,
201
+ oldPosition,
202
+ newPosition
203
+ ) // change position
181
204
return true
182
205
}
183
206
@@ -196,7 +219,34 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
196
219
}
197
220
198
221
companion object {
199
- private val ALPHABET = arrayOf(" A" , " B" , " C" , " D" , " E" , " F" , " G" , " H" , " I" , " J" , " K" , " L" , " M" , " N" , " O" , " P" , " Q" , " R" , " S" , " T" , " U" , " V" , " W" , " X" , " Y" , " Z" )
222
+ private val ALPHABET = arrayOf(
223
+ " A" ,
224
+ " B" ,
225
+ " C" ,
226
+ " D" ,
227
+ " E" ,
228
+ " F" ,
229
+ " G" ,
230
+ " H" ,
231
+ " I" ,
232
+ " J" ,
233
+ " K" ,
234
+ " L" ,
235
+ " M" ,
236
+ " N" ,
237
+ " O" ,
238
+ " P" ,
239
+ " Q" ,
240
+ " R" ,
241
+ " S" ,
242
+ " T" ,
243
+ " U" ,
244
+ " V" ,
245
+ " W" ,
246
+ " X" ,
247
+ " Y" ,
248
+ " Z"
249
+ )
200
250
}
201
251
202
252
override fun itemSwiped (position : Int , direction : Int ) {
0 commit comments