Set max chars

This commit is contained in:
J-Jamet
2021-07-09 13:54:46 +02:00
parent 32b8c505d9
commit 876e749b31
4 changed files with 44 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ class TemplateEditView @JvmOverloads constructor(context: Context,
return context?.let {
TextEditFieldView(it).apply {
setProtection(field.protectedValue.isProtected, mHideProtectedValue)
// TODO Max chars
setMaxChars(templateAttribute.options.getNumberChars())
setMaxLines(templateAttribute.options.getNumberLines())
setActionClick(templateAttribute, field, this)
}

View File

@@ -52,6 +52,7 @@ class TemplateView @JvmOverloads constructor(context: Context,
setProtection(field.protectedValue.isProtected, mHideProtectedValue)
label = templateAttribute.alias
?: TemplateField.getLocalizedName(context, field.name)
setMaxChars(templateAttribute.options.getNumberChars())
setMaxLines(templateAttribute.options.getNumberLines())
// TODO Linkify
value = field.protectedValue.stringValue

View File

@@ -1,6 +1,7 @@
package com.kunzisoft.keepass.view
import android.content.Context
import android.text.InputFilter
import android.text.InputType
import android.util.AttributeSet
import android.util.TypedValue
@@ -121,6 +122,18 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
valueView.setText(value)
}
fun setMaxChars(numberChars: Int) {
when {
numberChars <= 0 -> {
valueView.filters += InputFilter.LengthFilter(MAX_CHARS_LIMIT)
}
else -> {
val chars = if (numberChars > MAX_CHARS_LIMIT) MAX_CHARS_LIMIT else numberChars
valueView.filters += InputFilter.LengthFilter(chars)
}
}
}
fun setMaxLines(numberLines: Int) {
when {
numberLines == 1 -> {
@@ -131,14 +144,13 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
numberLines <= 0 -> {
valueView.inputType = valueView.inputType or
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
valueView.maxEms = 40
valueView.maxLines = 40
valueView.maxLines = MAX_LINES_LIMIT
}
else -> {
val lines = if (numberLines > MAX_LINES_LIMIT) MAX_LINES_LIMIT else numberLines
valueView.inputType = valueView.inputType or
InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
valueView.maxEms = numberLines
valueView.maxLines = numberLines
valueView.maxLines = lines
}
}
}
@@ -167,4 +179,9 @@ class TextEditFieldView @JvmOverloads constructor(context: Context,
set(value) {
isVisible = value
}
companion object {
const val MAX_CHARS_LIMIT = Integer.MAX_VALUE
const val MAX_LINES_LIMIT = 40
}
}

View File

@@ -20,6 +20,7 @@
package com.kunzisoft.keepass.view
import android.content.Context
import android.text.InputFilter
import android.text.util.Linkify
import android.util.AttributeSet
import android.view.LayoutInflater
@@ -87,15 +88,26 @@ class TextFieldView @JvmOverloads constructor(context: Context,
changeProtectedValueParameters()
}
fun setMaxChars(numberChars: Int) {
when {
numberChars <= 0 -> {
valueView.filters += InputFilter.LengthFilter(MAX_CHARS_LIMIT)
}
else -> {
val chars = if (numberChars > MAX_CHARS_LIMIT) MAX_CHARS_LIMIT else numberChars
valueView.filters += InputFilter.LengthFilter(chars)
}
}
}
fun setMaxLines(numberLines: Int) {
when {
numberLines <= 0 -> {
valueView.maxEms = 40
valueView.maxLines = 40
valueView.maxLines = MAX_LINES_LIMIT
}
else -> {
valueView.maxEms = numberLines
valueView.maxLines = numberLines
val lines = if (numberLines > MAX_LINES_LIMIT) MAX_LINES_LIMIT else numberLines
valueView.maxLines = lines
}
}
}
@@ -202,4 +214,9 @@ class TextFieldView @JvmOverloads constructor(context: Context,
enum class ButtonState {
ACTIVATE, DEACTIVATE, GONE
}
companion object {
const val MAX_CHARS_LIMIT = Integer.MAX_VALUE
const val MAX_LINES_LIMIT = 40
}
}