properly fetch root filediritem children counts and file sizes
This commit is contained in:
parent
4d5a4098b4
commit
641658ead6
|
@ -189,7 +189,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
|
|||
}
|
||||
|
||||
private fun getRootItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
|
||||
RootHelpers().getFiles(context, path, callback)
|
||||
RootHelpers().getFiles(context, path.trimEnd('/'), callback)
|
||||
}
|
||||
|
||||
private fun getChildren(file: File): Int {
|
||||
|
|
|
@ -43,7 +43,7 @@ class RootHelpers {
|
|||
override fun commandOutput(id: Int, line: String) {
|
||||
val parts = line.split(" ")
|
||||
|
||||
val filename = parts[1]
|
||||
val filename = parts[1].trimStart('/')
|
||||
if (showHidden || !filename.startsWith(".")) {
|
||||
val filePath = "${path.trimEnd('/')}/$filename"
|
||||
val isDirectory = parts[0].startsWith("d")
|
||||
|
@ -60,9 +60,40 @@ class RootHelpers {
|
|||
|
||||
override fun commandCompleted(id: Int, exitcode: Int) {
|
||||
super.commandCompleted(id, exitcode)
|
||||
callback(files)
|
||||
getFileDirParameters(files, callback)
|
||||
}
|
||||
}
|
||||
RootTools.getShell(true).add(command)
|
||||
}
|
||||
|
||||
fun getFileDirParameters(oldItems: ArrayList<FileDirItem>, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
|
||||
val files = ArrayList<FileDirItem>()
|
||||
oldItems.forEach {
|
||||
val childrenCount = "find ${it.path} -mindepth 1 -maxdepth 1 | wc -l"
|
||||
val fileSize = if (it.isDirectory) "" else "wc -c < ${it.path}"
|
||||
val command = object : Command(0, "echo $($childrenCount) $($fileSize)") {
|
||||
override fun commandOutput(id: Int, line: String) {
|
||||
val areDigitsOnly = line.matches(Regex("[0-9 ]+"))
|
||||
if (areDigitsOnly) {
|
||||
val parts = line.split(' ')
|
||||
val children = parts[0].toInt()
|
||||
val bytes = if (parts.size > 1) parts[1].toLong() else 0L
|
||||
val fileDirItem = FileDirItem(it.path, it.name, it.isDirectory, children, bytes)
|
||||
files.add(fileDirItem)
|
||||
}
|
||||
super.commandOutput(id, line)
|
||||
}
|
||||
|
||||
override fun commandTerminated(id: Int, reason: String?) {
|
||||
super.commandTerminated(id, reason)
|
||||
}
|
||||
|
||||
override fun commandCompleted(id: Int, exitcode: Int) {
|
||||
callback(files)
|
||||
super.commandCompleted(id, exitcode)
|
||||
}
|
||||
}
|
||||
RootTools.getShell(true).add(command)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue