blob: 612c14e5352866a7118da364db3d48448777be90 (
plain)
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
|
package net.lacolaco.smileessence.view.adapter
import android.widget.BaseAdapter
import net.lacolaco.smileessence.util.UIHandler
import java.util.*
abstract class CustomListAdapter<out T> : BaseAdapter() {
private var isNotifiable = true
private var frozenList: List<T> = ArrayList()
fun setNotifiable(notifiable: Boolean) {
isNotifiable = notifiable
}
override fun getCount(): Int {
return frozenList.size
}
override fun getItem(position: Int): T {
return frozenList[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun notifyDataSetChanged() {
frozenList = Collections.unmodifiableList(list)
super.notifyDataSetChanged()
}
protected abstract val list: List<T>
fun update() {
if (isNotifiable) {
updateForce()
}
}
fun updateForce() {
UIHandler().post { this.notifyDataSetChanged() }
}
}
|