### Initiating Drag with a Specific UI Element Source: https://github.com/liangjingkanji/brv/blob/master/docs/drag.md To avoid gesture conflicts, it's recommended to start drag operations from a specific UI element like a button. This example demonstrates how to use setOnTouchListener on a button to initiate drag when the user presses down on it. ```kotlin rv.linear().setup { addType(R.layout.item_drag) onCreate { findView(R.id.btnDrag).setOnTouchListener { _, event -> if (event.action == MotionEvent.ACTION_DOWN) { // 如果手指按下则开始拖拽 itemTouchHelper?.startDrag(this) } true } } }.models = getData() ``` -------------------------------- ### Setup RecyclerView with BRV Source: https://github.com/liangjingkanji/brv/blob/master/docs/state.md Configure your RecyclerView using the BRV library, defining item types and providing data. ```kotlin rv.linear().setup { addType(R.layout.item_simple) }.models = getData() ``` -------------------------------- ### onBind Data Binding Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md Use the onBind function to fill data directly within the setup block. This is suitable for simple data binding scenarios. ```kotlin rv.linear().setup { addType(R.layout.item_simple) onBind { findView(R.id.tv_simple).text = getModel().name } }.models = getData() ``` -------------------------------- ### Setting up RecyclerView and Initial Refresh Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Configure your RecyclerView with a linear layout and setup item types. Trigger an initial auto-refresh on the PageRefreshLayout. ```kotlin rv.linear().setup { addType(R.layout.item_simple) } page.onRefresh { postDelayed({ // 模拟网络请求2秒后成功, 创建假的数据集 val data = getData() addData(data) { index < total // 判断是否有更多页 } }, 2000) }.autoRefresh() ``` -------------------------------- ### Sample Data for Interface Type Example Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md This is sample data used to demonstrate how interface types are handled in BRV. It includes different concrete implementations of a base interface. ```kotlin private fun getData(): List { return List(3) { InterfaceModel1("item $it") } + List(3) { InterfaceModel2(it, "item ${3 + it}") } + List(3) { InterfaceModel3("item ${6 + it}") } } ``` -------------------------------- ### Setup Grid Layout Manager Source: https://github.com/liangjingkanji/brv/blob/master/docs/extension.md Use the `grid()` extension to create a GridLayoutManager for your RecyclerView. Specify the number of columns (e.g., 3) for a grid layout. ```kotlin rv.grid(3).setup { addType(R.layout.item_simple) }.models = getData() ``` -------------------------------- ### startVisible Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Controls the visibility of the start divider. For VERTICAL orientation, this controls the top divider. For HORIZONTAL orientation, this controls the left divider. For GRID orientation, it controls the leftmost dividers. ```APIDOC ## startVisible ### Description Controls the visibility of the start divider. For VERTICAL orientation, this controls the top divider. For HORIZONTAL orientation, this controls the left divider. For GRID orientation, it controls the leftmost dividers. ### Properties * **startVisible** (Boolean) - True to show the start divider, false otherwise. Defaults to false. ``` -------------------------------- ### Setup Linear Layout Manager Source: https://github.com/liangjingkanji/brv/blob/master/docs/extension.md Use the `linear()` extension to quickly set up a LinearLayoutManager for your RecyclerView. This is useful for creating standard vertical or horizontal lists. ```kotlin rv.linear().setup { addType(R.layout.item_simple) }.models = getData() ``` -------------------------------- ### Setting Custom Pagination Start Index Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Modify the default starting index for pagination. By default, the index starts at 0, but this can be changed to 1 or any other value by setting PageRefreshLayout.startIndex. ```kotlin PageRefreshLayout.startIndex = 1 // startIndex即index变量的初始值 ``` -------------------------------- ### Setup RecyclerView with Divider Source: https://github.com/liangjingkanji/brv/blob/master/docs/extension.md Use the `divider()` extension to quickly add a DefaultDecoration to your RecyclerView. This allows for easy customization of item dividers. ```kotlin rv.linear().divider(R.drawable.divider_horizontal).setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### Get ViewBinding Object in RecyclerView Setup Source: https://github.com/liangjingkanji/brv/blob/master/docs/view-binding.md Obtain the ViewBinding object within the `onBind` scope of a RecyclerView setup. Ensure correct type casting to avoid crashes. ```kotlin rv.linear().setup { addType(R.layout.item_simple) onBind { val binding = getBinding() } }.models = getData() ``` -------------------------------- ### Setup Staggered Layout Manager Source: https://github.com/liangjingkanji/brv/blob/master/docs/extension.md Use the `staggered()` extension to create a StaggeredLayoutManager for your RecyclerView. This is suitable for creating staggered or masonry-style layouts. ```kotlin rv.staggered(3).setup { addType(R.layout.item_simple) }.models = getData() ``` -------------------------------- ### Custom Alpha Item Animation Example Source: https://github.com/liangjingkanji/brv/blob/master/docs/animation.md An example of a custom item animation that applies a fade-in effect. The `AlphaItemAnimation` class animates the view's alpha property from a specified starting value to 1f over 300 milliseconds. ```kotlin class AlphaItemAnimation @JvmOverloads constructor(private val mFrom: Float = DEFAULT_ALPHA_FROM) : ItemAnimation { override fun onItemEnterAnimation(view: View) { ObjectAnimator.ofFloat(view, "alpha", mFrom, 1f).setDuration(300).start() // 渐变动画 } companion object { private val DEFAULT_ALPHA_FROM = 0f // 初始透明度 } } ``` -------------------------------- ### setMargin Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Sets the margin for the item decorations. This can be used to define spacing on the start, end, top, or bottom edges, depending on the orientation. ```APIDOC ## setMargin ### Description Sets the margin for the item decorations. This can be used to define spacing on the start, end, top, or bottom edges, depending on the orientation. ### Parameters * **start** (Int) - The margin for the start side (default is 0). * **end** (Int) - The margin for the end side (default is the same as start). * **dp** (Boolean) - If true, the margin values are treated as density-independent pixels (dp). Defaults to false. * **baseItemStart** (Boolean) - If true, applies the start margin to the first item in the list. Defaults to false. * **baseItemEnd** (Boolean) - If true, applies the end margin to the last item in the list. Defaults to false. ``` -------------------------------- ### Implementing ItemDrag for Drag Functionality Source: https://github.com/liangjingkanji/brv/blob/master/docs/drag.md To enable drag and drop, your data model class must implement the ItemDrag interface. This example shows a basic data model with a default drag orientation. ```kotlin data class DragModel(override var itemOrientationDrag: Int = ItemOrientation.ALL) : ItemDrag ``` -------------------------------- ### Set Divider Spacing with Item Baseline Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Configures divider spacing relative to the item's baseline. `setMargin` with `baseItemStart = true` applies spacing from the item's start edge. ```kotlin binding.rv.grid(3, orientation = RecyclerView.VERTICAL).divider { orientation = DividerOrientation.GRID setDivider(1, true) setMargin(16, 16, dp = true, baseItemStart = true) setColor(Color.WHITE) }.setup { addType(R.layout.item_divider_vertical) }.models = getData() ``` -------------------------------- ### Customizing ItemTouchHelper Callback Source: https://github.com/liangjingkanji/brv/blob/master/docs/drag.md You can customize the drag and drop behavior by extending DefaultItemTouchCallback or implementing ItemTouchHelper.Callback directly. This example shows how to override the onDrag method to perform actions after a drag operation is completed. ```kotlin rv.linear().setup { addType(R.layout.item) itemTouchHelper = ItemTouchHelper(object : DefaultItemTouchCallback(this) { /** * 当拖拽动作完成且松开手指时触发 */ open fun onDrag( source: BindingAdapter.BindingViewHolder, target: BindingAdapter.BindingViewHolder ) { // 这是拖拽交换后回调, 这里可以同步服务器 } }) }.models = data ``` -------------------------------- ### Add Interface Type to BRV Setup Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md When adding an interface type with `addType`, BRV recognizes its subclasses. If the generic type is an abstract or regular class, use `addInterfaceType()` instead to ensure subclasses are recognized. ```kotlin binding.rv.linear().setup { addType(R.layout.item_interface_type) }.models = getData() ``` -------------------------------- ### Single Instance Debounce Click Interval Source: https://github.com/liangjingkanji/brv/blob/master/docs/click.md Overrides the global debounce click interval for a specific RecyclerView instance. This allows for customized debounce timing per adapter setup. ```kotlin binding.rv.linear().setup { debounceClickInterval = 1000 // 覆盖全局设置 addType(R.layout.item_simple) R.id.item.onClick { toast("点击文本") } }.models = getData() ``` -------------------------------- ### Initialize StateLayout Configuration Source: https://github.com/liangjingkanji/brv/blob/master/docs/state.md Configure the default layouts for empty, error, and loading states globally in your Application class. ```kotlin StateConfig.apply { emptyLayout = R.layout.layout_empty errorLayout = R.layout.layout_error loadingLayout = R.layout.layout_loading } ``` -------------------------------- ### Enable and Configure Up Fetching Programmatically Source: https://github.com/liangjingkanji/brv/blob/master/docs/upfetch.md Enable up-fetching for a RecyclerView and define the data loading logic. This snippet shows how to set up the RecyclerView, enable up-fetching, and handle the refresh event to load more data. ```kotlin rv.setup { addType(R.layout.item_simple) } page.upFetchEnabled = true page.onRefresh { // 模拟网络请求2秒后成功 postDelayed({ val data = getData() addData(data) { index <= 2 } }, 1000) }.showLoading() // 加载中(缺省页) ``` -------------------------------- ### Add JitPack Repository to Project Settings Source: https://github.com/liangjingkanji/brv/blob/master/README_EN.md Configure your project's settings.gradle file to include the JitPack repository for dependency resolution. ```kotlin dependencyResolutionManagement { repositories { // ... maven { url 'https://jitpack.io' } } } ``` -------------------------------- ### Configuring Default Page Layouts in Code Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Set the loading, empty, and error layouts programmatically for a specific PageRefreshLayout instance. This overrides global configurations. ```kotlin page.run { loadingLayout = R.layout.layout_loading emptyLayout = R.layout.layout_empty errorLayout = R.layout.layout_error } ``` -------------------------------- ### Configuring Default Page Layouts in XML Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Declare specific layouts for error, empty, and loading states directly within the PageRefreshLayout XML declaration using app attributes. ```xml ``` -------------------------------- ### Configuring Default Page Layouts Globally Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Globally configure the layouts for empty, error, and loading states within your Application class. This sets the default appearance for all StateLayout instances. ```kotlin // 在Application中 StateConfig.apply { emptyLayout = R.layout.layout_empty errorLayout = R.layout.layout_error loadingLayout = R.layout.layout_loading } ``` -------------------------------- ### Enable DataBinding in Gradle Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md To use DataBinding, you must enable it in your module's build.gradle file and apply the kotlin-kapt plugin. ```groovy apply plugin: "kotlin-kapt" // 必要 android { /.* buildFeatures.dataBinding = true } ``` -------------------------------- ### Configure Top/Bottom Edge Divider in Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Enables the display of top and bottom edge dividers in a grid layout. The `startVisible` parameter controls the visibility of these edge dividers. ```kotlin rv.grid(3).divider { setDrawable(R.drawable.divider_horizontal) orientation = DividerOrientation.GRID startVisible = true }.setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### SmartRefreshLayout Animation Dependencies Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh-animation.md Include these dependencies in your Gradle file to use various built-in refresh header and footer animations provided by SmartRefreshLayout. ```groovy implementation 'io.github.scwang90:refresh-header-classics:2.0.5' //经典刷新头 implementation 'io.github.scwang90:refresh-header-radar:2.0.5' //雷达刷新头 implementation 'io.github.scwang90:refresh-header-falsify:2.0.5' //虚拟刷新头 implementation 'io.github.scwang90:refresh-header-material:2.0.5' //谷歌刷新头 implementation 'io.github.scwang90:refresh-header-two-level:2.0.5' //二级刷新头 implementation 'io.github.scwang90:refresh-footer-ball:2.0.5' //球脉冲加载 implementation 'io.github.scwang90:refresh-footer-classics:2.0.5' //经典加载 ``` -------------------------------- ### smoothScrollToPosition Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-linear-layout-manager/index.html Initiates a smooth scroll to the specified adapter position. ```APIDOC ## smoothScrollToPosition ### Description Initiates a smooth scroll to the specified adapter position. ### Method open fun ### Parameters - **recyclerView** (RecyclerView) - The RecyclerView to scroll. - **state** (RecyclerView.State) - The current RecyclerView state. - **position** (Int) - The adapter position to scroll to. ``` -------------------------------- ### ViewBinding Integration Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md This snippet demonstrates how to use ViewBinding within the onBind lambda to access views. It supports both ViewBinding and DataBinding. ```kotlin rv.linear().setup { addType(R.layout.item_simple) onBind { val binding = getBinding() // ViewBinding/DataBinding都支持 val data = holder.getModel() } }.models = getData() ``` -------------------------------- ### Configure Up Fetching via XML Attributes Source: https://github.com/liangjingkanji/brv/blob/master/docs/upfetch.md Configure up-fetching and RecyclerView layout properties using XML attributes. This approach is useful for setting up the initial state of the up-fetching feature directly in the layout file. ```xml ``` -------------------------------- ### OnMultiStateListener Methods Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.listener/-on-multi-state-listener/index.html This section outlines the various callback methods provided by the OnMultiStateListener interface for managing refresh and load more states. ```APIDOC ## OnMultiStateListener open class OnMultiStateListener : OnMultiListener ### Description Interface for handling multi-state refresh and load more operations. ### Methods #### onFooterFinish ```kotlin open override fun onFooterFinish(footer: RefreshFooter?, success: Boolean) ``` Callback when the footer refresh operation finishes. #### onFooterMoving ```kotlin open override fun onFooterMoving(footer: RefreshFooter?, isDragging: Boolean, percent: Float, offset: Int, footerHeight: Int, maxDragHeight: Int) ``` Callback when the footer is being dragged. #### onFooterReleased ```kotlin open override fun onFooterReleased(footer: RefreshFooter?, footerHeight: Int, maxDragHeight: Int) ``` Callback when the user releases the footer drag. #### onFooterStartAnimator ```kotlin open override fun onFooterStartAnimator(footer: RefreshFooter?, footerHeight: Int, maxDragHeight: Int) ``` Callback when the footer animation starts. #### onHeaderFinish ```kotlin open override fun onHeaderFinish(header: RefreshHeader?, success: Boolean) ``` Callback when the header refresh operation finishes. #### onHeaderMoving ```kotlin open override fun onHeaderMoving(header: RefreshHeader?, isDragging: Boolean, percent: Float, offset: Int, headerHeight: Int, maxDragHeight: Int) ``` Callback when the header is being dragged. #### onHeaderReleased ```kotlin open override fun onHeaderReleased(header: RefreshHeader?, headerHeight: Int, maxDragHeight: Int) ``` Callback when the user releases the header drag. #### onHeaderStartAnimator ```kotlin open override fun onHeaderStartAnimator(header: RefreshHeader?, headerHeight: Int, maxDragHeight: Int) ``` Callback when the header animation starts. #### onLoadMore ```kotlin open override fun onLoadMore(refreshLayout: RefreshLayout) ``` Callback when the load more operation is triggered. #### onRefresh ```kotlin open override fun onRefresh(refreshLayout: RefreshLayout) ``` Callback when the refresh operation is triggered. #### onStateChanged ```kotlin open override fun onStateChanged(refreshLayout: RefreshLayout, oldState: RefreshState, newState: RefreshState) ``` Callback when the refresh state changes. ``` -------------------------------- ### Add Net Dependency Source: https://github.com/liangjingkanji/brv/blob/master/docs/net.md Add the Net framework dependency to your project's build.gradle file. It is recommended to use a specific version instead of '+'. ```groovy dependencies { implementation 'com.github.liangjingkanji:Net:+' } ``` -------------------------------- ### Configure All Edge Dividers in Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Enables the display of all surrounding edge dividers (top, bottom, left, right) in a grid layout. Both `startVisible` and `endVisible` are set to true. ```kotlin rv.grid(3).divider { setDrawable(R.drawable.divider_horizontal) orientation = DividerOrientation.GRID startVisible = true endVisible = true }.setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### Create StateLayout View in XML Source: https://github.com/liangjingkanji/brv/blob/master/docs/state.md Define the StateLayout container in your XML layout, wrapping the RecyclerView or other content it will manage. ```xml ``` -------------------------------- ### Triggering Refresh Actions Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Use autoRefresh, showLoading, refresh, or refreshing functions to manually trigger refresh states. Each function provides a different visual feedback or behavior. ```kotlin autoRefresh() // 显示下拉刷新动画 showLoading() // 显示加载中缺省页, 得先设置`loadingLayout` refresh() // 静默刷新, 无动画 refreshing() // 初次调用等于`showLoading`, 当加载成功后, 再次调用等于`refresh` ``` -------------------------------- ### Automatic Pagination with addData Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Utilize the addData function within the onRefresh scope to handle automatic pagination. The provided lambda determines if more pages are available based on adapter item count and total count. ```kotlin pageLayout.onRefresh { scope { val data = Get("/path").await() addData(data.list){ // 该回调返回一个布尔值判断是否有更多页, 决定上拉加载是否关闭 adapter.itemCount < data.count } } } ``` -------------------------------- ### Set Custom Item Animation Source: https://github.com/liangjingkanji/brv/blob/master/docs/animation.md Implement custom animations by creating a class that extends `ItemAnimation` and passing an instance to the `setAnimation` function. This allows for unique visual effects during item entry. ```kotlin fun setAnimation(itemAnimation: ItemAnimation) ``` -------------------------------- ### Nested Grid with Spacing and Dividers Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Demonstrates creating a nested grid layout where the inner RecyclerView has custom dividers and spacing. This is useful for complex list structures. ```kotlin binding.rv.linear().setup { onCreate { if (itemViewType == R.layout.item_simple_list) { // 构建嵌套网格列表 findView(R.id.rv).divider { // 构建间距 setDivider(20) includeVisible = true orientation = DividerOrientation.GRID }.grid(2).setup { addType(R.layout.item_group_none_margin) } } } onBind { if (itemViewType == R.layout.item_simple_list) { // 为嵌套的网格列表赋值数据 findView(R.id.rv).models = getModel().getItemSublist() } } addType(R.layout.item_simple_list) addType(R.layout.item_hover_header) }.models = getData() ``` -------------------------------- ### Listening for Refresh and Load More Events Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Implement listeners for onRefresh (pull-to-refresh) and onLoadMore (scroll-to-load) events. These are typically used for network requests. ```kotlin // 下拉刷新 page.onRefresh { // 这里可以进行网络请求等异步操作 } // 上拉加载 page.onLoadMore { // 这里可以进行网络请求等异步操作 } ``` -------------------------------- ### typePool Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html A list of item view types for which dividers should be displayed. If null, dividers are shown for all item types. ```APIDOC ## typePool ### Description A list of item view types for which dividers should be displayed. If null, dividers are shown for all item types. ### Properties * **typePool** (MutableList?) - A nullable list of integers representing the view types that should have dividers. ``` -------------------------------- ### Automatic Data Binding Initialization Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md Initialize BRV with the modelId in your Application class to enable automatic data binding between your models and layout variables. ```kotlin BRV.modelId = BR.m ``` -------------------------------- ### Control StateLayout Visibility Source: https://github.com/liangjingkanji/brv/blob/master/docs/state.md Manually trigger the display of different states (loading, content, error, empty) on your StateLayout instance. ```kotlin state.showLoading() // 加载中 state.showContent() // 加载成功 state.showError() // 加载错误 state.showEmpty() // 加载失败 ``` -------------------------------- ### Single ID Click Event Source: https://github.com/liangjingkanji/brv/blob/master/docs/click.md Sets up a specific click or long-click listener for a single ID. This provides a more concise syntax for one-to-one event handling. ```kotlin rv.linear().setup { addType(R.layout.item_simple) R.id.tv_simple.onClick { toast("点击Text") } R.id.item.onLongClick { toast("点击Item") } }.models = getData() ``` -------------------------------- ### onFocusSearchFailed Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Handles focus search failures within the layout manager. ```APIDOC ## onFocusSearchFailed ### Description Handles focus search failures within the layout manager. ### Method open fun onFocusSearchFailed(focused: View, focusDirection: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): View ``` -------------------------------- ### Set Divider Spacing and Color in Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Configures the spacing and color for dividers in a grid layout. `setDivider` sets the size, `setMargin` defines the padding, and `setColor` sets the divider color. ```kotlin binding.rv.grid(3, orientation = RecyclerView.VERTICAL).divider { orientation = DividerOrientation.GRID setDivider(1, true) setMargin(16, 16, dp = true) setColor(Color.WHITE) }.setup { addType(R.layout.item_divider_vertical) }.models = getData() ``` -------------------------------- ### Multiple IDs Click Event Source: https://github.com/liangjingkanji/brv/blob/master/docs/click.md Handles click events for multiple specified IDs with a single callback. Useful when several views share the same business logic. ```kotlin rv.linear().setup { addType(R.layout.item_simple) onClick(R.id.item, R.id.btn_confirm) { // 此处it即指定的id // Item设置点击事件, 就是给Item的根布局设置一个id, 这里设置的是R.id.item } onLongClick(R.id.item) { } }.models = getData() ``` -------------------------------- ### Differentiate Types by getModel() Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md This snippet demonstrates how to differentiate item data models using `getModel()`. It allows you to cast the model to its specific type and then perform type-specific operations, such as updating model properties and notifying changes. ```kotlin when (val model = getModel()) { is ChatModel -> { model.input = "消息内容" model.notifyChange() } is CommentModel -> { model.input = "评论内容" model.notifyChange() } } ``` -------------------------------- ### DataBinding Layout Declaration Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md Declare a variable within your item's layout file using the tag. This variable will be used for data binding. ```xml ``` -------------------------------- ### Implement ItemBind for Data Binding Source: https://github.com/liangjingkanji/brv/blob/master/docs/item.md Implement the ItemBind interface to listen for onBindViewHolder events and bind data to your views within the Model itself. This is useful for custom data binding logic. ```kotlin data class SimpleModel(var name: String = "BRV") : ItemBind { override fun onBind(holder: BindingAdapter.BindingViewHolder) { // 在Model内可以为视图绑定数据 } } ``` -------------------------------- ### Differentiate Types by getBindingOrNull() Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md This approach uses `getBindingOrNull()` to safely access and manipulate bindings for different item types. It's a robust way to handle type-specific UI updates without risking NullPointerExceptions. ```kotlin getBindingOrNull()?.run { tvSimple.text = layoutPosition.toString() } getBindingOrNull()?.run { tvContent.text = layoutPosition.toString() } ``` -------------------------------- ### onSaveInstanceState Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Saves the current state of the layout manager to a Parcelable. ```APIDOC ## onSaveInstanceState ### Description Saves the current state of the layout manager to a Parcelable. ### Method open fun onSaveInstanceState(): Parcelable? ``` -------------------------------- ### Add BRV Dependency to Module Build Gradle Source: https://github.com/liangjingkanji/brv/blob/master/README_EN.md Include the BRV library as a dependency in your module's build.gradle file. ```groovy dependencies { implementation 'com.github.liangjingkanji:BRV:1.6.1' } ``` -------------------------------- ### Add Item Types Based on Data Field (One-to-Many) Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md Use this when all data models are of the same type, but you need to display them using different item layouts based on a field within the data model. The `when` statement inside `addType` allows conditional layout selection. ```kotlin rv.linear().setup { addType{ // 使用年龄来作为判断返回不同的布局 when (age) { 23 -> { R.layout.item_1 } else -> { R.layout.item_2 } } } }.models = data ``` -------------------------------- ### RecyclerView.grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.utils/grid.html Extension function to create a HoverGridLayoutManager for RecyclerViews, enabling grid-like layouts. It allows customization of span count, orientation, reverse layout, and scroll enabled properties. ```APIDOC ## RecyclerView.grid ### Description Extension function to create a HoverGridLayoutManager for RecyclerViews, enabling grid-like layouts. It allows customization of span count, orientation, reverse layout, and scroll enabled properties. ### Method Extension Function ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **spanCount** (Int) - The number of spans in the grid. - **orientation** (Int) - The orientation of the list (e.g., VERTICAL). - **reverseLayout** (Boolean) - Whether to reverse the layout. - **scrollEnabled** (Boolean) - Whether scrolling is enabled. ``` -------------------------------- ### Add Multiple Item Types (Many-to-Many) Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md Use this when each data model in your list corresponds to a unique item view type. Simply call `addType()` for each model-layout pair. ```kotlin rv.linear().setup { addType(R.layout.item_1) addType(R.layout.item_2) }.models = data ``` -------------------------------- ### Differentiate Types by itemViewType Source: https://github.com/liangjingkanji/brv/blob/master/docs/multi-type.md This snippet shows how to differentiate item views based on their `itemViewType`. It's useful when you have distinct layouts for different data types and need to apply specific logic or UI updates. ```kotlin when(itemViewType) { R.layout.item_simple -> { getBinding().tvName.text = "文本内容" } R.layout.item_simple_2 -> { getBinding().tvName.text = "类型2-文本内容" } } ``` -------------------------------- ### Disable Pull-Up Load Animation (XML Configuration) Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh-animation.md Configure pull-up load animation disabling by setting `srlFooterHeight` to "0dp" in the XML layout. This applies to a specific instance of PageRefreshLayout. ```xml ``` -------------------------------- ### includeVisible Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html A convenience property to show dividers on all four sides of the list. Equivalent to setting both `startVisible` and `endVisible` to true. ```APIDOC ## includeVisible ### Description A convenience property to show dividers on all four sides of the list. Equivalent to setting both `startVisible` and `endVisible` to true. ### Properties * **includeVisible** (Boolean) - True to show dividers on all sides, false otherwise. ``` -------------------------------- ### Configure Left/Right Edge Divider in Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Enables the display of left and right edge dividers in a grid layout. The `endVisible` parameter controls the visibility of these edge dividers. ```kotlin rv.grid(3).divider { setDrawable(R.drawable.divider_horizontal) orientation = DividerOrientation.GRID endVisible = true }.setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### Disable Pull-Up Load Animation (Global Configuration) Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh-animation.md Globally configure SmartRefreshLayout to disable pull-up load animations by setting footer height to 0 and visibility to GONE. This does not affect preloading functionality. ```kotlin SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout -> layout.setFooterHeight(0F) val classicsFooter = ClassicsFooter(context) classicsFooter.visibility = View.GONE classicsFooter } ``` -------------------------------- ### scrollToPosition Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Scrolls to a specific item position. ```APIDOC ## scrollToPosition ### Description Scrolls to a specific item position. ### Method open fun scrollToPosition(position: Int) ``` -------------------------------- ### Update SmartRefreshLayout Dependency Source: https://github.com/liangjingkanji/brv/blob/master/docs/updates.md Update the SmartRefreshLayout dependencies to version 2.0.5. Ensure any associated refresh headers are also updated to the latest mavenCentral() version. ```groovy api 'io.github.scwang90:refresh-layout-kernel:2.0.5' api 'io.github.scwang90:refresh-header-material:2.0.5' api 'io.github.scwang90:refresh-footer-classics:2.0.5' ``` -------------------------------- ### onRefresh Function Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-page-refresh-layout/on-refresh.html Sets a callback for pull-to-refresh. If onLoadMore is not set, this function will also handle pull-up loading. Triggering can occur in three ways. ```APIDOC ## onRefresh ### Description Sets a callback for pull-to-refresh. If onLoadMore is not set, this function will also handle pull-up loading. Triggering can occur in three ways. ### Signature ```kotlin fun onRefresh(block: PageRefreshLayout.() -> Unit): PageRefreshLayout ``` ### Parameters * `block` (PageRefreshLayout.() -> Unit) - The callback function to execute when a refresh is triggered. ``` -------------------------------- ### Add Grid Divider with Custom Drawable Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Applies a grid divider using a custom drawable. The orientation is set to GRID, allowing for flexible divider placement within the grid structure. ```kotlin rv.grid(3).divider { setDrawable(R.drawable.divider_horizontal) orientation = DividerOrientation.GRID }.setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### setColor(color: Int) Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/set-color.html Sets the divider color using an integer color resource. If the divider width is not set using setDivider, the default width is 1px. The divider width refers to the thickness of the divider, not its horizontal length. ```APIDOC ## setColor(color: Int) ### Description Sets the divider color using an integer color resource. If the divider width is not set using `setDivider`, the default width is 1px. The divider width refers to the thickness of the divider, not its horizontal length. ### Parameters #### Path Parameters - **color** (Int) - Description: The color to set for the divider, specified as an integer. ### Method fun setColor(color: Int) ``` -------------------------------- ### onRestoreInstanceState Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Restores the layout manager's state from a Parcelable. ```APIDOC ## onRestoreInstanceState ### Description Restores the layout manager's state from a Parcelable. ### Method open fun onRestoreInstanceState(state: Parcelable?) ``` -------------------------------- ### ItemBind Interface for Data Binding Source: https://github.com/liangjingkanji/brv/blob/master/docs/index.md Implement the ItemBind interface in your model class for data binding. This approach is useful for complex data structures when avoiding two-way data binding. ```kotlin class SimpleModel(var name: String = "BRV") : ItemBind { override fun onBind(holder: BindingAdapter.BindingViewHolder) { holder.findView(R.id.tv_simple).text = holder.layoutPosition.toString() } } ``` -------------------------------- ### setHoverTranslationX Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-linear-layout-manager/index.html Offsets the horizontal location of the hover header relative to its default position. ```APIDOC ## setHoverTranslationX ### Description Offsets the horizontal location of the hover header relative to the its default position. ### Method open fun ### Parameters - **translationX** (Float) - The horizontal offset value. ``` -------------------------------- ### setColor(color: String) Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/set-color.html Sets the divider color using a hexadecimal color string. If the divider width is not set using setDivider, the default width is 1px. The divider width refers to the thickness of the divider, not its horizontal length. ```APIDOC ## setColor(color: String) ### Description Sets the divider color using a hexadecimal color string. If the divider width is not set using `setDivider`, the default width is 1px. The divider width refers to the thickness of the divider, not its horizontal length. ### Parameters #### Path Parameters - **color** (String) - Description: The color to set for the divider, specified as a hexadecimal string. ### Method fun setColor(color: String) ``` -------------------------------- ### setHoverTranslationY Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-linear-layout-manager/index.html Offsets the vertical location of the hover header relative to its default position. ```APIDOC ## setHoverTranslationY ### Description Offsets the vertical location of the hover header relative to the its default position. ### Method open fun ### Parameters - **translationY** (Float) - The vertical offset value. ``` -------------------------------- ### scrollToPositionWithOffset Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Scrolls to a specific item position with a given offset. ```APIDOC ## scrollToPositionWithOffset ### Description Scrolls to a specific item position with a given offset. ### Method open fun scrollToPositionWithOffset(position: Int, offset: Int) ``` -------------------------------- ### isHover Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Checks if a given view is the current hover header. ```APIDOC ## isHover ### Description Returns true if `view` is the current hover header. ### Method open fun isHover(view: View): Boolean ``` -------------------------------- ### computeVerticalScrollOffset Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Computes the vertical scroll offset of the layout manager. ```APIDOC ## computeVerticalScrollOffset ### Description Computes the vertical scroll offset of the layout manager. ### Method open fun computeVerticalScrollOffset(state: RecyclerView.State): Int ``` -------------------------------- ### onLayoutChildren Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Layouts the children of the RecyclerView. ```APIDOC ## onLayoutChildren ### Description Layouts the children of the RecyclerView. ### Method open fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) ``` -------------------------------- ### scrollVerticallyBy Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Scrolls the layout vertically by a specified amount. ```APIDOC ## scrollVerticallyBy ### Description Scrolls the layout vertically by a specified amount. ### Method open fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int ``` -------------------------------- ### Add Horizontal Divider to Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Configures a horizontal divider for a grid layout. Use this when you need a visual separator between items in a grid that are arranged horizontally. ```kotlin rv.grid(3).divider(R.drawable.divider_horizontal).setup { addType(R.layout.item_divider_horizontal) }.models = getData() ``` -------------------------------- ### onRefresh Override Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-page-refresh-layout/on-refresh.html The overridden onRefresh method from the RefreshLayout interface, used for handling refresh events. ```APIDOC ## onRefresh Override ### Description This is an override of the onRefresh method from the RefreshLayout interface, used internally to handle refresh events. ### Signature ```kotlin open override fun onRefresh(refreshLayout: RefreshLayout) ``` ### Parameters * `refreshLayout` (RefreshLayout) - The RefreshLayout instance triggering the event. ``` -------------------------------- ### Set Built-in Animation Type Source: https://github.com/liangjingkanji/brv/blob/master/docs/animation.md Use the `setAnimation` function with the `AnimationType` enum to apply predefined animations. Supported types include ALPHA, SCALE, SLIDE_BOTTOM, SLIDE_LEFT, and SLIDE_RIGHT. ```kotlin fun setAnimation(animationType: AnimationType) ``` -------------------------------- ### scrollToPosition Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-linear-layout-manager/index.html Scrolls the RecyclerView to the specified adapter position. ```APIDOC ## scrollToPosition ### Description Scrolls the RecyclerView to the specified adapter position. ### Method open fun ### Parameters - **position** (Int) - The adapter position to scroll to. ``` -------------------------------- ### Global Debounce Click Interval Source: https://github.com/liangjingkanji/brv/blob/master/docs/click.md Sets the global interval for debounce click functionality across all RecyclerView instances. The default is 500 milliseconds. ```kotlin BRV.debounceClickInterval = 1000 // 单位毫秒 ``` -------------------------------- ### orientation Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Sets the orientation of the dividers. This is primarily relevant for `GridLayoutManager`. For other layout managers, the orientation is automatically adjusted. ```APIDOC ## orientation ### Description Sets the orientation of the dividers. This is primarily relevant for `GridLayoutManager`. For other layout managers, the orientation is automatically adjusted. ### Properties * **orientation** (DividerOrientation) - The orientation of the dividers (e.g., VERTICAL, HORIZONTAL, GRID). ``` -------------------------------- ### scrollToPositionWithOffset Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-linear-layout-manager/index.html Scrolls the RecyclerView to the specified adapter position with a given offset. ```APIDOC ## scrollToPositionWithOffset ### Description Scrolls the RecyclerView to the specified adapter position with a given offset. ### Method open fun ### Parameters - **position** (Int) - The adapter position to scroll to. - **offset** (Int) - The offset in pixels from the start of the item. ``` -------------------------------- ### computeVerticalScrollRange Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Computes the total vertical scroll range of the layout manager. ```APIDOC ## computeVerticalScrollRange ### Description Computes the total vertical scroll range of the layout manager. ### Method open fun computeVerticalScrollRange(state: RecyclerView.State): Int ``` -------------------------------- ### XML Layout Declaration for PageRefreshLayout Source: https://github.com/liangjingkanji/brv/blob/master/docs/refresh.md Declare PageRefreshLayout in your XML layout, including the RecyclerView as its child. Configure attributes like stateEnabled and context. ```xml ``` -------------------------------- ### scrollHorizontallyBy Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Scrolls the layout horizontally by a specified amount. ```APIDOC ## scrollHorizontallyBy ### Description Scrolls the layout horizontally by a specified amount. ### Method open fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int ``` -------------------------------- ### onAdapterChanged Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Called when the RecyclerView's adapter is changed. ```APIDOC ## onAdapterChanged ### Description Called when the RecyclerView's adapter is changed. ### Method open fun onAdapterChanged(oldAdapter: RecyclerView.Adapter<*>, newAdapter: RecyclerView.Adapter<*>) ``` -------------------------------- ### Add Vertical Divider to Grid Source: https://github.com/liangjingkanji/brv/blob/master/docs/divider-grid.md Configures a vertical divider for a grid layout, specifying the orientation. This is useful for separating items in a grid that are arranged vertically. ```kotlin rv.grid(3, RecyclerView.HORIZONTAL) .divider(R.drawable.divider_vertical, DividerOrientation.VERTICAL) .setup { addType(R.layout.item_divider_vertical) }.models = getData() ``` -------------------------------- ### Shared Debounce Click Enabled Source: https://github.com/liangjingkanji/brv/blob/master/docs/click.md Enables shared debounce interval for all view click events within an item. By default, BRV's debounce applies only to individual views. ```kotlin // 启用item所有view点击事件共享防抖动间隔, BRV默认防抖动仅针对单个view BRV.debounceGlobalEnabled = true ``` -------------------------------- ### onAttachedToWindow Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv.layoutmanager/-hover-grid-layout-manager/index.html Called when the layout manager is attached to the RecyclerView's window. ```APIDOC ## onAttachedToWindow ### Description Called when the layout manager is attached to the RecyclerView's window. ### Method open fun onAttachedToWindow(view: RecyclerView) ``` -------------------------------- ### endVisible Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Controls the visibility of the end divider. For VERTICAL orientation, this controls the bottom divider. For HORIZONTAL orientation, this controls the right divider. For GRID orientation, it controls the rightmost dividers. ```APIDOC ## endVisible ### Description Controls the visibility of the end divider. For VERTICAL orientation, this controls the bottom divider. For HORIZONTAL orientation, this controls the right divider. For GRID orientation, it controls the rightmost dividers. ### Properties * **endVisible** (Boolean) - True to show the end divider, false otherwise. Defaults to false. ``` -------------------------------- ### setDrawable Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Sets a drawable resource to be used as a divider. The dimensions of the drawable will determine the dimensions of the divider. ```APIDOC ## setDrawable ### Description Sets a drawable resource to be used as a divider. The dimensions of the drawable will determine the dimensions of the divider. ### Parameters * **drawableRes** (Int) - The resource ID of the drawable to use as a divider. ``` -------------------------------- ### expandVisible Source: https://github.com/liangjingkanji/brv/blob/master/docs/api/-b-r-v/com.drake.brv/-default-decoration/index.html Determines if a divider should be shown for expanded group items. This property is ignored if `onEnabled` is configured. ```APIDOC ## expandVisible ### Description Determines if a divider should be shown for expanded group items. This property is ignored if `onEnabled` is configured. ### Properties * **expandVisible** (Boolean) - True to show dividers for expanded group items, false otherwise. Defaults to false. ``` -------------------------------- ### Configuring Drag Directions with ItemOrientation Source: https://github.com/liangjingkanji/brv/blob/master/docs/drag.md The ItemOrientation enum class defines the possible directions for drag and drop operations. These include ALL, VERTICAL, HORIZONTAL, specific directions like LEFT, RIGHT, UP, DOWN, or NONE to disable dragging. ```kotlin enum class ItemOrientation { ALL, VERTICAL, HORIZONTAL, LEFT, RIGHT, UP, DOWN, NONE } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.