mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better node action refresh
This commit is contained in:
@@ -443,9 +443,14 @@ class GroupActivity : LockingActivity(),
|
||||
|
||||
private var actionNodeMode: ActionMode? = null
|
||||
|
||||
private fun finishNodeAction() {
|
||||
actionNodeMode?.finish()
|
||||
actionNodeMode = null
|
||||
}
|
||||
|
||||
override fun onNodeSelected(nodes: List<NodeVersioned>): Boolean {
|
||||
if (nodes.isNotEmpty()) {
|
||||
if (actionNodeMode == null) {
|
||||
if (actionNodeMode == null || toolbarAction?.getSupportActionModeCallback() == null) {
|
||||
mListNodesFragment?.actionNodesCallback(nodes, this)?.let {
|
||||
actionNodeMode = toolbarAction?.startSupportActionMode(it)
|
||||
}
|
||||
@@ -453,19 +458,19 @@ class GroupActivity : LockingActivity(),
|
||||
actionNodeMode?.invalidate()
|
||||
}
|
||||
} else {
|
||||
actionNodeMode?.finish()
|
||||
finishNodeAction()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOpenMenuClick(node: NodeVersioned): Boolean {
|
||||
actionNodeMode?.finish()
|
||||
finishNodeAction()
|
||||
onNodeClick(node)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onEditMenuClick(node: NodeVersioned): Boolean {
|
||||
actionNodeMode?.finish()
|
||||
finishNodeAction()
|
||||
when (node.type) {
|
||||
Type.GROUP -> {
|
||||
mOldGroupToUpdate = node as GroupVersioned
|
||||
@@ -532,13 +537,14 @@ class GroupActivity : LockingActivity(),
|
||||
}
|
||||
|
||||
override fun onDeleteMenuClick(nodes: List<NodeVersioned>): Boolean {
|
||||
val node = nodes[0]
|
||||
actionNodeMode?.finish()
|
||||
// TODO multiple deletion
|
||||
when (node.type) {
|
||||
Type.GROUP -> deleteGroup(node as GroupVersioned)
|
||||
Type.ENTRY -> deleteEntry(node as EntryVersioned)
|
||||
// TODO multiple copy
|
||||
nodes.forEach {
|
||||
when (it.type) {
|
||||
Type.GROUP -> deleteGroup(it as GroupVersioned)
|
||||
Type.ENTRY -> deleteEntry(it as EntryVersioned)
|
||||
}
|
||||
}
|
||||
finishNodeAction()
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -598,6 +604,7 @@ class GroupActivity : LockingActivity(),
|
||||
mNodeToMove = null
|
||||
}
|
||||
}
|
||||
finishNodeAction()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
mAdapter = NodeAdapter(context)
|
||||
mAdapter?.apply {
|
||||
setOnNodeClickListener(object : NodeAdapter.NodeClickCallback {
|
||||
override fun onNodeClick(node: NodeVersioned, position: Int) {
|
||||
override fun onNodeClick(node: NodeVersioned) {
|
||||
if (nodeActionSelectionMode) {
|
||||
if (listActionNodes.contains(node)) {
|
||||
// Remove selected item if already selected
|
||||
@@ -110,13 +110,13 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
}
|
||||
nodeClickListener?.onNodeSelected(listActionNodes)
|
||||
setActionNodes(listActionNodes)
|
||||
notifyItemChanged(position)
|
||||
notifyNodeChanged(node)
|
||||
} else {
|
||||
nodeClickListener?.onNodeClick(node)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNodeLongClick(node: NodeVersioned, position: Int): Boolean {
|
||||
override fun onNodeLongClick(node: NodeVersioned): Boolean {
|
||||
// Select the first item after a long click
|
||||
if (!listActionNodes.contains(node))
|
||||
listActionNodes.add(node)
|
||||
@@ -124,7 +124,7 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
nodeClickListener?.onNodeSelected(listActionNodes)
|
||||
|
||||
setActionNodes(listActionNodes)
|
||||
notifyItemChanged(position)
|
||||
notifyNodeChanged(node)
|
||||
return true
|
||||
}
|
||||
})
|
||||
@@ -321,7 +321,6 @@ class ListNodesFragment : StylishFragment(), SortDialogFragment.SortSelectionLis
|
||||
R.id.menu_delete -> menuListener.onDeleteMenuClick(nodes)
|
||||
R.id.menu_paste -> {
|
||||
val returnValue = menuListener.onPasteMenuClick(pasteMode, nodes)
|
||||
mode?.finish()
|
||||
pasteMode = null
|
||||
returnValue
|
||||
}
|
||||
|
||||
@@ -185,6 +185,10 @@ class NodeAdapter
|
||||
nodeSortedList.endBatchedUpdates()
|
||||
}
|
||||
|
||||
fun notifyNodeChanged(node: NodeVersioned) {
|
||||
notifyItemChanged(nodeSortedList.indexOf(node))
|
||||
}
|
||||
|
||||
fun setActionNodes(actionNodes: List<NodeVersioned>) {
|
||||
this.actionNodesList.apply {
|
||||
clear()
|
||||
@@ -249,10 +253,10 @@ class NodeAdapter
|
||||
}
|
||||
// Assign click
|
||||
holder.container.setOnClickListener {
|
||||
nodeClickCallback?.onNodeClick(subNode, position)
|
||||
nodeClickCallback?.onNodeClick(subNode)
|
||||
}
|
||||
holder.container.setOnLongClickListener {
|
||||
nodeClickCallback?.onNodeLongClick(subNode, position) ?: false
|
||||
nodeClickCallback?.onNodeLongClick(subNode) ?: false
|
||||
}
|
||||
|
||||
holder.container.isSelected = actionNodesList.contains(subNode)
|
||||
@@ -312,8 +316,8 @@ class NodeAdapter
|
||||
* Callback listener to redefine to do an action when a node is click
|
||||
*/
|
||||
interface NodeClickCallback {
|
||||
fun onNodeClick(node: NodeVersioned, position: Int)
|
||||
fun onNodeLongClick(node: NodeVersioned, position: Int): Boolean
|
||||
fun onNodeClick(node: NodeVersioned)
|
||||
fun onNodeLongClick(node: NodeVersioned): Boolean
|
||||
}
|
||||
|
||||
class NodeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class ToolbarAction @JvmOverloads constructor(context: Context,
|
||||
mActionModeCallback?.onActionItemClicked(actionMode, it) ?: false
|
||||
}
|
||||
setNavigationOnClickListener{
|
||||
close()
|
||||
actionMode.finish()
|
||||
}
|
||||
|
||||
setNavigationIcon(R.drawable.ic_close_white_24dp)
|
||||
@@ -42,6 +42,14 @@ class ToolbarAction @JvmOverloads constructor(context: Context,
|
||||
return actionMode
|
||||
}
|
||||
|
||||
fun getSupportActionModeCallback(): ActionMode.Callback? {
|
||||
return mActionModeCallback
|
||||
}
|
||||
|
||||
fun removeSupportActionModeCallback() {
|
||||
mActionModeCallback = null
|
||||
}
|
||||
|
||||
fun invalidateMenu() {
|
||||
open()
|
||||
mActionModeCallback?.onPrepareActionMode(actionMode, menu)
|
||||
@@ -63,6 +71,7 @@ class ToolbarAction @JvmOverloads constructor(context: Context,
|
||||
override fun finish() {
|
||||
menu.clear()
|
||||
toolbarAction.close()
|
||||
toolbarAction.removeSupportActionModeCallback()
|
||||
}
|
||||
|
||||
override fun getMenu(): Menu {
|
||||
|
||||
Reference in New Issue
Block a user