diff options
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/AccountFragment.kt | 18 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/InformationView.kt | 14 |
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) + "..." } } |
