Skip to content

Commit

Permalink
add method
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang committed Jan 2, 2020
1 parent af9a1ed commit 607c0aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chad.baserecyclerviewadapterhelper.activity.node;

import android.os.Bundle;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -39,11 +40,15 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void run() {
SecondNode seNode = new SecondNode(new ArrayList<BaseNode>(), "Second Node(This is added)");
SecondNode seNode2 = new SecondNode(new ArrayList<BaseNode>(), "Second Node(This is added)");
List<SecondNode> nodes = new ArrayList<>();
nodes.add(seNode);
nodes.add(seNode2);
//第一个夫node,位置为子node的3号位置
adapter.nodeAddData(adapter.getData().get(0), 3, seNode);
Tips.show("新增node");
adapter.nodeAddData(adapter.getData().get(0), 2, nodes);
Tips.show("新插入了两个node", Toast.LENGTH_LONG);
}
}, 3000);
}, 2000);
}

private List<BaseNode> getEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,19 @@ abstract class BaseNodeAdapter(data: MutableList<BaseNode>? = null)
}
}

fun nodeAddData(parentNode: BaseNode, childIndex: Int, newData: Collection<BaseNode>) {
parentNode.childNode?.let {
it.addAll(childIndex, newData)

if (parentNode is BaseExpandNode && !parentNode.isExpanded) {
return
}
val parentIndex = this.data.indexOf(parentNode)
val pos = parentIndex + 1 + childIndex
addData(parentIndex + pos, newData)
}
}

/**
* 对指定的父node下对子node进行移除
* @param parentNode BaseNode 夫node
Expand Down

0 comments on commit 607c0aa

Please sign in to comment.