Add creation template

This commit is contained in:
J-Jamet committed 2021-06-04 12:46:42 +02:00
1 parent 5050052710
commit cdfc7e4158
6 files changed
+50 -19

No files matched your search

@@ -90,6 +90,7 @@ class EntryEditActivity : LockingActivity(),
private var mEntry: Entry? = null
private var mParent: Group? = null
private var mIsNew: Boolean = false
private var mIsTemplate: Boolean = false
// Views
private var coordinatorLayout: CoordinatorLayout? = null
@@ -197,7 +198,10 @@ class EntryEditActivity : LockingActivity(),
}
// Build template selector
val templates = mDatabase?.getTemplates()
mIsTemplate = mDatabase?.templatesGroup?.let {
mDatabase?.templatesGroup == mParent
} ?: false
val templates = mDatabase?.getTemplates(mIsTemplate)
val entryTemplate: Template? = mEntry?.let {
mDatabase?.getTemplate(it)
} ?: if (templates?.isNotEmpty() == true) Template.STANDARD else null
@@ -434,11 +438,19 @@ class EntryEditActivity : LockingActivity(),
* Add a new customized field
*/
private fun addNewCustomField() {
EntryCustomFieldDialogFragment.getInstance().show(supportFragmentManager, "customFieldDialog")
//if (mIsTemplate) {
// TODO Custom Dialog to add a complete template field
//} else {
EntryCustomFieldDialogFragment.getInstance().show(supportFragmentManager, "customFieldDialog")
//}
}
private fun editCustomField(field: Field) {
EntryCustomFieldDialogFragment.getInstance(field).show(supportFragmentManager, "customFieldDialog")
//if (mIsTemplate) {
// TODO Custom Dialog to edit a complete template field
//} else {
EntryCustomFieldDialogFragment.getInstance(field).show(supportFragmentManager, "customFieldDialog")
//}
}
private fun showAddCustomFieldError() {
@@ -620,19 +632,23 @@ class EntryEditActivity : LockingActivity(),
menu?.findItem(R.id.menu_add_field)?.apply {
isEnabled = allowCustomField
isVisible = allowCustomField
isVisible = isEnabled
}
// Attachment not compatible below KitKat
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
menu?.findItem(R.id.menu_add_attachment)?.isVisible = false
menu?.findItem(R.id.menu_add_attachment)?.apply {
// Attachment not compatible below KitKat
isEnabled = !mIsTemplate
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
isVisible = isEnabled
}
menu?.findItem(R.id.menu_add_otp)?.apply {
val allowOTP = mDatabase?.allowOTP == true
isEnabled = allowOTP
// OTP not compatible below KitKat
isVisible = allowOTP && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
isEnabled = allowOTP
&& !mIsTemplate
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
isVisible = isEnabled
}
entryEditActivityEducation?.let {
@@ -143,8 +143,8 @@ class Database {
iconsManager.removeCustomIcon(binaryCache, customIcon.uuid)
}
fun getTemplates(): List<Template> {
return mDatabaseKDBX?.getTemplates() ?: listOf()
fun getTemplates(templateCreation: Boolean = false): List<Template> {
return mDatabaseKDBX?.getTemplates(templateCreation) ?: listOf()
}
fun getTemplate(entry: Entry): Template? {
@@ -358,8 +358,8 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
return null
}
fun getTemplates(): List<Template> {
return mTemplateEngine.getTemplates()
fun getTemplates(templateCreation: Boolean): List<Template> {
return mTemplateEngine.getTemplates(templateCreation)
}
fun getTemplate(entry: EntryKDBX): Template? {
@@ -75,6 +75,7 @@ class IconImageStandard : IconImageDraw {
companion object {
const val KEY_ID = 0
const val BUILD_ID = 6
const val TRASH_ID = 43
const val FOLDER_ID = 48
@@ -23,6 +23,8 @@ import android.os.ParcelUuid
import android.os.Parcelable
import com.kunzisoft.keepass.database.element.database.DatabaseVersioned
import com.kunzisoft.keepass.database.element.icon.IconImage
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.BUILD_ID
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_EXPIRATION
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_NOTES
import com.kunzisoft.keepass.database.element.template.TemplateField.STANDARD_PASSWORD
@@ -120,5 +122,13 @@ class Template : Parcelable {
sections.add(mainSection)
return Template(DatabaseVersioned.UUID_ZERO, "Standard", IconImage(), sections)
}
val CREATION: Template
get() {
return Template(UUID(0, 1),
"Template",
IconImage(IconImageStandard(BUILD_ID)),
listOf())
}
}
}
@@ -15,19 +15,23 @@ class TemplateEngine(private val databaseKDBX: DatabaseKDBX) {
private val mCacheTemplates = HashMap<UUID, Template>()
fun getTemplates(): List<Template> {
fun getTemplates(templateCreation: Boolean): List<Template> {
val templates = mutableListOf<Template>()
try {
val templateGroup = databaseKDBX.getTemplatesGroup()
mCacheTemplates.clear()
if (templateGroup != null) {
templates.add(Template.STANDARD)
templateGroup.getChildEntries().forEach { templateEntry ->
getTemplateFromTemplateEntry(templateEntry)?.let {
mCacheTemplates[templateEntry.id] = it
if (templateCreation) {
templates.add(Template.CREATION)
} else {
templates.add(Template.STANDARD)
templateGroup.getChildEntries().forEach { templateEntry ->
getTemplateFromTemplateEntry(templateEntry)?.let {
mCacheTemplates[templateEntry.id] = it
}
}
templates.addAll(mCacheTemplates.values)
}
templates.addAll(mCacheTemplates.values)
}
} catch (e: Exception) {
Log.e(TAG, "Unable to get templates from group", e)