From e9ad361575e5d610cf591747f50ce209bb84bcfd Mon Sep 17 00:00:00 2001 From: YHKOO95 Date: Sat, 4 Mar 2023 07:10:26 +0900 Subject: [PATCH] =?UTF-8?q?[D83T-66]=20SignUp=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=B9=B4=EC=B9=B4=EC=98=A4=20=EC=9D=B4=EB=A6=84=20=EB=84=98?= =?UTF-8?q?=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- presentation/src/main/AndroidManifest.xml | 12 ++++------- .../presentation/ui/sign_up/SignUpActivity.kt | 16 ++++++++++++-- .../ui/sign_up/SignUpViewModel.kt | 21 +++++++++++++++++-- .../presentation/ui/splash/SplashActivity.kt | 16 +++++++++----- .../bpm/presentation/ui/splash/SplashState.kt | 4 ++-- .../presentation/ui/splash/SplashViewModel.kt | 8 +++---- .../src/main/res/layout/fragment_home.xml | 8 +++++++ 7 files changed, 62 insertions(+), 23 deletions(-) diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml index 5e4728a..b55f0fe 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/presentation/src/main/AndroidManifest.xml @@ -22,10 +22,10 @@ android:name=".ui.splash.SplashActivity" android:exported="true" android:theme="@style/Theme.Bpm.NoActionBar"> - - - - + + + + - - - - (SignUpActivity.KEY_BUNDLE) + } + + val kakaoUserInfo: Pair by lazy { + Pair( + getBundle()?.getLong(SignUpActivity.KEY_KAKAO_USER_ID) ?: 0L, + getBundle()?.getString(SignUpActivity.KEY_KAKAO_NICK_NAME) ?: "" + ) + } + fun onClickSignUp() { viewModelScope.launch(mainDispatcher) { _event.emit(SignUpViewEvent.SignUp) diff --git a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashActivity.kt b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashActivity.kt index e51cd59..4c8a64a 100644 --- a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashActivity.kt +++ b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashActivity.kt @@ -78,10 +78,10 @@ class SplashActivity : BaseComponentActivity() { } } is SplashState.ValidationCheck -> { - viewModel.sendKakaoIdVerification(state.id) + viewModel.sendKakaoIdVerification(state.id, state.kakaoNickName) } is SplashState.SignUp -> { - goToSignUp(state.id) + goToSignUp(state.id, state.kakaoNickName) } SplashState.NoUserInfo -> { startButtonVisibilityState.value = true @@ -112,7 +112,8 @@ class SplashActivity : BaseComponentActivity() { } else if (loginInfo != null) { // 로그인 성공 kakaoLoginInstance.me { user, error -> - user?.id?.let { viewModel.setKakaoUserId(it) } + viewModel.setKakaoUserId(user?.id ?: 0L, user?.kakaoAccount?.profile?.nickname ?: "") +// user?.id?.let { viewModel.setKakaoUserId(it) } showDebugToast("login succeed. user token : ${user?.id}") } } @@ -122,8 +123,13 @@ class SplashActivity : BaseComponentActivity() { } } - private fun goToSignUp(kakaoUserId: Long?) { - startActivity(SignUpActivity.newIntent(this)) + private fun goToSignUp( + kakaoUserId: Long?, + kakaoNickName: String + ) { + startActivity( + SignUpActivity.newIntent(this, kakaoUserId, kakaoNickName) + ) finish() } diff --git a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashState.kt b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashState.kt index 3090f3d..223298e 100644 --- a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashState.kt +++ b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashState.kt @@ -19,11 +19,11 @@ sealed interface SplashState : ComposeUiState { // 카카오 유저 정보 가져오기 성공 // 이후 Validation Check 진행 - data class ValidationCheck(val id: Long) : SplashState + data class ValidationCheck(val id: Long, val kakaoNickName : String) : SplashState // Validation 완료 (신규 유저) // SignUp 페이지 이동 - data class SignUp(val id: Long?) : SplashState + data class SignUp(val id: Long?, val kakaoNickName : String) : SplashState // 유저 토큰 저장 data class SaveToken(val token: String?) : SplashState diff --git a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashViewModel.kt b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashViewModel.kt index 0c1de43..ac99710 100644 --- a/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashViewModel.kt +++ b/presentation/src/main/java/com/d83t/bpm/presentation/ui/splash/SplashViewModel.kt @@ -74,11 +74,11 @@ class SplashViewModel @Inject constructor( // 2. 카카오 SDK에서 가져온 유저ID set // state - Init, SignIn - fun setKakaoUserId(kakaoUserId: Long) { + fun setKakaoUserId(kakaoUserId: Long, kakaoNickName : String) { viewModelScope.launch(ioDispatcher + exceptionHandler) { setKakaoUserIdUseCase(kakaoUserId).onEach { kakaoUserId -> withContext(mainDispatcher) { - kakaoUserId?.let { _state.emit(SplashState.ValidationCheck(it)) } + kakaoUserId?.let { _state.emit(SplashState.ValidationCheck(it, kakaoNickName)) } } }.launchIn(viewModelScope) } @@ -87,7 +87,7 @@ class SplashViewModel @Inject constructor( // 3. 서버에서 카카오 UserId로 Valid Check 완료 이후 // 완료 이후 서버에서 받은 토큰 저장 이후 메인 화면으로 이동 // state - ValidationCheck - fun sendKakaoIdVerification(kakaoUserId: Long) { + fun sendKakaoIdVerification(kakaoUserId: Long, kakaoNickName : String) { viewModelScope.launch(ioDispatcher + exceptionHandler) { sendKakaoUserIdVerificationUseCase(kakaoUserId).onEach { state -> withContext(mainDispatcher) { @@ -97,7 +97,7 @@ class SplashViewModel @Inject constructor( if (state.error.code == CODE_NOT_FOUND_USER_ID) { // TODO : 카카오 SDK에서 내려받은 객체 던지기 // 좋은 방법 찾아보자.. - _state.emit(SplashState.SignUp(null)) + _state.emit(SplashState.SignUp(kakaoUserId, kakaoNickName)) } else { _state.emit(SplashState.Error(state.error)) } diff --git a/presentation/src/main/res/layout/fragment_home.xml b/presentation/src/main/res/layout/fragment_home.xml index 12a216b..bf6f177 100644 --- a/presentation/src/main/res/layout/fragment_home.xml +++ b/presentation/src/main/res/layout/fragment_home.xml @@ -282,6 +282,14 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="@id/tab" /> + +