mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-18 12:50:35 +01:00
create a helper function for converting files to FileDirItems
This commit is contained in:
parent
3af942c5a2
commit
2fb89645e5
@ -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'
|
||||||
}
|
}
|
||||||
|
@ -193,31 +193,38 @@ 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 curPath = file.absolutePath
|
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize)
|
||||||
val curName = file.name
|
if (fileDirItem != null) {
|
||||||
if (!showHidden && curName.startsWith(".")) {
|
items.add(fileDirItem)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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) {
|
private fun itemClicked(item: FileDirItem) {
|
||||||
if (item.isDirectory) {
|
if (item.isDirectory) {
|
||||||
(activity as? MainActivity)?.apply {
|
(activity as? MainActivity)?.apply {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user