Commit 82628c48 authored by Xinghaoxiang's avatar Xinghaoxiang

树形结构

parent f0db6af4
......@@ -7,9 +7,11 @@ import android.util.Log;
import android.view.View;
import com.bril.webfile.FileActivity;
import com.bril.webfile.NextCloudActivity;
public class MainActivity extends AppCompatActivity {
public static final int FILE_CHOOSE = 0x012;
public static final int FILE_NEXTCLOUD= 0x013;
String notification = "";
String conferenceManagement = "";
private static final String TAG = "MainActivity";
......@@ -86,7 +88,33 @@ public class MainActivity extends AppCompatActivity {
String fileId = data.getStringExtra("fileId");
Log.d(TAG, "fileID:" + fileId + " filePath:" + filePath + " fileName:" + fileName);
break;
case FILE_NEXTCLOUD:
String absolutePath = data.getStringExtra("absolutePath");
String filePaths = data.getStringExtra("filePaths");
Log.d(TAG, "onActivityResult: " + absolutePath + " " + filePaths);
break;
}
}
}
public void shareFolder(View view) {
Intent intent = new Intent(this, NextCloudActivity.class);
intent.putExtra("userId", "716");
intent.putExtra("moduleName", "shareFolder");
startActivityForResult(intent,FILE_NEXTCLOUD);
}
public void myselfNetDisk(View view) {
Intent intent = new Intent(this, NextCloudActivity.class);
intent.putExtra("userId", "716");
intent.putExtra("moduleName", "myselfNetDisk");
startActivityForResult(intent,FILE_NEXTCLOUD);
}
public void documentManager(View view) {
Intent intent = new Intent(this, NextCloudActivity.class);
intent.putExtra("userId", "716");
intent.putExtra("moduleName", "documentManager");
startActivityForResult(intent,FILE_NEXTCLOUD);
}
}
......@@ -91,7 +91,36 @@
android:onClick="documentScan"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="共享文件夹"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:onClick="shareFolder"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="个人网盘"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:onClick="myselfNetDisk"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文档管理"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:onClick="documentManager"
/>
</LinearLayout>
include ':app', ':webfile'
include ':sample', ':webfile'
......@@ -5,6 +5,7 @@
<application
android:supportsRtl="true">
<activity android:name=".FileActivity" />
<activity android:name=".NextCloudActivity" />
</application>
</manifest>
......@@ -67,8 +67,44 @@ public class FileActivity extends AppCompatActivity implements AdapterView.OnIte
throwable.printStackTrace();
}
});
// fileClient.nextCloud(userId, "2")
// .observeOn(AndroidSchedulers.mainThread())
// .subscribeOn(Schedulers.io())
// .subscribe(new Consumer<NextCloudResponse>() {
// @Override
// public void accept(NextCloudResponse nextCloudResponses) throws Exception {
// List<NextCloudResponse.ListBean> list = nextCloudResponses.getList();
// for (NextCloudResponse.ListBean listBean : list) {
// ChildrenBeans childrenBeans = new ChildrenBeans();
// String type = listBean.getType();
// String name = listBean.getName();
// childrenBeans.setName(name);
// childrenBeans.setType(type);
// childrenBeansList.add(childrenBeans);
// addData(listBean.getChildren());
// }
// Log.d(TAG, "" + childrenBeansList.size());
// for (ChildrenBeans childrenBeans : childrenBeansList) {
// Log.e(TAG, childrenBeans.toString() );
// }
//
// SimpleTreeListViewAdapter simpleTreeListViewAdapter
// = new SimpleTreeListViewAdapter(fileLv, FileActivity.this, childrenBeansList, 1);
// fileLv.setAdapter(simpleTreeListViewAdapter);
//
// }
// }, new Consumer<Throwable>() {
// @Override
// public void accept(Throwable throwable) throws Exception {
// throwable.printStackTrace();
// }
// });
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FileResponse fileResponse = fileBean.get(position);
......
package com.bril.webfile;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import com.bril.webfile.net.client.FileClient;
import com.bril.webfile.response.ChildrenBeans;
import com.bril.webfile.response.NextCloudResponse;
import com.bril.webfile.treeview.adapter.SimpleTreeListViewAdapter;
import com.bril.webfile.treeview.adapter.TreeViewAdapter;
import com.bril.webfile.treeview.node.Node;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Created by Xinghx on 2018/6/26 0026.
*/
public class NextCloudActivity extends AppCompatActivity {
ListView mTree;
List<ChildrenBeans> childrenBeansList = new ArrayList<>();
private String userId;
private static final String TAG = "NextCloudActivity";
private String moduleName;
private LinearLayout file_img_backs;
private NextCloudResponse cloudResponse;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_layout);
userId = getIntent().getStringExtra("userId");
moduleName = getIntent().getStringExtra("moduleName");
mTree = (ListView) findViewById(R.id.file_lv);
file_img_backs = (LinearLayout) findViewById(R.id.file_img_backs);
file_img_backs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
initData();
}
public void initData() {
String realType = "";
switch (moduleName) {
case "myselfNetDisk":
realType = "1";
break;
case "shareFolder":
realType = "2";
break;
case "documentManager":
realType = "3";
break;
}
FileClient fileClient = new FileClient();
fileClient.nextCloud(userId, realType).enqueue(new Callback<NextCloudResponse>() {
@Override
public void onResponse(Call<NextCloudResponse> call, Response<NextCloudResponse> response) {
try {
cloudResponse = response.body();
List<NextCloudResponse.ListBean> list = response.body().getList();
for (NextCloudResponse.ListBean listBean : list) {
ChildrenBeans childrenBeans = new ChildrenBeans();
String type = listBean.getType();
String name = listBean.getName();
childrenBeans.setName(name);
childrenBeans.setType(type);
childrenBeansList.add(childrenBeans);
addData(listBean.getChildren());
}
for (ChildrenBeans childrenBeans : childrenBeansList) {
Log.e(TAG, childrenBeans.toString() );
}
SimpleTreeListViewAdapter simpleTreeListViewAdapter
= new SimpleTreeListViewAdapter(mTree, NextCloudActivity.this, childrenBeansList, 0);
mTree.setAdapter(simpleTreeListViewAdapter);
simpleTreeListViewAdapter.setOnNodeClickListener(new TreeViewAdapter.OnTreeNodeClickListener() {
@Override
public void onClick(Node node, int position) {
if (node.isFile()) {
Toast.makeText(NextCloudActivity.this, node.getName(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("absolutePath",cloudResponse.getAbsolutePath());
intent.putExtra("filePaths", node.getName());
setResult(0x013, intent);
finish();
}
}
});
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<NextCloudResponse> call, Throwable t) {
t.printStackTrace();
}
});
}
private void addData(List<NextCloudResponse.ListBean.ChildrenBean> mList) {
for (NextCloudResponse.ListBean.ChildrenBean childrenBean : mList) {
if (childrenBean == null) return;
ChildrenBeans childrenBeans = new ChildrenBeans();
String name = childrenBean.getName();
String type = childrenBean.getType();
childrenBeans.setName(name);
childrenBeans.setType(type);
childrenBeansList.add(childrenBeans);
if (childrenBean.getChildrenBeen() != null) {
addData(childrenBean.getChildrenBeen());
}
}
}
}
......@@ -5,6 +5,6 @@ package com.bril.webfile.net;
*/
public class Constant {
public static String SWAGGERURL = "http://zjk.haomo-tech.com/zhangjiakouOA/";
// public static String SWAGGERURL = "http://143.19.128.79/api/";
// public static String SWAGGERURL = "http://zjk.haomo-tech.com/zhangjiakouOA/";
public static String SWAGGERURL = "http://143.19.128.79/api/";
}
package com.bril.webfile.net.api;
import com.bril.webfile.response.FileResponse;
import com.bril.webfile.response.NextCloudResponse;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
......@@ -19,4 +21,9 @@ public interface FileAPI {
Observable<List<FileResponse>> fileModel(@Field("user_id") String userId,
@Field("module_names") String moduleNames);
@FormUrlEncoded
@POST("get_nextcloud_folders")
Call<NextCloudResponse> nextCloud(@Field("userId") String userId,
@Field("modular") String modular,
@Field("addEmptyFolder") boolean addEmptyFolder);
}
......@@ -4,10 +4,12 @@ package com.bril.webfile.net.client;
import com.bril.webfile.net.Constant;
import com.bril.webfile.net.api.FileAPI;
import com.bril.webfile.response.FileResponse;
import com.bril.webfile.response.NextCloudResponse;
import java.util.List;
import io.reactivex.Observable;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
......@@ -29,4 +31,8 @@ public class FileClient extends BaseClient {
return fileAPI.fileModel(userId,moduleName);
}
public Call<NextCloudResponse> nextCloud(String userId, String moduleName) {
return fileAPI.nextCloud(userId,moduleName,false);
}
}
package com.bril.webfile.response;
import com.bril.webfile.treeview.annotation.NodeName;
import com.bril.webfile.treeview.annotation.NodeType;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
public class ChildrenBeans {
@NodeName
private String name;
private String state;
@NodeType
private String type;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "ChildrenBeans{" +
"name='" + name + '\'' +
", state='" + state + '\'' +
", type='" + type + '\'' +
'}';
}
}
package com.bril.webfile.response;
import com.google.gson.annotations.SerializedName;
import java.util.List;
/**
* Created by Xinghx on 2018/6/21
*/
public class NextCloudResponse {
/**
* absolutePath : /data/nextcloud/networkdisk/data/19803130208/files/
* list : [{"children":[{"children":[],"name":"Photos/Hummingbird.jpg","state":"open","type":"file"},{"children":[],"name":"Photos/Coast.jpg","state":"open","type":"file"},{"children":[],"name":"Photos/Nut.jpg","state":"open","type":"file"}],"name":"Photos","state":"closed","type":"folder"},{"children":[],"name":"Docker������Java Web������.docx","state":"open","type":"file"},{"children":[],"name":"Nex tcloud.mp4","state":"open","type":"file"},{"children":[],"name":"B02D88149D896F1D004B03F4076D218E.jpg","state":"open","type":"file"},{"children":[{"children":[],"name":"Documents/About.odt","state":"open","type":"file"},{"children":[],"name":"Documents/About.txt","state":"open","type":"file"}],"name":"Documents","state":"closed","type":"folder"}]
*/
private String absolutePath;
private List<ListBean> list;
public String getAbsolutePath() {
return absolutePath;
}
public void setAbsolutePath(String absolutePath) {
this.absolutePath = absolutePath;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean {
/**
* children : [{"children":[],"name":"Photos/Hummingbird.jpg","state":"open","type":"file"},{"children":[],"name":"Photos/Coast.jpg","state":"open","type":"file"},{"children":[],"name":"Photos/Nut.jpg","state":"open","type":"file"}]
* name : Photos
* state : closed
* type : folder
*/
private String name;
private String state;
private String type;
private List<ChildrenBean> children;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<ChildrenBean> getChildren() {
return children;
}
public void setChildren(List<ChildrenBean> children) {
this.children = children;
}
public class ChildrenBean {
/**
* children : []
* name : Photos/Hummingbird.jpg
* state : open
* type : file
*/
@SerializedName("children")
private List<ChildrenBean> childrenBeen;
private String name;
private String state;
private String type;
public List<ChildrenBean> getChildrenBeen() {
return childrenBeen;
}
public void setChildrenBeen(List<ChildrenBean> childrenBeen) {
this.childrenBeen = childrenBeen;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "ChildrenBean{" +
"childrenBeen=" + childrenBeen +
", name='" + name + '\'' +
", state='" + state + '\'' +
", type='" + type + '\'' +
'}';
}
}
}
}
package com.bril.webfile.treeview.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.bril.webfile.R;
import com.bril.webfile.treeview.node.Node;
import java.util.List;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
public class SimpleTreeListViewAdapter extends TreeViewAdapter {
public SimpleTreeListViewAdapter(ListView tree, Context context, List datas, int defaultLevel) throws IllegalAccessException {
super(tree, context, datas, defaultLevel);
}
@Override
public View getConvertView(Node node, int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.mIcon = convertView.findViewById(R.id.id_item_icon);
viewHolder.mText = convertView.findViewById(R.id.id_item_text);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
if (node.getIcon() == -1) {
viewHolder.mIcon.setVisibility(View.INVISIBLE);
} else {
viewHolder.mIcon.setVisibility(View.VISIBLE);
viewHolder.mIcon.setImageResource(node.getIcon());
}
String name = node.getName();
int i = name.lastIndexOf("/");
String realName = name.substring(i + 1, name.length());
viewHolder.mText.setText(realName);
// if (i == -1) {
// viewHolder.mText.setText(name);
// } else {
//
// }
return convertView;
}
public class ViewHolder{
ImageView mIcon;
TextView mText;
}
}
package com.bril.webfile.treeview.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import com.bril.webfile.treeview.helper.TreeHelper;
import com.bril.webfile.treeview.node.Node;
import java.util.List;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
public abstract class TreeViewAdapter<T> extends BaseAdapter{
private Context mContext;
private List<Node> mAllNodes;
private List<Node> mVisiableNodes;
protected LayoutInflater mInflater;
private ListView tree;
public interface OnTreeNodeClickListener{
void onClick(Node node,int position);
}
private OnTreeNodeClickListener mListener;
public void setOnNodeClickListener(OnTreeNodeClickListener mListener) {
this.mListener = mListener;
}
public TreeViewAdapter(ListView tree, Context context, List<T> datas, int defaultLevel) throws IllegalAccessException {
this.mContext = context;
mAllNodes = TreeHelper.getSortedNodes(datas, defaultLevel);
mVisiableNodes = TreeHelper.filterVisibleNodes(mAllNodes);
mInflater= LayoutInflater.from(context);
this.tree = tree;
tree.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
expandOrCollapse(position);
if (mListener != null) {
mListener.onClick(mVisiableNodes.get(position),position);
}
}
});
}
/**
* 点击收缩或者展开
* @param position
*/
private void expandOrCollapse(int position) {
Node n = mVisiableNodes.get(position);
if (n.isFile()) return;
n.setExpand(!n.isExpand());
mVisiableNodes = TreeHelper.filterVisibleNodes(mAllNodes);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mVisiableNodes.size();
}
@Override
public Object getItem(int position) {
return mVisiableNodes.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Node node = mVisiableNodes.get(position);
convertView = getConvertView(node, position, convertView, parent);
// 设置内边距
convertView.setPadding(node.getLevel() * 50 ,3 , 3 ,3);
return convertView;
}
public abstract View getConvertView(Node node,int position, View convertView, ViewGroup parent);
}
package com.bril.webfile.treeview.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NodeName {
}
package com.bril.webfile.treeview.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NodePID {
}
package com.bril.webfile.treeview.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface NodeType {
}
package com.bril.webfile.treeview.helper;
import android.util.Log;
import com.bril.webfile.R;
import com.bril.webfile.treeview.annotation.NodeName;
import com.bril.webfile.treeview.annotation.NodeType;
import com.bril.webfile.treeview.node.Node;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
public class TreeHelper {
private static final String TAG = "TreeHelper";
/**
* 把用户提供的数据 转为NODE
*
* @param <T>
* @return
*/
public static <T> List<Node> convertData2Nodes(List<T> datas) throws IllegalAccessException {
List<Node> nodes = new ArrayList<>();
Node node = null;
for (T t : datas) {
String type = "folder";
String name = "";
Class clazz = t.getClass();
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(NodeType.class) != null) {
field.setAccessible(true);
type = (String) field.get(t);
}
if (field.getAnnotation(NodeName.class) != null) {
field.setAccessible(true);
name = (String) field.get(t);
}
}
node = new Node(name, type);
nodes.add(node);
}
// 设置node间节点关系
for (int i = 0; i < nodes.size(); i++) {
Node n = nodes.get(i);
for (int j = i + 1; j < nodes.size(); j++) {
Node m = nodes.get(j);
Log.d(TAG, "" + m.getName() + " " + n.getName());
String aaa = m.getName();
String bbb = n.getName();
if (aaa.lastIndexOf("/") != -1) {
aaa = aaa.substring(0, aaa.lastIndexOf("/"));
}
if (aaa.equals(n.getName()) && n.isFolder()) {
Log.d(TAG, "convertData2Nodes: " + m.getName() + " " + n.getName());
n.getChildren().add(m);
m.setParent(n);
} else if (n.getName().equals(aaa) && m.isFolder()) {
Log.d(TAG, "convertData2Nodes else : " + m.getName() + " " + n.getName());
m.getChildren().add(n);
n.setParent(m);
}
}
}
for (Node n : nodes) {
setNodeIcons(n);
}
//方法2
// for (int i = 0; i < datas.size(); i++) {
// Node n = nodes.get(i);
// for (int j = i + 1; j < nodes.size(); j++) {
// Node m = nodes.get(j);
// if (m.getpId() instanceof String) {
// if (m.getpId().equals(n.getId())) {
// n.getChildren().add(m);
// m.setParent(n);
// } else if (m.getId().equals(n.getpId())) {
// m.getChildren().add(n);
// n.setParent(m);
// }
// } else {
// if (m.getpId() == n.getId()) {
// n.getChildren().add(m);
// m.setParent(n);
// } else if (m.getId() == n.getpId()) {
// m.getChildren().add(n);
// n.setParent(m);
// }
// }
// }
return nodes;
}
/**
* 为node设置图标
*
* @param n
*/
public static void setNodeIcons(Node n) {
if (n.getChildren().size() > 0 && n.isExpand() && n.isFolder()) {
n.setIcon(R.drawable.tree_ex);
} else if (n.getChildren().size() > 0 && !n.isExpand() && n.isFolder()) {
n.setIcon(R.drawable.tree_ec);
} else {
n.setIcon(-1);
}
}
public static <T> List<Node> getSortedNodes(List<T> datas,int defaultExpandLevel) throws IllegalAccessException {
List<Node> result = new ArrayList<>();
List<Node> nodes = convertData2Nodes(datas);
List<Node> rootNodes = getRootNodes(nodes);
for (Node node : rootNodes) {
addNode(result, node, defaultExpandLevel, 1);
}
Log.e("TAG", result.size() + "");
return result;
}
/**
* 从所有节点中过滤出根节点
*
* @param nodes
* @return
*/
private static List<Node> getRootNodes(List<Node> nodes) {
List<Node> root = new ArrayList<Node>();
for (Node node : nodes) {
if (node.isRoot()) {
root.add(node);
}
}
return root;
}
private static void addNode(List<Node> result, Node node,
int defaultExpandLevel, int currentLevel) {
result.add(node);
if (defaultExpandLevel >= currentLevel) {
node.setExpand(true);
}
if (node.isFile())
return;
for (int i = 0; i < node.getChildren().size(); i++) {
addNode(result, node.getChildren().get(i), defaultExpandLevel,
currentLevel + 1);
}
}
/**
* 过滤出可见的节点
*
* @param nodes
* @return
*/
public static List<Node> filterVisibleNodes(List<Node> nodes) {
List<Node> result = new ArrayList<Node>();
for (Node node : nodes) {
if (node.isRoot() || node.isParentExpand()) {
setNodeIcons(node);
result.add(node);
}
}
return result;
}
}
package com.bril.webfile.treeview.node;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Xinghx on 2018/6/25 0025.
*/
public class Node {
private String id;
private String pId = "0";
private String name; // 文件的名字
private String type = "folder"; // 属于文件还是文件夹
private int level; // 树的深度
private boolean isExpand; // 是否展开
private int icon;
private Node parent;
private List<Node> children = new ArrayList<>();
public Node() {
}
public Node(String pId, String name, String type) {
this.pId = pId;
this.name = name;
this.type = type;
}
public Node(String name, String type) {
this.name = name;
this.type = type;
}
/**
* 是否是根节点
* @return
*/
public boolean isRoot() {
return parent == null;
}
public boolean isParentExpand() {
if (parent == null) return false;
return parent.isExpand();
}
/**
* 是否是文件夹
* @return
*/
public boolean isFolder() {
return "folder".equals(getType());
}
public boolean isFile() {
return "file".equals(getType());
}
/**
* 是否是叶子节点
* @return
*/
public boolean isLeaf() {
return children.size() == 0;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getpId() {
return pId;
}
public void setpId(String pId) {
this.pId = pId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
/**
* 得到当前节点的层级
* @return
*/
public int getLevel() {
return parent == null ? 0 : parent.getLevel() + 1;
}
public void setLevel(int level) {
this.level = level;
}
public boolean isExpand() {
return isExpand;
}
public void setExpand(boolean expand) {
isExpand = expand;
if (!isExpand) {
for (Node node : children) {
node.setExpand(false);
}
}
}
public int getIcon() {
return icon;
}
public void setIcon(int icon) {
this.icon = icon;
}
public Node getParent() {
return parent;
}
public void setParent(Node parent) {
this.parent = parent;
}
public List<Node> getChildren() {
return children;
}
public void setChildren(List<Node> children) {
this.children = children;
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="40dp" >
<ImageView
android:id="@+id/id_item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:src="@drawable/tree_ec" />
<TextView
android:layout_centerVertical="true"
android:id="@+id/id_item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/id_item_icon"
android:text=""
android:textSize="18sp" />
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment