Skip to content

Commit

Permalink
fix qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
shineM committed Jan 31, 2019
1 parent 344f3f5 commit 5137b37
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 82 deletions.
2 changes: 1 addition & 1 deletion treeview_lib/src/main/java/me/texy/treeview/TreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String getId() {
return getLevel() + "," + getIndex();
}

private int getIndex() {
public int getIndex() {
return index;
}

Expand Down
102 changes: 41 additions & 61 deletions treeview_lib/src/main/java/me/texy/treeview/TreeViewAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,19 @@
public class TreeViewAdapter extends RecyclerView.Adapter {

private Context context;
/**
* Tree root.
*/

private TreeNode root;
/**
* The current data set of Adapter,which means excluding the collapsed nodes.
*/

private List<TreeNode> expandedNodeList;
/**
* The binder factory.A binder provide the layoutId which needed in method
* <code>onCreateViewHolder</code> and the way how to render ViewHolder.
*/

private BaseNodeViewFactory baseNodeViewFactory;
/**
* This parameter make no sense just for avoiding IllegalArgumentException of ViewHolder's
* constructor.
*/

private View EMPTY_PARAMETER;

private TreeView treeView;

public TreeViewAdapter(Context context, TreeNode root,
@NonNull BaseNodeViewFactory baseNodeViewFactory) {
TreeViewAdapter(Context context, TreeNode root,
@NonNull BaseNodeViewFactory baseNodeViewFactory) {
this.context = context;
this.root = root;
this.baseNodeViewFactory = baseNodeViewFactory;
Expand Down Expand Up @@ -96,8 +86,9 @@ public int getItemViewType(int position) {
return expandedNodeList.get(position).getLevel();
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int level) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int level) {
View view = LayoutInflater.from(context).inflate(baseNodeViewFactory
.getNodeViewBinder(EMPTY_PARAMETER, level).getLayoutId(), parent, false);

Expand All @@ -107,7 +98,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int level) {
}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
final View nodeView = holder.itemView;
final TreeNode treeNode = expandedNodeList.get(position);
final BaseNodeViewBinder viewBinder = (BaseNodeViewBinder) holder;
Expand Down Expand Up @@ -135,31 +126,36 @@ public void onClick(View v) {
}

if (viewBinder instanceof CheckableNodeViewBinder) {
final View view = nodeView
.findViewById(((CheckableNodeViewBinder) viewBinder).getCheckableViewId());

if (view != null && view instanceof CheckBox) {
final CheckBox checkableView = (CheckBox) view;
checkableView.setChecked(treeNode.isSelected());

checkableView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = checkableView.isChecked();
selectNode(checked, treeNode);
((CheckableNodeViewBinder) viewBinder).onNodeSelectedChanged(treeNode, checked);
}
});
} else {
throw new ClassCastException("The getCheckableViewId() " +
"must return a CheckBox's id");
}
setupCheckableItem(nodeView, treeNode, (CheckableNodeViewBinder) viewBinder);
}

viewBinder.bindView(treeNode);
}

public void selectNode(boolean checked, TreeNode treeNode) {
private void setupCheckableItem(View nodeView,
final TreeNode treeNode,
final CheckableNodeViewBinder viewBinder) {
final View view = nodeView.findViewById(viewBinder.getCheckableViewId());

if (view instanceof CheckBox) {
final CheckBox checkableView = (CheckBox) view;
checkableView.setChecked(treeNode.isSelected());

checkableView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = checkableView.isChecked();
selectNode(checked, treeNode);
viewBinder.onNodeSelectedChanged(treeNode, checked);
}
});
} else {
throw new ClassCastException("The getCheckableViewId() " +
"must return a CheckBox's id");
}
}

