Inherit color from template #1213

This commit is contained in:
J-Jamet
2022-01-25 12:41:44 +01:00
parent 82177a386e
commit b8005466cd
10 changed files with 82 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
KeePassDX(3.2.0)
* Manage data merge #840 #977
* Inherit color from template #1213
* Add path in quick search
KeePassDX(3.1.0)

View File

@@ -195,6 +195,7 @@ class EntryActivity : DatabaseLockActivity() {
ColorDrawable(mColorAccent)
}
val entryTemplate = entryInfoHistory.template
val entryInfo = entryInfoHistory.entryInfo
// Manage entry copy to start notification if allowed (at the first start)
if (savedInstanceState == null) {
@@ -214,8 +215,8 @@ class EntryActivity : DatabaseLockActivity() {
toolbar?.title = entryTitle
mUrl = entryInfo.url
// Assign colors
mBackgroundColor = entryInfo.backgroundColor
mForegroundColor = entryInfo.foregroundColor
mBackgroundColor = entryInfo.backgroundColor ?: entryTemplate.backgroundColor
mForegroundColor = entryInfo.foregroundColor ?: entryTemplate.foregroundColor
loadingView?.hideByFading()
mEntryLoaded = true

View File

@@ -185,6 +185,7 @@ class NodesAdapter (private val context: Context,
&& oldItem.username == newItem.username
&& oldItem.backgroundColor == newItem.backgroundColor
&& oldItem.foregroundColor == newItem.foregroundColor
&& database.getTemplate(oldItem) == database.getTemplate(newItem)
&& oldItem.getOtpElement() == newItem.getOtpElement()
&& oldItem.containsAttachment() == newItem.containsAttachment()
} else if (oldItem is Group && newItem is Group) {
@@ -397,6 +398,8 @@ class NodesAdapter (private val context: Context,
// Specific elements for entry
if (subNode.type == Type.ENTRY) {
val entry = subNode as Entry
val entryTemplate = database.getTemplate(entry)
database.startManageEntry(entry)
holder.text.text = entry.getVisualTitle()
@@ -436,7 +439,7 @@ class NodesAdapter (private val context: Context,
if (entry.containsAttachment()) View.VISIBLE else View.GONE
// Assign colors
val backgroundColor = entry.backgroundColor
val backgroundColor = entry.backgroundColor ?: entryTemplate?.backgroundColor
if (!holder.container.isSelected) {
if (backgroundColor != null) {
holder.container.setBackgroundColor(backgroundColor)
@@ -446,7 +449,7 @@ class NodesAdapter (private val context: Context,
} else {
holder.container.setBackgroundColor(mColorAccentLight)
}
val foregroundColor = entry.foregroundColor
val foregroundColor = entry.foregroundColor ?: entryTemplate?.foregroundColor
if (!holder.container.isSelected) {
if (foregroundColor != null) {
holder.text.setTextColor(foregroundColor)

View File

@@ -9,23 +9,23 @@ import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Database
import com.kunzisoft.keepass.database.element.template.Template
import com.kunzisoft.keepass.database.element.template.TemplateField
import com.kunzisoft.keepass.icons.IconDrawableFactory
class TemplatesSelectorAdapter(private val context: Context,
private var templates: List<Template>): BaseAdapter() {
class TemplatesSelectorAdapter(
context: Context,
private var templates: List<Template>): BaseAdapter() {
var iconDrawableFactory: IconDrawableFactory? = null
private val inflater: LayoutInflater = LayoutInflater.from(context)
private var mIconColor = Color.BLACK
private var mTextColor = Color.BLACK
init {
val taIconColor = context.theme.obtainStyledAttributes(intArrayOf(android.R.attr.textColor))
mIconColor = taIconColor.getColor(0, Color.BLACK)
taIconColor.recycle()
val taTextColor = context.theme.obtainStyledAttributes(intArrayOf(android.R.attr.textColor))
mTextColor = taTextColor.getColor(0, Color.BLACK)
taTextColor.recycle()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
@@ -36,6 +36,7 @@ class TemplatesSelectorAdapter(private val context: Context,
if (templateView == null) {
holder = TemplateSelectorViewHolder()
templateView = inflater.inflate(R.layout.item_template, parent, false)
holder.background = templateView?.findViewById(R.id.template_background)
holder.icon = templateView?.findViewById(R.id.template_image)
holder.name = templateView?.findViewById(R.id.template_name)
templateView?.tag = holder
@@ -43,10 +44,15 @@ class TemplatesSelectorAdapter(private val context: Context,
holder = templateView.tag as TemplateSelectorViewHolder
}
holder.background?.setBackgroundColor(template.backgroundColor ?: Color.TRANSPARENT)
val textColor = template.foregroundColor ?: mTextColor
holder.icon?.let { icon ->
iconDrawableFactory?.assignDatabaseIcon(icon, template.icon, mIconColor)
iconDrawableFactory?.assignDatabaseIcon(icon, template.icon, textColor)
}
holder.name?.apply {
setTextColor(textColor)
text = TemplateField.getLocalizedName(context, template.title)
}
holder.name?.text = TemplateField.getLocalizedName(context, template.title)
return templateView!!
}
@@ -64,6 +70,7 @@ class TemplatesSelectorAdapter(private val context: Context,
}
inner class TemplateSelectorViewHolder {
var background: View? = null
var icon: ImageView? = null
var name: TextView? = null
}

View File

@@ -23,10 +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 java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.LinkedHashMap
class Template : Parcelable {
@@ -34,6 +32,8 @@ class Template : Parcelable {
var uuid: UUID = DatabaseVersioned.UUID_ZERO
var title = ""
var icon = IconImage()
var backgroundColor: Int? = null
var foregroundColor: Int? = null
var sections: MutableList<TemplateSection> = ArrayList()
private set
@@ -41,7 +41,8 @@ class Template : Parcelable {
title: String,
icon: IconImage,
section: TemplateSection,
version: Int = 1): this(uuid, title, icon, ArrayList<TemplateSection>().apply {
version: Int = 1)
: this(uuid, title, icon, ArrayList<TemplateSection>().apply {
add(section)
}, version)
@@ -49,11 +50,22 @@ class Template : Parcelable {
title: String,
icon: IconImage,
sections: List<TemplateSection>,
version: Int = 1)
: this(uuid, title, icon, null, null, sections, version)
constructor(uuid: UUID,
title: String,
icon: IconImage,
backgroundColor: Int?,
foregroundColor: Int?,
sections: List<TemplateSection>,
version: Int = 1) {
this.version = version
this.uuid = uuid
this.title = title
this.icon = icon
this.backgroundColor = backgroundColor
this.foregroundColor = foregroundColor
this.sections.clear()
this.sections.addAll(sections)
}
@@ -63,6 +75,8 @@ class Template : Parcelable {
this.uuid = template.uuid
this.title = template.title
this.icon = template.icon
this.backgroundColor = template.backgroundColor
this.foregroundColor = template.foregroundColor
this.sections.clear()
this.sections.addAll(template.sections)
}
@@ -72,6 +86,8 @@ class Template : Parcelable {
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: uuid
title = parcel.readString() ?: title
icon = parcel.readParcelable(IconImage::class.java.classLoader) ?: icon
backgroundColor = parcel.readInt()
foregroundColor = parcel.readInt()
parcel.readList(sections, TemplateSection::class.java.classLoader)
}
@@ -80,6 +96,8 @@ class Template : Parcelable {
parcel.writeParcelable(ParcelUuid(uuid), flags)
parcel.writeString(title)
parcel.writeParcelable(icon, flags)
parcel.writeInt(backgroundColor ?: -1)
parcel.writeInt(foregroundColor ?: -1)
parcel.writeList(sections)
}

View File

@@ -18,6 +18,7 @@ package com.kunzisoft.keepass.database.element.template
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
*/
import android.content.res.Resources
import android.graphics.Color
import android.util.Log
import com.kunzisoft.keepass.R
import com.kunzisoft.keepass.database.element.Field
@@ -43,7 +44,7 @@ abstract class TemplateEngine(private val mDatabase: DatabaseKDBX) {
if (templateGroup != null) {
templates.add(Template.STANDARD)
templateGroup.getChildEntries().forEach { templateEntry ->
getTemplateFromTemplateEntry(templateEntry)?.let {
getTemplateFromTemplateEntry(templateEntry).let {
mCacheTemplates[templateEntry.id] = it
templates.add(it)
}
@@ -87,7 +88,7 @@ abstract class TemplateEngine(private val mDatabase: DatabaseKDBX) {
return mCacheTemplates[uuid]
else {
mDatabase.getEntryById(uuid)?.let { templateEntry ->
getTemplateFromTemplateEntry(templateEntry)?.let { newTemplate ->
getTemplateFromTemplateEntry(templateEntry).let { newTemplate ->
mCacheTemplates[uuid] = newTemplate
return newTemplate
}
@@ -151,7 +152,7 @@ abstract class TemplateEngine(private val mDatabase: DatabaseKDBX) {
return TemplateSection(sectionAttributes)
}
private fun getTemplateFromTemplateEntry(templateEntry: EntryKDBX): Template? {
private fun getTemplateFromTemplateEntry(templateEntry: EntryKDBX): Template {
val templateEntryDecoded = decodeTemplateEntry(templateEntry)
val templateSections = mutableListOf<TemplateSection>()
@@ -166,7 +167,28 @@ abstract class TemplateEngine(private val mDatabase: DatabaseKDBX) {
}
templateSections.add(buildTemplateSectionFromFields(sectionFields))
return Template(templateEntry.id, templateEntry.title, templateEntry.icon, templateSections, getVersion())
var backgroundColor: Int? = null
templateEntry.backgroundColor.let {
try {
backgroundColor = Color.parseColor(it)
} catch (e: Exception) {}
}
var foregroundColor: Int? = null
templateEntry.foregroundColor.let {
try {
foregroundColor = Color.parseColor(it)
} catch (e: Exception) {}
}
return Template(
templateEntry.id,
templateEntry.title,
templateEntry.icon,
backgroundColor,
foregroundColor,
templateSections,
getVersion()
)
}
companion object {

View File

@@ -275,6 +275,9 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
entryCopy.putField(field)
}
}
// Add colors
entryCopy.foregroundColor = templateEntry.foregroundColor
entryCopy.backgroundColor = templateEntry.backgroundColor
return entryCopy
}
@@ -377,6 +380,9 @@ class TemplateEngineCompatible(database: DatabaseKDBX): TemplateEngine(database)
}
}
}
// Add colors
entryCopy.foregroundColor = templateEntry.foregroundColor
entryCopy.backgroundColor = templateEntry.backgroundColor
return entryCopy
}

View File

@@ -26,7 +26,8 @@
android:layout_height="wrap_content"
style="?attr/cardViewStyle">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:id="@+id/template_background"
android:layout_width="match_parent"
android:layout_height="42dp"
android:orientation="horizontal">
<ImageView

View File

@@ -1,2 +1,3 @@
* Manage data merge #840 #977
* Inherit color from template #1213
* Add path in quick search

View File

@@ -1,2 +1,3 @@
* Gestion de la fusion des données #840 #977
* Héritage de la couleur du gabarit #1213
* Ajout du chemin dans la recherche rapide