Skip to content

Commit

Permalink
refactor: make tree view sorts in constant to avoid instantiating a n…
Browse files Browse the repository at this point in the history
…ew sort
  • Loading branch information
teixeira0x committed Dec 10, 2024
1 parent cb4001d commit fb5e310
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,
}

private fun listFilesForNode(files: Array<File>, parent: TreeNode) {
Arrays.sort(files, SortFileName())
Arrays.sort(files, SortFolder())
Arrays.sort(files, SORT_FILE_NAME)
Arrays.sort(files, SORT_FOLDER)
for (file in files) {
val node = TreeNode(file)
node.viewHolder = FileTreeViewHolder(context)
Expand Down Expand Up @@ -278,6 +278,9 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,
}

companion object {

private val SORT_FILE_NAME = SortFileName()
private val SORT_FOLDER = SortFolder()

// Should be same as defined in layout/activity_editor.xml
const val TAG = "editor.fileTree"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
/** Created by Bogdan Melnychuk on 2/10/15. */
public class TreeNode {

private static final SortFileName SORT_FILE_NAME = new SortFileName();
private static final SortFolder SORT_FOLDER = new SortFolder();

public static final String NODES_ID_SEPARATOR = ":";
private final List<TreeNode> children;
private int mId;
Expand Down Expand Up @@ -63,8 +66,8 @@ public TreeNode addChild(TreeNode childNode, boolean sort) {
children.add(childNode);

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

0 comments on commit fb5e310

Please sign in to comment.