Fix update group

This commit is contained in:
J-Jamet
2019-10-16 11:48:35 +02:00
parent e087e19120
commit a21de3b892
6 changed files with 56 additions and 9 deletions

View File

@@ -111,7 +111,7 @@ class EntryEditActivity : LockingHideActivity(),
// Create a copy to modify
mNewEntry = EntryVersioned(entry).also { newEntry ->
// WARNING Remove the parent to keep memory with parcelable
newEntry.parent = null
newEntry.removeParent()
}
}
}

View File

@@ -749,11 +749,15 @@ class GroupActivity : LockingActivity(),
// If update add new elements
mOldGroupToUpdate?.let { oldGroupToUpdate ->
GroupVersioned(oldGroupToUpdate).let { updateGroup ->
updateGroup.title = name
// TODO custom icon
updateGroup.icon = icon
updateGroup.apply {
// WARNING remove parent and children to keep memory
removeParent()
removeChildren()
title = name
this.icon = icon // TODO custom icon
}
mListNodesFragment?.removeNode(oldGroupToUpdate)
// If group updated save it in the database
progressDialogThread?.startDatabaseUpdateGroup(
oldGroupToUpdate, updateGroup, !mReadOnly)

View File

@@ -38,7 +38,7 @@ class UpdateEntryRunnable constructor(
override fun nodeAction() {
// WARNING : Re attribute parent removed in entry edit activity to save memory
mNewEntry.parent = mOldEntry.parent
mNewEntry.addParentFrom(mOldEntry)
// Update entry with new values
mOldEntry.updateWith(mNewEntry)
@@ -46,10 +46,9 @@ class UpdateEntryRunnable constructor(
// Create an entry history (an entry history don't have history)
mOldEntry.addEntryToHistory(EntryVersioned(mBackupEntryHistory, copyHistory = false))
database.removeOldestHistory(mOldEntry)
// Only change data un index
// Only change data in index
database.updateEntry(mOldEntry)
}

View File

@@ -37,11 +37,15 @@ class UpdateGroupRunnable constructor(
private val mBackupGroup: GroupVersioned = GroupVersioned(mOldGroup)
override fun nodeAction() {
// WARNING : Re attribute parent and children removed in group activity to save memory
mNewGroup.addParentFrom(mOldGroup)
mNewGroup.addChildrenFrom(mOldGroup)
// Update group with new values
mOldGroup.updateWith(mNewGroup)
mOldGroup.touch(modified = true, touchParents = true)
// Only change data un index
// Only change data in index
database.updateGroup(mOldGroup)
}

View File

@@ -114,6 +114,38 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
pwGroupV4?.afterAssignNewParent()
}
fun addChildrenFrom(group: GroupVersioned) {
group.pwGroupV3?.getChildEntries()?.forEach { entryToAdd ->
pwGroupV3?.addChildEntry(entryToAdd)
}
group.pwGroupV3?.getChildGroups()?.forEach { groupToAdd ->
pwGroupV3?.addChildGroup(groupToAdd)
}
group.pwGroupV4?.getChildEntries()?.forEach { entryToAdd ->
pwGroupV4?.addChildEntry(entryToAdd)
}
group.pwGroupV4?.getChildGroups()?.forEach { groupToAdd ->
pwGroupV4?.addChildGroup(groupToAdd)
}
}
fun removeChildren() {
pwGroupV3?.getChildEntries()?.forEach { entryToRemove ->
pwGroupV3?.removeChildEntry(entryToRemove)
}
pwGroupV3?.getChildGroups()?.forEach { groupToRemove ->
pwGroupV3?.removeChildGroup(groupToRemove)
}
pwGroupV4?.getChildEntries()?.forEach { entryToRemove ->
pwGroupV4?.removeChildEntry(entryToRemove)
}
pwGroupV4?.getChildGroups()?.forEach { groupToRemove ->
pwGroupV4?.removeChildGroup(groupToRemove)
}
}
override fun touch(modified: Boolean, touchParents: Boolean) {
pwGroupV3?.touch(modified, touchParents)
pwGroupV4?.touch(modified, touchParents)

View File

@@ -14,6 +14,14 @@ interface NodeVersioned: PwNodeInterface<GroupVersioned> {
}
return -1
}
fun addParentFrom(node: NodeVersioned) {
parent = node.parent
}
fun removeParent() {
parent = null
}
}
/**