Skip to content

Commit

Permalink
Converting the transaction create screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuppan committed Jul 7, 2024
1 parent de663dd commit 453dfe6
Show file tree
Hide file tree
Showing 7 changed files with 521 additions and 358 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.naveenapps.expensemanager.core.navigation

import androidx.navigation.NavOptionsBuilder
import androidx.navigation.navOptions
import javax.inject.Inject

class ExpenseManagerComposeNavigator @Inject constructor() : AppComposeNavigator() {

override fun navigate(route: Any) {
navigationCommands.tryEmit(ComposeNavigationCommand.NavigateTo(route))
navigationCommands.tryEmit(NavigationCommand.NavigateTo(route))
}

override fun navigateAndClearBackStack(route: Any) {
navigationCommands.tryEmit(
ComposeNavigationCommand.NavigateToRoute(
NavigationCommand.NavigateToRoute(
route,
navOptions {
popUpTo(0)
Expand All @@ -22,11 +21,11 @@ class ExpenseManagerComposeNavigator @Inject constructor() : AppComposeNavigator
}

override fun popBackStack() {
navigationCommands.tryEmit(ComposeNavigationCommand.PopBackStack)
navigationCommands.tryEmit(NavigationCommand.PopBackStack)
}

override fun popUpTo(route: String, inclusive: Boolean) {
navigationCommands.tryEmit(ComposeNavigationCommand.PopUpToRoute(route, inclusive))
navigationCommands.tryEmit(NavigationCommand.PopUpToRoute(route, inclusive))
}

override fun <T> navigateUpWithResult(
Expand All @@ -35,7 +34,7 @@ class ExpenseManagerComposeNavigator @Inject constructor() : AppComposeNavigator
route: String?,
) {
navigationCommands.tryEmit(
ComposeNavigationCommand.NavigateUpWithResult(
NavigationCommand.NavigateUpWithResult(
key = key,
result = result,
route = route,
Expand All @@ -45,7 +44,7 @@ class ExpenseManagerComposeNavigator @Inject constructor() : AppComposeNavigator

override fun <T> navigateBackWithResult(key: String, result: T) {
navigationCommands.tryEmit(
ComposeNavigationCommand.NavigateBackWithResult(
NavigationCommand.NavigateBackWithResult(
key = key,
result = result,
),
Expand All @@ -54,7 +53,7 @@ class ExpenseManagerComposeNavigator @Inject constructor() : AppComposeNavigator

override fun navigateBackWithMultipleResult(values: MutableMap<String, Any>) {
navigationCommands.tryEmit(
ComposeNavigationCommand.NavigateBackWithMultipleResult(values = values)
NavigationCommand.NavigateBackWithMultipleResult(values = values)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,32 @@ package com.naveenapps.expensemanager.core.navigation
import androidx.navigation.NavOptions

sealed class NavigationCommand {

data object NavigateUp : NavigationCommand()
}

sealed class ComposeNavigationCommand : NavigationCommand() {
data class NavigateTo(val route: Any) : ComposeNavigationCommand()
data class NavigateTo(val route: Any) : NavigationCommand()

data class NavigateToRoute(
val route: Any,
val options: NavOptions? = null
) : ComposeNavigationCommand()
) : NavigationCommand()

data class NavigateUpWithResult<T>(
val key: String,
val result: T,
val route: String? = null,
) : ComposeNavigationCommand()
) : NavigationCommand()

data class NavigateBackWithResult<T>(
val key: String,
val result: T,
) : ComposeNavigationCommand()
) : NavigationCommand()

data class NavigateBackWithMultipleResult(
val values: Map<String, Any>
) : ComposeNavigationCommand()
) : NavigationCommand()

data class PopUpToRoute(val route: String, val inclusive: Boolean) : ComposeNavigationCommand()
data class PopUpToRoute(val route: String, val inclusive: Boolean) : NavigationCommand()

data object PopBackStack : ComposeNavigationCommand()
data object PopBackStack : NavigationCommand()
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ abstract class AppComposeNavigator : Navigator() {

private fun NavController.handleComposeNavigationCommand(navigationCommand: NavigationCommand) {
when (navigationCommand) {
is ComposeNavigationCommand.NavigateToRoute -> {
is NavigationCommand.NavigateToRoute -> {
navigate(navigationCommand.route, navigationCommand.options)
}

NavigationCommand.NavigateUp -> navigateUp()
is ComposeNavigationCommand.PopUpToRoute -> popBackStack(
is NavigationCommand.PopUpToRoute -> popBackStack(
navigationCommand.route,
navigationCommand.inclusive,
)

is ComposeNavigationCommand.NavigateUpWithResult<*> -> {
is NavigationCommand.NavigateUpWithResult<*> -> {
navUpWithResult(navigationCommand)
}

ComposeNavigationCommand.PopBackStack -> {
NavigationCommand.PopBackStack -> {
popBackStack()
}

is ComposeNavigationCommand.NavigateBackWithResult<*> -> {
is NavigationCommand.NavigateBackWithResult<*> -> {
previousBackStackEntry?.savedStateHandle?.set(
navigationCommand.key,
navigationCommand.result,
)
popBackStack()
}

is ComposeNavigationCommand.NavigateBackWithMultipleResult -> {
is NavigationCommand.NavigateBackWithMultipleResult -> {
navigationCommand.values.forEach {
previousBackStackEntry?.savedStateHandle?.set(
it.key,
Expand All @@ -78,14 +78,14 @@ abstract class AppComposeNavigator : Navigator() {
popBackStack()
}

is ComposeNavigationCommand.NavigateTo -> {
is NavigationCommand.NavigateTo -> {
navigate(navigationCommand.route)
}
}
}

private fun NavController.navUpWithResult(
navigationCommand: ComposeNavigationCommand.NavigateUpWithResult<*>,
navigationCommand: NavigationCommand.NavigateUpWithResult<*>,
) {
val backStackEntry =
navigationCommand.route?.let { getBackStackEntry(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.naveenapps.expensemanager.feature.transaction.create

import com.naveenapps.expensemanager.core.model.AccountUiModel
import com.naveenapps.expensemanager.core.model.Category
import com.naveenapps.expensemanager.core.model.TransactionType
import java.util.Date

sealed class TransactionCreateAction {

data object ClosePage : TransactionCreateAction()

data object ShowDeleteDialog : TransactionCreateAction()

data object DismissDeleteDialog : TransactionCreateAction()

data class OpenAccountCreate(val account: AccountUiModel?) : TransactionCreateAction()

data class SelectAccount(val account: AccountUiModel) : TransactionCreateAction()

data object DismissAccountSelection : TransactionCreateAction()

data class ShowAccountSelection(val type: AccountSelection) : TransactionCreateAction()

data class OpenCategoryCreate(val category: Category?) : TransactionCreateAction()

data class SelectCategory(val category: Category) : TransactionCreateAction()

data object DismissCategorySelection : TransactionCreateAction()

data object ShowCategorySelection : TransactionCreateAction()

data object Delete : TransactionCreateAction()

data object Save : TransactionCreateAction()

data class SetNumberPadValue(val amount: String?) : TransactionCreateAction()

data object ShowNumberPad : TransactionCreateAction()

data object DismissNumberPad : TransactionCreateAction()

data class ChangeTransactionType(val type: TransactionType) : TransactionCreateAction()

data class SelectDate(val date: Date) : TransactionCreateAction()

data object ShowDateSelection : TransactionCreateAction()

data object DismissDateSelection : TransactionCreateAction()

data object ShowTimeSelection : TransactionCreateAction()
}
Loading

0 comments on commit 453dfe6

Please sign in to comment.