Comments (4)
数据本身添加个字段, 然后去用集合迭代赋值就好了, 耦合低扩展性好
示例代码
rv.models = list.forEach {
it.depth = 0
it.itemSublist.forEach {
it.depth = 1
it.itemSublist.forEach {
it.depth = 2
}
}
}
from brv.
提供一个item深度的 Utils
- BrvItemDepth.kt
import com.drake.brv.item.ItemExpand
interface ItemDepth {
/** 当前item在分组中的深度 */
var itemDepth: Int
}
/**
* 刷新item深度
*/
fun <T> List<T>.refreshItemDepth(depth: Int = 0): List<T> = onEach { item ->
if (item is ItemDepth) {
item.itemDepth = depth
}
if (item is ItemExpand) {
item.itemSublist?.run { refreshItemDepth(depth + 1) }
}
}
- 使用方法
/**
* 使用方法
* 在数据赋值给[BindingAdapter]前,刷新一次item深度即可
* [BindingAdapter.models] [BindingAdapter.mutable] [BindingAdapter.addModels]
*/
fun sample() {
class SampleItemDepth(override var itemDepth: Int) : ItemDepth
fun getData(): List<ItemDepth> = List(10) { SampleItemDepth(it) }
RecyclerView(TODO()).linear().setup {
// ...
}.models = getData().refreshItemDepth()
}
from brv.
感觉可以. 创建个pr吧. 另外文件名建议为: ItemDepthUtils
from brv.
修复分割线错误, 新增深度辅助计算类 #60
from brv.
Related Issues (20)
- 首页多布局快速上下滑动时会有跟不上的情况 HOT 1
- 拖拽+脚布局 闪退 HOT 6
- 使用ViewBinding 在选择模式下的问题以及复现步骤 HOT 1
- PageRefreshLayout的setnomoredata出现的底部文字不对 HOT 2
- 部分一加手机上使用grid会出现Unable to create layer for RecyclerView HOT 2
- 无法下载sources HOT 2
- Staggered布局+header+分割线,addModels 后出现的问题 HOT 1
- 关于checkedAll(false)的一些问题 HOT 3
- 在下拉刷新上拉加载的网络请求中再次滑动页面会再次网络请求
- 求助,列表滑上滑下后发现item的Textview状态会自动改变 HOT 2
- 单选模式下,onChecked不被调用 HOT 11
- 你很有趣! HOT 1
- 使用autoRefresh时,使用TabLayout+ViewPager2快速切换会导致中间的onRefresh不被调用到。 HOT 4
- 在demo的GroupDragFragment拖拽分组中,如果设置 singleExpandMode = true,会出现闪退 HOT 1
- More method to update list HOT 4
- 跨 item或者id 防抖问题 HOT 8
- 你这个LICENSE不太正经啊 HOT 2
- 编译依赖失败 HOT 10
- 疑问,结合SmartRefreshLayout HOT 1
- 预拉取功能,加载更多后回弹举例超过列表顶部的举例 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brv.