Add NavHost for incoming and outgoing server settings editing
This commit is contained in:
parent
10cb49cbb4
commit
dc142fea79
3 changed files with 180 additions and 0 deletions
|
@ -0,0 +1,75 @@
|
||||||
|
package app.k9mail.feature.account.edit.navigation
|
||||||
|
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavGraphBuilder
|
||||||
|
import androidx.navigation.NavType
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.navArgument
|
||||||
|
import app.k9mail.core.ui.compose.common.navigation.getArgument
|
||||||
|
import app.k9mail.feature.account.edit.ui.EditIncomingServerSettingsNavHost
|
||||||
|
import app.k9mail.feature.account.edit.ui.EditOutgoingServerSettingsNavHost
|
||||||
|
import kotlinx.collections.immutable.ImmutableMap
|
||||||
|
import kotlinx.collections.immutable.persistentMapOf
|
||||||
|
|
||||||
|
internal const val ARGUMENT_ACCOUNT_UUID = "accountUuid"
|
||||||
|
|
||||||
|
const val NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_INCOMING = "/account/edit/config/incoming/{accountUuid}"
|
||||||
|
const val NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_OUTGOING = "/account/edit/config/outgoing/{accountUuid}"
|
||||||
|
|
||||||
|
fun NavController.navigateToAccountEditConfigIncoming(accountUuid: String) {
|
||||||
|
navigate(
|
||||||
|
route = NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_INCOMING.withAccountUuid(accountUuid),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavController.navigateToAccountEditConfigOutgoing(accountUuid: String) {
|
||||||
|
navigate(
|
||||||
|
route = NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_OUTGOING.withAccountUuid(accountUuid),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun NavGraphBuilder.accountEditRoute(
|
||||||
|
startDestinationArguments: ImmutableMap<String, String> = persistentMapOf(),
|
||||||
|
onBack: () -> Unit,
|
||||||
|
onFinish: () -> Unit,
|
||||||
|
) {
|
||||||
|
composable(
|
||||||
|
route = NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_INCOMING,
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument(ARGUMENT_ACCOUNT_UUID) {
|
||||||
|
type = NavType.StringType
|
||||||
|
defaultValue = startDestinationArguments[ARGUMENT_ACCOUNT_UUID] ?: ""
|
||||||
|
},
|
||||||
|
),
|
||||||
|
) { backStackEntry ->
|
||||||
|
val accountUuid = backStackEntry.getArgument(ARGUMENT_ACCOUNT_UUID)
|
||||||
|
EditIncomingServerSettingsNavHost(
|
||||||
|
accountUuid = accountUuid,
|
||||||
|
onFinish = { onFinish() },
|
||||||
|
onBack = onBack,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable(
|
||||||
|
route = NAVIGATION_ROUTE_ACCOUNT_EDIT_CONFIG_OUTGOING,
|
||||||
|
arguments = listOf(
|
||||||
|
navArgument(ARGUMENT_ACCOUNT_UUID) {
|
||||||
|
type = NavType.StringType
|
||||||
|
defaultValue = startDestinationArguments[ARGUMENT_ACCOUNT_UUID] ?: ""
|
||||||
|
},
|
||||||
|
),
|
||||||
|
) { backStackEntry ->
|
||||||
|
val accountUuid = backStackEntry.getArgument(ARGUMENT_ACCOUNT_UUID)
|
||||||
|
EditOutgoingServerSettingsNavHost(
|
||||||
|
accountUuid = accountUuid,
|
||||||
|
onFinish = { onFinish() },
|
||||||
|
onBack = onBack,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.withAccountUuid(accountUuid: String): String {
|
||||||
|
return replace(
|
||||||
|
oldValue = "{$ARGUMENT_ACCOUNT_UUID}",
|
||||||
|
newValue = accountUuid,
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package app.k9mail.feature.account.edit.ui
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
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.validation.ui.IncomingServerValidationViewModel
|
||||||
|
import app.k9mail.feature.account.server.validation.ui.ServerValidationScreen
|
||||||
|
import org.koin.androidx.compose.koinViewModel
|
||||||
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
||||||
|
private const val NESTED_NAVIGATION_ROUTE_CONFIG = "config"
|
||||||
|
private const val NESTED_NAVIGATION_ROUTE_VALIDATION = "validation"
|
||||||
|
|
||||||
|
private fun NavController.navigateToValidation() {
|
||||||
|
navigate(NESTED_NAVIGATION_ROUTE_VALIDATION)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun EditIncomingServerSettingsNavHost(
|
||||||
|
accountUuid: String,
|
||||||
|
onFinish: () -> Unit,
|
||||||
|
onBack: () -> Unit,
|
||||||
|
) {
|
||||||
|
val navController = rememberNavController()
|
||||||
|
|
||||||
|
NavHost(
|
||||||
|
navController = navController,
|
||||||
|
startDestination = NESTED_NAVIGATION_ROUTE_CONFIG,
|
||||||
|
) {
|
||||||
|
composable(route = NESTED_NAVIGATION_ROUTE_CONFIG) {
|
||||||
|
IncomingServerSettingsScreen(
|
||||||
|
onBack = onBack,
|
||||||
|
onNext = { navController.navigateToValidation() },
|
||||||
|
viewModel = koinViewModel<EditIncomingServerSettingsViewModel> {
|
||||||
|
parametersOf(accountUuid)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable(route = NESTED_NAVIGATION_ROUTE_VALIDATION) {
|
||||||
|
ServerValidationScreen(
|
||||||
|
onBack = { navController.popBackStack() },
|
||||||
|
onNext = onFinish,
|
||||||
|
viewModel = koinViewModel<IncomingServerValidationViewModel> {
|
||||||
|
parametersOf(accountUuid)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package app.k9mail.feature.account.edit.ui
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.compose.NavHost
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
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.OutgoingServerValidationViewModel
|
||||||
|
import app.k9mail.feature.account.server.validation.ui.ServerValidationScreen
|
||||||
|
import org.koin.androidx.compose.koinViewModel
|
||||||
|
import org.koin.core.parameter.parametersOf
|
||||||
|
|
||||||
|
private const val NESTED_NAVIGATION_ROUTE_CONFIG = "config"
|
||||||
|
private const val NESTED_NAVIGATION_ROUTE_VALIDATION = "validation"
|
||||||
|
|
||||||
|
private fun NavController.navigateToValidation() {
|
||||||
|
navigate(NESTED_NAVIGATION_ROUTE_VALIDATION)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun EditOutgoingServerSettingsNavHost(
|
||||||
|
accountUuid: String,
|
||||||
|
onFinish: () -> Unit,
|
||||||
|
onBack: () -> Unit,
|
||||||
|
) {
|
||||||
|
val navController = rememberNavController()
|
||||||
|
|
||||||
|
NavHost(
|
||||||
|
navController = navController,
|
||||||
|
startDestination = NESTED_NAVIGATION_ROUTE_CONFIG,
|
||||||
|
) {
|
||||||
|
composable(route = NESTED_NAVIGATION_ROUTE_CONFIG) {
|
||||||
|
OutgoingServerSettingsScreen(
|
||||||
|
onBack = onBack,
|
||||||
|
onNext = { navController.navigateToValidation() },
|
||||||
|
viewModel = koinViewModel<OutgoingServerSettingsViewModel> {
|
||||||
|
parametersOf(accountUuid)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
composable(route = NESTED_NAVIGATION_ROUTE_VALIDATION) {
|
||||||
|
ServerValidationScreen(
|
||||||
|
onBack = { navController.popBackStack() },
|
||||||
|
onNext = onFinish,
|
||||||
|
viewModel = koinViewModel<OutgoingServerValidationViewModel> {
|
||||||
|
parametersOf(accountUuid)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue