Skip to content

Commit

Permalink
feat: apply random loading view
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannijunseokim committed Apr 11, 2024
1 parent 8eb3eff commit 8f0174f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import univ.earthbreaker.namu.ToFinalCharacterUiModel
import univ.earthbreaker.namu.feature.character.growfinal.FinalCharacterActivity
import univ.earthbreaker.namu.ui.theme.GTTheme
import univ.earthbreaker.namu.util.ContentUriRequestBody
import univ.earthbreaker.namu.util.finishSafely
import univ.earthbreaker.namu.util.getBase64FromUri
import univ.earthbreaker.namu.util.extension.finishSafely
import univ.earthbreaker.namu.util.extension.getBase64FromUri

class HomeActivity : ComponentActivity() {
private val viewModel: HomeViewModel by viewModels()
Expand Down Expand Up @@ -50,7 +50,7 @@ class HomeActivity : ComponentActivity() {

setContent {
GTTheme {
HomeRoute(viewModel = viewModel, onClickCameraIcon = {
HomeRoute(onClickCameraIcon = {
pickMedia.launch(
PickVisualMediaRequest(PickVisualMedia.ImageOnly),
)
Expand Down
28 changes: 22 additions & 6 deletions app/src/main/java/univ/earthbreaker/namu/feature/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import univ.earthbreaker.namu.feature.home.model.HomeActions
import univ.earthbreaker.namu.feature.home.model.HomeUiState
import univ.earthbreaker.namu.feature.loading.LoadingActions
import univ.earthbreaker.namu.feature.loading.LoadingScreen
import univ.earthbreaker.namu.feature.loading.LoadingViewModel

@Composable
fun HomeRoute(
viewModel: HomeViewModel = viewModel(),
onClickCameraIcon: () -> Unit,
) {
val homeViewModel: HomeViewModel = viewModel()
val loadingViewModel: LoadingViewModel = viewModel()

// State observing and declarations
val uiState by viewModel.homeUiStateFlow.collectAsStateWithLifecycle()
val homeUiState by homeViewModel.homeUiStateFlow.collectAsStateWithLifecycle()

val loadingContent by loadingViewModel.loadingContent.collectAsStateWithLifecycle()

// UI Rendering
when (uiState) {
when (homeUiState) {
HomeUiState.Loading -> {
HomeLoadingScreen()
LoadingScreen(loadingContent, rememberLoadingActions(loadingViewModel))
}

HomeUiState.Error -> {
}

is HomeUiState.Success -> {
HomeScreen(
state = uiState as HomeUiState.Success,
actions = rememberHomeActions(viewModel, onClickCameraIcon = onClickCameraIcon),
state = homeUiState as HomeUiState.Success,
actions = rememberHomeActions(homeViewModel, onClickCameraIcon = onClickCameraIcon),
)
}
}
Expand All @@ -52,3 +59,12 @@ fun rememberHomeActions(viewModel: HomeViewModel, onClickCameraIcon: () -> Unit)
)
}
}

@Composable
fun rememberLoadingActions(viewModel: LoadingViewModel): LoadingActions {
return remember(viewModel) {
LoadingActions(
generateNewLoadingContent = viewModel::getNewLoadingContent,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package univ.earthbreaker.namu.feature.loading

data class LoadingActions(
val generateNewLoadingContent: () -> Unit,
)

0 comments on commit 8f0174f

Please sign in to comment.