mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Create new templates group in settings
This commit is contained in:
@@ -353,11 +353,17 @@ class Database {
|
||||
val allowConfigurableRecycleBin: Boolean
|
||||
get() = mDatabaseKDBX != null
|
||||
|
||||
var isRecycleBinEnabled: Boolean
|
||||
val isRecycleBinEnabled: Boolean
|
||||
// Backup is always enabled in KDB database
|
||||
get() = mDatabaseKDB != null || mDatabaseKDBX?.isRecycleBinEnabled ?: false
|
||||
set(value) {
|
||||
mDatabaseKDBX?.isRecycleBinEnabled = value
|
||||
|
||||
fun enableRecycleBin(enable: Boolean, resources: Resources) {
|
||||
mDatabaseKDBX?.isRecycleBinEnabled = enable
|
||||
if (enable) {
|
||||
ensureRecycleBinExists(resources)
|
||||
} else {
|
||||
removeRecycleBin()
|
||||
}
|
||||
}
|
||||
|
||||
val recycleBin: Group?
|
||||
@@ -379,10 +385,11 @@ class Database {
|
||||
get() = mDatabaseKDBX != null
|
||||
|
||||
// Maybe another templates method with KDBX5
|
||||
var isTemplatesEnabled: Boolean
|
||||
val isTemplatesEnabled: Boolean
|
||||
get() = mDatabaseKDBX?.isTemplatesGroupEnabled() ?: false
|
||||
set(value) {
|
||||
mDatabaseKDBX?.enableTemplatesGroup(value)
|
||||
|
||||
fun enableTemplates(enable: Boolean) {
|
||||
mDatabaseKDBX?.enableTemplatesGroup(enable)
|
||||
}
|
||||
|
||||
val templatesGroup: Group?
|
||||
|
||||
@@ -341,8 +341,11 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
|
||||
fun enableTemplatesGroup(enable: Boolean) {
|
||||
if (enable) {
|
||||
// TODO Build default templates group
|
||||
setTemplatesGroup(UUID_ZERO)
|
||||
val uuidTemplatesGroup = mTemplateEngine.createNewTemplatesGroup()
|
||||
|
||||
addGroupTo(uuidTemplatesGroup, rootGroup)
|
||||
entryTemplatesGroup = uuidTemplatesGroup.id
|
||||
entryTemplatesGroupChanged = uuidTemplatesGroup.lastModificationTime
|
||||
} else {
|
||||
entryTemplatesGroup = UUID_ZERO
|
||||
mTemplateEngine.clearCache()
|
||||
@@ -356,11 +359,6 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
return null
|
||||
}
|
||||
|
||||
fun setTemplatesGroup(uuid: UUID) {
|
||||
entryTemplatesGroup = uuid
|
||||
entryTemplatesGroupChanged = DateInstant()
|
||||
}
|
||||
|
||||
fun getTemplates(): List<Template> {
|
||||
return mTemplateEngine.getTemplates()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.kunzisoft.keepass.database.element.template
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDBX
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.utils.UuidUtil
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
@@ -31,6 +33,16 @@ class TemplateEngine(private val databaseKDBX: DatabaseKDBX) {
|
||||
return templates
|
||||
}
|
||||
|
||||
fun createNewTemplatesGroup(): GroupKDBX {
|
||||
return databaseKDBX.createGroup().apply {
|
||||
title = TEMPLATE_GROUP_NAME
|
||||
icon.standard = databaseKDBX.getStandardIcon(IconImageStandard.FOLDER_ID)
|
||||
enableAutoType = false
|
||||
enableSearching = false
|
||||
isExpanded = false
|
||||
}
|
||||
}
|
||||
|
||||
fun clearCache() {
|
||||
mCacheTemplates.clear()
|
||||
}
|
||||
@@ -159,6 +171,7 @@ class TemplateEngine(private val databaseKDBX: DatabaseKDBX) {
|
||||
private data class TemplateAttributePosition(var position: Int, var attribute: TemplateAttribute)
|
||||
|
||||
private val TAG = TemplateEngine::class.java.name
|
||||
private const val TEMPLATE_GROUP_NAME = "Templates"
|
||||
private const val TEMPLATE_LABEL_VERSION = "_etm_template"
|
||||
private const val TEMPLATE_ENTRY_UUID = "_etm_template_uuid"
|
||||
private const val TEMPLATE_ATTRIBUTE_POSITION_PREFIX = "_etm_position"
|
||||
|
||||
@@ -159,13 +159,7 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment() {
|
||||
isEnabled = if (!mDatabaseReadOnly) {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val recycleBinEnabled = newValue as Boolean
|
||||
mDatabase.isRecycleBinEnabled = recycleBinEnabled
|
||||
// TODO Change method
|
||||
if (recycleBinEnabled) {
|
||||
mDatabase.ensureRecycleBinExists(resources)
|
||||
} else {
|
||||
mDatabase.removeRecycleBin()
|
||||
}
|
||||
mDatabase.enableRecycleBin(recycleBinEnabled, resources)
|
||||
refreshRecycleBinGroup()
|
||||
// Save the database if not in readonly mode
|
||||
(context as SettingsActivity?)?.
|
||||
@@ -193,7 +187,7 @@ class NestedDatabaseSettingsFragment : NestedSettingsFragment() {
|
||||
isEnabled = if (!mDatabaseReadOnly) {
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val templatesEnabled = newValue as Boolean
|
||||
mDatabase.isTemplatesEnabled = templatesEnabled
|
||||
mDatabase.enableTemplates(templatesEnabled)
|
||||
refreshTemplatesGroup()
|
||||
// Save the database if not in readonly mode
|
||||
(context as SettingsActivity?)?.
|
||||
|
||||
@@ -411,7 +411,7 @@
|
||||
<string name="compression_none">None</string>
|
||||
<string name="compression_gzip">Gzip</string>
|
||||
<string name="recycle_bin">Recycle bin</string>
|
||||
<string name="templates">Recycle bin</string>
|
||||
<string name="templates">Templates</string>
|
||||
<string name="keyboard">Keyboard</string>
|
||||
<string name="magic_keyboard_title">Magikeyboard</string>
|
||||
<string name="magic_keyboard_explanation_summary">Activate a custom keyboard populating your passwords and all identity fields</string>
|
||||
|
||||
Reference in New Issue
Block a user