diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/SettingsNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/SettingsNavigation.kt index 19358a0e9..add6f90a0 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/SettingsNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/SettingsNavigation.kt @@ -15,8 +15,8 @@ import com.x8bit.bitwarden.ui.platform.feature.settings.autofill.autoFillDestina import com.x8bit.bitwarden.ui.platform.feature.settings.autofill.navigateToAutoFill import com.x8bit.bitwarden.ui.platform.feature.settings.other.navigateToOther import com.x8bit.bitwarden.ui.platform.feature.settings.other.otherDestination -import com.x8bit.bitwarden.ui.platform.feature.settings.vault.navigateToVault -import com.x8bit.bitwarden.ui.platform.feature.settings.vault.vaultDestination +import com.x8bit.bitwarden.ui.platform.feature.settings.vault.navigateToVaultSettings +import com.x8bit.bitwarden.ui.platform.feature.settings.vault.vaultSettingsDestination import com.x8bit.bitwarden.ui.platform.theme.TransitionProviders const val SETTINGS_GRAPH_ROUTE: String = "settings_graph" @@ -45,7 +45,7 @@ fun NavGraphBuilder.settingsGraph( onNavigateToAppearance = { navController.navigateToAppearance() }, onNavigateToAutoFill = { navController.navigateToAutoFill() }, onNavigateToOther = { navController.navigateToOther() }, - onNavigateToVault = { navController.navigateToVault() }, + onNavigateToVault = { navController.navigateToVaultSettings() }, ) } aboutDestination(onNavigateBack = { navController.popBackStack() }) @@ -53,7 +53,7 @@ fun NavGraphBuilder.settingsGraph( appearanceDestination(onNavigateBack = { navController.popBackStack() }) autoFillDestination(onNavigateBack = { navController.popBackStack() }) otherDestination(onNavigateBack = { navController.popBackStack() }) - vaultDestination(onNavigateBack = { navController.popBackStack() }) + vaultSettingsDestination(onNavigateBack = { navController.popBackStack() }) } } diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsNavigation.kt similarity index 60% rename from app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultNavigation.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsNavigation.kt index f575538ac..97feb7728 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsNavigation.kt @@ -6,28 +6,28 @@ import androidx.navigation.NavOptions import androidx.navigation.compose.composable import com.x8bit.bitwarden.ui.platform.theme.TransitionProviders -private const val VAULT_ROUTE = "settings_vault" +private const val VAULT_SETTINGS_ROUTE = "vault_settings" /** - * Add settings destinations to the nav graph. + * Add vault settings destinations to the nav graph. */ -fun NavGraphBuilder.vaultDestination( +fun NavGraphBuilder.vaultSettingsDestination( onNavigateBack: () -> Unit, ) { composable( - route = VAULT_ROUTE, + route = VAULT_SETTINGS_ROUTE, enterTransition = TransitionProviders.Enter.pushLeft, exitTransition = TransitionProviders.Exit.pushLeft, popEnterTransition = TransitionProviders.Enter.pushLeft, popExitTransition = TransitionProviders.Exit.pushRight, ) { - VaultScreen(onNavigateBack = onNavigateBack) + VaultSettingsScreen(onNavigateBack = onNavigateBack) } } /** - * Navigate to the vault screen. + * Navigate to the vault settings screen. */ -fun NavController.navigateToVault(navOptions: NavOptions? = null) { - navigate(VAULT_ROUTE, navOptions) +fun NavController.navigateToVaultSettings(navOptions: NavOptions? = null) { + navigate(VAULT_SETTINGS_ROUTE, navOptions) } diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreen.kt similarity index 90% rename from app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreen.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreen.kt index 6d1e3548e..188b3e144 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreen.kt @@ -25,13 +25,13 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar */ @OptIn(ExperimentalMaterial3Api::class) @Composable -fun VaultScreen( +fun VaultSettingsScreen( onNavigateBack: () -> Unit, - viewModel: VaultViewModel = hiltViewModel(), + viewModel: VaultSettingsViewModel = hiltViewModel(), ) { EventsEffect(viewModel = viewModel) { event -> when (event) { - VaultEvent.NavigateBack -> onNavigateBack.invoke() + VaultSettingsEvent.NavigateBack -> onNavigateBack.invoke() } } @@ -47,7 +47,7 @@ fun VaultScreen( navigationIcon = painterResource(id = R.drawable.ic_back), navigationIconContentDescription = stringResource(id = R.string.back), onNavigationIconClick = remember(viewModel) { - { viewModel.trySendAction(VaultAction.BackClick) } + { viewModel.trySendAction(VaultSettingsAction.BackClick) } }, ) }, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModel.kt new file mode 100644 index 000000000..f1afc2adb --- /dev/null +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModel.kt @@ -0,0 +1,38 @@ +package com.x8bit.bitwarden.ui.platform.feature.settings.vault + +import com.x8bit.bitwarden.ui.platform.base.BaseViewModel +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +/** + * View model for the vault screen. + */ +@HiltViewModel +class VaultSettingsViewModel @Inject constructor() : + BaseViewModel( + initialState = Unit, + ) { + override fun handleAction(action: VaultSettingsAction): Unit = when (action) { + VaultSettingsAction.BackClick -> sendEvent(VaultSettingsEvent.NavigateBack) + } +} + +/** + * Models events for the vault screen. + */ +sealed class VaultSettingsEvent { + /** + * Navigate back. + */ + data object NavigateBack : VaultSettingsEvent() +} + +/** + * Models actions for the vault screen. + */ +sealed class VaultSettingsAction { + /** + * User clicked back button. + */ + data object BackClick : VaultSettingsAction() +} diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModel.kt deleted file mode 100644 index 2382ff2c6..000000000 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModel.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.x8bit.bitwarden.ui.platform.feature.settings.vault - -import com.x8bit.bitwarden.ui.platform.base.BaseViewModel -import dagger.hilt.android.lifecycle.HiltViewModel -import javax.inject.Inject - -/** - * View model for the vault screen. - */ -@HiltViewModel -class VaultViewModel @Inject constructor() : BaseViewModel( - initialState = Unit, -) { - override fun handleAction(action: VaultAction): Unit = when (action) { - VaultAction.BackClick -> sendEvent(VaultEvent.NavigateBack) - } -} - -/** - * Models events for the vault screen. - */ -sealed class VaultEvent { - /** - * Navigate back. - */ - data object NavigateBack : VaultEvent() -} - -/** - * Models actions for the vault screen. - */ -sealed class VaultAction { - /** - * User clicked back button. - */ - data object BackClick : VaultAction() -} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt similarity index 70% rename from app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreenTest.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt index 294e3b4b3..fe7e6bfa5 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt @@ -11,32 +11,32 @@ import kotlinx.coroutines.flow.flowOf import org.junit.Assert.assertTrue import org.junit.Test -class VaultScreenTest : BaseComposeTest() { +class VaultSettingsScreenTest : BaseComposeTest() { @Test fun `on back click should send BackClick`() { - val viewModel: VaultViewModel = mockk { + val viewModel: VaultSettingsViewModel = mockk { every { eventFlow } returns emptyFlow() - every { trySendAction(VaultAction.BackClick) } returns Unit + every { trySendAction(VaultSettingsAction.BackClick) } returns Unit } composeTestRule.setContent { - VaultScreen( + VaultSettingsScreen( viewModel = viewModel, onNavigateBack = { }, ) } composeTestRule.onNodeWithContentDescription("Back").performClick() - verify { viewModel.trySendAction(VaultAction.BackClick) } + verify { viewModel.trySendAction(VaultSettingsAction.BackClick) } } @Test fun `on NavigateAbout should call onNavigateToVault`() { var haveCalledNavigateBack = false - val viewModel = mockk { - every { eventFlow } returns flowOf(VaultEvent.NavigateBack) + val viewModel = mockk { + every { eventFlow } returns flowOf(VaultSettingsEvent.NavigateBack) } composeTestRule.setContent { - VaultScreen( + VaultSettingsScreen( viewModel = viewModel, onNavigateBack = { haveCalledNavigateBack = true }, ) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModelTest.kt similarity index 62% rename from app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModelTest.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModelTest.kt index 7102eefb4..0aae81b86 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsViewModelTest.kt @@ -6,14 +6,14 @@ import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -class VaultViewModelTest : BaseViewModelTest() { +class VaultSettingsViewModelTest : BaseViewModelTest() { @Test fun `on BackClick should emit NavigateBack`() = runTest { - val viewModel = VaultViewModel() + val viewModel = VaultSettingsViewModel() viewModel.eventFlow.test { - viewModel.trySendAction(VaultAction.BackClick) - assertEquals(VaultEvent.NavigateBack, awaitItem()) + viewModel.trySendAction(VaultSettingsAction.BackClick) + assertEquals(VaultSettingsEvent.NavigateBack, awaitItem()) } } }