forked from hardcoresushi/DroidFS
Thread-safe directory listing
This commit is contained in:
parent
e5ed825557
commit
f58517e904
@ -26,19 +26,19 @@ import sushi.hardcore.droidfs.ConstValues.Companion.isAudio
|
|||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isImage
|
import sushi.hardcore.droidfs.ConstValues.Companion.isImage
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isText
|
import sushi.hardcore.droidfs.ConstValues.Companion.isText
|
||||||
import sushi.hardcore.droidfs.ConstValues.Companion.isVideo
|
import sushi.hardcore.droidfs.ConstValues.Companion.isVideo
|
||||||
import sushi.hardcore.droidfs.file_operations.FileOperationService
|
import sushi.hardcore.droidfs.GocryptfsVolume
|
||||||
import sushi.hardcore.droidfs.R
|
import sushi.hardcore.droidfs.R
|
||||||
import sushi.hardcore.droidfs.adapters.DialogSingleChoiceAdapter
|
import sushi.hardcore.droidfs.adapters.DialogSingleChoiceAdapter
|
||||||
import sushi.hardcore.droidfs.adapters.ExplorerElementAdapter
|
import sushi.hardcore.droidfs.adapters.ExplorerElementAdapter
|
||||||
import sushi.hardcore.droidfs.adapters.OpenAsDialogAdapter
|
import sushi.hardcore.droidfs.adapters.OpenAsDialogAdapter
|
||||||
|
import sushi.hardcore.droidfs.content_providers.ExternalProvider
|
||||||
|
import sushi.hardcore.droidfs.content_providers.RestrictedFileProvider
|
||||||
|
import sushi.hardcore.droidfs.file_operations.FileOperationService
|
||||||
import sushi.hardcore.droidfs.file_operations.OperationFile
|
import sushi.hardcore.droidfs.file_operations.OperationFile
|
||||||
import sushi.hardcore.droidfs.file_viewers.AudioPlayer
|
import sushi.hardcore.droidfs.file_viewers.AudioPlayer
|
||||||
import sushi.hardcore.droidfs.file_viewers.ImageViewer
|
import sushi.hardcore.droidfs.file_viewers.ImageViewer
|
||||||
import sushi.hardcore.droidfs.file_viewers.TextEditor
|
import sushi.hardcore.droidfs.file_viewers.TextEditor
|
||||||
import sushi.hardcore.droidfs.file_viewers.VideoPlayer
|
import sushi.hardcore.droidfs.file_viewers.VideoPlayer
|
||||||
import sushi.hardcore.droidfs.content_providers.RestrictedFileProvider
|
|
||||||
import sushi.hardcore.droidfs.content_providers.ExternalProvider
|
|
||||||
import sushi.hardcore.droidfs.GocryptfsVolume
|
|
||||||
import sushi.hardcore.droidfs.util.PathUtils
|
import sushi.hardcore.droidfs.util.PathUtils
|
||||||
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
|
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
|
||||||
|
|
||||||
@ -214,34 +214,42 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun setCurrentPath(path: String) {
|
protected fun setCurrentPath(path: String) {
|
||||||
explorerElements = gocryptfsVolume.listDir(path)
|
synchronized(this) {
|
||||||
|
explorerElements = gocryptfsVolume.listDir(path)
|
||||||
|
}
|
||||||
textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.INVISIBLE
|
textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.INVISIBLE
|
||||||
currentDirectoryPath = path
|
currentDirectoryPath = path
|
||||||
currentPathText.text = getString(R.string.location, currentDirectoryPath)
|
currentPathText.text = getString(R.string.location, currentDirectoryPath)
|
||||||
Thread{
|
Thread{
|
||||||
var totalSize: Long = 0
|
var totalSize: Long = 0
|
||||||
for (element in explorerElements){
|
synchronized(this) {
|
||||||
if (element.isDirectory){
|
for (element in explorerElements){
|
||||||
var dirSize: Long = 0
|
if (element.isDirectory){
|
||||||
for (subFile in gocryptfsVolume.recursiveMapFiles(element.fullPath)){
|
var dirSize: Long = 0
|
||||||
if (subFile.isRegularFile){
|
for (subFile in gocryptfsVolume.recursiveMapFiles(element.fullPath)){
|
||||||
dirSize += subFile.size
|
if (subFile.isRegularFile){
|
||||||
|
dirSize += subFile.size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
element.size = dirSize
|
||||||
|
totalSize += dirSize
|
||||||
|
} else if (element.isRegularFile) {
|
||||||
|
totalSize += element.size
|
||||||
}
|
}
|
||||||
element.size = dirSize
|
|
||||||
totalSize += dirSize
|
|
||||||
} else if (element.isRegularFile) {
|
|
||||||
totalSize += element.size
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
totalSizeText.text = getString(R.string.total_size, PathUtils.formatSize(totalSize))
|
totalSizeText.text = getString(R.string.total_size, PathUtils.formatSize(totalSize))
|
||||||
sortExplorerElements()
|
synchronized(this) {
|
||||||
|
sortExplorerElements()
|
||||||
|
}
|
||||||
if (path.isNotEmpty()) { //not root
|
if (path.isNotEmpty()) { //not root
|
||||||
explorerElements.add(
|
synchronized(this) {
|
||||||
0,
|
explorerElements.add(
|
||||||
ExplorerElement("..", (-1).toShort(), -1, -1, currentDirectoryPath)
|
0,
|
||||||
)
|
ExplorerElement("..", (-1).toShort(), -1, -1, currentDirectoryPath)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
explorerAdapter.setExplorerElements(explorerElements)
|
explorerAdapter.setExplorerElements(explorerElements)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user