Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a helper function for fetching root items
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/kotlin/com/simplemobiletools/filemanager/helpers/RootHelpers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.simplemobiletools.filemanager.helpers | ||
|
||
import com.simplemobiletools.commons.models.FileDirItem | ||
import com.stericson.RootShell.execution.Command | ||
import com.stericson.RootTools.RootTools | ||
|
||
class RootHelpers { | ||
fun getFiles(path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) { | ||
val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") { | ||
override fun commandOutput(id: Int, line: String) { | ||
super.commandOutput(id, line) | ||
val parts = line.split(" ") | ||
|
||
val files = ArrayList<FileDirItem>() | ||
val filename = parts[1] | ||
val filePath = "${path.trimEnd('/')}/$filename" | ||
val isDirectory = parts[0].startsWith("d") | ||
val fileDirItem = FileDirItem(filePath, filename, isDirectory, 0, 0) | ||
files.add(fileDirItem) | ||
callback(files) | ||
} | ||
|
||
override fun commandTerminated(id: Int, reason: String?) { | ||
super.commandTerminated(id, reason) | ||
} | ||
|
||
override fun commandCompleted(id: Int, exitcode: Int) { | ||
super.commandCompleted(id, exitcode) | ||
} | ||
} | ||
RootTools.getShell(true).add(command) | ||
} | ||
} |
Binary file not shown.