diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-04 19:51:25 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-27 16:21:52 +0000 |
| commit | 13f53f0f0370891c22e15dbb5e83d75976cb7998 (patch) | |
| tree | f09cdfe29b3be6f025ffdfdb054a0df6dc637fe0 /android | |
| parent | 40f65b316ec342a7f1b8c8f7bdebe4dcc26e344e (diff) | |
| download | mullvadvpn-13f53f0f0370891c22e15dbb5e83d75976cb7998.tar.xz mullvadvpn-13f53f0f0370891c22e15dbb5e83d75976cb7998.zip | |
Allow showing errors in `InformationView`
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt | 32 | ||||
| -rw-r--r-- | android/src/main/res/values/attrs.xml | 1 |
2 files changed, 28 insertions, 5 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 934c2efa25..38f4da7a18 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 @@ -47,17 +47,27 @@ open class InformationView : LinearLayout { updateEnabled() } + var error: String? = null + set(value) { + field = value + updateStatus() + } + + var errorColor = context.resources.getColor(R.color.red) + set(value) { + field = value + updateStatus() + } + var information: String? = null set(value) { field = value - informationDisplay.text = value updateStatus() } var informationColor = context.resources.getColor(R.color.white) set(value) { field = value - informationDisplay.setTextColor(value) updateStatus() } @@ -109,6 +119,8 @@ open class InformationView : LinearLayout { try { description.text = getString(R.styleable.InformationView_description) ?: "" + errorColor = getInteger(R.styleable.InformationView_errorColor, errorColor) + informationColor = getInteger( R.styleable.InformationView_informationColor, informationColor @@ -124,13 +136,23 @@ open class InformationView : LinearLayout { } private fun updateStatus() { - if (whenMissing == WhenMissing.Hide && information == null) { + val hasText = information != null || error != null + + if (error != null) { + informationDisplay.setTextColor(errorColor) + informationDisplay.text = error + } else if (information != null) { + informationDisplay.setTextColor(informationColor) + informationDisplay.text = information + } + + if (whenMissing == WhenMissing.Hide && !hasText) { visibility = INVISIBLE } else { visibility = VISIBLE } - if (whenMissing == WhenMissing.ShowSpinner && information == null) { + if (whenMissing == WhenMissing.ShowSpinner && !hasText) { spinner.visibility = VISIBLE informationDisplay.visibility = INVISIBLE } else { @@ -142,6 +164,6 @@ open class InformationView : LinearLayout { } private fun updateEnabled() { - setEnabled(shouldEnable && information != null) + setEnabled(shouldEnable && error == null && information != null) } } diff --git a/android/src/main/res/values/attrs.xml b/android/src/main/res/values/attrs.xml index f44c4e8e4e..29ea770918 100644 --- a/android/src/main/res/values/attrs.xml +++ b/android/src/main/res/values/attrs.xml @@ -14,6 +14,7 @@ </declare-styleable> <declare-styleable name="InformationView"> <attr name="description" format="reference|string"/> + <attr name="errorColor" format="reference|color"/> <attr name="informationColor" format="reference|color"/> <attr name="whenMissing" format="enum"> <enum name="nothing" value="0"/> |
