Skip to content

Commit

Permalink
add a helper function for fetching root items
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed Sep 3, 2017
1 parent 4ad0175 commit 80d834e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Expand Up @@ -40,6 +40,8 @@ dependencies {
compile 'com.simplemobiletools:commons:2.27.7'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

compile files('../libs/RootTools.jar')
}

buildscript {
Expand Down
@@ -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 added libs/RootTools.jar
Binary file not shown.

0 comments on commit 80d834e

Please sign in to comment.