Fix duplicate groups with settings

This commit is contained in:
J-Jamet committed 2021-07-25 14:37:23 +02:00
1 parent a7700ce27e
commit d4cd5b73bd
3 files changed
+33 -12

No files matched your search

@@ -373,8 +373,8 @@ class Database {
* Do not modify groups here, used for read only
*/
fun getAllGroupsWithoutRoot(): List<Group> {
return mDatabaseKDB?.getGroupIndexes()?.filter { it != mDatabaseKDB?.rootGroup }?.map { Group(it) }
?: mDatabaseKDBX?.getGroupIndexes()?.filter { it != mDatabaseKDBX?.rootGroup }?.map { Group(it) }
return mDatabaseKDB?.getAllGroupsWithoutRoot()?.map { Group(it) }
?: mDatabaseKDBX?.getAllGroupsWithoutRoot()?.map { Group(it) }
?: listOf()
}
@@ -358,9 +358,18 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
}
fun enableTemplatesGroup(enable: Boolean, resources: Resources) {
// Create templates group only if a group with a valid name don't already exists
val firstGroupWithValidName = getGroupIndexes().firstOrNull {
it.title == TemplateEngine.getDefaultTemplateGroupName(resources)
}
if (enable) {
val uuidTemplatesGroup = mTemplateEngine.createNewTemplatesGroup(resources)
addGroupTo(uuidTemplatesGroup, rootGroup)
val uuidTemplatesGroup = if (firstGroupWithValidName == null) {
val newUuidTemplatesGroup = mTemplateEngine.createNewTemplatesGroup(resources)
addGroupTo(newUuidTemplatesGroup, rootGroup)
newUuidTemplatesGroup
} else {
firstGroupWithValidName
}
entryTemplatesGroup = uuidTemplatesGroup.id
entryTemplatesGroupChanged = uuidTemplatesGroup.lastModificationTime
} else {
@@ -713,15 +722,23 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
*/
fun ensureRecycleBinExists(resources: Resources) {
if (recycleBin == null) {
// Create recycle bin
val recycleBinGroup = createGroup().apply {
title = resources.getString(R.string.recycle_bin)
icon.standard = getStandardIcon(IconImageStandard.TRASH_ID)
enableAutoType = false
enableSearching = false
isExpanded = false
// Create recycle bin only if a group with a valid name don't already exists
val firstGroupWithValidName = getGroupIndexes().firstOrNull {
it.title == resources.getString(R.string.recycle_bin)
}
val recycleBinGroup = if (firstGroupWithValidName == null) {
val newRecycleBinGroup = createGroup().apply {
title = resources.getString(R.string.recycle_bin)
icon.standard = getStandardIcon(IconImageStandard.TRASH_ID)
enableAutoType = false
enableSearching = false
isExpanded = false
}
addGroupTo(newRecycleBinGroup, rootGroup)
newRecycleBinGroup
} else {
firstGroupWithValidName
}
addGroupTo(recycleBinGroup, rootGroup)
recycleBinUUID = recycleBinGroup.id
recycleBinChanged = recycleBinGroup.lastModificationTime
}
@@ -93,6 +93,10 @@ abstract class DatabaseVersioned<
}
}
fun getAllGroupsWithoutRoot(): List<Group> {
return getGroupIndexes().filter { it != rootGroup }
}
@Throws(IOException::class)
protected abstract fun getMasterKey(key: String?, keyInputStream: InputStream?): ByteArray