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