Fix concurrent exception when update group

This commit is contained in:
J-Jamet
2019-11-14 16:28:44 +01:00
parent 56805defb6
commit c9475d1dc2
4 changed files with 17 additions and 22 deletions

View File

@@ -799,20 +799,19 @@ class GroupActivity : LockingActivity(),
GroupEditDialogFragment.EditGroupDialogAction.UPDATE -> {
// If update add new elements
mOldGroupToUpdate?.let { oldGroupToUpdate ->
GroupVersioned(oldGroupToUpdate).let { updateGroup ->
val updateGroup = GroupVersioned(oldGroupToUpdate).let { updateGroup ->
updateGroup.apply {
// WARNING remove parent and children to keep memory
removeParent()
removeChildren() // TODO concurrent exception
removeChildren()
title = name
this.icon = icon // TODO custom icon
}
// If group updated save it in the database
progressDialogThread?.startDatabaseUpdateGroup(
oldGroupToUpdate, updateGroup, !mReadOnly)
}
// If group updated save it in the database
progressDialogThread?.startDatabaseUpdateGroup(
oldGroupToUpdate, updateGroup, !mReadOnly)
}
}
else -> {}

View File

@@ -130,22 +130,6 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
}
}
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)
@@ -287,6 +271,11 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
}
}
override fun removeChildren() {
pwGroupV3?.removeChildren()
pwGroupV4?.removeChildren()
}
override fun allowAddEntryIfIsRoot(): Boolean {
return pwGroupV3?.allowAddEntryIfIsRoot() ?: pwGroupV4?.allowAddEntryIfIsRoot() ?: false
}

View File

@@ -69,6 +69,11 @@ abstract class PwGroup
this.childEntries.remove(entry)
}
override fun removeChildren() {
this.childGroups.clear()
this.childEntries.clear()
}
override fun toString(): String {
return titleGroup
}

View File

@@ -16,6 +16,8 @@ interface PwGroupInterface<Group: PwGroupInterface<Group, Entry>, Entry> : PwNod
fun removeChildEntry(entry: Entry)
fun removeChildren()
fun allowAddEntryIfIsRoot(): Boolean
fun doForEachChildAndForIt(entryHandler: NodeHandler<Entry>,