diff options
| author | Albin <albin@mullvad.net> | 2022-07-29 07:29:50 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-07-29 13:24:41 +0200 |
| commit | ff908af238ca7929dda6356ac16c43f5f930a339 (patch) | |
| tree | ee160b51a5bc9d3b62d8167b8bd46de22f6a0235 /android | |
| parent | 2f9262d344aa35367a0a3de726444092ad6cd70f (diff) | |
| download | mullvadvpn-ff908af238ca7929dda6356ac16c43f5f930a339.tar.xz mullvadvpn-ff908af238ca7929dda6356ac16c43f5f930a339.zip | |
Fix flicker on login to expired account
Diffstat (limited to 'android')
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt index c7eae144c5..9e1448d006 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/MainActivity.kt @@ -18,11 +18,16 @@ import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.debounce +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch +import kotlinx.coroutines.withTimeoutOrNull import net.mullvad.mullvadvpn.BuildConfig import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.dataproxy.MullvadProblemReport import net.mullvad.mullvadvpn.di.uiModule +import net.mullvad.mullvadvpn.model.AccountExpiry import net.mullvad.mullvadvpn.model.DeviceState import net.mullvad.mullvadvpn.ui.fragments.DeviceRevokedFragment import net.mullvad.mullvadvpn.ui.serviceconnection.AccountRepository @@ -189,9 +194,16 @@ open class MainActivity : FragmentActivity() { private suspend fun openLoggedInView(accountToken: String, shouldDelayLogin: Boolean) { val isNewAccount = accountToken == accountRepository.cachedCreatedAccount.value + val isExpired = isNewAccount.not() && isExpired(LOGIN_AWAIT_EXPIRY_MILLIS) val fragment = when { isNewAccount -> WelcomeFragment() + isExpired -> { + if (shouldDelayLogin) { + delay(LOGIN_DELAY_MILLIS) + } + OutOfTimeFragment() + } else -> { if (shouldDelayLogin) { delay(LOGIN_DELAY_MILLIS) @@ -206,6 +218,15 @@ open class MainActivity : FragmentActivity() { } } + private suspend fun isExpired(timeoutMillis: Long): Boolean { + return withTimeoutOrNull(timeoutMillis) { + accountRepository.accountExpiryState + .filter { it is AccountExpiry.Available } + .map { it.date()?.isBeforeNow } + .first() + } ?: false + } + private fun openLoginView() { clearBackStack() supportFragmentManager.beginTransaction().apply { @@ -238,5 +259,6 @@ open class MainActivity : FragmentActivity() { companion object { private const val LOGIN_DELAY_MILLIS = 1000L + private const val LOGIN_AWAIT_EXPIRY_MILLIS = 1000L } } |
