Avoiding state getters on home model
This commit is contained in:
parent
a58a734af4
commit
ac2c975d3f
|
@ -10,15 +10,18 @@ import app.dapk.st.core.LifecycleEffect
|
|||
import app.dapk.st.core.components.CenteredLoading
|
||||
import app.dapk.st.design.components.CircleishAvatar
|
||||
import app.dapk.st.directory.DirectoryScreen
|
||||
import app.dapk.st.directory.state.DirectoryState
|
||||
import app.dapk.st.home.HomeScreenState.*
|
||||
import app.dapk.st.home.HomeScreenState.Page.Directory
|
||||
import app.dapk.st.home.HomeScreenState.Page.Profile
|
||||
import app.dapk.st.login.LoginScreen
|
||||
import app.dapk.st.login.state.LoginState
|
||||
import app.dapk.st.profile.ProfileScreen
|
||||
import app.dapk.st.profile.state.ProfileState
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
internal fun HomeScreen(homeViewModel: HomeViewModel) {
|
||||
internal fun HomeScreen(homeViewModel: HomeViewModel, directoryState: DirectoryState, loginState: LoginState, profileState: ProfileState) {
|
||||
LifecycleEffect(
|
||||
onStart = { homeViewModel.start() },
|
||||
onStop = { homeViewModel.stop() }
|
||||
|
@ -34,9 +37,9 @@ internal fun HomeScreen(homeViewModel: HomeViewModel) {
|
|||
content = { innerPadding ->
|
||||
Box(modifier = Modifier.padding(innerPadding)) {
|
||||
when (state.page) {
|
||||
Directory -> DirectoryScreen(homeViewModel.directory())
|
||||
Directory -> DirectoryScreen(directoryState)
|
||||
Profile -> {
|
||||
ProfileScreen(homeViewModel.profile()) {
|
||||
ProfileScreen(profileState) {
|
||||
homeViewModel.changePage(Directory)
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +50,7 @@ internal fun HomeScreen(homeViewModel: HomeViewModel) {
|
|||
}
|
||||
|
||||
SignedOut -> {
|
||||
LoginScreen(homeViewModel.login()) {
|
||||
LoginScreen(loginState) {
|
||||
homeViewModel.loggedIn()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,6 @@ internal class HomeViewModel(
|
|||
|
||||
private var listenForInvitesJob: Job? = null
|
||||
|
||||
fun directory() = directoryState
|
||||
fun login() = loginState
|
||||
fun profile() = profileState
|
||||
|
||||
fun start() {
|
||||
viewModelScope.launch {
|
||||
state = if (chatEngine.isSignedIn()) {
|
||||
|
|
|
@ -43,7 +43,7 @@ class MainActivity : DapkActivity() {
|
|||
BetaUpgradeDialog()
|
||||
} else {
|
||||
Surface(Modifier.fillMaxSize()) {
|
||||
HomeScreen(homeViewModel)
|
||||
HomeScreen(homeViewModel, directoryState, loginState, profileState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue