package net.lacolaco.smileessence.view.adapter import android.widget.BaseAdapter import net.lacolaco.smileessence.util.UIHandler import java.util.* abstract class CustomListAdapter : BaseAdapter() { private var isNotifiable = true private var frozenList: List = 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 fun update() { if (isNotifiable) { updateForce() } } fun updateForce() { UIHandler().post { this.notifyDataSetChanged() } } }