Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lpb node tree #3682

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<activity android:name=".activity.DiffUtilActivity" />
<activity android:name=".activity.node.ChooseNodeUseTypeActivity" />
<activity android:name=".activity.node.NodeTreeUseActivity" />
<activity android:name=".activity.node.NotdeNTreeUserActivity"/>
<activity android:name=".activity.multi.BinderUseActivity" />
</application>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ public void onClick(View v) {
}
});

findViewById(R.id.card_view3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ChooseNodeUseTypeActivity.this, NotdeNTreeUserActivity.class));
}
});






}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.chad.baserecyclerviewadapterhelper.activity.node;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.baserecyclerviewadapterhelper.R;
import com.chad.baserecyclerviewadapterhelper.adapter.node.tree.NodeNTreeAdapter;
import com.chad.baserecyclerviewadapterhelper.adapter.node.tree.NodeTreeAdapter;
import com.chad.baserecyclerviewadapterhelper.base.BaseActivity;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.FirstNode;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.SecondNode;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.ThirdNode;
import com.chad.baserecyclerviewadapterhelper.utils.Tips;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.listener.GridSpanSizeLookup;

import java.util.ArrayList;
import java.util.List;

/**
* @author : lipengbp
* @email : lipengbo@okay.cn
* @date : 2022/08/28 15:41
* @desc : 描述
*/
public class NotdeNTreeUserActivity extends BaseActivity {

private RecyclerView mRecyclerView;
private NodeNTreeAdapter adapter = new NodeNTreeAdapter();

private List<BaseNode> data=new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_node_n_tree);
setBackBtn();
setTitle("Node Use (Tree)");

mRecyclerView = findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));
data=getEntity();
mRecyclerView.setAdapter(adapter);
adapter.setList(data);

// 模拟新增node
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
SecondNode seNode = new SecondNode(new ArrayList<BaseNode>(), "Second Node(This is added)");
List<BaseNode> thirdNodeList1 = new ArrayList<>();
for (int i = 0; i < 8; i++) {
ThirdNode node = new ThirdNode("Third Node (This is added)" + i);
thirdNodeList1.add(node);
}
seNode.getChildNode().addAll(thirdNodeList1);
SecondNode seNode2 = new SecondNode(new ArrayList<BaseNode>(), "Second Node(This is added)");
List<BaseNode> thirdNodeList2 = new ArrayList<>();
for (int i = 0; i < 8; i++) {
ThirdNode node = new ThirdNode("Third Node (This is added)" + i);
thirdNodeList2.add(node);
}
seNode2.getChildNode().addAll(thirdNodeList2);
List<SecondNode> nodes = new ArrayList<>();
nodes.add(seNode);
nodes.add(seNode2);
//第一个夫node,位置为子node的3号位置
adapter.nodeAddData(adapter.getData().get(0), 2, nodes);
// adapter.nodeSetData(adapter.getData().get(0), 2, seNode2);
// adapter.nodeReplaceChildData(adapter.getData().get(0), nodes);
Tips.show("新插入了两个node", Toast.LENGTH_LONG);
// adapter.nodeRemoveData(adapter.getData().get(0), 0);
// Tips.show("删除一个Node节点", Toast.LENGTH_LONG);
}
}, 2000);
}

private List<BaseNode> getEntity() {
List<BaseNode> list = new ArrayList<>();
for (int i = 0; i < 8; i++) {

List<BaseNode> secondNodeList = new ArrayList<>();
for (int n = 0; n <= 5; n++) {

List<BaseNode> thirdNodeList = new ArrayList<>();
for (int t = 0; t <= 10; t++) {
ThirdNode node = new ThirdNode("Third Node " + t);
thirdNodeList.add(node);
}

SecondNode seNode = new SecondNode(thirdNodeList, "Second Node " + n);
secondNodeList.add(seNode);
}

FirstNode entity = new FirstNode(secondNodeList, "First Node " + i);

// 模拟 默认第0个是展开的
entity.setExpanded(i == 0);

list.add(entity);
}
return list;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.chad.baserecyclerviewadapterhelper.adapter.node.tree;

import com.chad.baserecyclerviewadapterhelper.adapter.node.tree.provider.FirstProvider;
import com.chad.baserecyclerviewadapterhelper.adapter.node.tree.provider.SecondProvider;
import com.chad.baserecyclerviewadapterhelper.adapter.node.tree.provider.ThirdProvider;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.FirstNode;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.SecondNode;
import com.chad.baserecyclerviewadapterhelper.entity.node.tree.ThirdNode;
import com.chad.library.adapter.base.BaseNodeAdapter;
import com.chad.library.adapter.base.entity.node.BaseNode;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
* @author : lipengbp
* @email : lipengbo@okay.cn
* @date : 2022/08/28 15:43
* @desc : 描述
*/
public class NodeNTreeAdapter extends BaseNodeAdapter {

public NodeNTreeAdapter() {
super();
addFullSpanNodeProvider(new FirstProvider());
addFullSpanNodeProvider(new SecondProvider());
addNodeProvider(new ThirdProvider());
}

@Override
protected int getItemType(@NotNull List<? extends BaseNode> data, int position) {
BaseNode node = data.get(position);
if (node instanceof FirstNode) {
return 1;
} else if (node instanceof SecondNode) {
return 2;
} else if (node instanceof ThirdNode) {
return 3;
}
return -1;
}

public static final int EXPAND_COLLAPSE_PAYLOAD = 110;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public void onClick(@NotNull BaseViewHolder helper, @NotNull View view, BaseNode
if (entity.isExpanded()) {
getAdapter().collapse(position);
} else {
getAdapter().expandAndCollapseOther(position);
getAdapter().expand(position);
// getAdapter().expandAndCollapseOther(position);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package com.chad.baserecyclerviewadapterhelper.entity.node.tree;

import com.chad.library.adapter.base.entity.node.BaseExpandNode;
import com.chad.library.adapter.base.entity.node.BaseNode;

import org.jetbrains.annotations.Nullable;

import java.util.List;

public class ThirdNode extends BaseNode {
public class ThirdNode extends BaseExpandNode {
private String title;


public ThirdNode(String title) {
this.title = title;
}





public String getTitle() {
return title;
}
Expand Down
37 changes: 37 additions & 0 deletions app/src/main/res/layout/activity_choose_node_use_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,42 @@
</LinearLayout>
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:id="@+id/card_view3"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:layout_marginRight="5dp"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardBackgroundColor="@color/item_bg"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="2dp"
card_view:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@mipmap/animation_img1" />

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="BaseNodeAdapter (NTree)"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />

</LinearLayout>
</androidx.cardview.widget.CardView>


</LinearLayout>
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_node_n_tree.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/bg"
tools:context=".activity.SectionQuickUseActivity">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />


</LinearLayout>
Loading