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 { dependencies {
implementation 'com.simplemobiletools:commons:5.10.12' implementation 'com.simplemobiletools:commons:5.10.15'
implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2' implementation 'com.alexvasilkov:gesture-views:2.5.2'
} }

View File

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