This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Re-write EditTransaction screen
- Loading branch information
1 parent
64eebb7
commit 16dc98c
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/ivy/wallet/ui/transaction/TransactionScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/ivy/wallet/ui/transaction/TransactionViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
app/src/main/java/com/ivy/wallet/ui/transaction/TrnEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
app/src/main/java/com/ivy/wallet/ui/transaction/TrnState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |