Giter Site home page Giter Site logo

Comments (4)

liangjingkanji avatar liangjingkanji commented on June 12, 2024

数据本身添加个字段, 然后去用集合迭代赋值就好了, 耦合低扩展性好

示例代码

rv.models = list.forEach {
    it.depth = 0
    it.itemSublist.forEach {
        it.depth = 1
        it.itemSublist.forEach {
            it.depth = 2
        }
    }
}

from brv.

TxcA avatar TxcA commented on June 12, 2024

提供一个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.

liangjingkanji avatar liangjingkanji commented on June 12, 2024

感觉可以. 创建个pr吧. 另外文件名建议为: ItemDepthUtils

from brv.

TxcA avatar TxcA commented on June 12, 2024

修复分割线错误, 新增深度辅助计算类 #60

from brv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.