mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Fix remove action for natural order
This commit is contained in:
@@ -54,6 +54,7 @@ import com.kunzisoft.keepass.autofill.AutofillHelper
|
||||
import com.kunzisoft.keepass.database.SortNodeEnum
|
||||
import com.kunzisoft.keepass.database.action.ProgressDialogSaveDatabaseThread
|
||||
import com.kunzisoft.keepass.database.action.node.*
|
||||
import com.kunzisoft.keepass.database.action.node.ActionNodeDatabaseRunnable.Companion.NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY
|
||||
import com.kunzisoft.keepass.database.element.*
|
||||
import com.kunzisoft.keepass.education.GroupActivityEducation
|
||||
import com.kunzisoft.keepass.icons.assignDatabaseIcon
|
||||
@@ -61,7 +62,6 @@ import com.kunzisoft.keepass.magikeyboard.KeyboardHelper
|
||||
import com.kunzisoft.keepass.magikeyboard.MagikIME
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.timeout.TimeoutHelper
|
||||
import com.kunzisoft.keepass.utils.LOCK_ACTION
|
||||
import com.kunzisoft.keepass.utils.MenuUtil
|
||||
import com.kunzisoft.keepass.view.AddNodeButtonView
|
||||
import net.cachapa.expandablelayout.ExpandableLayout
|
||||
@@ -812,22 +812,30 @@ class GroupActivity : LockingActivity(),
|
||||
override fun onActionNodeFinish(actionNodeValues: ActionNodeValues) {
|
||||
runOnUiThread {
|
||||
if (actionNodeValues.result.isSuccess) {
|
||||
actionNodeValues.oldNode?.let { oldNode ->
|
||||
|
||||
mListNodesFragment?.removeNode(oldNode)
|
||||
// If the action register the position, use it to remove the entry view
|
||||
val positionNode = actionNodeValues.result.data?.getInt(NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY)
|
||||
if (PreferencesUtil.getListSort(this@GroupActivity) == SortNodeEnum.DB
|
||||
&& positionNode != null) {
|
||||
mListNodesFragment?.removeNodeAt(positionNode)
|
||||
} else {
|
||||
// else use the old Node that was the entry unchanged with the old parent
|
||||
actionNodeValues.oldNode?.let { oldNode ->
|
||||
mListNodesFragment?.removeNode(oldNode)
|
||||
}
|
||||
}
|
||||
|
||||
// Add trash in views list if it doesn't exists
|
||||
val database = Database.getInstance()
|
||||
if (database.isRecycleBinEnabled) {
|
||||
val recycleBin = database.recycleBin
|
||||
if (mCurrentGroup != null && recycleBin != null
|
||||
// Add trash in views list if it doesn't exists
|
||||
val database = Database.getInstance()
|
||||
if (database.isRecycleBinEnabled) {
|
||||
val recycleBin = database.recycleBin
|
||||
if (mCurrentGroup != null && recycleBin != null
|
||||
&& mCurrentGroup!!.parent == null
|
||||
&& mCurrentGroup != recycleBin) {
|
||||
if (mListNodesFragment?.contains(recycleBin) == true)
|
||||
mListNodesFragment?.updateNode(recycleBin)
|
||||
else
|
||||
mListNodesFragment?.addNode(recycleBin)
|
||||
}
|
||||
if (mListNodesFragment?.contains(recycleBin) == true)
|
||||
mListNodesFragment?.updateNode(recycleBin)
|
||||
else
|
||||
mListNodesFragment?.addNode(recycleBin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.activities.stylish.StylishFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import org.w3c.dom.Node
|
||||
|
||||
class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionListener {
|
||||
|
||||
@@ -269,6 +268,10 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
mAdapter?.removeNode(pwNode)
|
||||
}
|
||||
|
||||
fun removeNodeAt(position: Int) {
|
||||
mAdapter?.removeNodeAt(position)
|
||||
}
|
||||
|
||||
interface OnScrollListener {
|
||||
|
||||
/**
|
||||
|
||||
@@ -171,6 +171,13 @@ class NodeAdapter
|
||||
nodeSortedList.remove(node)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a node at [position] in the list
|
||||
*/
|
||||
fun removeNodeAt(position: Int) {
|
||||
nodeSortedList.removeItemAt(position)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a node in the list
|
||||
* @param oldNode Node before the update
|
||||
|
||||
@@ -31,7 +31,7 @@ enum class SortNodeEnum {
|
||||
|
||||
fun getNodeComparator(ascending: Boolean, groupsBefore: Boolean, recycleBinBottom: Boolean): Comparator<NodeVersioned> {
|
||||
return when (this) {
|
||||
DB -> NodeNaturalComparator(ascending, groupsBefore, recycleBinBottom)
|
||||
DB -> NodeNaturalComparator(ascending, groupsBefore, false) // Force false because natural order contains recycle bin
|
||||
TITLE -> NodeTitleComparator(ascending, groupsBefore, recycleBinBottom)
|
||||
USERNAME -> NodeUsernameComparator(ascending, groupsBefore, recycleBinBottom)
|
||||
CREATION_TIME -> NodeCreationComparator(ascending, groupsBefore, recycleBinBottom)
|
||||
|
||||
@@ -45,4 +45,8 @@ abstract class ActionNodeDatabaseRunnable(
|
||||
|
||||
super.onFinishRun(result)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY = "NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.FragmentActivity
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.EntryVersioned
|
||||
@@ -35,11 +36,19 @@ class DeleteEntryRunnable constructor(
|
||||
private var mParent: GroupVersioned? = null
|
||||
private var mCanRecycle: Boolean = false
|
||||
|
||||
private var mEntryToDeleteBackup: EntryVersioned? = null
|
||||
private var mNodePosition: Int? = null
|
||||
|
||||
override fun nodeAction() {
|
||||
mParent = mEntryToDelete.parent
|
||||
mParent?.touch(modified = false, touchParents = true)
|
||||
|
||||
// Get the node position
|
||||
mNodePosition = mEntryToDelete.nodePositionInParent
|
||||
|
||||
// Create a copy to keep the old ref and remove it visually
|
||||
mEntryToDeleteBackup = EntryVersioned(mEntryToDelete)
|
||||
|
||||
// Remove Entry from parent
|
||||
mCanRecycle = database.canRecycle(mEntryToDelete)
|
||||
if (mCanRecycle) {
|
||||
@@ -59,6 +68,16 @@ class DeleteEntryRunnable constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
return ActionNodeValues(result, mEntryToDelete, null)
|
||||
|
||||
// Add position in bundle to delete the node in view
|
||||
mNodePosition?.let { position ->
|
||||
result.data = Bundle().apply {
|
||||
putInt(NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY, position )
|
||||
}
|
||||
}
|
||||
|
||||
// Return a copy of unchanged entry as old param
|
||||
// and entry deleted or moved in recycle bin as new param
|
||||
return ActionNodeValues(result, mEntryToDeleteBackup, mEntryToDelete)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.action.node
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v4.app.FragmentActivity
|
||||
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
@@ -32,10 +33,19 @@ class DeleteGroupRunnable(context: FragmentActivity,
|
||||
private var mParent: GroupVersioned? = null
|
||||
private var mRecycle: Boolean = false
|
||||
|
||||
private var mGroupToDeleteBackup: GroupVersioned? = null
|
||||
private var mNodePosition: Int? = null
|
||||
|
||||
override fun nodeAction() {
|
||||
mParent = mGroupToDelete.parent
|
||||
mParent?.touch(modified = false, touchParents = true)
|
||||
|
||||
// Get the node position
|
||||
mNodePosition = mGroupToDelete.nodePositionInParent
|
||||
|
||||
// Create a copy to keep the old ref and remove it visually
|
||||
mGroupToDeleteBackup = GroupVersioned(mGroupToDelete)
|
||||
|
||||
// Remove Group from parent
|
||||
mRecycle = database.canRecycle(mGroupToDelete)
|
||||
if (mRecycle) {
|
||||
@@ -56,6 +66,16 @@ class DeleteGroupRunnable(context: FragmentActivity,
|
||||
// TODO database.undoDeleteGroupFrom(mGroup, mParent);
|
||||
}
|
||||
}
|
||||
return ActionNodeValues(result, mGroupToDelete, null)
|
||||
|
||||
// Add position in bundle to delete the node in view
|
||||
mNodePosition?.let { position ->
|
||||
result.data = Bundle().apply {
|
||||
putInt(NODE_POSITION_FOR_ACTION_NATURAL_ORDER_KEY, position )
|
||||
}
|
||||
}
|
||||
|
||||
// Return a copy of unchanged group as old param
|
||||
// and group deleted or moved in recycle bin as new param
|
||||
return ActionNodeValues(result, mGroupToDeleteBackup, mGroupToDelete)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.tasks
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
|
||||
@@ -88,5 +89,5 @@ abstract class ActionRunnable(private var nestedActionRunnable: ActionRunnable?
|
||||
/**
|
||||
* Class to manage result from ActionRunnable
|
||||
*/
|
||||
data class Result(var isSuccess: Boolean = true, var message: String? = null)
|
||||
data class Result(var isSuccess: Boolean = true, var message: String? = null, var data: Bundle? = null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user