-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
280 additions
and
35 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
core/src/main/java/com/terning/core/designsystem/component/dialog/SplashDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.terning.core.designsystem.component.dialog | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.Dialog | ||
import androidx.compose.ui.window.DialogProperties | ||
import com.terning.core.R | ||
import com.terning.core.designsystem.theme.Grey300 | ||
import com.terning.core.designsystem.theme.White | ||
import com.terning.core.extension.noRippleClickable | ||
|
||
@Composable | ||
fun SplashDialog( | ||
onDismissRequest: () -> Unit, | ||
properties: DialogProperties = DialogProperties( | ||
usePlatformDefaultWidth = false, | ||
decorFitsSystemWindows = true, | ||
dismissOnBackPress = true, | ||
dismissOnClickOutside = true, | ||
), | ||
content: @Composable () -> Unit, | ||
) { | ||
Dialog( | ||
onDismissRequest = { onDismissRequest() }, | ||
properties = properties, | ||
) { | ||
Box( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.wrapContentHeight() | ||
.padding(30.dp) | ||
.background( | ||
color = White, | ||
shape = RoundedCornerShape(20.dp) | ||
), | ||
) { | ||
Row( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.End | ||
) { | ||
IconButton( | ||
onClick = { onDismissRequest() }, | ||
modifier = Modifier | ||
.padding(6.dp) | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_dialog_x_32), | ||
contentDescription = null, | ||
tint = Grey300, | ||
modifier = Modifier | ||
.noRippleClickable { onDismissRequest() } | ||
) | ||
} | ||
} | ||
content() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
feature/src/main/java/com/terning/feature/onboarding/splash/NetworkChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.terning.feature.onboarding.splash | ||
|
||
import android.content.Context | ||
import android.net.ConnectivityManager | ||
import android.net.NetworkCapabilities | ||
|
||
object NetworkManager { | ||
fun checkNetworkState(context: Context): Boolean { | ||
val connectivityManager: ConnectivityManager = | ||
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
|
||
val network = connectivityManager.activeNetwork ?: return false | ||
val actNetwork = connectivityManager.getNetworkCapabilities(network) ?: return false | ||
return when { | ||
actNetwork.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true | ||
actNetwork.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true | ||
else -> false | ||
} | ||
} | ||
} |
68 changes: 59 additions & 9 deletions
68
feature/src/main/java/com/terning/feature/onboarding/splash/SplashScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,77 @@ | ||
package com.terning.feature.onboarding.splash | ||
|
||
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.getValue | ||
import androidx.compose.runtime.SideEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
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 | ||
import kotlinx.coroutines.delay | ||
|
||
@Composable | ||
fun SplashScreen( | ||
navController: NavController | ||
navController: NavController, | ||
viewModel: SplashViewModel = hiltViewModel() | ||
) { | ||
var isNavigate by remember { mutableStateOf(false) } | ||
val systemUiController = rememberSystemUiController() | ||
SideEffect { | ||
systemUiController.setStatusBarColor( | ||
color = TerningMain | ||
) | ||
systemUiController.setNavigationBarColor( | ||
color = TerningMain | ||
) | ||
} | ||
|
||
val context = LocalContext.current | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
|
||
var showDialog = remember { mutableStateOf(false) } | ||
|
||
LaunchedEffect(key1 = true) { | ||
delay(1000) | ||
isNavigate = 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 -> { | ||
showDialog.value = true | ||
} | ||
} | ||
} | ||
} | ||
TerningImage(painter = R.drawable.ic_splash) | ||
|
||
if (isNavigate) navController.navigateSignIn() | ||
TerningImage(painter = R.drawable.ic_splash, modifier = Modifier.fillMaxSize()) | ||
|
||
if (showDialog.value) { | ||
SplashDialog( | ||
onDismissRequest = { | ||
showDialog.value = false | ||
}, | ||
content = { | ||
Text(text = "인터넷 연결 확인 바람") | ||
|
||
}, | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
feature/src/main/java/com/terning/feature/onboarding/splash/SplashState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.terning.feature.onboarding.splash | ||
|
||
import androidx.appcompat.app.AlertDialog | ||
|
||
sealed class SplashState { | ||
data object AlertDialog : SplashState() | ||
data class GetHasAccessToken(val hasAccessToken: Boolean) : SplashState() | ||
} |
47 changes: 47 additions & 0 deletions
47
feature/src/main/java/com/terning/feature/onboarding/splash/SplashViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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 { | ||
if (NetworkManager.checkNetworkState(context)) { | ||
initSplash(lifecycleOwner) | ||
} else { | ||
_sideEffects.emit(SplashState.AlertDialog) | ||
} | ||
} | ||
} | ||
|
||
private fun initSplash(lifecycleOwner: LifecycleOwner) { | ||
lifecycleOwner.lifecycleScope.launch { | ||
delay(DELAY_TIME) | ||
_sideEffects.emit(SplashState.GetHasAccessToken(getHasAccessToken())) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DELAY_TIME = 2200L | ||
} | ||
} |
Oops, something went wrong.