summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-27 09:34:15 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-27 09:34:15 -0300
commit380e2004224e92822ec80888f68259a6eb60deab (patch)
tree89b4bba13d5097bee1f80eb522255203ed4a54ac /android/src
parent25dfa99c3de49419c0739c08ac514467d399b17d (diff)
parent1b12e84d308d10b10564455bbd7f91b9979f9945 (diff)
downloadmullvadvpn-380e2004224e92822ec80888f68259a6eb60deab.tar.xz
mullvadvpn-380e2004224e92822ec80888f68259a6eb60deab.zip
Merge branch 'format-account-number-on-android'
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt18
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt14
2 files changed, 28 insertions, 4 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt
index b13863f108..2893729917 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt
@@ -28,7 +28,10 @@ class AccountFragment : ServiceDependentFragment(OnNoService.GoBack) {
view.findViewById<View>(R.id.logout).setOnClickListener { logout() }
- accountNumberView = view.findViewById(R.id.account_number)
+ accountNumberView = view.findViewById<CopyableInformationView>(R.id.account_number).apply {
+ displayFormatter = { rawAccountNumber -> addSpacesToAccountNumber(rawAccountNumber) }
+ }
+
accountExpiryView = view.findViewById(R.id.account_expiry)
return view
@@ -96,4 +99,17 @@ class AccountFragment : ServiceDependentFragment(OnNoService.GoBack) {
commit()
}
}
+
+ private fun addSpacesToAccountNumber(rawAccountNumber: String): String {
+ return rawAccountNumber
+ .asSequence()
+ .fold(StringBuilder()) { formattedAccountNumber, nextDigit ->
+ if ((formattedAccountNumber.length % 5) == 4) {
+ formattedAccountNumber.append(' ')
+ }
+
+ formattedAccountNumber.append(nextDigit)
+ }
+ .toString()
+ }
}
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 67d2dd07cc..8395d6ad27 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
@@ -41,6 +41,12 @@ open class InformationView : LinearLayout {
private val informationDisplay: TextView = findViewById(R.id.information_display)
private val spinner: View = findViewById(R.id.spinner)
+ var displayFormatter: ((String) -> String)? = null
+ set(value) {
+ field = value
+ updateStatus()
+ }
+
var shouldEnable = false
set(value) {
field = value
@@ -150,12 +156,14 @@ open class InformationView : LinearLayout {
informationDisplay.setTextColor(errorColor)
informationDisplay.text = error
} else if (information != null) {
+ val formattedInformation = displayFormatter?.invoke(information) ?: information
+
informationDisplay.setTextColor(informationColor)
- if (maxLength == 0 || information.length <= maxLength) {
- informationDisplay.text = information
+ if (maxLength == 0 || formattedInformation.length <= maxLength) {
+ informationDisplay.text = formattedInformation
} else {
- informationDisplay.text = information.substring(0, maxLength) + "..."
+ informationDisplay.text = formattedInformation.substring(0, maxLength) + "..."
}
}