Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
Better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Jun 26, 2024
1 parent 128de54 commit 26f5cde
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ internal interface IMutableRvAdapter<M : IVhModelType> : IRvAdapter<M> {
get() = super.list
set(value) {
_list.clear()
_list.addAll(transform(value))
_list.addAll(flat(value))
}

override fun refreshItems(items: List<M>) {
transform(items).forEach {
flat(items).forEach {
if (it in _list) {
adapter.notifyItemChanged(_list.indexOf(it))
}
Expand All @@ -199,22 +199,16 @@ internal interface IMutableRvAdapter<M : IVhModelType> : IRvAdapter<M> {
}
}

/**
* Transform data list. Always return a new list.
*/
private fun transform(original: List<M>): List<M> {
private fun flat(original: List<M>): List<M> {
val result = mutableListOf<M>()
original.forEach { findLeaf(it, result) }
return result
}

/**
* Recursively traversing all leaf nodes.
*/
@Suppress("UNCHECKED_CAST")
private fun findLeaf(model: M, list: MutableList<M>) {
if (model is IVhModelWrapper<*>) {
if (model.viewType != -1) list += model
@Suppress("UNCHECKED_CAST")
model.subList.forEach { findLeaf(it as M, list) }
} else {
list += model
Expand Down

0 comments on commit 26f5cde

Please sign in to comment.