void selectNode(boolean checked, TreeNode treeNode) {
treeNode.setSelected(checked);

selectChildren(treeNode, checked);
Expand Down Expand Up @@ -203,17 +199,12 @@ public int getItemCount() {
* Refresh all,this operation is only used for refreshing list when a large of nodes have
* changed value or structure because it take much calculation.
*/
public void refreshView() {
void refreshView() {
buildExpandedNodeList();
notifyDataSetChanged();
}

/**
* Insert a node list after index.
*
* @param index the index before new addition nodes's first position
* @param additionNodes nodes to add
*/
// Insert a node list after index.
private void insertNodesAtIndex(int index, List<TreeNode> additionNodes) {
if (index < 0 || index > expandedNodeList.size() - 1 || additionNodes == null) {
return;
Expand All @@ -222,12 +213,7 @@ private void insertNodesAtIndex(int index, List<TreeNode> additionNodes) {
notifyItemRangeInserted(index + 1, additionNodes.size());
}

/**
* Remove a node list after index.
*
* @param index the index before the removedNodes nodes's first position
* @param removedNodes nodes to remove
*/
//Remove a node list after index.
private void removeNodesAtIndex(int index, List<TreeNode> removedNodes) {
if (index < 0 || index > expandedNodeList.size() - 1 || removedNodes == null) {
return;
Expand All @@ -238,10 +224,8 @@ private void removeNodesAtIndex(int index, List<TreeNode> removedNodes) {

/**
* Expand node. This operation will keep the structure of children(not expand children)
*
* @param treeNode
*/
public void expandNode(TreeNode treeNode) {
void expandNode(TreeNode treeNode) {
if (treeNode == null) {
return;
}
Expand All @@ -254,10 +238,8 @@ public void expandNode(TreeNode treeNode) {

/**
* Collapse node. This operation will keep the structure of children(not collapse children)
*
* @param treeNode
*/
public void collapseNode(TreeNode treeNode) {
void collapseNode(TreeNode treeNode) {
if (treeNode == null) {
return;
}
Expand All @@ -269,10 +251,8 @@ public void collapseNode(TreeNode treeNode) {

/**
* Delete a node from list.This operation will also delete its children.
*
* @param node
*/
public void deleteNode(TreeNode node) {
void deleteNode(TreeNode node) {
if (node == null || node.getParent() == null) {
return;
}
Expand All @@ -291,7 +271,7 @@ public void deleteNode(TreeNode node) {
notifyItemRemoved(index);
}

public void setTreeView(TreeView treeView) {
void setTreeView(TreeView treeView) {
this.treeView = treeView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public void setTreeView(TreeView treeView) {

/**
* Get node item layout id
*
* @return
*/
public abstract int getLayoutId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class BaseNodeViewFactory {
* @param view The parameter for BaseNodeViewBinder's constructor, do not use this for other
* purpose!
* @param level The treeNode level
* @return
* @return BaseNodeViewBinder
*/
public abstract BaseNodeViewBinder getNodeViewBinder(View view, int level);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CheckableNodeViewBinder(View itemView) {
}

/**
* Get the checkable view id. MUST BE A CheckBox CLASS
* Get the checkable view id. MUST BE A CheckBox type
*
* @return
*/
Expand Down
16 changes: 0 additions & 16 deletions treeview_lib/src/main/java/me/texy/treeview/helper/TreeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static List<TreeNode> expandNode(TreeNode treeNode, boolean includeChild)
*
* @param root the tree root
* @param level the level to expand
* @return
*/
public static void expandLevel(TreeNode root, int level) {
if (root == null) {
Expand All @@ -81,7 +80,6 @@ public static void expandLevel(TreeNode root, int level) {
} else {
expandLevel(child, level);
}

}
}

Expand Down Expand Up @@ -178,10 +176,6 @@ private static void fillNodeList(List<TreeNode> treeNodes, TreeNode treeNode) {

/**
* Select the node and node's children,return the visible nodes
*
* @param treeNode
* @param select
* @return
*/
public static List<TreeNode> selectNodeAndChild(TreeNode treeNode, boolean select) {
List<TreeNode> expandChildren = new ArrayList<>();
Expand Down Expand Up @@ -227,10 +221,6 @@ private static void selectNodeInner(TreeNode treeNode, boolean select) {
/**
* Select parent when all the brothers have been selected, otherwise deselect parent,
* and check the grand parent recursive.
*
* @param treeNode
* @param select
* @return
*/
public static List<TreeNode> selectParentIfNeedWhenNodeSelected(TreeNode treeNode, boolean select) {
List<TreeNode> impactedParents = new ArrayList<>();
Expand Down Expand Up @@ -266,9 +256,6 @@ public static List<TreeNode> selectParentIfNeedWhenNodeSelected(TreeNode treeNod

/**
* Get the selected nodes under current node, include itself
*
* @param treeNode
* @return
*/
public static List<TreeNode> getSelectedNodes(TreeNode treeNode) {
List<TreeNode> selectedNodes = new ArrayList<>();
Expand All @@ -287,9 +274,6 @@ public static List<TreeNode> getSelectedNodes(TreeNode treeNode) {
/**
* Return true when the node has one selected child(recurse all children) at least,
* otherwise return false
*
* @param treeNode
* @return
*/
public static boolean hasOneSelectedNodeAtLeast(TreeNode treeNode) {
if (treeNode == null || treeNode.getChildren().size() == 0) {
Expand Down

0 comments on commit 5137b37

Please sign in to comment.