Fix bugs when renaming

This commit is contained in:
Matéo Duparc 2021-11-11 20:14:48 +01:00
parent 23a20b7ddb
commit 2ee0c679fb
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
3 changed files with 38 additions and 31 deletions

View File

@ -14,8 +14,8 @@ android {
applicationId "sushi.hardcore.droidfs" applicationId "sushi.hardcore.droidfs"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 19 versionCode 20
versionName "1.6.0" versionName "1.7.0"
ndk { ndk {
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a" abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

View File

@ -217,22 +217,32 @@ open class BaseExplorerActivity : BaseActivity() {
invalidateOptionsMenu() invalidateOptionsMenu()
} }
private fun sortExplorerElements() { private fun displayExplorerElements(totalSizeValue: String) {
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], foldersFirst, explorerElements) totalSizeText.text = getString(R.string.total_size, totalSizeValue)
synchronized(this) {
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], foldersFirst, explorerElements)
}
explorerAdapter.explorerElements = explorerElements
val sharedPrefsEditor = sharedPrefs.edit() val sharedPrefsEditor = sharedPrefs.edit()
sharedPrefsEditor.putString(ConstValues.sort_order_key, sortOrderValues[currentSortOrderIndex]) sharedPrefsEditor.putString(ConstValues.sort_order_key, sortOrderValues[currentSortOrderIndex])
sharedPrefsEditor.apply() sharedPrefsEditor.apply()
} }
protected fun setCurrentPath(path: String) { protected fun setCurrentPath(path: String, onDisplayed: (() -> Unit)? = null) {
synchronized(this) { synchronized(this) {
explorerElements = gocryptfsVolume.listDir(path) explorerElements = gocryptfsVolume.listDir(path)
if (path.isNotEmpty()) { //not root
explorerElements.add(
0,
ExplorerElement("..", (-1).toShort(), parentPath = currentDirectoryPath)
)
}
} }
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{ if (mapFolders) {
val totalSizeValue = if (mapFolders) { Thread {
var totalSize: Long = 0 var totalSize: Long = 0
synchronized(this) { synchronized(this) {
for (element in explorerElements){ for (element in explorerElements){
@ -250,26 +260,16 @@ open class BaseExplorerActivity : BaseActivity() {
} }
} }
} }
PathUtils.formatSize(totalSize) val totalSizeValue = PathUtils.formatSize(totalSize)
} else { runOnUiThread {
getString(R.string.default_total_size) displayExplorerElements(totalSizeValue)
} onDisplayed?.invoke()
runOnUiThread {
totalSizeText.text = getString(R.string.total_size, totalSizeValue)
synchronized(this) {
sortExplorerElements()
} }
if (path.isNotEmpty()) { //not root }.start()
synchronized(this) { } else {
explorerElements.add( displayExplorerElements(getString(R.string.default_total_size))
0, onDisplayed?.invoke()
ExplorerElement("..", (-1).toShort(), parentPath = currentDirectoryPath) }
)
}
}
explorerAdapter.explorerElements = explorerElements
}
}.start()
} }
private fun askCloseVolume() { private fun askCloseVolume() {
@ -458,8 +458,9 @@ open class BaseExplorerActivity : BaseActivity() {
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.show() .show()
} else { } else {
setCurrentPath(currentDirectoryPath) setCurrentPath(currentDirectoryPath) {
invalidateOptionsMenu() invalidateOptionsMenu()
}
} }
} }
} }

View File

@ -37,10 +37,16 @@ class ExplorerElement(val name: String, val elementType: Short, var size: Long =
} }
} }
private fun doSort(a: ExplorerElement, b: ExplorerElement, foldersFirst: Boolean, sorter: () -> Int): Int { private fun doSort(a: ExplorerElement, b: ExplorerElement, foldersFirst: Boolean, sorter: () -> Int): Int {
return if (foldersFirst) { return if (b.isParentFolder) {
foldersFirst(a, b, sorter) 1
} else if (a.isParentFolder) {
-1
} else { } else {
sorter() if (foldersFirst) {
foldersFirst(a, b, sorter)
} else {
sorter()
}
} }
} }
fun sortBy(sortOrder: String, foldersFirst: Boolean, explorerElements: MutableList<ExplorerElement>) { fun sortBy(sortOrder: String, foldersFirst: Boolean, explorerElements: MutableList<ExplorerElement>) {