list the root files that should be visible

This commit is contained in:
tibbi 2017-09-03 20:09:03 +02:00
parent 57aa9054f2
commit 2532c43f7e
2 changed files with 16 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.adapters.ItemsAdapter import com.simplemobiletools.filemanager.adapters.ItemsAdapter
import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog import com.simplemobiletools.filemanager.dialogs.CreateNewItemDialog
import com.simplemobiletools.filemanager.extensions.config import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.helpers.RootHelpers
import kotlinx.android.synthetic.main.items_fragment.* import kotlinx.android.synthetic.main.items_fragment.*
import kotlinx.android.synthetic.main.items_fragment.view.* import kotlinx.android.synthetic.main.items_fragment.view.*
import java.io.File import java.io.File
@ -188,7 +189,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
} }
private fun getRootItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) { private fun getRootItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
RootHelpers().getFiles(context, path, callback)
} }
private fun getChildren(file: File): Int { private fun getChildren(file: File): Int {

View File

@ -1,8 +1,10 @@
package com.simplemobiletools.filemanager.helpers package com.simplemobiletools.filemanager.helpers
import android.content.Context
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.activities.SimpleActivity import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.simplemobiletools.filemanager.extensions.config
import com.stericson.RootShell.execution.Command import com.stericson.RootShell.execution.Command
import com.stericson.RootTools.RootTools import com.stericson.RootTools.RootTools
@ -33,18 +35,22 @@ class RootHelpers {
} }
} }
fun getFiles(path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) { fun getFiles(context: Context, path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
val files = ArrayList<FileDirItem>()
val showHidden = context.config.shouldShowHidden
val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") { val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") {
override fun commandOutput(id: Int, line: String) { override fun commandOutput(id: Int, line: String) {
val parts = line.split(" ") val parts = line.split(" ")
val files = ArrayList<FileDirItem>()
val filename = parts[1] val filename = parts[1]
val filePath = "${path.trimEnd('/')}/$filename" if (showHidden || !filename.startsWith(".")) {
val isDirectory = parts[0].startsWith("d") val filePath = "${path.trimEnd('/')}/$filename"
val fileDirItem = FileDirItem(filePath, filename, isDirectory, 0, 0) val isDirectory = parts[0].startsWith("d")
files.add(fileDirItem) val fileDirItem = FileDirItem(filePath, filename, isDirectory, 0, 0)
callback(files) files.add(fileDirItem)
}
super.commandOutput(id, line) super.commandOutput(id, line)
} }
@ -54,6 +60,7 @@ class RootHelpers {
override fun commandCompleted(id: Int, exitcode: Int) { override fun commandCompleted(id: Int, exitcode: Int) {
super.commandCompleted(id, exitcode) super.commandCompleted(id, exitcode)
callback(files)
} }
} }
RootTools.getShell(true).add(command) RootTools.getShell(true).add(command)