mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-05 16:22:31 -08:00
Edit group on long click
This commit is contained in:
1 parent
4d3f4ed5c2
commit
7eeed8f670
4 files changed
+72
-32
No files matched your search
@@ -62,6 +62,7 @@ import com.kunzisoft.keepass.model.GroupInfo
|
||||
import com.kunzisoft.keepass.model.RegisterInfo
|
||||
import com.kunzisoft.keepass.model.SearchInfo
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_ENTRY_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_UPDATE_GROUP_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.NEW_NODES_KEY
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.getListNodesFromBundle
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
@@ -167,14 +168,22 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
// If last item
|
||||
val currentGroup = mCurrentGroup
|
||||
if (currentGroup != null && node == currentGroup) {
|
||||
GroupDialogFragment.launch(currentGroup.getGroupInfo())
|
||||
.show(supportFragmentManager, "group_fragment")
|
||||
launchDialogToShowGroupInfo(currentGroup)
|
||||
} else {
|
||||
mDatabase?.let { database ->
|
||||
onNodeClick(database, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
onLongItemClickListener = { node, position ->
|
||||
finishNodeAction()
|
||||
val currentGroup = mCurrentGroup
|
||||
if (currentGroup != null && node == currentGroup && currentGroup.containsParent()) {
|
||||
launchDialogForGroupUpdate(currentGroup)
|
||||
} else {
|
||||
onItemClickListener?.invoke(node, position)
|
||||
}
|
||||
}
|
||||
}
|
||||
breadcrumbListView?.apply {
|
||||
adapter = mBreadcrumbAdapter
|
||||
@@ -234,19 +243,9 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
// Update last access time.
|
||||
currentGroup.touch(modified = false, touchParents = false)
|
||||
|
||||
// Add breadcrumb
|
||||
mBreadcrumbAdapter?.apply {
|
||||
setNode(currentGroup)
|
||||
breadcrumbListView?.scrollToPosition(itemCount -1)
|
||||
}
|
||||
|
||||
// Add listeners to the add buttons
|
||||
addNodeButtonView?.setAddGroupClickListener {
|
||||
GroupEditDialogFragment.create(GroupInfo().apply {
|
||||
if (currentGroup.allowAddNoteInGroup) {
|
||||
notes = ""
|
||||
}
|
||||
}).show(supportFragmentManager, GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||
launchDialogForGroupCreation(currentGroup)
|
||||
}
|
||||
addNodeButtonView?.setAddEntryClickListener {
|
||||
mDatabase?.let { database ->
|
||||
@@ -477,17 +476,27 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
)
|
||||
}
|
||||
}
|
||||
ACTION_DATABASE_UPDATE_GROUP_TASK -> {
|
||||
if (result.isSuccess) {
|
||||
try {
|
||||
if (mCurrentGroup == newNodes[0] as Group)
|
||||
reloadCurrentGroup()
|
||||
} catch (e: Exception) {
|
||||
Log.e(
|
||||
TAG,
|
||||
"Unable to perform action after group update",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coordinatorLayout?.showActionErrorIfNeeded(result)
|
||||
if (!result.isSuccess) {
|
||||
reloadCurrentGroup()
|
||||
}
|
||||
|
||||
finishNodeAction()
|
||||
|
||||
// Refresh breadcrumb
|
||||
mBreadcrumbAdapter?.setNode(mCurrentGroup)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -547,12 +556,12 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
databaseNameView?.visibility = View.VISIBLE
|
||||
// Refresh breadcrumb
|
||||
if (toolbarBreadcrumb?.isVisible != true) {
|
||||
mBreadcrumbAdapter?.setNode(null)
|
||||
toolbarBreadcrumb?.expand {
|
||||
mBreadcrumbAdapter?.setNode(group)
|
||||
setBreadcrumbNode(group)
|
||||
}
|
||||
} else {
|
||||
mBreadcrumbAdapter?.setNode(group)
|
||||
// Add breadcrumb
|
||||
setBreadcrumbNode(group)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -560,6 +569,13 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
initAddButton(group)
|
||||
}
|
||||
|
||||
private fun setBreadcrumbNode(group: Group?) {
|
||||
mBreadcrumbAdapter?.apply {
|
||||
setNode(group)
|
||||
breadcrumbListView?.scrollToPosition(itemCount -1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initAddButton(group: Group?) {
|
||||
addNodeButtonView?.apply {
|
||||
closeButtonIfOpen()
|
||||
@@ -805,12 +821,7 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
finishNodeAction()
|
||||
when (node.type) {
|
||||
Type.GROUP -> {
|
||||
mOldGroupToUpdate = node as Group
|
||||
GroupEditDialogFragment.update(mOldGroupToUpdate!!.getGroupInfo())
|
||||
.show(
|
||||
supportFragmentManager,
|
||||
GroupEditDialogFragment.TAG_CREATE_GROUP
|
||||
)
|
||||
launchDialogForGroupUpdate(node as Group)
|
||||
}
|
||||
Type.ENTRY -> {
|
||||
mNodesFragment?.mEntryActivityResultLauncher?.let { resultLauncher ->
|
||||
@@ -827,6 +838,25 @@ class GroupActivity : DatabaseLockActivity(),
|
||||
return true
|
||||
}
|
||||
|
||||
private fun launchDialogToShowGroupInfo(group: Group) {
|
||||
GroupDialogFragment.launch(group.getGroupInfo())
|
||||
.show(supportFragmentManager, GroupDialogFragment.TAG_SHOW_GROUP)
|
||||
}
|
||||
|
||||
private fun launchDialogForGroupCreation(group: Group) {
|
||||
GroupEditDialogFragment.create(GroupInfo().apply {
|
||||
if (group.allowAddNoteInGroup) {
|
||||
notes = ""
|
||||
}
|
||||
}).show(supportFragmentManager, GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||
}
|
||||
|
||||
private fun launchDialogForGroupUpdate(group: Group) {
|
||||
mOldGroupToUpdate = group
|
||||
GroupEditDialogFragment.update(group.getGroupInfo())
|
||||
.show(supportFragmentManager, GroupEditDialogFragment.TAG_CREATE_GROUP)
|
||||
}
|
||||
|
||||
override fun onCopyMenuClick(
|
||||
database: Database,
|
||||
nodes: List<Node>
|
||||
|
||||
@@ -115,7 +115,8 @@ class GroupDialogFragment : DatabaseDialogFragment() {
|
||||
data class Error(val isError: Boolean, val messageId: Int?)
|
||||
|
||||
companion object {
|
||||
const val KEY_GROUP_INFO = "KEY_GROUP_INFO"
|
||||
const val TAG_SHOW_GROUP = "TAG_SHOW_GROUP"
|
||||
private const val KEY_GROUP_INFO = "KEY_GROUP_INFO"
|
||||
|
||||
fun launch(groupInfo: GroupInfo): GroupDialogFragment {
|
||||
val bundle = Bundle()
|
||||
|
||||
+2
-2
@@ -246,8 +246,8 @@ class GroupEditDialogFragment : DatabaseDialogFragment() {
|
||||
companion object {
|
||||
|
||||
const val TAG_CREATE_GROUP = "TAG_CREATE_GROUP"
|
||||
const val KEY_ACTION_ID = "KEY_ACTION_ID"
|
||||
const val KEY_GROUP_INFO = "KEY_GROUP_INFO"
|
||||
private const val KEY_ACTION_ID = "KEY_ACTION_ID"
|
||||
private const val KEY_GROUP_INFO = "KEY_GROUP_INFO"
|
||||
|
||||
fun create(groupInfo: GroupInfo): GroupEditDialogFragment {
|
||||
val bundle = Bundle()
|
||||
|
||||
@@ -28,6 +28,7 @@ class BreadcrumbAdapter(val context: Context)
|
||||
}
|
||||
private var mNodeBreadcrumb: MutableList<Node?> = mutableListOf()
|
||||
var onItemClickListener: ((item: Node, position: Int)->Unit)? = null
|
||||
var onLongItemClickListener: ((item: Node, position: Int)->Unit)? = null
|
||||
|
||||
private var mShowNumberEntries = false
|
||||
private var mShowUUID = false
|
||||
@@ -86,9 +87,17 @@ class BreadcrumbAdapter(val context: Context)
|
||||
}
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
node?.let {
|
||||
onItemClickListener?.invoke(it, position)
|
||||
holder.itemView.apply {
|
||||
setOnClickListener {
|
||||
node?.let {
|
||||
onItemClickListener?.invoke(it, position)
|
||||
}
|
||||
}
|
||||
setOnLongClickListener {
|
||||
node?.let {
|
||||
onLongItemClickListener?.invoke(it, position)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user