mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-12-01 06:12:45 -08:00
Better cardview implementation
This commit is contained in:
1 parent
05d0d9e501
commit
f65b6e5484
13 files changed
+109
-148
No files matched your search
@@ -89,6 +89,7 @@ class EntryEditFragment : StylishFragment() {
|
||||
// Elements to modify the current entry
|
||||
private var mEntryInfo = EntryInfo()
|
||||
|
||||
private var mCustomFields = LinkedHashMap<String, FieldId>() // <label>, <viewId>
|
||||
// Current date time selection
|
||||
@IdRes
|
||||
private var mTempDateTimeViewId: Int? = null
|
||||
@@ -212,23 +213,25 @@ class EntryEditFragment : StylishFragment() {
|
||||
}
|
||||
|
||||
private fun populateViewsWithEntry() {
|
||||
context?.let { context ->
|
||||
// Build each template section
|
||||
templateContainerView.removeAllViews()
|
||||
customFieldsContainerView.clear()
|
||||
mCustomFields.clear()
|
||||
// Build each template section
|
||||
templateContainerView.removeAllViews()
|
||||
customFieldsContainerView.removeAllViews()
|
||||
mCustomFields.clear()
|
||||
|
||||
// Set info in view
|
||||
setIcon(mEntryInfo.icon)
|
||||
entryTitleView.apply {
|
||||
label = getString(R.string.entry_title)
|
||||
setValue(mEntryInfo.title, EntryEditFieldView.TextType.NORMAL)
|
||||
}
|
||||
// Set info in view
|
||||
setIcon(mEntryInfo.icon)
|
||||
entryTitleView.apply {
|
||||
label = getString(R.string.entry_title)
|
||||
setValue(mEntryInfo.title, EntryEditFieldView.TextType.NORMAL)
|
||||
}
|
||||
|
||||
activity?.let { context ->
|
||||
val customFieldsNotConsumed = ArrayList(mEntryInfo.customFields)
|
||||
mTemplate.sections.forEach { templateSection ->
|
||||
|
||||
val sectionView = SectionView(context)
|
||||
val sectionView = SectionView(context, null, R.attr.cardViewStyle)
|
||||
// Add build view to parent
|
||||
templateContainerView.addView(sectionView)
|
||||
|
||||
// Build each attribute
|
||||
templateSection.attributes.forEach { templateAttribute ->
|
||||
@@ -280,17 +283,14 @@ class EntryEditFragment : StylishFragment() {
|
||||
ProtectedString(templateAttribute.protected, fieldValue)),
|
||||
fieldTag)
|
||||
// Add created view to this parent
|
||||
sectionView.addAttributeView(attributeView)
|
||||
sectionView.addView(attributeView)
|
||||
}
|
||||
|
||||
// Add build view to parent
|
||||
templateContainerView.addView(sectionView)
|
||||
}
|
||||
|
||||
// Add custom fields not in template
|
||||
customFieldsNotConsumed.forEach { customDynamicField ->
|
||||
val fieldView = buildViewForCustomField(customDynamicField)
|
||||
customFieldsContainerView.addAttributeView(fieldView)
|
||||
customFieldsContainerView.addView(fieldView)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,6 @@ class EntryEditFragment : StylishFragment() {
|
||||
* -------------
|
||||
*/
|
||||
|
||||
private var mCustomFields = LinkedHashMap<String, FieldId>() // <label>, <viewId>
|
||||
private data class FieldId(var viewId: Int, var protected: Boolean)
|
||||
|
||||
private fun isStandardFieldName(name: String): Boolean {
|
||||
@@ -593,23 +592,9 @@ class EntryEditFragment : StylishFragment() {
|
||||
}
|
||||
|
||||
fun removeCustomField(oldCustomField: Field) {
|
||||
val previousSize = mCustomFields.size
|
||||
mCustomFields[oldCustomField.name]?.viewId?.let { viewId ->
|
||||
customFieldsContainerView.findViewById<View>(viewId)?.let { viewToRemove ->
|
||||
viewToRemove.collapse(true) {
|
||||
mCustomFields.remove(oldCustomField.name)
|
||||
|
||||
// TODO collapse empty section
|
||||
/*
|
||||
val newSize = mCustomFields.size
|
||||
if (previousSize > 0 && newSize == 0) {
|
||||
extraFieldsContainerView.collapse(true)
|
||||
} else if (previousSize == 0 && newSize == 1) {
|
||||
extraFieldsContainerView.expand(true)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
customFieldsContainerView.removeViewById(viewId)
|
||||
mCustomFields.remove(oldCustomField.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
* Copyright 2021 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
@@ -21,33 +21,46 @@ package com.kunzisoft.keepass.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.cardview.widget.CardView
|
||||
import com.kunzisoft.keepass.R
|
||||
|
||||
class SectionView @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0)
|
||||
: FrameLayout(context, attrs, defStyle) {
|
||||
: CardView(context, attrs, defStyle) {
|
||||
|
||||
private val containerSectionView: ViewGroup
|
||||
|
||||
init {
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater?
|
||||
inflater?.inflate(R.layout.view_section, this)
|
||||
|
||||
containerSectionView = findViewById(R.id.section_container)
|
||||
containerSectionView.visibility = View.GONE
|
||||
private var containerSectionView = LinearLayout(context).apply {
|
||||
val margin = resources.getDimension(R.dimen.card_view_padding).toInt()
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT).also {
|
||||
it.setMargins(margin, margin, margin, margin)
|
||||
}
|
||||
orientation = LinearLayout.VERTICAL
|
||||
}
|
||||
|
||||
fun addAttributeView(view: View?) {
|
||||
//TODO containerSectionView.postDelayed({
|
||||
init {
|
||||
val marginHorizontal = resources.getDimension(R.dimen.card_view_margin_horizontal).toInt()
|
||||
val marginVertical = resources.getDimension(R.dimen.card_view_margin_vertical).toInt()
|
||||
layoutParams = LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
LayoutParams.WRAP_CONTENT).also {
|
||||
it.setMargins(marginHorizontal, marginVertical, marginHorizontal, marginVertical)
|
||||
}
|
||||
visibility = View.GONE
|
||||
super.addView(containerSectionView)
|
||||
}
|
||||
|
||||
override fun addView(child: View?) {
|
||||
visibility = View.VISIBLE
|
||||
// TODO Smoother but prevent keep focus on orientation change
|
||||
// containerSectionView.postDelayed({
|
||||
containerSectionView.apply {
|
||||
alpha = 0f
|
||||
visibility = View.VISIBLE
|
||||
addView(view)
|
||||
addView(child)
|
||||
animate()
|
||||
.alpha(1f)
|
||||
.setDuration(200)
|
||||
@@ -56,8 +69,24 @@ class SectionView @JvmOverloads constructor(context: Context,
|
||||
//}, 200)
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
containerSectionView.visibility = View.GONE
|
||||
fun removeViewById(@IdRes viewId: Int, onFinish: ((View) ->Unit)? = null) {
|
||||
containerSectionView.findViewById<View?>(viewId)?.let { viewToRemove ->
|
||||
viewToRemove.collapse(true) {
|
||||
onFinish?.invoke(viewToRemove)
|
||||
// Hide section if needed
|
||||
try {
|
||||
if (containerSectionView.childCount == 0) {
|
||||
collapse(true)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun removeAllViews() {
|
||||
containerSectionView.removeAllViews()
|
||||
visibility = View.GONE
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user