Fix autolink #720

This commit is contained in:
J-Jamet
2020-09-25 20:41:24 +02:00
parent 2c669deae5
commit daf239c93c
5 changed files with 25 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ KeePassDX(2.8.6)
* Fix dialog background #717 * Fix dialog background #717
* Better domain recognition for autofill #702 * Better domain recognition for autofill #702
* Write custom data #651 * Write custom data #651
* Fix autolink #720
KeePassDX(2.8.5) KeePassDX(2.8.5)
* Fix Base 64 #708 * Fix Base 64 #708

View File

@@ -96,11 +96,11 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
urlFieldView = findViewById(R.id.entry_url_field) urlFieldView = findViewById(R.id.entry_url_field)
urlFieldView.setLabel(R.string.entry_url) urlFieldView.setLabel(R.string.entry_url)
urlFieldView.setValueAutoLink(true) urlFieldView.setLinkAll()
notesFieldView = findViewById(R.id.entry_notes_field) notesFieldView = findViewById(R.id.entry_notes_field)
notesFieldView.setLabel(R.string.entry_notes) notesFieldView.setLabel(R.string.entry_notes)
notesFieldView.setValueAutoLink(true) notesFieldView.setAutoLink()
extraFieldsContainerView = findViewById(R.id.extra_fields_container) extraFieldsContainerView = findViewById(R.id.extra_fields_container)
extraFieldsListView = findViewById(R.id.extra_fields_list) extraFieldsListView = findViewById(R.id.extra_fields_list)
@@ -304,7 +304,7 @@ class EntryContentsView @JvmOverloads constructor(context: Context,
entryCustomField?.apply { entryCustomField?.apply {
setLabel(title) setLabel(title)
setValue(value.toString(), value.isProtected) setValue(value.toString(), value.isProtected)
setValueAutoLink(true) setAutoLink()
activateCopyButton(allowCopy) activateCopyButton(allowCopy)
assignCopyButtonClickListener(onCopyButtonClickListener) assignCopyButtonClickListener(onCopyButtonClickListener)
applyFontVisibility(fontInVisibility) applyFontVisibility(fontInVisibility)

View File

@@ -30,6 +30,7 @@ import android.widget.TextView
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.core.text.util.LinkifyCompat import androidx.core.text.util.LinkifyCompat
import com.kunzisoft.keepass.R import com.kunzisoft.keepass.R
import java.util.regex.Pattern
class EntryField @JvmOverloads constructor(context: Context, class EntryField @JvmOverloads constructor(context: Context,
attrs: AttributeSet? = null, attrs: AttributeSet? = null,
@@ -100,19 +101,27 @@ class EntryField @JvmOverloads constructor(context: Context,
setTextIsSelectable(true) setTextIsSelectable(true)
} }
applyHiddenStyle(isProtected && !showButtonView.isSelected) applyHiddenStyle(isProtected && !showButtonView.isSelected)
if (valueView.autoLinkMask == Linkify.ALL) { if (valueView.autoLinkMask == LINKIFY_MASKS) {
try { linkify()
LinkifyCompat.addLinks(this, Linkify.ALL)
} catch (e: Exception) {}
} }
} }
} }
fun setValueAutoLink(autoLink: Boolean) { fun setAutoLink() {
valueView.autoLinkMask = if (autoLink && !isProtected) Linkify.ALL else 0 if (!isProtected) linkify()
changeProtectedValueParameters() changeProtectedValueParameters()
} }
private fun linkify() {
valueView.autoLinkMask = LINKIFY_MASKS
LinkifyCompat.addLinks(valueView, LINKIFY_MASKS)
}
fun setLinkAll() {
valueView.autoLinkMask = LINKIFY_ALL
LinkifyCompat.addLinks(valueView, LINKIFY_ALL)
}
fun activateCopyButton(enable: Boolean) { fun activateCopyButton(enable: Boolean) {
// Reverse because isActivated show custom color and allow click // Reverse because isActivated show custom color and allow click
copyButtonView.isActivated = !enable copyButtonView.isActivated = !enable
@@ -122,4 +131,8 @@ class EntryField @JvmOverloads constructor(context: Context,
copyButtonView.setOnClickListener(onClickActionListener) copyButtonView.setOnClickListener(onClickActionListener)
copyButtonView.visibility = if (onClickActionListener == null) GONE else VISIBLE copyButtonView.visibility = if (onClickActionListener == null) GONE else VISIBLE
} }
companion object {
private const val LINKIFY_MASKS = Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES
private const val LINKIFY_ALL = Linkify.ALL
}
} }

View File

@@ -4,3 +4,4 @@
* Fix dialog background #717 * Fix dialog background #717
* Better domain recognition for autofill #702 * Better domain recognition for autofill #702
* Write custom data #651 * Write custom data #651
* Fix autolink #720

View File

@@ -4,3 +4,4 @@
* Correction du fond des dialogues #717 * Correction du fond des dialogues #717
* Meilleure reconnaissance du domaine pour l'autofill #702 * Meilleure reconnaissance du domaine pour l'autofill #702
* Ecriture des données customisées #651 * Ecriture des données customisées #651
* Correction de l'autolink #720