Skip to content

Commit

Permalink
Add dropUnlessResumed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jun 14, 2024
1 parent 001ef93 commit fa999e7
Show file tree
Hide file tree
Showing 36 changed files with 337 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -24,6 +25,6 @@ fun ContentBlockersInfoDialog(navigator: DestinationsNavigator) {
stringResource(id = R.string.settings_changes_effect_warning_content_blocker)
)
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewCustomDnsInfoDialog() {
fun CustomDnsInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.settings_changes_effect_warning_content_blocker),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -19,6 +20,6 @@ fun DeviceNameInfoDialog(navigator: DestinationsNavigator) {
appendLine()
append(stringResource(id = R.string.device_name_info_third_paragraph))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun DiscardChangesDialog(resultBackNavigator: ResultBackNavigator<Boolean>) {
dismissButton = {
PrimaryButton(
modifier = Modifier.focusRequester(FocusRequester()),
onClick = dropUnlessResumed {resultBackNavigator.navigateBack()},
onClick = dropUnlessResumed { resultBackNavigator.navigateBack() },
text = stringResource(id = R.string.cancel)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ fun DnsDialog(
viewModel::onDnsInputChange,
onSaveDnsClick = viewModel::onSaveDnsClick,
onRemoveDnsClick = viewModel::onRemoveDnsClick,
onDismiss = dropUnlessResumed { resultNavigator.navigateBack(result = DnsDialogResult.Cancel) }
onDismiss =
dropUnlessResumed { resultNavigator.navigateBack(result = DnsDialogResult.Cancel) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -26,6 +27,6 @@ fun LocalNetworkSharingInfoDialog(navigator: DestinationsNavigator) {
appendLine(stringResource(id = R.string.local_network_sharing_additional_info))
appendLine(textResource(id = R.string.local_network_sharing_ip_ranges))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewMalwareInfoDialog() {
fun MalwareInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.malware_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewObfuscationInfoDialog() {
fun ObfuscationInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.obfuscation_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -21,6 +22,6 @@ fun QuantumResistanceInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.quantum_resistant_info_first_paragaph),
additionalInfo = stringResource(id = R.string.quantum_resistant_info_second_paragaph),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private fun PreviewReportProblemNoEmailDialog() {
@Composable
fun ReportProblemNoEmailDialog(resultBackNavigator: ResultBackNavigator<Boolean>) {
AlertDialog(
onDismissRequest = dropUnlessResumed {resultBackNavigator.navigateBack() },
onDismissRequest = dropUnlessResumed { resultBackNavigator.navigateBack() },
icon = {
Icon(
painter = painterResource(id = R.drawable.icon_alert),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -27,6 +28,6 @@ fun ServerIpOverridesInfoDialog(navigator: DestinationsNavigator) {
appendLine()
append(stringResource(id = R.string.server_ip_overrides_info_third_paragraph))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -21,6 +22,6 @@ private fun PreviewUdpOverTcpPortInfoDialog() {
fun UdpOverTcpPortInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.udp_over_tcp_port_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Parcelable
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand Down Expand Up @@ -40,6 +41,6 @@ fun WireguardPortInfoDialog(
id = R.string.wireguard_port_info_port_range,
argument.portRanges.asString()
),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -24,7 +25,7 @@ private fun PreviewVerificationPendingDialog() {
@Destination(style = DestinationStyle.Dialog::class)
@Composable
fun VerificationPendingDialog(navigator: DestinationsNavigator) {
VerificationPendingDialog(onClose = navigator::navigateUp)
VerificationPendingDialog(onClose = dropUnlessResumed { navigator.navigateUp() })
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.popUpTo
Expand Down Expand Up @@ -123,9 +124,7 @@ fun Account(
AccountScreen(
state = state,
uiSideEffect = vm.uiSideEffect,
onRedeemVoucherClick = {
navigator.navigate(RedeemVoucherDestination) { launchSingleTop = true }
},
onRedeemVoucherClick = dropUnlessResumed { navigator.navigate(RedeemVoucherDestination) },
onManageAccountClick = vm::onManageAccountClick,
onLogoutClick = vm::onLogoutClick,
navigateToLogin = {
Expand All @@ -135,16 +134,14 @@ fun Account(
}
},
onCopyAccountNumber = vm::onCopyAccountNumber,
onBackClick = navigator::navigateUp,
navigateToDeviceInfo = {
navigator.navigate(DeviceNameInfoDialogDestination) { launchSingleTop = true }
},
onBackClick = dropUnlessResumed { navigator.navigateUp() },
navigateToDeviceInfo =
dropUnlessResumed { navigator.navigate(DeviceNameInfoDialogDestination) },
onPurchaseBillingProductClick = { productId ->
navigator.navigate(PaymentDestination(productId)) { launchSingleTop = true }
navigator.navigate(PaymentDestination(productId), onlyIfResumed = true)
},
navigateToVerificationPendingDialog = {
navigator.navigate(VerificationPendingDialogDestination) { launchSingleTop = true }
}
navigateToVerificationPendingDialog =
dropUnlessResumed { navigator.navigate(VerificationPendingDialogDestination) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import androidx.constraintlayout.compose.ConstrainedLayoutReference
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.ConstraintLayoutScope
import androidx.core.text.HtmlCompat
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -74,7 +75,7 @@ private fun PreviewAutoConnectAndLockdownModeScreen() {
@Destination(style = SlideInFromRightTransition::class)
@Composable
fun AutoConnectAndLockdownMode(navigator: DestinationsNavigator) {
AutoConnectAndLockdownModeScreen(onBackClick = navigator::navigateUp)
AutoConnectAndLockdownModeScreen(onBackClick = dropUnlessResumed { navigator.navigateUp() })
}

@OptIn(ExperimentalFoundationApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.popUpTo
Expand Down Expand Up @@ -143,12 +144,12 @@ fun Connect(
openAccountPage(sideEffect.token)
}
is ConnectViewModel.UiSideEffect.OutOfTime ->
navigator.navigate(OutOfTimeDestination, true) {
navigator.navigate(OutOfTimeDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
ConnectViewModel.UiSideEffect.RevokedDevice ->
navigator.navigate(DeviceRevokedDestination, true) {
navigator.navigate(DeviceRevokedDestination) {
launchSingleTop = true
popUpTo(NavGraphs.root) { inclusive = true }
}
Expand All @@ -175,9 +176,7 @@ fun Connect(
onReconnectClick = connectViewModel::onReconnectClick,
onConnectClick = connectViewModel::onConnectClick,
onCancelClick = connectViewModel::onCancelClick,
onSwitchLocationClick = {
navigator.navigate(SelectLocationDestination, true) { launchSingleTop = true }
},
onSwitchLocationClick = dropUnlessResumed { navigator.navigate(SelectLocationDestination) },
onUpdateVersionClick = {
val intent =
Intent(
Expand All @@ -192,12 +191,8 @@ fun Connect(
context.startActivity(intent)
},
onManageAccountClick = connectViewModel::onManageAccountClick,
onSettingsClick = {
navigator.navigate(SettingsDestination, true) { launchSingleTop = true }
},
onAccountClick = {
navigator.navigate(AccountDestination, true) { launchSingleTop = true }
},
onSettingsClick = dropUnlessResumed { navigator.navigate(SettingsDestination) },
onAccountClick = dropUnlessResumed { navigator.navigate(AccountDestination) },
onDismissNewDeviceClick = connectViewModel::dismissNewDeviceNotification,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.NavResult
Expand Down Expand Up @@ -115,13 +116,14 @@ fun CustomListLocations(
onSearchTermInput = customListsViewModel::onSearchTermInput,
onSaveClick = customListsViewModel::save,
onRelaySelectionClick = customListsViewModel::onRelaySelectionClick,
onBackClick = {
if (state.hasUnsavedChanges) {
navigator.navigate(DiscardChangesDialogDestination) { launchSingleTop = true }
} else {
backNavigator.navigateBack()
onBackClick =
dropUnlessResumed {
if (state.hasUnsavedChanges) {
navigator.navigate(DiscardChangesDialogDestination)
} else {
backNavigator.navigateBack()
}
}
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.NavResult
Expand Down Expand Up @@ -92,19 +93,19 @@ fun CustomLists(
CustomListsScreen(
state = state,
snackbarHostState = snackbarHostState,
addCustomList = {
navigator.navigate(
CreateCustomListDestination(),
) {
launchSingleTop = true
}
},
addCustomList =
dropUnlessResumed {
navigator.navigate(
CreateCustomListDestination(),
)
},
openCustomList = { customList ->
navigator.navigate(EditCustomListDestination(customListId = customList.id)) {
launchSingleTop = true
}
navigator.navigate(
EditCustomListDestination(customListId = customList.id),
onlyIfResumed = true
)
},
onBackClick = navigator::navigateUp
onBackClick = dropUnlessResumed { navigator.navigateUp() }
)
}

Expand Down
Loading

0 comments on commit fa999e7

Please sign in to comment.