PageRefreshLayout

open class PageRefreshLayout : SmartRefreshLayout, OnRefreshLoadMoreListener

扩展SmartRefreshLayout的功能

功能

  1. 下拉刷新

  2. 上拉加载

  3. 拉取

  4. 预加载

  5. 预拉取

  6. 自动分页

  7. 添加数据

  8. 缺省状态页

Constructors

PageRefreshLayout
Link copied to clipboard
fun PageRefreshLayout(context: Context)
PageRefreshLayout
Link copied to clipboard
fun PageRefreshLayout(context: Context, attrs: AttributeSet?)

Types

Companion
Link copied to clipboard
object Companion

Functions

addData
Link copied to clipboard
fun addData(data: List<Any?>?, adapter: BindingAdapter? = null, isEmpty: () -> Boolean = { data.isNullOrEmpty() }, hasMore: BindingAdapter.() -> Boolean = { true })
自动分页自动加载数据, 自动判断当前属于下拉刷新还是上拉加载更多

实现

getState等于RefreshState.Refreshing或者index等于startIndex会判断为下拉刷新 index初始值为startIndex, 每次调用本方法会将index递增, 下拉刷新会将index重置为startIndex

注意事项

请勿每次给data赋值同一个集合对象, 因为为了保证rv持有数据集合为一个对象, 覆盖数据会先clear再addAll新的数据集合本方法只是简化分页列表数据赋值, 如果出现特别的需求请尝试自己更新rv数据集(即不使用本方法), 比如使用BindingAdapter.models
finish
Link copied to clipboard
fun finish(success: Boolean = true, hasMore: Boolean = true)
关闭下拉加载|上拉刷新
finishLoadMore
Link copied to clipboard
open override fun finishLoadMore(delayed: Int, success: Boolean, noMoreData: Boolean): RefreshLayout
复写函数实现以下 当下拉刷新未成功完成不显示上拉加载
finishRefresh
Link copied to clipboard
open override fun finishRefresh(delayed: Int, success: Boolean, noMoreData: Boolean?): RefreshLayout
复写函数实现以下
  1. 当不满一屏幕的时候默认不显示上拉加载更多

  2. 当下拉刷新未成功完成不显示上拉加载

onContent
Link copied to clipboard
fun onContent(block: View.(Any?) -> Unit): PageRefreshLayout
showContent时会回调该函数参数, 一般将网络请求等异步操作放入其中
onEmpty
Link copied to clipboard
fun onEmpty(block: View.(Any?) -> Unit): PageRefreshLayout
当空缺省页显示时回调
onError
Link copied to clipboard
fun onError(block: View.(Any?) -> Unit): PageRefreshLayout
当错误缺省页显示时回调
onLoading
Link copied to clipboard
fun onLoading(block: View.(Any?) -> Unit): PageRefreshLayout
当加载中缺省页显示时回调
onLoadMore
Link copied to clipboard
open override fun onLoadMore(refreshLayout: RefreshLayout)
fun onLoadMore(block: PageRefreshLayout.() -> Unit): PageRefreshLayout
上拉加载回调 如果不执行该方法, 上拉加载会自动触发onRefresh
onRefresh
Link copied to clipboard
open override fun onRefresh(refreshLayout: RefreshLayout)
fun onRefresh(block: PageRefreshLayout.() -> Unit): PageRefreshLayout
下拉刷新回调 如果不设置onLoadMore, 上拉加载也会执行此方法触发方式有以下三种:
refresh
Link copied to clipboard
fun refresh()
触发刷新 (不包含下拉动画)
refreshing
Link copied to clipboard
fun refreshing(tag: Any? = null)
初次调用等效于showLoading.
setEnableLoadMore
Link copied to clipboard
open override fun setEnableLoadMore(enabled: Boolean): RefreshLayout
setEnableRefresh
Link copied to clipboard
open override fun setEnableRefresh(enabled: Boolean): RefreshLayout
setOnMultiStateListener
Link copied to clipboard
fun setOnMultiStateListener(onMultiStateListener: OnMultiStateListener): PageRefreshLayout
监听多种状态, 不会拦截已有的刷新(onRefresh)和加载生命周期(onLoadMore)
setRetryIds
Link copied to clipboard
fun setRetryIds(@IdRes() vararg ids: Int): PageRefreshLayout
设置errorLayout中的视图点击后会执行StateLayout.showLoading 并且500ms内防重复点击
showContent
Link copied to clipboard
fun showContent(hasMore: Boolean = true, tag: Any? = null)
显示内容页
showEmpty
Link copied to clipboard
fun showEmpty(tag: Any? = null)
显示空缺省页
showError
Link copied to clipboard
fun showError(tag: Any? = null, force: Boolean = false)
加载成功以后不会再显示错误页面, 除非指定强制显示
showLoading
Link copied to clipboard
fun showLoading(tag: Any? = null, refresh: Boolean = true)
有网则显示加载中缺省页, 无网络直接显示错误缺省页
trigger
Link copied to clipboard
fun trigger(): Boolean
用于网络请求的触发器, 作用于暂停/继续缺省状态变化 开发者无需关心该函数

Properties

emptyLayout
Link copied to clipboard
var emptyLayout: Int
空页面布局
errorLayout
Link copied to clipboard
var errorLayout: Int
错误页面布局
index
Link copied to clipboard
var index: Int
分页索引
loaded
Link copied to clipboard
var loaded: Boolean = false
标记是否已加载, 已加载后将不再显示错误页面
loadingLayout
Link copied to clipboard
var loadingLayout: Int
加载中页面布局
onBindViewHolderListener
Link copied to clipboard
var onBindViewHolderListener: OnBindViewHolderListener
监听onBindViewHolder事件
preloadIndex
Link copied to clipboard
var preloadIndex: Int
指定列表位置(倒序索引)显示自动预加载
recyclerViewId
Link copied to clipboard
var recyclerViewId: Int
列表ID, 会根据ID自动赋值rv
refreshEnableWhenEmpty
Link copied to clipboard
var refreshEnableWhenEmpty: Boolean
是否显示空缺省页时启用下拉刷新
refreshEnableWhenError
Link copied to clipboard
var refreshEnableWhenError: Boolean
是否显示错误缺省页时启用下拉刷新
rv
Link copied to clipboard
var rv: RecyclerView? = null
手动指定列表, 用于获取BindingAdapter来让addData方法处理自动分页, 如果PageRefreshLayout直接嵌套RecyclerView本方法没必要调用
stateChangedHandler
Link copied to clipboard
var stateChangedHandler: StateChangedHandler
处理缺省页状态变更
stateEnabled
Link copied to clipboard
var stateEnabled: Boolean = true
启用缺省页
stateLayout
Link copied to clipboard
var stateLayout: StateLayout? = null
缺省页视图
stateLayoutId
Link copied to clipboard
var stateLayoutId: Int
缺省页ID, 默认不配置会自动创建StateLayout并且包裹PageRefreshLayout的RefreshContent
upFetchEnabled
Link copied to clipboard
var upFetchEnabled: Boolean = false
变更为下拉加载更多, 上拉刷新