Skip to content

Commit

Permalink
Merge pull request #7354 from thunderbird/change_account_setup_naviga…
Browse files Browse the repository at this point in the history
…tion

Replace `AccountSetupScreen` with `AccountSetupNavHost`
  • Loading branch information
wmontwe authored Nov 16, 2023
2 parents 3dc3b52 + 1fac2f5 commit 0393f23
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 765 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import app.k9mail.feature.account.server.validation.featureAccountServerValidati
import app.k9mail.feature.account.setup.domain.DomainContract
import app.k9mail.feature.account.setup.domain.usecase.CreateAccount
import app.k9mail.feature.account.setup.domain.usecase.GetAutoDiscovery
import app.k9mail.feature.account.setup.ui.AccountSetupViewModel
import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryContract
import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryValidator
import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryViewModel
Expand Down Expand Up @@ -56,11 +55,6 @@ val featureAccountSetupModule: Module = module {
factory<AccountAutoDiscoveryContract.Validator> { AccountAutoDiscoveryValidator() }
factory<AccountOptionsContract.Validator> { AccountOptionsValidator() }

viewModel {
AccountSetupViewModel(
accountStateRepository = get(),
)
}
viewModel {
AccountAutoDiscoveryViewModel(
validator = get(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package app.k9mail.feature.account.setup.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsScreen
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsViewModel
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsScreen
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsViewModel
import app.k9mail.feature.account.server.validation.ui.IncomingServerValidationViewModel
import app.k9mail.feature.account.server.validation.ui.OutgoingServerValidationViewModel
import app.k9mail.feature.account.server.validation.ui.ServerValidationScreen
import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryScreen
import app.k9mail.feature.account.setup.ui.autodiscovery.AccountAutoDiscoveryViewModel
import app.k9mail.feature.account.setup.ui.createaccount.CreateAccountScreen
import app.k9mail.feature.account.setup.ui.createaccount.CreateAccountViewModel
import app.k9mail.feature.account.setup.ui.options.AccountOptionsScreen
import app.k9mail.feature.account.setup.ui.options.AccountOptionsViewModel
import org.koin.androidx.compose.koinViewModel

private const val NESTED_NAVIGATION_AUTO_CONFIG = "autoconfig"
private const val NESTED_NAVIGATION_INCOMING_SERVER_CONFIG = "incoming-server/config"
private const val NESTED_NAVIGATION_INCOMING_SERVER_VALIDATION = "incoming-server/validation"
private const val NESTED_NAVIGATION_OUTGOING_SERVER_CONFIG = "outgoing-server/config"
private const val NESTED_NAVIGATION_OUTGOING_SERVER_VALIDATION = "outgoing-server/validation"
private const val NESTED_NAVIGATION_ACCOUNT_OPTIONS = "account-options"
private const val NESTED_NAVIGATION_CREATE_ACCOUNT = "create-account"

@Suppress("LongMethod")
@Composable
fun AccountSetupNavHost(
onBack: () -> Unit,
onFinish: (String) -> Unit,
) {
val navController = rememberNavController()
var isAutomaticConfig by rememberSaveable { mutableStateOf(false) }

NavHost(
navController = navController,
startDestination = NESTED_NAVIGATION_AUTO_CONFIG,
) {
composable(route = NESTED_NAVIGATION_AUTO_CONFIG) {
AccountAutoDiscoveryScreen(
onNext = { automaticConfig ->
isAutomaticConfig = automaticConfig
if (isAutomaticConfig) {
navController.navigate(NESTED_NAVIGATION_INCOMING_SERVER_VALIDATION)
} else {
navController.navigate(NESTED_NAVIGATION_INCOMING_SERVER_CONFIG)
}
},
onBack = onBack,
viewModel = koinViewModel<AccountAutoDiscoveryViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_INCOMING_SERVER_CONFIG) {
IncomingServerSettingsScreen(
onNext = { navController.navigate(NESTED_NAVIGATION_INCOMING_SERVER_VALIDATION) },
onBack = { navController.popBackStack() },
viewModel = koinViewModel<IncomingServerSettingsViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_INCOMING_SERVER_VALIDATION) {
ServerValidationScreen(
onNext = {
if (isAutomaticConfig) {
navController.navigate(NESTED_NAVIGATION_OUTGOING_SERVER_VALIDATION) {
popUpTo(NESTED_NAVIGATION_AUTO_CONFIG)
}
} else {
navController.navigate(NESTED_NAVIGATION_OUTGOING_SERVER_CONFIG) {
popUpTo(NESTED_NAVIGATION_INCOMING_SERVER_CONFIG)
}
}
},
onBack = { navController.popBackStack() },
viewModel = koinViewModel<IncomingServerValidationViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_OUTGOING_SERVER_CONFIG) {
OutgoingServerSettingsScreen(
onNext = { navController.navigate(NESTED_NAVIGATION_OUTGOING_SERVER_VALIDATION) },
onBack = { navController.popBackStack() },
viewModel = koinViewModel<OutgoingServerSettingsViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_OUTGOING_SERVER_VALIDATION) {
ServerValidationScreen(
onNext = {
navController.navigate(NESTED_NAVIGATION_ACCOUNT_OPTIONS) {
if (isAutomaticConfig) {
popUpTo(NESTED_NAVIGATION_AUTO_CONFIG)
} else {
popUpTo(NESTED_NAVIGATION_OUTGOING_SERVER_CONFIG)
}
}
},
onBack = { navController.popBackStack() },
viewModel = koinViewModel<OutgoingServerValidationViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_ACCOUNT_OPTIONS) {
AccountOptionsScreen(
onNext = { navController.navigate(NESTED_NAVIGATION_CREATE_ACCOUNT) },
onBack = { navController.popBackStack() },
viewModel = koinViewModel<AccountOptionsViewModel>(),
)
}

composable(route = NESTED_NAVIGATION_CREATE_ACCOUNT) {
CreateAccountScreen(
onNext = { accountUuid -> onFinish(accountUuid.value) },
onBack = { navController.popBackStack() },
viewModel = koinViewModel<CreateAccountViewModel>(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
package app.k9mail.feature.account.setup.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import app.k9mail.core.ui.compose.common.navigation.deepLinkComposable
import app.k9mail.feature.account.setup.ui.AccountSetupScreen

const val NAVIGATION_ROUTE_ACCOUNT_SETUP = "account/setup"

fun NavController.navigateToAccountSetup(navOptions: NavOptions? = null) {
navigate(NAVIGATION_ROUTE_ACCOUNT_SETUP, navOptions)
}

fun NavGraphBuilder.accountSetupRoute(
onBack: () -> Unit,
onFinish: (String) -> Unit,
) {
deepLinkComposable(route = NAVIGATION_ROUTE_ACCOUNT_SETUP) {
AccountSetupScreen(
onBack = onBack,
onFinish = onFinish,
)
}
}

fun NavGraphBuilder.nestedAccountSetupRoute(
route: String,
onBack: () -> Unit,
onFinish: (String) -> Unit,
) {
composable(route) {
AccountSetupScreen(
AccountSetupNavHost(
onBack = onBack,
onFinish = onFinish,
)
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0393f23

Please sign in to comment.