-
Notifications
You must be signed in to change notification settings - Fork 1
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/#5] 온보딩 뷰 / 카카오 연결 #13
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9ecb7b0
[ADD/#5] 로그인, 회원가입 화면 추가
leeeyubin 185fda5
[ADD/#5] 카카오 sdk 추가
leeeyubin ea5ee90
Merge branch 'develop' of https://github.com/teamterning/Terning-Andr…
leeeyubin 0f06850
Merge branch 'develop' of https://github.com/teamterning/Terning-Andr…
leeeyubin 95d0f42
[ADD/#5] 카카오 의존성 추가
leeeyubin 7e34229
[FEAT/#5] NATIVE_APP_KEY 구현
leeeyubin ee4abf8
[FEAT/#5] kakaoVersion Update
leeeyubin a08222f
[ADD/#5] add signin, signup, filtering screen
leeeyubin 4156194
[ADD/#5] add signin, signup navigation
leeeyubin de120c9
[UI/#5] KakaoButton UI 구현
leeeyubin 552b34f
[FEAT/#5] 카카오톡 소셜 로그인 구현
leeeyubin 8b3b34b
[FEAT/#5] SignInViewModel 함수화
leeeyubin 350c569
[CHORE/#5] 코드 수정
leeeyubin ac8dd67
[CHORE/#5] nonnull로 수정
leeeyubin 47aa109
[CHORE/#5] 불필요한 코드 삭제
leeeyubin f8b4ab8
[CHORE/#5] 컨플릭 수정
leeeyubin 3540521
[FIX/#5] 컨플릭 수정
leeeyubin 4bcb604
[FIX/#5] 무한 로딩 수정
leeeyubin 1110416
[FIX/#5] 코드 수정
leeeyubin 2dc3f98
[CHORE/#5] NavigateToHome 네이밍 수정
leeeyubin da0b647
[CHORE/#5] startDestination SignIn -> Home
leeeyubin a8449f0
[CHORE/#5] startDestination Home -> SignIn
leeeyubin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[where]_[what] 네이밍 컨벤션 다시 한 번 확인합니당!