-
Notifications
You must be signed in to change notification settings - Fork 51
/
StickyHeaderActivity.kt
47 lines (39 loc) · 1.61 KB
/
StickyHeaderActivity.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
package smartrecycleradapter.feature
/*
* Created by Manne Öhlund on 2020-10-10.
* Copyright (c) All rights reserved.
*/
import android.graphics.Color
import android.os.Bundle
import android.view.MotionEvent
import kotlinx.android.synthetic.main.activity_simple_item.recyclerView
import smartadapter.SmartRecyclerAdapter
import smartadapter.stickyheader.StickyHeaderItemDecorationExtension
import smartrecycleradapter.feature.simpleitem.SimpleHeaderViewHolder
import smartrecycleradapter.feature.simpleitem.SimpleItemViewHolder
import smartrecycleradapter.utils.showToast
class StickyHeaderActivity : BaseSampleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportActionBar?.title = "Sticky header"
val items = (0..200).toMutableList().toIntArray().mapIndexed { index, item ->
when {
index % 5 == 0 -> arrayOf(item.toString(), item)
else -> arrayOf(item)
}
}.toTypedArray().flatten()
SmartRecyclerAdapter
.items(items)
.map(String::class, SimpleHeaderViewHolder::class)
.map(Integer::class, SimpleItemViewHolder::class)
.add(StickyHeaderItemDecorationExtension(
headerItemType = String::class
) { motionEvent, itemPosition ->
if (motionEvent.action == MotionEvent.ACTION_UP) {
showToast("Header $itemPosition clicked")
}
})
.into<SmartRecyclerAdapter>(recyclerView)
SimpleHeaderViewHolder.color = Color.DKGRAY
}
}