-
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.
Merge remote-tracking branch 'origin/develop' into add/#15-top-app-bar
# Conflicts: # feature/src/main/res/values/strings.xml
- Loading branch information
Showing
23 changed files
with
394 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
9 changes: 9 additions & 0 deletions
9
feature/src/main/java/com/terning/feature/onboarding/filtering/FilteringRoute.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,9 @@ | ||
package com.terning.feature.onboarding.filtering | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.terning.feature.onboarding.filtering.navigation.FilteringNavigation | ||
|
||
@Composable | ||
fun FilteringRoute(){ | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
.../src/main/java/com/terning/feature/onboarding/filtering/navigation/FilteringNavigation.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,4 @@ | ||
package com.terning.feature.onboarding.filtering.navigation | ||
|
||
class FilteringNavigation { | ||
} |
83 changes: 83 additions & 0 deletions
83
feature/src/main/java/com/terning/feature/onboarding/signin/SignInRoute.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,83 @@ | ||
package com.terning.feature.onboarding.signin | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
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.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.LocalLifecycleOwner | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.navigation.NavHostController | ||
import com.terning.core.designsystem.theme.TerningTheme | ||
import com.terning.core.extension.toast | ||
import com.terning.feature.R | ||
import com.terning.feature.home.navigation.navigateHome | ||
import com.terning.feature.onboarding.signin.component.KakaoButton | ||
|
||
@Composable | ||
fun SignInRoute( | ||
viewModel: SignInViewModel = hiltViewModel(), | ||
navController: NavHostController, | ||
) { | ||
val context = LocalContext.current | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
val signInState by viewModel.signInState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner) | ||
|
||
LaunchedEffect(viewModel.signInSideEffects, lifecycleOwner) { | ||
viewModel.signInSideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle) | ||
.collect { sideEffect -> | ||
when (sideEffect) { | ||
is SignInSideEffect.ShowToast -> context.toast(sideEffect.message) | ||
is SignInSideEffect.NavigateToHome -> navController.navigateHome() | ||
} | ||
} | ||
} | ||
|
||
SignInScreen( | ||
onSignInClick = { viewModel.startKakaoLogIn(context) } | ||
) | ||
} | ||
|
||
@Composable | ||
fun SignInScreen( | ||
modifier: Modifier = Modifier, | ||
onSignInClick: () -> Unit = {} | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Image( | ||
painter = painterResource(id = R.drawable.img_terning_point), | ||
contentDescription = null, | ||
modifier = Modifier | ||
.size(500.dp), | ||
) | ||
KakaoButton( | ||
title = stringResource(id = R.string.sign_in_kakao_button), | ||
onSignInClick = { onSignInClick() }, | ||
modifier = modifier.padding(horizontal = 20.dp) | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun SignInScreenPreview() { | ||
TerningTheme { | ||
SignInScreen() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
feature/src/main/java/com/terning/feature/onboarding/signin/SignInSideEffect.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.signin | ||
|
||
import androidx.annotation.StringRes | ||
|
||
sealed class SignInSideEffect { | ||
data object NavigateToHome : SignInSideEffect() | ||
data class ShowToast(@StringRes val message: Int) : SignInSideEffect() | ||
} |
7 changes: 7 additions & 0 deletions
7
feature/src/main/java/com/terning/feature/onboarding/signin/SignInState.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,7 @@ | ||
package com.terning.feature.onboarding.signin | ||
|
||
import com.terning.core.state.UiState | ||
|
||
data class SignInState ( | ||
val accessToken: UiState<String> = UiState.Loading | ||
) |
86 changes: 86 additions & 0 deletions
86
feature/src/main/java/com/terning/feature/onboarding/signin/SignInViewModel.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,86 @@ | ||
package com.terning.feature.onboarding.signin | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.kakao.sdk.auth.model.OAuthToken | ||
import com.kakao.sdk.common.model.ClientError | ||
import com.kakao.sdk.common.model.ClientErrorCause | ||
import com.kakao.sdk.user.UserApiClient | ||
import com.terning.core.state.UiState | ||
import com.terning.feature.R | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SignInViewModel @Inject constructor() : ViewModel() { | ||
|
||
private val _signInState = MutableStateFlow(SignInState()) | ||
val signInState: StateFlow<SignInState> | ||
get() = _signInState.asStateFlow() | ||
|
||
private val _signInSideEffects = MutableSharedFlow<SignInSideEffect>() | ||
val signInSideEffects: SharedFlow<SignInSideEffect> | ||
get() = _signInSideEffects.asSharedFlow() | ||
|
||
fun startKakaoLogIn(context: Context) { | ||
if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) { | ||
UserApiClient.instance.loginWithKakaoTalk(context) { token, error -> | ||
signInResult(context, token, error) | ||
} | ||
} else { | ||
UserApiClient.instance.loginWithKakaoAccount(context) { token, error -> | ||
signInResult(context, token, error) | ||
} | ||
} | ||
} | ||
|
||
private fun signInResult(context: Context, token: OAuthToken?, error: Throwable?) { | ||
viewModelScope.launch { | ||
if (error != null) { | ||
signInFailure(context, error) | ||
} else if (token != null) { | ||
signInSuccess(token) | ||
} | ||
} | ||
} | ||
|
||
private fun signInFailure(context: Context, error: Throwable?) { | ||
if (error.toString().contains(KAKAO_NOT_LOGGED_IN)) { | ||
UserApiClient.instance.loginWithKakaoAccount(context) { token, error -> | ||
signInResult(context, token, error) | ||
} | ||
} else { | ||
sigInCancellationOrError(error) | ||
} | ||
} | ||
|
||
private fun sigInCancellationOrError(error: Throwable?) { | ||
viewModelScope.launch { | ||
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) { | ||
_signInSideEffects.emit(SignInSideEffect.ShowToast(R.string.sign_in_kakao_cancel)) | ||
} else { | ||
_signInSideEffects.emit(SignInSideEffect.ShowToast(R.string.sign_in_kakao_login_fail)) | ||
} | ||
} | ||
} | ||
|
||
private fun signInSuccess(token: OAuthToken) { | ||
viewModelScope.launch { | ||
_signInState.value = | ||
_signInState.value.copy(accessToken = UiState.Success(token.accessToken)) | ||
_signInSideEffects.emit(SignInSideEffect.NavigateToHome) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val KAKAO_NOT_LOGGED_IN = "statusCode=302" | ||
} | ||
} |
Oops, something went wrong.