Skip to content

Commit

Permalink
[feature/univ_save] 대학인덱스 presentation 구현 및 분기처리 추가 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed Nov 16, 2023
1 parent b4006b5 commit c84e076
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.everymeal.data.repository.local

import com.everymeal.data.datasource.local.LocalDataSource
import com.everymeal.domain.repository.local.LocalRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class LocalRepositoryImpl @Inject constructor(
Expand All @@ -11,4 +12,8 @@ class LocalRepositoryImpl @Inject constructor(
override suspend fun saveUniversity(index: Int, univName: String) {
localDataSource.saveUniversity(index, univName)
}

override suspend fun getUniversityIndex(): Flow<String> {
return localDataSource.getUniversityIndex()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.everymeal.domain.repository.local

import kotlinx.coroutines.flow.Flow

interface LocalRepository {
suspend fun saveUniversity(index : Int, univName : String)

suspend fun getUniversityIndex() : Flow<String>
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.everymeal.domain.usecase.local

import com.everymeal.domain.repository.local.LocalRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetUniversityIndexUseCase @Inject constructor(
private val localRepository: LocalRepository
) {
suspend operator fun invoke() : Flow<String> {
return localRepository.getUniversityIndex()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import com.everymeal.presentation.ui.main.MainActivity
import com.everymeal.presentation.ui.onboarding.OnboardingActivity
import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme
import com.everymeal.presentation.ui.signup.UnivSelectActivity
import dagger.hilt.android.AndroidEntryPoint

@SuppressLint("CustomSplashScreen")
@AndroidEntryPoint
class SplashActivity : ComponentActivity() {

private val viewModel: SplashViewModel by viewModels()

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

Expand All @@ -22,8 +26,13 @@ class SplashActivity : ComponentActivity() {
setContent {
EveryMeal_AndroidTheme {
SplashScreen(onFinishSplash = {
OnboardingActivity.startActivity(this)
finish()
if(viewModel.viewState.value.selectedUnitIndex.isNullOrBlank()) {
OnboardingActivity.startActivity(this)
finish()
} else {
MainActivity.startActivity(this)
finish()
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import com.everymeal.presentation.base.ViewState

class SplashContract {
data class SplashViewState(
val loginState: LoadState = LoadState.LOADING
val loginState: LoadState = LoadState.SUCCESS,
val selectedUnitIndex: String? = null,
) : ViewState

sealed class SplashSideEffect : ViewSideEffect {
object MoveToMain: SplashSideEffect()
object MoveToOnboarding: SplashSideEffect()
}
sealed class SplashSideEffect : ViewSideEffect

sealed class SplashEvent : ViewEvent
sealed class SplashEvent : ViewEvent {
object InitSplashScreen: SplashEvent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.animateLottieCompositionAsState
Expand All @@ -20,11 +22,16 @@ import com.everymeal.presentation.ui.theme.EveryMeal_AndroidTheme
@SuppressLint("CoroutineCreationDuringComposition")
@Composable
fun SplashScreen(
viewModel : SplashViewModel = hiltViewModel(),
onFinishSplash: () -> Unit,
) {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("everymeal_splash.json"))
val progress by animateLottieCompositionAsState(composition)

LaunchedEffect(Unit) {
viewModel.setEvent(SplashContract.SplashEvent.InitSplashScreen)
}

Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
package com.everymeal.presentation.ui.splash

import androidx.lifecycle.viewModelScope
import com.everymeal.domain.usecase.local.GetUniversityIndexUseCase
import com.everymeal.presentation.base.BaseViewModel
import com.everymeal.presentation.base.LoadState
import com.everymeal.presentation.ui.splash.SplashContract.SplashEvent
import com.everymeal.presentation.ui.splash.SplashContract.SplashSideEffect
import com.everymeal.presentation.ui.splash.SplashContract.SplashViewState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SplashViewModel @Inject constructor(

private val getUniversityIndexUseCase: GetUniversityIndexUseCase
) : BaseViewModel<SplashViewState, SplashSideEffect, SplashEvent>(
SplashViewState()
) {

override fun handleEvents(event: SplashEvent) {
when (event) {
is SplashEvent.InitSplashScreen -> {
getUniversityIndex()
}
}
}

private fun getUniversityIndex() {
viewModelScope.launch {
val univIndex = getUniversityIndexUseCase().first()
updateState {
copy(
selectedUnitIndex = univIndex,
)
}
}
}
}

0 comments on commit c84e076

Please sign in to comment.