mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Beter code
This commit is contained in:
@@ -581,6 +581,7 @@ class GroupActivity : LockingActivity(),
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -328,6 +328,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
R.id.menu_paste -> {
|
||||
val returnValue = menuListener.onPasteMenuClick(nodeActionPasteMode, nodes)
|
||||
nodeActionPasteMode = PasteMode.UNDEFINED
|
||||
nodeActionSelectionMode = false
|
||||
returnValue
|
||||
}
|
||||
else -> false
|
||||
|
||||
@@ -26,12 +26,13 @@ import com.kunzisoft.keepass.tasks.ActionRunnable
|
||||
import java.io.IOException
|
||||
|
||||
abstract class SaveDatabaseRunnable(protected var context: Context,
|
||||
protected var database: Database,
|
||||
private val save: Boolean,
|
||||
nestedAction: ActionRunnable? = null) : ActionRunnable(nestedAction) {
|
||||
protected var database: Database,
|
||||
protected var saveDatabase: Boolean,
|
||||
nestedAction: ActionRunnable? = null)
|
||||
: ActionRunnable(nestedAction) {
|
||||
|
||||
override fun run() {
|
||||
if (save) {
|
||||
if (saveDatabase) {
|
||||
try {
|
||||
database.saveData(context.contentResolver)
|
||||
} catch (e: IOException) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.kunzisoft.keepass.database.action.node
|
||||
import android.content.Context
|
||||
import com.kunzisoft.keepass.database.action.SaveDatabaseRunnable
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.exception.LoadDatabaseException
|
||||
|
||||
abstract class ActionNodeDatabaseRunnable(
|
||||
context: Context,
|
||||
@@ -23,6 +24,12 @@ abstract class ActionNodeDatabaseRunnable(
|
||||
}
|
||||
}
|
||||
|
||||
protected fun throwErrorAndFinish(throwable: LoadDatabaseException) {
|
||||
saveDatabase = false
|
||||
super.run()
|
||||
finishRun(false, throwable)
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
nodeAction()
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class CopyNodesRunnable constructor(
|
||||
when (currentNode.type) {
|
||||
Type.GROUP -> {
|
||||
Log.e(TAG, "Copy not allowed for group")// Only finish thread
|
||||
finishRun(false, CopyDatabaseGroupException())
|
||||
throwErrorAndFinish(CopyDatabaseGroupException())
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
// Root can contains entry
|
||||
@@ -55,11 +55,11 @@ class CopyNodesRunnable constructor(
|
||||
mEntriesCopied.add(entryCopied)
|
||||
} ?: run {
|
||||
Log.e(TAG, "Unable to create a copy of the entry")
|
||||
finishRun(false, CopyDatabaseEntryException())
|
||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
||||
}
|
||||
} else {
|
||||
// Only finish thread
|
||||
finishRun(false, CopyDatabaseEntryException())
|
||||
throwErrorAndFinish(CopyDatabaseEntryException())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class MoveNodesRunnable constructor(
|
||||
database.moveGroupTo(groupToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
finishRun(false, MoveDatabaseGroupException())
|
||||
throwErrorAndFinish(MoveDatabaseGroupException())
|
||||
}
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
@@ -64,7 +64,7 @@ class MoveNodesRunnable constructor(
|
||||
database.moveEntryTo(entryToMove, mNewParent)
|
||||
} else {
|
||||
// Only finish thread
|
||||
finishRun(false, MoveDatabaseEntryException())
|
||||
throwErrorAndFinish(MoveDatabaseEntryException())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user