Skip to content

Commit 3248960

Browse files
committed
adding a couple performance improvements to casual file fetching
1 parent f191664 commit 3248960

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/fragments/ItemsFragment.kt

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
190190

191191
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<FileDirItem>) -> Unit) {
192192
val items = ArrayList<FileDirItem>()
193+
if (context == null) {
194+
callback(path, items)
195+
}
196+
193197
val files = File(path).listFiles()?.filterNotNull()
198+
val isSortingBySize = context!!.config.sorting and SORT_BY_SIZE != 0
194199
if (files != null) {
195200
for (file in files) {
196201
val curPath = file.absolutePath
@@ -199,12 +204,22 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
199204
continue
200205
}
201206

202-
val children = file.getDirectChildrenCount(showHidden)
203-
val size = if (file.isDirectory && context?.config?.sorting == SORT_BY_SIZE) file.getProperSize(showHidden) else file.length()
204-
val fileDirItem = FileDirItem(curPath, curName, file.isDirectory, children, size)
207+
val isDirectory = file.isDirectory
208+
val children = if (isDirectory) file.getDirectChildrenCount(showHidden) else 0
209+
val size = if (isDirectory) {
210+
if (isSortingBySize) {
211+
file.getProperSize(showHidden)
212+
} else {
213+
0L
214+
}
215+
} else {
216+
file.length()
217+
}
218+
val fileDirItem = FileDirItem(curPath, curName, isDirectory, children, size)
205219
items.add(fileDirItem)
206220
}
207221
}
222+
208223
callback(path, items)
209224
}
210225

0 commit comments

Comments
 (0)