BindingAdapter

open class BindingAdapter : RecyclerView.Adapter<BindingAdapter.BindingViewHolder>

< Android上最强大的RecyclerView框架 >

  1. 一行代码添加多类型 addType

  2. 数据模型可以为任何对象 models

  3. 通过接口实现来扩展功能 com.drake.brv.item

  4. 快速添加触摸事件(防抖点击/快速点击/长按/选择/侧滑/拖拽)

  5. 强大的分组/展开/折叠/粘性头部/递归深度/动画/组position expandOrCollapse

  6. 自定义列表动画 setAnimation 默认动画 com.drake.brv.animation

  7. 头布局/脚布局 addHeader

  8. 快速设置分隔物

  9. 缺省页 PageRefreshLayout

  10. 下拉刷新/上拉加载/自动分页加载 PageRefreshLayout

  11. 强大的选择状态 setChecked (切换模式/多选/单选/全选/取消全选/反选/选中数据集/选中数量/单选和多选模式切换)

  12. 遵守高内聚低耦合原则, 支持功能配合使用, 代码简洁函数分组

Constructors

BindingAdapter
Link copied to clipboard
fun BindingAdapter()

Types

BindingViewHolder
Link copied to clipboard
inner class BindingViewHolder : RecyclerView.ViewHolder
Companion
Link copied to clipboard
object Companion

Functions

