mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
feat(folio): annotate ViewModels with Metro @Inject / @AssistedInject
LedgerViewModel and AddTransactionViewModel use @AssistedInject for their accountId param plus a nested @AssistedFactory; the rest are plain @Inject constructor classes.
This commit is contained in:
1 parent
783fb9804e
commit
d0b1c3f07c
5 files changed
+26
-2
No files matched your search
+2
@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import app.folio.core.data.Repository
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import dev.zacsweers.metro.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -22,6 +23,7 @@ sealed interface AddAccountEvent {
|
||||
data object Back : AddAccountEvent
|
||||
}
|
||||
|
||||
@Inject
|
||||
class AddAccountViewModel(
|
||||
private val repository: Repository,
|
||||
private val navigator: Navigator,
|
||||
|
||||
+2
@@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import app.folio.core.data.Repository
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import dev.zacsweers.metro.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -26,6 +27,7 @@ sealed interface LoginEvent {
|
||||
data object Submit : LoginEvent
|
||||
}
|
||||
|
||||
@Inject
|
||||
class LoginViewModel(
|
||||
private val repository: Repository,
|
||||
private val navigator: Navigator,
|
||||
|
||||
+2
@@ -7,6 +7,7 @@ import app.folio.core.data.Repository
|
||||
import app.folio.core.data.Transaction
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import dev.zacsweers.metro.Inject
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
@@ -25,6 +26,7 @@ sealed interface HomeEvent {
|
||||
data class OpenAccount(val accountId: String) : HomeEvent
|
||||
}
|
||||
|
||||
@Inject
|
||||
class HomeViewModel(
|
||||
private val repository: Repository,
|
||||
private val navigator: Navigator,
|
||||
|
||||
+10
-1
@@ -8,6 +8,9 @@ import app.folio.core.data.TxnType
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import app.folio.util.parseCents
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedFactory
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -36,10 +39,11 @@ sealed interface AddTransactionEvent {
|
||||
data object BackToHome : AddTransactionEvent
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
class AddTransactionViewModel(
|
||||
private val repository: Repository,
|
||||
private val navigator: Navigator,
|
||||
private val accountId: String,
|
||||
@Assisted private val accountId: String,
|
||||
) : ViewModel() {
|
||||
private val form = MutableStateFlow(AddTransactionUiState())
|
||||
|
||||
@@ -85,4 +89,9 @@ class AddTransactionViewModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
fun interface Factory {
|
||||
fun create(accountId: String): AddTransactionViewModel
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -7,6 +7,9 @@ import app.folio.core.data.Repository
|
||||
import app.folio.core.data.Transaction
|
||||
import app.folio.navigation.Navigator
|
||||
import app.folio.navigation.Route
|
||||
import dev.zacsweers.metro.Assisted
|
||||
import dev.zacsweers.metro.AssistedFactory
|
||||
import dev.zacsweers.metro.AssistedInject
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
@@ -24,10 +27,11 @@ sealed interface LedgerEvent {
|
||||
data object BackToHome : LedgerEvent
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
class LedgerViewModel(
|
||||
private val repository: Repository,
|
||||
private val navigator: Navigator,
|
||||
private val accountId: String,
|
||||
@Assisted private val accountId: String,
|
||||
) : ViewModel() {
|
||||
val state: StateFlow<LedgerUiState> = combine(
|
||||
repository.accounts,
|
||||
@@ -49,4 +53,9 @@ class LedgerViewModel(
|
||||
LedgerEvent.BackToHome -> navigator.replace(Route.Home)
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
fun interface Factory {
|
||||
fun create(accountId: String): LedgerViewModel
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user