mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Set max chars
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user