create a helper function for converting files to FileDirItems

This commit is contained in:
tibbi 2019-03-24 22:02:49 +01:00
parent 3af942c5a2
commit 2fb89645e5
2 changed files with 26 additions and 19 deletions

View file

@ -51,7 +51,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.10.12'
implementation 'com.simplemobiletools:commons:5.10.15'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
}

View file

@ -193,31 +193,38 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
val isSortingBySize = context!!.config.sorting and SORT_BY_SIZE != 0
if (files != null) {
for (file in files) {
val curPath = file.absolutePath
val curName = file.name
if (!showHidden && curName.startsWith(".")) {
continue
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize)
if (fileDirItem != null) {
items.add(fileDirItem)
}
val isDirectory = file.isDirectory
val children = if (isDirectory) file.getDirectChildrenCount(showHidden) else 0
val size = if (isDirectory) {
if (isSortingBySize) {
file.getProperSize(showHidden)
} else {
0L
}
} else {
file.length()
}
val fileDirItem = FileDirItem(curPath, curName, isDirectory, children, size)
items.add(fileDirItem)
}
}
callback(path, items)
}
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean): FileDirItem? {
val curPath = file.absolutePath
val curName = file.name
if (!showHidden && curName.startsWith(".")) {
return null
}
val isDirectory = file.isDirectory
val children = if (isDirectory) file.getDirectChildrenCount(showHidden) else 0
val size = if (isDirectory) {
if (isSortingBySize) {
file.getProperSize(showHidden)
} else {
0L
}
} else {
file.length()
}
return FileDirItem(curPath, curName, isDirectory, children, size)
}
private fun itemClicked(item: FileDirItem) {
if (item.isDirectory) {
(activity as? MainActivity)?.apply {