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.isText
|
||||
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.adapters.DialogSingleChoiceAdapter
|
||||
import sushi.hardcore.droidfs.adapters.ExplorerElementAdapter
|
||||
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_viewers.AudioPlayer
|
||||
import sushi.hardcore.droidfs.file_viewers.ImageViewer
|
||||
import sushi.hardcore.droidfs.file_viewers.TextEditor
|
||||
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.widgets.ColoredAlertDialogBuilder
|
||||
|
||||
@ -214,12 +214,15 @@ open class BaseExplorerActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
protected fun setCurrentPath(path: String) {
|
||||
synchronized(this) {
|
||||
explorerElements = gocryptfsVolume.listDir(path)
|
||||
}
|
||||
textDirEmpty.visibility = if (explorerElements.size == 0) View.VISIBLE else View.INVISIBLE
|
||||
currentDirectoryPath = path
|
||||
currentPathText.text = getString(R.string.location, currentDirectoryPath)
|
||||
Thread{
|
||||
var totalSize: Long = 0
|
||||
synchronized(this) {
|
||||
for (element in explorerElements){
|
||||
if (element.isDirectory){
|
||||
var dirSize: Long = 0
|
||||
@ -234,15 +237,20 @@ open class BaseExplorerActivity : BaseActivity() {
|
||||
totalSize += element.size
|
||||
}
|
||||
}
|
||||
}
|
||||
runOnUiThread {
|
||||
totalSizeText.text = getString(R.string.total_size, PathUtils.formatSize(totalSize))
|
||||
synchronized(this) {
|
||||
sortExplorerElements()
|
||||
}
|
||||
if (path.isNotEmpty()) { //not root
|
||||
synchronized(this) {
|
||||
explorerElements.add(
|
||||
0,
|
||||
ExplorerElement("..", (-1).toShort(), -1, -1, currentDirectoryPath)
|
||||
)
|
||||
}
|
||||
}
|
||||
explorerAdapter.setExplorerElements(explorerElements)
|
||||
}
|
||||
}.start()
|
||||
|
Loading…
Reference in New Issue
Block a user