SmartAdapter

open class SmartAdapter<T>(list: MutableList<T>, bind: SmartContainer<T>?) : RecyclerView.Adapter<SmartViewHolder<T>>

RecyclerView.Adapter的继承类,可以继承重写open方法,可以使用smart满足大多数需求.

Author

Ayvytr 's GitHub

Since

0.1.0

Constructors

SmartAdapter
Link copied to clipboard
fun <T> SmartAdapter(list: MutableList<T> = mutableListOf(), bind: SmartContainer<T>? = null)

Functions

add
Link copied to clipboard
fun add(item: T, index: Int = list.size)

添加itemlistindex,默认是追加到末尾.

addAll
Link copied to clipboard
fun addAll(items: List<T>, index: Int = list.size)

添加itemslistindex位置,默认追加到末尾.

bindViewHolder
Link copied to clipboard
fun bindViewHolder(@NonNull p0: SmartViewHolder<T>, p1: Int)
clear
Link copied to clipboard
fun clear()

清空list中所有元素

click
Link copied to clipboard
fun click(onItemClickListener: (T, position: Int) -> Unit): SmartAdapter<T>
createViewHolder
Link copied to clipboard
@NonNull
fun createViewHolder(@NonNull p0: ViewGroup, p1: Int): SmartViewHolder<T>
diff
Link copied to clipboard
open fun diff(smartDiffCallback: SmartDiffCallback<T>? = SmartDiffCallback(), detectMovies: Boolean = true): SmartAdapter<T>

设置diff callback(实际使用了smartDiffCallback包装了DiffUtil.Callback).

getItemCount
Link copied to clipboard
open override fun getItemCount(): Int
getItemId
Link copied to clipboard
open fun getItemId(p0: Int): Long
getItemViewType
Link copied to clipboard
open override fun getItemViewType(position: Int): Int
hasDiff
Link copied to clipboard
fun hasDiff(): Boolean

SmartAdapter是否设置了diffCallback.

hasObservers
Link copied to clipboard
fun hasObservers(): Boolean
hasStableIds
Link copied to clipboard
fun hasStableIds(): Boolean
isEmpty
Link copied to clipboard
fun isEmpty(): Boolean

list是否为空.

longClick
Link copied to clipboard
fun longClick(onItemLongClickListener: (T, position: Int) -> Unit): SmartAdapter<T>
map
Link copied to clipboard
open fun map(smartContainer: SmartContainer<T>): SmartAdapter<T>

设置RecyclerView多类型item view的方法.

open fun map(@LayoutRes layoutId: Int, type: Int, bind: View.(T, position: Int) -> Unit): SmartAdapter<T>
notifyDataSetChanged
Link copied to clipboard
fun notifyDataSetChanged()
notifyItemChanged
Link copied to clipboard
fun notifyItemChanged(p0: Int)
fun notifyItemChanged(p0: Int, @Nullable p1: Any?)
notifyItemInserted
Link copied to clipboard
fun notifyItemInserted(p0: Int)
notifyItemMoved
Link copied to clipboard
fun notifyItemMoved(p0: Int, p1: Int)
notifyItemRangeChanged
Link copied to clipboard
fun notifyItemRangeChanged(p0: Int, p1: Int)
fun notifyItemRangeChanged(p0: Int, p1: Int, @Nullable p2: Any?)
notifyItemRangeInserted
Link copied to clipboard
fun notifyItemRangeInserted(p0: Int, p1: Int)
notifyItemRangeRemoved
Link copied to clipboard
fun notifyItemRangeRemoved(p0: Int, p1: Int)
notifyItemRemoved
Link copied to clipboard
fun notifyItemRemoved(p0: Int)
onAttachedToRecyclerView
Link copied to clipboard
open fun onAttachedToRecyclerView(@NonNull p0: RecyclerView)
onBindViewHolder
Link copied to clipboard
open override fun onBindViewHolder(holder: SmartViewHolder<T>, position: Int)
open override fun onBindViewHolder(holder: SmartViewHolder<T>, position: Int, payloads: MutableList<Any>)
onCreateViewHolder
Link copied to clipboard
open override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SmartViewHolder<T>
onDetachedFromRecyclerView
Link copied to clipboard
open fun onDetachedFromRecyclerView(@NonNull p0: RecyclerView)
onFailedToRecycleView
Link copied to clipboard
open fun onFailedToRecycleView(@NonNull p0: SmartViewHolder<T>): Boolean
onViewAttachedToWindow
Link copied to clipboard
open fun onViewAttachedToWindow(@NonNull p0: SmartViewHolder<T>)
onViewDetachedFromWindow
Link copied to clipboard
open fun onViewDetachedFromWindow(@NonNull p0: SmartViewHolder<T>)
onViewRecycled
Link copied to clipboard
open fun onViewRecycled(@NonNull p0: SmartViewHolder<T>)
registerAdapterDataObserver
Link copied to clipboard
open fun registerAdapterDataObserver(@NonNull p0: RecyclerView.AdapterDataObserver)
remove
Link copied to clipboard
fun remove(item: T): Boolean

删除list中的item.

removeAll
Link copied to clipboard
fun removeAll(items: List<T>)

删除listitems.

removeAt
Link copied to clipboard
fun removeAt(index: Int)

如果存在,删除listindex所在的item.

removeDiff
Link copied to clipboard
fun removeDiff()

移除diff callback.

setHasStableIds
Link copied to clipboard
open fun setHasStableIds(p0: Boolean)
type
Link copied to clipboard
fun type(predicate: (T, position: Int) -> Int): SmartAdapter<T>

设置 view type 获取方法.

unregisterAdapterDataObserver
Link copied to clipboard
open fun unregisterAdapterDataObserver(@NonNull p0: RecyclerView.AdapterDataObserver)
update
Link copied to clipboard
fun update(newList: List<T>, isAppend: Boolean = false, isAppendToHead: Boolean = false)

isAppend=false: 更新listnewList; isAppend=true: isAppendToHead=true:追加到list开头;isAppendToHead=false:追加到list末尾.

Properties

detectMovies
Link copied to clipboard
var detectMovies: Boolean = true
diffCallback
Link copied to clipboard
var diffCallback: DiffUtil.Callback? = null

内部真实创建的Diff Callback.

itemClickListener
Link copied to clipboard
var itemClickListener: (T, Int) -> Unit
itemLongClickListener
Link copied to clipboard
var itemLongClickListener: (T, Int) -> Unit
list
Link copied to clipboard
val list: MutableList<T>