Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
WIP: Re-write EditTransaction screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 28, 2022
1 parent 64eebb7 commit 16dc98c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.ivy.wallet.ui.transaction

import androidx.compose.foundation.layout.BoxWithConstraintsScope
import androidx.compose.runtime.Composable
import com.ivy.frp.view.navigation.Screen
import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.ui.architecture.FRP

sealed class TransactionScreen : Screen {
data class NewTransaction(
val type: TransactionType
) : TransactionScreen()

data class EditTransaction(
val transaction: Transaction
) : TransactionScreen()
}

@Composable
fun BoxWithConstraintsScope.TransactionScreen(screen: TransactionScreen) {
FRP<TrnState, TrnEvent, TransactionViewModel>(
initialEvent = when (screen) {
is TransactionScreen.EditTransaction -> TrnEvent.LoadTransaction(screen.transaction)
is TransactionScreen.NewTransaction -> TrnEvent.NewTransaction(screen.type)
}
) { state, onEvent ->
UI(state = state, onEvent = onEvent)
}
}

@Composable
private fun UI(
state: TrnState,

onEvent: (TrnEvent) -> Unit
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ivy.wallet.ui.transaction

import com.ivy.frp.viewmodel.FRPViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import javax.inject.Inject

@HiltViewModel
class TransactionViewModel @Inject constructor(

) : FRPViewModel<TrnState, TrnEvent>() {
override val _state: MutableStateFlow<TrnState> = MutableStateFlow(TrnState.Initial)

override suspend fun handleEvent(event: TrnEvent): suspend () -> TrnState {
TODO("Not yet implemented")
}

}
14 changes: 14 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/transaction/TrnEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.ivy.wallet.ui.transaction

import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Transaction

sealed class TrnEvent {
data class NewTransaction(
val type: TransactionType
) : TrnEvent()

data class LoadTransaction(
val transaction: Transaction
) : TrnEvent()
}
27 changes: 27 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/transaction/TrnState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ivy.wallet.ui.transaction

import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.data.core.Transaction
import java.math.BigDecimal
import java.time.LocalDateTime

sealed class TrnState {
object Initial : TrnState()

data class NewTransaction(
val type: TransactionType,
val account: Account,
val toAccount: Account?,
val amount: BigDecimal,
val category: Category?,
val dateTime: LocalDateTime,
val title: String?,
val description: String?
) : TrnState()

data class EditTransaction(
val transaction: Transaction
) : TrnState()
}

0 comments on commit 16dc98c

Please sign in to comment.