summaryrefslogtreecommitdiffhomepage
path: root/android/lib
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2024-10-09 13:08:23 +0200
committerDavid Göransson <david.goransson@mullvad.net>2024-10-15 14:38:37 +0200
commit57aa8880dcd2d739d852fee1fa60bdd49dec9f80 (patch)
tree698af4176e8685c2ca8d2517fb16488df391ae32 /android/lib
parent9e2e53486a66fd3ad83d5775b050041a29131652 (diff)
downloadmullvadvpn-57aa8880dcd2d739d852fee1fa60bdd49dec9f80.tar.xz
mullvadvpn-57aa8880dcd2d739d852fee1fa60bdd49dec9f80.zip
Show create account confirm when user has account
Diffstat (limited to 'android/lib')
-rw-r--r--android/lib/resource/src/main/res/values/strings.xml3
-rw-r--r--android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt15
2 files changed, 16 insertions, 2 deletions
diff --git a/android/lib/resource/src/main/res/values/strings.xml b/android/lib/resource/src/main/res/values/strings.xml
index e3a591257d..693ac3a789 100644
--- a/android/lib/resource/src/main/res/values/strings.xml
+++ b/android/lib/resource/src/main/res/values/strings.xml
@@ -18,6 +18,8 @@
<string name="login_fail_description">Invalid account number</string>
<string name="dont_have_an_account">Don’t have an account number?</string>
<string name="create_account">Create account</string>
+ <string name="create_new_account_warning_paragraph1">You already have a saved account number, by creating a new account the saved account number will be removed from this device. This cannot be undone.</string>
+ <string name="create_new_account_warning_paragraph2">Do you want to create a new account?</string>
<string name="creating_new_account">Creating account...</string>
<string name="failed_to_create_account">Failed to create account</string>
<string name="account_created">Account created</string>
@@ -282,6 +284,7 @@
<string name="all_locations">All locations</string>
<string name="edit_lists">Edit lists</string>
<string name="create_new_list">Create new list</string>
+ <string name="create_new_account">Create new account</string>
<string name="create">Create</string>
<string name="no_locations_found">No locations found</string>
<string name="add_locations">Add locations</string>
diff --git a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
index b605bf7ac0..f6b146ecd3 100644
--- a/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
+++ b/android/lib/shared/src/main/kotlin/net/mullvad/mullvadvpn/lib/shared/AccountRepository.kt
@@ -16,6 +16,7 @@ import kotlinx.coroutines.flow.update
import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService
import net.mullvad.mullvadvpn.lib.model.AccountData
import net.mullvad.mullvadvpn.lib.model.AccountNumber
+import net.mullvad.mullvadvpn.lib.model.ClearAccountHistoryError
import net.mullvad.mullvadvpn.lib.model.CreateAccountError
import net.mullvad.mullvadvpn.lib.model.DeviceState
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
@@ -31,7 +32,13 @@ class AccountRepository(
private val _mutableAccountDataCache: MutableSharedFlow<AccountData> = MutableSharedFlow()
private val _isNewAccount: MutableStateFlow<Boolean> = MutableStateFlow(false)
+
+ private val _mutableAccountHistory: MutableStateFlow<AccountNumber?> = MutableStateFlow(null)
+
val isNewAccount: StateFlow<Boolean> = _isNewAccount
+
+ val accountHistory: StateFlow<AccountNumber?> = _mutableAccountHistory
+
val accountData: StateFlow<AccountData?> =
merge(
managementService.deviceState.filterNotNull().map { deviceState ->
@@ -58,9 +65,13 @@ class AccountRepository(
managementService.logoutAccount().onRight { _isNewAccount.update { false } }
suspend fun fetchAccountHistory(): AccountNumber? =
- managementService.getAccountHistory().getOrNull()
+ managementService
+ .getAccountHistory()
+ .onRight { _mutableAccountHistory.value = it }
+ .getOrNull()
- suspend fun clearAccountHistory() = managementService.clearAccountHistory()
+ suspend fun clearAccountHistory(): Either<ClearAccountHistoryError, Unit> =
+ managementService.clearAccountHistory().onRight { _mutableAccountHistory.value = null }
suspend fun getAccountData(): AccountData? = nullable {
val deviceState = ensureNotNull(deviceRepository.deviceState.value as? DeviceState.LoggedIn)