Skip to content

Commit

Permalink
Merge branch 'outoftimescreen-is-navigated-to-despite-the-connectscre…
Browse files Browse the repository at this point in the history
…en-droid-658'
  • Loading branch information
Rawa committed Mar 11, 2024
2 parents 4869427 + c6b1744 commit bed06a1
Show file tree
Hide file tree
Showing 39 changed files with 477 additions and 409 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -22,6 +21,7 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.NegativeButton
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.textfield.DnsTextField
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.viewmodel.DnsDialogSideEffect
Expand Down Expand Up @@ -100,11 +100,9 @@ fun DnsDialog(
val viewModel =
koinViewModel<DnsDialogViewModel>(parameters = { parametersOf(initialValue, index) })

LaunchedEffect(Unit) {
viewModel.uiSideEffect.collect {
when (it) {
DnsDialogSideEffect.Complete -> resultNavigator.navigateBack(result = true)
}
LaunchedEffectCollect(viewModel.uiSideEffect) {
when (it) {
DnsDialogSideEffect.Complete -> resultNavigator.navigateBack(result = true)
}
}
val state by viewModel.uiState.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
Expand All @@ -21,6 +20,7 @@ import com.ramcosta.composedestinations.spec.DestinationStyle
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.textfield.MtuTextField
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.constant.MTU_MAX_VALUE
import net.mullvad.mullvadvpn.constant.MTU_MIN_VALUE
import net.mullvad.mullvadvpn.lib.theme.AppTheme
Expand All @@ -42,11 +42,9 @@ private fun PreviewMtuDialog() {
fun MtuDialog(mtuInitial: Int?, navigator: DestinationsNavigator) {
val viewModel = koinViewModel<MtuDialogViewModel>()

LaunchedEffect(Unit) {
viewModel.uiSideEffect.collect {
when (it) {
MtuDialogSideEffect.Complete -> navigator.navigateUp()
}
LaunchedEffectCollect(viewModel.uiSideEffect) {
when (it) {
MtuDialogSideEffect.Complete -> navigator.navigateUp()
}
}
MtuDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.ramcosta.composedestinations.spec.DestinationStyle
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.component.MullvadCircularProgressIndicatorMedium
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.lib.payment.model.ProductId
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.color.AlphaDescription
Expand Down Expand Up @@ -125,12 +126,10 @@ fun Payment(productId: ProductId, resultBackNavigator: ResultBackNavigator<Boole
val vm = koinViewModel<PaymentViewModel>()
val state by vm.uiState.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
vm.uiSideEffect.collect {
when (it) {
is PaymentUiSideEffect.PaymentCancelled ->
resultBackNavigator.navigateBack(result = false)
}
LaunchedEffectCollect(vm.uiSideEffect) {
when (it) {
is PaymentUiSideEffect.PaymentCancelled ->
resultBackNavigator.navigateBack(result = false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -55,6 +54,7 @@ import net.mullvad.mullvadvpn.compose.destinations.RedeemVoucherDestination
import net.mullvad.mullvadvpn.compose.destinations.VerificationPendingDialogDestination
import net.mullvad.mullvadvpn.compose.state.PaymentState
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromBottomTransition
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.compose.util.SecureScreenWhileInView
import net.mullvad.mullvadvpn.lib.common.util.openAccountPageInBrowser
import net.mullvad.mullvadvpn.lib.payment.model.PaymentProduct
Expand Down Expand Up @@ -171,22 +171,20 @@ fun AccountScreen(
val clipboardManager = LocalClipboardManager.current
val snackbarHostState = remember { SnackbarHostState() }
val copyTextString = stringResource(id = R.string.copied_mullvad_account_number)
LaunchedEffect(Unit) {
uiSideEffect.collect { uiSideEffect ->
when (uiSideEffect) {
AccountViewModel.UiSideEffect.NavigateToLogin -> navigateToLogin()
is AccountViewModel.UiSideEffect.OpenAccountManagementPageInBrowser ->
context.openAccountPageInBrowser(uiSideEffect.token)
is AccountViewModel.UiSideEffect.CopyAccountNumber ->
launch {
clipboardManager.setText(AnnotatedString(uiSideEffect.accountNumber))
LaunchedEffectCollect(uiSideEffect) { sideEffect ->
when (sideEffect) {
AccountViewModel.UiSideEffect.NavigateToLogin -> navigateToLogin()
is AccountViewModel.UiSideEffect.OpenAccountManagementPageInBrowser ->
context.openAccountPageInBrowser(sideEffect.token)
is AccountViewModel.UiSideEffect.CopyAccountNumber ->
launch {
clipboardManager.setText(AnnotatedString(sideEffect.accountNumber))

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(message = copyTextString)
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
snackbarHostState.currentSnackbarData?.dismiss()
snackbarHostState.showSnackbar(message = copyTextString)
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableLongStateOf
Expand All @@ -39,6 +38,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
Expand Down Expand Up @@ -66,6 +66,7 @@ import net.mullvad.mullvadvpn.compose.test.RECONNECT_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SCROLLABLE_COLUMN_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.compose.transitions.HomeTransition
import net.mullvad.mullvadvpn.compose.util.CollectSideEffectWithLifecycle
import net.mullvad.mullvadvpn.constant.SECURE_ZOOM
import net.mullvad.mullvadvpn.constant.SECURE_ZOOM_ANIMATION_MILLIS
import net.mullvad.mullvadvpn.constant.UNSECURE_ZOOM
Expand Down Expand Up @@ -111,35 +112,36 @@ fun Connect(navigator: DestinationsNavigator) {
val state by connectViewModel.uiState.collectAsStateWithLifecycle()

val context = LocalContext.current
LaunchedEffect(key1 = Unit) {
connectViewModel.uiSideEffect.collect { uiSideEffect ->
when (uiSideEffect) {
is ConnectViewModel.UiSideEffect.OpenAccountManagementPageInBrowser -> {
context.openAccountPageInBrowser(uiSideEffect.token)
}
is ConnectViewModel.UiSideEffect.OutOfTime -> {
navigator.navigate(OutOfTimeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}

CollectSideEffectWithLifecycle(
connectViewModel.uiSideEffect,
minActiveState = Lifecycle.State.RESUMED
) { sideEffect ->
when (sideEffect) {
is ConnectViewModel.UiSideEffect.OpenAccountManagementPageInBrowser -> {
context.openAccountPageInBrowser(sideEffect.token)
}
is ConnectViewModel.UiSideEffect.OutOfTime ->
navigator.navigate(OutOfTimeDestination, true) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
ConnectViewModel.UiSideEffect.RevokedDevice -> {
navigator.navigate(DeviceRevokedDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
ConnectViewModel.UiSideEffect.RevokedDevice ->
navigator.navigate(DeviceRevokedDestination, true) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
}
}
}

ConnectScreen(
state = state,
onDisconnectClick = connectViewModel::onDisconnectClick,
onReconnectClick = connectViewModel::onReconnectClick,
onConnectClick = connectViewModel::onConnectClick,
onCancelClick = connectViewModel::onCancelClick,
onSwitchLocationClick = {
navigator.navigate(SelectLocationDestination) { launchSingleTop = true }
navigator.navigate(SelectLocationDestination, true) { launchSingleTop = true }
},
onUpdateVersionClick = {
val intent =
Expand All @@ -155,8 +157,12 @@ fun Connect(navigator: DestinationsNavigator) {
context.startActivity(intent)
},
onManageAccountClick = connectViewModel::onManageAccountClick,
onSettingsClick = { navigator.navigate(SettingsDestination) { launchSingleTop = true } },
onAccountClick = { navigator.navigate(AccountDestination) { launchSingleTop = true } },
onSettingsClick = {
navigator.navigate(SettingsDestination, true) { launchSingleTop = true }
},
onAccountClick = {
navigator.navigate(AccountDestination, true) { launchSingleTop = true }
},
onDismissNewDeviceClick = connectViewModel::dismissNewDeviceNotification,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand All @@ -32,6 +31,7 @@ import net.mullvad.mullvadvpn.compose.component.ScaffoldWithTopBar
import net.mullvad.mullvadvpn.compose.destinations.LoginDestination
import net.mullvad.mullvadvpn.compose.destinations.SettingsDestination
import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.viewmodel.DeviceRevokedSideEffect
Expand All @@ -51,16 +51,13 @@ fun DeviceRevoked(navigator: DestinationsNavigator) {

val state by viewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
viewModel.uiSideEffect.collect { sideEffect ->
when (sideEffect) {
DeviceRevokedSideEffect.NavigateToLogin -> {
navigator.navigate(LoginDestination()) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
LaunchedEffectCollect(viewModel.uiSideEffect) { sideEffect ->
when (sideEffect) {
DeviceRevokedSideEffect.NavigateToLogin ->
navigator.navigate(LoginDestination()) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
Expand All @@ -39,6 +38,7 @@ import net.mullvad.mullvadvpn.compose.extensions.itemWithDivider
import net.mullvad.mullvadvpn.compose.extensions.itemsWithDivider
import net.mullvad.mullvadvpn.compose.state.RelayFilterState
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
import net.mullvad.mullvadvpn.compose.util.LaunchedEffectCollect
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.model.Ownership
Expand Down Expand Up @@ -72,11 +72,9 @@ fun FilterScreen(navigator: DestinationsNavigator) {
val viewModel = koinViewModel<FilterViewModel>()
val state by viewModel.uiState.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
viewModel.uiSideEffect.collect {
when (it) {
FilterScreenSideEffect.CloseScreen -> navigator.navigateUp()
}
LaunchedEffectCollect(viewModel.uiSideEffect) {
when (it) {
FilterScreenSideEffect.CloseScreen -> navigator.navigateUp()
}
}
FilterScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import net.mullvad.mullvadvpn.compose.test.LOGIN_INPUT_TEST_TAG
import net.mullvad.mullvadvpn.compose.test.LOGIN_TITLE_TEST_TAG
import net.mullvad.mullvadvpn.compose.textfield.mullvadWhiteTextFieldColors
import net.mullvad.mullvadvpn.compose.transitions.LoginTransition
import net.mullvad.mullvadvpn.compose.util.CollectSideEffectWithLifecycle
import net.mullvad.mullvadvpn.compose.util.accountTokenVisualTransformation
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
Expand Down Expand Up @@ -130,32 +131,27 @@ fun Login(
}
}

LaunchedEffect(Unit) {
vm.uiSideEffect.collect {
when (it) {
LoginUiSideEffect.NavigateToWelcome -> {
navigator.navigate(WelcomeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
CollectSideEffectWithLifecycle(vm.uiSideEffect) {
when (it) {
LoginUiSideEffect.NavigateToWelcome ->
navigator.navigate(WelcomeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
is LoginUiSideEffect.NavigateToConnect -> {
navigator.navigate(ConnectDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
is LoginUiSideEffect.NavigateToConnect ->
navigator.navigate(ConnectDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
is LoginUiSideEffect.TooManyDevices -> {
navigator.navigate(DeviceListDestination(it.accountToken.value)) {
launchSingleTop = true
}
is LoginUiSideEffect.TooManyDevices ->
navigator.navigate(DeviceListDestination(it.accountToken.value)) {
launchSingleTop = true
}
LoginUiSideEffect.NavigateToOutOfTime ->
navigator.navigate(OutOfTimeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
LoginUiSideEffect.NavigateToOutOfTime ->
navigator.navigate(OutOfTimeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
}
}
}
LoginScreen(
Expand Down
Loading

0 comments on commit bed06a1

Please sign in to comment.