Skip to content

Commit fb5e310

Browse files
committed
refactor: make tree view sorts in constant to avoid instantiating a new sort
1 parent cb4001d commit fb5e310

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

core/app/src/main/java/com/itsaky/androidide/fragments/sidebar/FileTreeFragment.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,
169169
}
170170

171171
private fun listFilesForNode(files: Array<File>, parent: TreeNode) {
172-
Arrays.sort(files, SortFileName())
173-
Arrays.sort(files, SortFolder())
172+
Arrays.sort(files, SORT_FILE_NAME)
173+
Arrays.sort(files, SORT_FOLDER)
174174
for (file in files) {
175175
val node = TreeNode(file)
176176
node.viewHolder = FileTreeViewHolder(context)
@@ -278,6 +278,9 @@ class FileTreeFragment : BottomSheetDialogFragment(), TreeNodeClickListener,
278278
}
279279

280280
companion object {
281+
282+
private val SORT_FILE_NAME = SortFileName()
283+
private val SORT_FOLDER = SortFolder()
281284

282285
// Should be same as defined in layout/activity_editor.xml
283286
const val TAG = "editor.fileTree"

utilities/treeview/src/main/java/com/unnamed/b/atv/model/TreeNode.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
/** Created by Bogdan Melnychuk on 2/10/15. */
1919
public class TreeNode {
2020

21+
private static final SortFileName SORT_FILE_NAME = new SortFileName();
22+
private static final SortFolder SORT_FOLDER = new SortFolder();
23+
2124
public static final String NODES_ID_SEPARATOR = ":";
2225
private final List<TreeNode> children;
2326
private int mId;
@@ -63,8 +66,8 @@ public TreeNode addChild(TreeNode childNode, boolean sort) {
6366
children.add(childNode);
6467

6568
if (sort) {
66-
Collections.sort(children, new SortFileName());
67-
Collections.sort(children, new SortFolder());
69+
Collections.sort(children, SORT_FILE_NAME);
70+
Collections.sort(children, SORT_FOLDER);
6871
}
6972
return this;
7073
}

0 commit comments

Comments
 (0)