Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT/#121] 자동 로그인 구현 #126

Merged
merged 8 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ dependencies {
implementation(libs.ossLicense)
implementation(libs.lottie)
implementation(libs.process.phoenix)
implementation(libs.accompanist.systemuicontroller)
implementation (libs.androidx.core.splashscreen)

// Compose Preview
debugImplementation(libs.compose.ui.tooling)
Expand Down
14 changes: 14 additions & 0 deletions feature/src/main/java/com/terning/feature/home/home/HomeRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
Expand All @@ -33,13 +34,15 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.NavHostController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.terning.core.designsystem.component.bottomsheet.SortingBottomSheet
import com.terning.core.designsystem.component.button.SortingButton
import com.terning.core.designsystem.component.item.InternItem
import com.terning.core.designsystem.component.topappbar.LogoTopAppBar
import com.terning.core.designsystem.theme.Black
import com.terning.core.designsystem.theme.Grey150
import com.terning.core.designsystem.theme.Grey200
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.designsystem.theme.White
import com.terning.core.extension.customShadow
Expand All @@ -64,6 +67,17 @@ fun HomeRoute(
navController: NavHostController,
viewModel: HomeViewModel = hiltViewModel(),
) {

val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setStatusBarColor(
color = White
)
systemUiController.setNavigationBarColor(
color = White
)
}

val currentSortBy: MutableState<Int> = remember {
mutableIntStateOf(0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.terning.feature.calendar.calendar.navigation.navigateCalendar
import com.terning.feature.home.home.navigation.navigateHome
import com.terning.feature.mypage.navigation.MyPage
import com.terning.feature.mypage.navigation.navigateMyPage
import com.terning.feature.onboarding.signin.navigation.SignIn
import com.terning.feature.onboarding.splash.navigation.Splash
import com.terning.feature.search.search.navigation.navigateSearch

class MainNavigator(
Expand All @@ -23,7 +22,7 @@ class MainNavigator(
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination

val startDestination = SignIn
val startDestination = Splash

val currentTab: MainTab?
@Composable get() = MainTab.find { tab ->
Expand Down
12 changes: 7 additions & 5 deletions feature/src/main/java/com/terning/feature/main/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.White
import com.terning.core.util.NoRippleInteractionSource
import com.terning.feature.calendar.calendar.navigation.calendarNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringOneNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringThreeNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringTwoNavGraph
import com.terning.feature.filtering.startfiltering.navigation.startFilteringNavGraph
import com.terning.feature.filtering.starthome.navigation.startHomeNavGraph
import com.terning.feature.home.changefilter.navigation.changeFilterNavGraph
import com.terning.feature.home.home.navigation.homeNavGraph
import com.terning.feature.intern.navigation.internNavGraph
import com.terning.feature.mypage.navigation.myPageNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringOneNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringThreeNavGraph
import com.terning.feature.filtering.filtering.navigation.filteringTwoNavGraph
import com.terning.feature.onboarding.signin.navigation.signInNavGraph
import com.terning.feature.onboarding.signup.navigation.signUpNavGraph
import com.terning.feature.filtering.startfiltering.navigation.startFilteringNavGraph
import com.terning.feature.filtering.starthome.navigation.startHomeNavGraph
import com.terning.feature.onboarding.splash.navigation.splashNavGraph
import com.terning.feature.search.search.navigation.searchNavGraph
import com.terning.feature.search.searchprocess.navigation.searchProcessNavGraph

Expand All @@ -58,6 +59,7 @@ fun MainScreen(
navController = navigator.navController,
startDestination = navigator.startDestination
) {
splashNavGraph(navHostController = navigator.navController)
homeNavGraph(navHostController = navigator.navController)
calendarNavGraph(navHostController = navigator.navController)
searchNavGraph(navHostController = navigator.navController)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -19,7 +20,10 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.NavHostController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningPointTheme
import com.terning.core.designsystem.theme.White
import com.terning.core.extension.toast
import com.terning.feature.R
import com.terning.feature.home.home.navigation.navigateHome
Expand All @@ -31,6 +35,16 @@ fun SignInRoute(
viewModel: SignInViewModel = hiltViewModel(),
navController: NavHostController,
) {

val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setStatusBarColor(
color = White
)
systemUiController.setNavigationBarColor(
color = White
)
}
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,74 @@
package com.terning.feature.onboarding.splash

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import androidx.navigation.NavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.terning.core.designsystem.component.dialog.SplashDialog
import com.terning.core.designsystem.component.image.TerningImage
import com.terning.core.designsystem.theme.TerningMain
import com.terning.feature.R
import com.terning.feature.home.home.navigation.navigateHome
import com.terning.feature.onboarding.signin.navigation.navigateSignIn

@Composable
fun SplashScreen(){
fun SplashScreen(
navController: NavController,
viewModel: SplashViewModel = hiltViewModel(),
modifier : Modifier = Modifier
) {
val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.setStatusBarColor(
color = TerningMain
)
systemUiController.setNavigationBarColor(
color = TerningMain
)
}

}
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current

LaunchedEffect(key1 = true) {
viewModel.checkConnectedNetwork(context, lifecycleOwner)
}

LaunchedEffect(viewModel.sideEffects, lifecycleOwner) {
viewModel.sideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
when (sideEffect) {
is SplashState.GetHasAccessToken -> {
if (sideEffect.hasAccessToken) navController.navigateHome()
else navController.navigateSignIn()
}

is SplashState.AlertDialog -> {
}
}
}
}

Column (
modifier = modifier
.fillMaxSize()
.background(TerningMain),
){
TerningImage(painter = R.drawable.ic_splash,
modifier = Modifier.fillMaxSize()
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.terning.feature.onboarding.splash

sealed class SplashState {
data object AlertDialog : SplashState()
data class GetHasAccessToken(val hasAccessToken: Boolean) : SplashState()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.terning.feature.onboarding.splash

import android.content.Context
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope
import com.terning.domain.repository.TokenRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SplashViewModel @Inject constructor(
private val tokenRepository: TokenRepository,
) : ViewModel() {

private val _sideEffects = MutableSharedFlow<SplashState>()
val sideEffects: SharedFlow<SplashState> get() = _sideEffects.asSharedFlow()

private fun getHasAccessToken(): Boolean = tokenRepository.getAccessToken().isNotBlank()

fun checkConnectedNetwork(context: Context, lifecycleOwner: LifecycleOwner) {
viewModelScope.launch {
initSplash(lifecycleOwner)
}
}

private fun initSplash(lifecycleOwner: LifecycleOwner) {
lifecycleOwner.lifecycleScope.launch {
delay(DELAY_TIME)
_sideEffects.emit(SplashState.GetHasAccessToken(getHasAccessToken()))
}
}

companion object {
private const val DELAY_TIME = 2200L
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.terning.feature.onboarding.splash.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import com.terning.core.navigation.Route
import com.terning.feature.onboarding.signup.SignUpRoute
import com.terning.feature.onboarding.splash.SplashScreen
import kotlinx.serialization.Serializable

fun NavController.navigateSplash(navOptions: NavOptions? = null) {
navigate(
route = Splash,
navOptions = navOptions
)
}

fun NavGraphBuilder.splashNavGraph(
navHostController: NavHostController
) {
composable<Splash> {
SplashScreen(
navController = navHostController,
)
}
}

@Serializable
data object Splash: Route
Loading
Loading