package biz growapp base utils import android util Log import android

 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
62
63
64
65
package biz.growapp.base.utils
import android.util.Log
import android.util.SparseBooleanArray
import ru.rambler.libs.swipe_layout.SwipeLayout
/*
* This manager need for correct showing item in 2 state: opened and closed
* */
class SwipeLayoutManager(val expandedItemOffset: Int) {
companion object {
private val TAG = SwipeLayoutManager::class.java.simpleName
}
private val expandedItemsArray: SparseBooleanArray
init {
expandedItemsArray = SparseBooleanArray()
}
fun bindSwipeLayout(swipeLayout: SwipeLayout, item: Any) {
swipeLayout.setOnSwipeListener(object: SwipeLayout.OnSwipeListener {
override fun onRightStickyEdge(swipeLayout: SwipeLayout?, moveToRight: Boolean) {
Log.d(TAG, "onRightStickyEdge:: moveToRight = $moveToRight")
}
override fun onBeginSwipe(swipeLayout: SwipeLayout?, moveToRight: Boolean) {
if ((swipeLayout?.offset ?: 0) < 0) {
Log.d(TAG, "onBeginSwipe:: moveToRight = $moveToRight")
Log.d(TAG, "onBeginSwipe:: set item ${item.hashCode()} to false")
expandedItemsArray.put(item.hashCode(), false)
}
}
override fun onLeftStickyEdge(swipeLayout: SwipeLayout?, moveToRight: Boolean) {
Log.d(TAG, "onLeftStickyEdge:: moveToRight = $moveToRight")
}
override fun onSwipeClampReached(swipeLayout: SwipeLayout?, moveToRight: Boolean) {
Log.d(TAG, "onSwipeClampReached:: moveToRight = $moveToRight")
if (!moveToRight) {
Log.d(TAG, "onSwipeClampReached:: set item ${item.hashCode()} to true")
expandedItemsArray.put(item.hashCode(), true)
}
}
})
val isExpanded = expandedItemsArray.get(item.hashCode(), false)
if (swipeLayout.offset < 0 && !isExpanded) {
Log.d(TAG, "reset item ${item.hashCode()}")
swipeLayout.reset()
} else if (isExpanded) {
Log.d(TAG, "expand item ${item.hashCode()}")
swipeLayout.offset = expandedItemOffset * (-1)
}
}
fun remove(item: Any) {
expandedItemsArray.put(item.hashCode(), false)
}
}