Skip to content

Commit

Permalink
Align Android UI with desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
opatry committed Sep 30, 2024
1 parent a07dff3 commit 9da2e26
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,58 @@ package net.opatry.tasks.app
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Surface
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import net.opatry.tasks.app.ui.TaskListsViewModel
import net.opatry.tasks.app.ui.TasksApp
import net.opatry.tasks.app.ui.UserState
import net.opatry.tasks.app.ui.UserViewModel
import net.opatry.tasks.app.ui.screen.AuthorizationScreen
import net.opatry.tasks.app.ui.theme.TasksAppTheme
import org.koin.compose.viewmodel.koinViewModel


class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
val userViewModel = koinViewModel<UserViewModel>()
val userState by userViewModel.state.collectAsState(null)

if (userState == null) {
LaunchedEffect(userState) {
userViewModel.refreshUserState()
}
}

TasksAppTheme {
Surface {
when (userState) {
null -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
CircularProgressIndicator(Modifier.size(24.dp), strokeWidth = 1.dp)
}

is UserState.Unsigned,
is UserState.SignedIn -> {
val tasksViewModel = koinViewModel<TaskListsViewModel>()
TasksApp(userViewModel, tasksViewModel)
}

is UserState.Newcomer -> AuthorizationScreen(
onSkip = userViewModel::skipSignIn,
onSuccess = userViewModel::signIn,
)
}
}
}
}
Expand Down

0 comments on commit 9da2e26

Please sign in to comment.