mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-02-17 04:10:39 +01:00
properly determine if the given root item is a file or folder
This commit is contained in:
parent
8f336838f5
commit
20183d448d
@ -32,22 +32,47 @@ class RootHelpers(val activity: Activity) {
|
|||||||
val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
|
val hiddenArgument = if (activity.config.shouldShowHidden) "-A " else ""
|
||||||
val cmd = "ls $hiddenArgument$path"
|
val cmd = "ls $hiddenArgument$path"
|
||||||
|
|
||||||
|
getFullLines(path) {
|
||||||
|
val fullLines = it
|
||||||
|
|
||||||
|
val command = object : Command(0, cmd) {
|
||||||
|
override fun commandOutput(id: Int, line: String) {
|
||||||
|
val file = File(path, line)
|
||||||
|
val fullLine = fullLines.firstOrNull { it.endsWith(" $line") }
|
||||||
|
val isDirectory = fullLine?.startsWith('d') ?: file.isDirectory
|
||||||
|
val fileDirItem = FileDirItem(file.absolutePath, line, isDirectory, 0, 0)
|
||||||
|
files.add(fileDirItem)
|
||||||
|
super.commandOutput(id, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun commandCompleted(id: Int, exitcode: Int) {
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
callback(path, files)
|
||||||
|
} else {
|
||||||
|
getChildrenCount(files, path, callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
super.commandCompleted(id, exitcode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runCommand(command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getFullLines(path: String, callback: (ArrayList<String>) -> Unit) {
|
||||||
|
val fullLines = ArrayList<String>()
|
||||||
|
val hiddenArgument = if (activity.config.shouldShowHidden) "-Al " else "-l "
|
||||||
|
val cmd = "ls $hiddenArgument$path"
|
||||||
|
|
||||||
val command = object : Command(0, cmd) {
|
val command = object : Command(0, cmd) {
|
||||||
override fun commandOutput(id: Int, line: String) {
|
override fun commandOutput(id: Int, line: String) {
|
||||||
val file = File(path, line)
|
fullLines.add(line)
|
||||||
val isDirectory = file.isDirectory
|
|
||||||
val fileDirItem = FileDirItem(file.absolutePath, line, isDirectory, 0, 0)
|
|
||||||
files.add(fileDirItem)
|
|
||||||
super.commandOutput(id, line)
|
super.commandOutput(id, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun commandCompleted(id: Int, exitcode: Int) {
|
override fun commandCompleted(id: Int, exitcode: Int) {
|
||||||
if (files.isEmpty()) {
|
callback(fullLines)
|
||||||
callback(path, files)
|
|
||||||
} else {
|
|
||||||
getChildrenCount(files, path, callback)
|
|
||||||
}
|
|
||||||
|
|
||||||
super.commandCompleted(id, exitcode)
|
super.commandCompleted(id, exitcode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user