summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-24 19:42:26 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-27 16:21:52 +0000
commit37e120656a80d24a654c1153c8b0a62c214ab888 (patch)
tree760ce624dd7e221d98b27d37265a3d1bf65a9e90 /android/src
parenta2790cc57a83217b6ca44f93c31c3bbba9260d6d (diff)
downloadmullvadvpn-37e120656a80d24a654c1153c8b0a62c214ab888.tar.xz
mullvadvpn-37e120656a80d24a654c1153c8b0a62c214ab888.zip
Allow setting a maximum length for the information
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt15
-rw-r--r--android/src/main/res/values/attrs.xml1
2 files changed, 15 insertions, 1 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt
index 38f4da7a18..67d2dd07cc 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt
@@ -71,6 +71,12 @@ open class InformationView : LinearLayout {
updateStatus()
}
+ var maxLength = 0
+ set(value) {
+ field = value
+ updateStatus()
+ }
+
var whenMissing = WhenMissing.Nothing
set(value) {
field = value
@@ -120,6 +126,7 @@ open class InformationView : LinearLayout {
description.text = getString(R.styleable.InformationView_description) ?: ""
errorColor = getInteger(R.styleable.InformationView_errorColor, errorColor)
+ maxLength = getInteger(R.styleable.InformationView_maxLength, 0)
informationColor = getInteger(
R.styleable.InformationView_informationColor,
@@ -136,6 +143,7 @@ open class InformationView : LinearLayout {
}
private fun updateStatus() {
+ val information = this.information
val hasText = information != null || error != null
if (error != null) {
@@ -143,7 +151,12 @@ open class InformationView : LinearLayout {
informationDisplay.text = error
} else if (information != null) {
informationDisplay.setTextColor(informationColor)
- informationDisplay.text = information
+
+ if (maxLength == 0 || information.length <= maxLength) {
+ informationDisplay.text = information
+ } else {
+ informationDisplay.text = information.substring(0, maxLength) + "..."
+ }
}
if (whenMissing == WhenMissing.Hide && !hasText) {
diff --git a/android/src/main/res/values/attrs.xml b/android/src/main/res/values/attrs.xml
index 29ea770918..85e9c24dd5 100644
--- a/android/src/main/res/values/attrs.xml
+++ b/android/src/main/res/values/attrs.xml
@@ -16,6 +16,7 @@
<attr name="description" format="reference|string"/>
<attr name="errorColor" format="reference|color"/>
<attr name="informationColor" format="reference|color"/>
+ <attr name="maxLength" format="integer"/>
<attr name="whenMissing" format="enum">
<enum name="nothing" value="0"/>
<enum name="hide" value="1"/>