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"
minSdkVersion 21
targetSdkVersion 29
versionCode 19
versionName "1.6.0"
versionCode 20
versionName "1.7.0"
ndk {
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

View File

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

View File

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