addFooter
Link copied to clipboard
fun addFooter(model: Any?, @IntRange(from = -1.toLong()index: Int = -1, animation: Boolean = false)
添加脚布局
addHeader
Link copied to clipboard
fun addHeader(model: Any?, @IntRange(from = -1.toLong()index: Int = -1, animation: Boolean = false)
添加头布局
addInterfaceType
Link copied to clipboard
inline fun <M> addInterfaceType(noinline block: Any.(Int) -> Int)
接口类型, 即类型必须为接口, 同时其子类都会被认为属于该接口而对应其布局
addModels
Link copied to clipboard
fun addModels(models: List<Any?>?, animation: Boolean = true, @IntRange(from = -1.toLong()index: Int = -1)
添加新的数据
addType
Link copied to clipboard
inline fun <M> addType(noinline block: M.(position: Int) -> Int)
通过回调函数添加多类型, 一对多多类型(即一个数据类对应多个布局) block中的position为当前item位于列表中的索引, M则为rv的models中对应的数据类型如果泛型为接口类型则自动等效于addInterfaceType
inline fun <M> addType(@LayoutRes() layout: Int)
添加多类型 BRV中一个Item类型对应一个Class布局Id, 而M即为对应该类型所需的数据类型.
checkedAll
Link copied to clipboard
fun checkedAll(checked: Boolean = true)
单选模式下不支持全选, 但支持取消全部选择
checkedReverse
Link copied to clipboard
fun checkedReverse()
反选
checkedSwitch
Link copied to clipboard
fun checkedSwitch(@IntRange(from = 0.toLong()position: Int)
切换选中
clearFooter
Link copied to clipboard
fun clearFooter(animation: Boolean = false)
清除全部脚布局
clearHeader
Link copied to clipboard
fun clearHeader(animation: Boolean = false)
collapse
Link copied to clipboard
fun collapse(@IntRange(from = 0.toLong()position: Int, @IntRange(from = -1.toLong()depth: Int = 0): Int
折叠
expand
Link copied to clipboard
fun expand(@IntRange(from = 0.toLong()position: Int, scrollTop: Boolean = false, @IntRange(from = -1.toLong()depth: Int = 0): Int
展开
expandOrCollapse
Link copied to clipboard
fun expandOrCollapse(@IntRange(from = 0.toLong()position: Int, scrollTop: Boolean = false, @IntRange(from = -1.toLong()depth: Int = 0): Int
展开或折叠
getCheckedModels
Link copied to clipboard
fun <M> getCheckedModels(): List<M>
返回被选中的条目对应的数据模型集合
getItemCount
Link copied to clipboard
open override fun getItemCount(): Int
getItemId
Link copied to clipboard
open override fun getItemId(position: Int): Long
getItemViewType
Link copied to clipboard
open override fun getItemViewType(position: Int): Int
getModel
Link copied to clipboard
fun <M> getModel(@IntRange(from = 0.toLong()position: Int): M
根据索引返回数据模型, 不存在该模型则抛出异常
getModelOrNull
Link copied to clipboard
inline fun <M> getModelOrNull(position: Int): M?
根据索引返回数据模型, 如果不存在该模型则返回Null
isCheckedAll
Link copied to clipboard
fun isCheckedAll(): Boolean
是否全选
isFooter
Link copied to clipboard
fun isFooter(@IntRange(from = 0.toLong()position: Int): Boolean
指定position是否为脚布局
isHeader
Link copied to clipboard
fun isHeader(@IntRange(from = 0.toLong()position: Int): Boolean
指定position是否为头布局
isHover
Link copied to clipboard
fun isHover(position: Int): Boolean
通过position判断是否启用悬停
isModel
Link copied to clipboard
fun isModel(@IntRange(from = 0.toLong()position: Int): Boolean
指定position是否为models
isSameGroup
Link copied to clipboard
fun isSameGroup(@IntRange(from = 0.toLong()position: Int, @IntRange(from = 0.toLong()otherPosition: Int): Boolean
判断两个位置的item是否属于同一分组下, 要求这两个位置的item都展开才有效 如果其中一个item都属于根节点则返回-1, 这种情况不算属于同一分组下
onAttachedToRecyclerView
Link copied to clipboard
open override fun onAttachedToRecyclerView(recyclerView: RecyclerView)
onBind
Link copied to clipboard
fun onBind(block: BindingAdapter.BindingViewHolder.() -> Unit)
onBindViewHolder执行时回调
onBindViewHolder
Link copied to clipboard
open override fun onBindViewHolder(holder: BindingAdapter.BindingViewHolder, position: Int)
open override fun onBindViewHolder(holder: BindingAdapter.BindingViewHolder, position: Int, payloads: MutableList<Any>)
onChecked
Link copied to clipboard
fun onChecked(block: (position: Int, checked: Boolean, allChecked: Boolean) -> Unit)
条目选中事件回调
onClick
Link copied to clipboard
fun Int.onClick(listener: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
添加点击事件, 点击启用防抖动
fun onClick(@IdRes() vararg id: Int, block: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
监听指定Id控件的点击事件, 包含防抖动
onCreate
Link copied to clipboard
fun onCreate(block: BindingAdapter.BindingViewHolder.(viewType: Int) -> Unit)
onCreateViewHolder执行时回调
onCreateViewHolder
Link copied to clipboard
open override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BindingAdapter.BindingViewHolder
onExpand
Link copied to clipboard
fun onExpand(block: BindingAdapter.BindingViewHolder.(Boolean) -> Unit)
监听展开分组
onFastClick
Link copied to clipboard
fun Int.onFastClick(listener: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
添加点击事件
fun onFastClick(@IdRes() vararg id: Int, block: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
监听指定Id控件的点击事件
onLongClick
Link copied to clipboard
fun Int.onLongClick(listener: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
添加长按事件
fun onLongClick(@IdRes() vararg id: Int, block: BindingAdapter.BindingViewHolder.(viewId: Int) -> Unit)
长按点击事件回调
onPayload
Link copied to clipboard
fun onPayload(block: BindingAdapter.BindingViewHolder.(payloads: MutableList<Any>) -> Unit)
增量更新回调 当你使用notifyItemChanged(int, Object)或者notifyItemRangeChanged(int, Object)等方法更新列表时才会触发, 并且形参payload要求不能为null
onToggle
Link copied to clipboard
fun onToggle(block: (position: Int, toggleMode: Boolean, end: Boolean) -> Unit)
切换模式事件回调
onViewAttachedToWindow
Link copied to clipboard
open override fun onViewAttachedToWindow(holder: BindingAdapter.BindingViewHolder)
onViewDetachedFromWindow
Link copied to clipboard
open override fun onViewDetachedFromWindow(holder: BindingAdapter.BindingViewHolder)
removeFooter
Link copied to clipboard
fun removeFooter(model: Any?, animation: Boolean = false)
通过数据模型删除脚布局
removeFooterAt
Link copied to clipboard
fun removeFooterAt(@IntRange(from = -1.toLong()index: Int = -1, animation: Boolean = false)
通过索引删除脚布局
removeHeader
Link copied to clipboard
fun removeHeader(model: Any?, animation: Boolean = false)
通过数据删除头布局
removeHeaderAt
Link copied to clipboard
fun removeHeaderAt(@IntRange(from = 0.toLong()index: Int = 0, animation: Boolean = false)
通过索引删除头布局
setAnimation
Link copied to clipboard
fun setAnimation(itemAnimation: ItemAnimation)
自定义条目的动画样式
fun setAnimation(animationType: AnimationType)
设置当前库自带的条目的动画样式
setCheckableType
Link copied to clipboard
fun setCheckableType(@LayoutRes() vararg checkableItemType: Int)
设置可以被选择的item类型
setChecked
Link copied to clipboard
fun setChecked(@IntRange(from = 0.toLong()position: Int, checked: Boolean)
设置选中
setDifferModels
Link copied to clipboard
fun setDifferModels(newModels: List<Any?>?, detectMoves: Boolean = true, commitCallback: Runnable? = null)
对比数据, 根据数据差异自动刷新列表 数据对比默认使用equals函数对比, 你可以为数据手动实现equals函数来修改对比逻辑.
toggle
Link copied to clipboard
fun toggle()
切换模式, 切换模式为遍历每个item
fun toggle(toggleMode: Boolean)
设置切换模式, 切换模式为遍历每个item
toModelPosition
Link copied to clipboard
fun Int.toModelPosition(): Int
对应models中的index

Properties

_data
Link copied to clipboard
var _data: MutableList<Any?>? = null
原始的数据集合对象, 不会经过任何处理
animationEnabled
Link copied to clipboard
var animationEnabled: Boolean = false
是否启用条目动画
animationRepeat
Link copied to clipboard
var animationRepeat: Boolean = false
是否重复显示列表动画, 默认item只显示一次动画
checkedCount
Link copied to clipboard
val checkedCount: Int
已选择条目数量
checkedPosition
Link copied to clipboard
val checkedPosition: <ERROR CLASS>
已选择条目的position
clickThrottle
Link copied to clipboard
var clickThrottle: Long
防抖动点击事件的间隔时间, 单位毫秒
expandAnimationEnabled
Link copied to clipboard
var expandAnimationEnabled: Boolean = true
分组展开和折叠是否启用动画
footerCount
Link copied to clipboard
val footerCount: Int
脚布局数量
footers
Link copied to clipboard
var footers: List<Any?>
全部脚布局数据集合
headerCount
Link copied to clipboard
val headerCount: Int
头布局数量
headers
Link copied to clipboard
var headers: List<Any?>
头布局的数据模型
hoverEnabled
Link copied to clipboard
var hoverEnabled: Boolean = true
是否启用条目悬停
interfacePool
Link copied to clipboard
val interfacePool: <ERROR CLASS>
itemDifferCallback
Link copied to clipboard
var itemDifferCallback: ItemDifferCallback
对比新旧数据更改列表接口
itemTouchHelper
Link copied to clipboard
var itemTouchHelper: ItemTouchHelper?
自定义ItemTouchHelper即可设置该属性 等效于RecyclerView.addItemDecoration设置
modelCount
Link copied to clipboard
val modelCount: Int
数据模型数量(不包含头布局和脚布局)
modelId
Link copied to clipboard
var modelId: Int
单独配置modelId, 会忽略BRV.modelId
models
Link copied to clipboard
var models: List<Any?>?
数据模型集合 如果赋值的是List不可变集合将会自动复制为MutableList, 将无法保持为同一个集合对象引用
mutable
Link copied to clipboard
var mutable: MutableList<Any?>
可增删的数据模型集合, 如果models为null则将为列表默认赋值为空集合
onBindViewHolders
Link copied to clipboard
var onBindViewHolders: <ERROR CLASS>
onBindViewHolder触发监听器集合
onHoverAttachListener
Link copied to clipboard
var onHoverAttachListener: OnHoverAttachListener? = null
监听开始悬停
rv
Link copied to clipboard
var rv: RecyclerView? = null
当前Adapter被setAdapter才不为null
singleExpandMode
Link copied to clipboard
var singleExpandMode: Boolean = false
只允许一个条目展开(展开当前条目就会折叠上个条目)
singleMode
Link copied to clipboard
var singleMode: Boolean = false
全局单选模式
toggleMode
Link copied to clipboard
var toggleMode: Boolean = false
是否开启切换模式
typePool
Link copied to clipboard
val typePool: <ERROR CLASS>
类型池