From 0d32c38c798487b5927364d623e72e484e96047f Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Fri, 6 Sep 2019 14:06:51 +0200 Subject: [PATCH] Fix custom fields hidden --- .../keepass/activities/EntryActivity.kt | 2 +- .../keepass/view/EntryContentsView.kt | 17 +++---- .../keepass/view/EntryCustomField.kt | 17 +++++-- .../keepass/view/EntryCustomFieldProtected.kt | 45 ------------------- 4 files changed, 22 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/java/com/kunzisoft/keepass/view/EntryCustomFieldProtected.kt diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt index 25001b55a..f99eeea84 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/EntryActivity.kt @@ -208,7 +208,6 @@ class EntryActivity : LockingHideActivity() { } entryContentsView?.assignURL(entry.url) - entryContentsView?.setHiddenPasswordStyle(!mShowPassword) entryContentsView?.assignComment(entry.notes) // Assign custom fields @@ -237,6 +236,7 @@ class EntryActivity : LockingHideActivity() { } } } + entryContentsView?.setHiddenPasswordStyle(!mShowPassword) // Assign dates entry.creationTime.date?.let { diff --git a/app/src/main/java/com/kunzisoft/keepass/view/EntryContentsView.kt b/app/src/main/java/com/kunzisoft/keepass/view/EntryContentsView.kt index 0739b3c1e..d2d36a523 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/EntryContentsView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/EntryContentsView.kt @@ -161,8 +161,9 @@ class EntryContentsView @JvmOverloads constructor(context: Context, extrasView.let { for (i in 0 until it.childCount) { val childCustomView = it.getChildAt(i) - if (childCustomView is EntryCustomFieldProtected) - return true + if (childCustomView is EntryCustomField) + if (childCustomView.isProtected) + return true } } return false @@ -178,7 +179,7 @@ class EntryContentsView @JvmOverloads constructor(context: Context, extrasView.let { for (i in 0 until it.childCount) { val childCustomView = it.getChildAt(i) - if (childCustomView is EntryCustomFieldProtected) + if (childCustomView is EntryCustomField) childCustomView.setHiddenPasswordStyle(hiddenStyle) } } @@ -212,14 +213,10 @@ class EntryContentsView @JvmOverloads constructor(context: Context, enableActionButton: Boolean, onActionClickListener: OnClickListener?) { - val entryCustomField: EntryCustomField = - if (value.isProtected) - EntryCustomFieldProtected(context, attrs, defStyle) - else - EntryCustomField(context, attrs, defStyle) + val entryCustomField = EntryCustomField(context, attrs, defStyle) entryCustomField.apply { - assignLabel(title) - assignValue(value.toString()) + setLabel(title) + setValue(value.toString(), value.isProtected) enableActionButton(enableActionButton) assignActionButtonClickListener(onActionClickListener) applyFontVisibility(fontInVisibility) diff --git a/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomField.kt b/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomField.kt index bd17bc7af..6935972ba 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomField.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomField.kt @@ -21,6 +21,7 @@ package com.kunzisoft.keepass.view import android.content.Context import android.graphics.Color +import android.text.method.PasswordTransformationMethod import androidx.core.content.ContextCompat import android.util.AttributeSet import android.view.LayoutInflater @@ -35,8 +36,9 @@ open class EntryCustomField @JvmOverloads constructor(context: Context, : LinearLayout(context, attrs, defStyle) { private val labelView: TextView - protected val valueView: TextView + private val valueView: TextView private val actionImageView: ImageView + var isProtected = false private val colorAccent: Int @@ -60,12 +62,21 @@ open class EntryCustomField @JvmOverloads constructor(context: Context, valueView.applyFontVisibility() } - fun assignLabel(label: String?) { + fun setLabel(label: String?) { labelView.text = label ?: "" } - fun assignValue(value: String?) { + fun setValue(value: String?, isProtected: Boolean = false) { valueView.text = value ?: "" + this.isProtected = isProtected + } + + fun setHiddenPasswordStyle(hiddenStyle: Boolean) { + if (isProtected && hiddenStyle) { + valueView.transformationMethod = PasswordTransformationMethod.getInstance() + } else { + valueView.transformationMethod = null + } } fun enableActionButton(enable: Boolean) { diff --git a/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomFieldProtected.kt b/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomFieldProtected.kt deleted file mode 100644 index 0a90b731c..000000000 --- a/app/src/main/java/com/kunzisoft/keepass/view/EntryCustomFieldProtected.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2019 Jeremy Jamet / Kunzisoft. - * - * This file is part of KeePass DX. - * - * KeePass DX is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * KeePass DX is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with KeePass DX. If not, see . - * - */ -package com.kunzisoft.keepass.view - -import android.content.Context -import android.text.method.PasswordTransformationMethod -import android.util.AttributeSet - -class EntryCustomFieldProtected @JvmOverloads constructor(context: Context, - attrs: AttributeSet? = null, - defStyle: Int = 0) - : EntryCustomField(context, attrs, defStyle) { - - fun setValue(value: String?, isProtected: Boolean) { - if (value != null) { - valueView.text = value - setHiddenPasswordStyle(isProtected) - } - } - - fun setHiddenPasswordStyle(hiddenStyle: Boolean) { - if (!hiddenStyle) { - valueView.transformationMethod = null - } else { - valueView.transformationMethod = PasswordTransformationMethod.getInstance() - } - } -}