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

fix(treeview): use sort only when necessary when adding a child #1456

Merged
merged 1 commit into from
Nov 15, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,
for (file in files) {
val node = TreeNode(file)
node.viewHolder = FileTreeViewHolder(context)
parent.addChild(node)
parent.addChild(node, false)
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,

val projectRoot = TreeNode.root(projectDir)
projectRoot.viewHolder = FileTreeViewHolder(context)
rootNode.addChild(projectRoot)
rootNode.addChild(projectRoot, false)

binding!!.horizontalCroll.visibility = View.GONE
binding!!.horizontalCroll.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void getNodeFromArray(File[] files, TreeNode parent) {
for (File file : files) {
TreeNode node = new TreeNode(file);
node.setViewHolder(new FileTreeViewHolder(ctx));
parent.addChild(node);
parent.addChild(node, false);
}
}

Expand Down
11 changes: 9 additions & 2 deletions treeview/src/main/java/com/unnamed/b/atv/model/TreeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ public TreeNode addChildren(TreeNode... nodes) {
}

public TreeNode addChild(TreeNode childNode) {
return addChild(childNode, true);
}

public TreeNode addChild(TreeNode childNode, boolean sort) {
childNode.mParent = this;
childNode.mId = generateId();
children.add(childNode);
Collections.sort(children, new SortFileName());
Collections.sort(children, new SortFolder());

if (sort) {
Collections.sort(children, new SortFileName());
Collections.sort(children, new SortFolder());
}
return this;
}

Expand Down
Loading