diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt | 15 | ||||
| -rw-r--r-- | android/src/main/res/values/attrs.xml | 1 |
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"/> |
