Skip to content

Commit

Permalink
[D83T-66] SignUp으로 카카오 이름 넘기기
Browse files Browse the repository at this point in the history
  • Loading branch information
YHKOO95 committed Mar 3, 2023
1 parent 44226f4 commit e9ad361
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 23 deletions.
12 changes: 4 additions & 8 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
android:name=".ui.splash.SplashActivity"
android:exported="true"
android:theme="@style/Theme.Bpm.NoActionBar">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.sign_up.SignUpActivity"
Expand All @@ -37,10 +37,6 @@
android:exported="true"
android:screenOrientation="portrait"
android:theme="@style/Theme.Bpm.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.studio_detail.StudioDetailActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.ui.text.font.FontWeight.Companion.Medium
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.os.bundleOf
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.d83t.bpm.presentation.R
import com.d83t.bpm.presentation.base.BaseComponentActivity
Expand Down Expand Up @@ -80,6 +81,8 @@ class SignUpActivity : BaseComponentActivity() {
override fun initUi() {
setContent {
BPMTheme {
nicknameTextState.value = viewModel.kakaoUserInfo.second

SignUpActivityContent(
imageState = imageState,
nicknameTextState = nicknameTextState,
Expand Down Expand Up @@ -124,8 +127,17 @@ class SignUpActivity : BaseComponentActivity() {

companion object {

fun newIntent(context: Context, ): Intent {
return Intent(context, SignUpActivity::class.java)
const val KEY_BUNDLE = "bundle"
const val KEY_KAKAO_USER_ID = "kakao_user_id"
const val KEY_KAKAO_NICK_NAME = "kakao_nickname"

fun newIntent(context: Context, kakaoUserId: Long?, kakaoNickName : String): Intent {
return Intent(context, SignUpActivity::class.java).apply {
putExtra(KEY_BUNDLE, bundleOf(
KEY_KAKAO_USER_ID to kakaoUserId,
KEY_KAKAO_NICK_NAME to kakaoNickName
))
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.d83t.bpm.presentation.ui.sign_up

import android.os.Bundle
import androidx.compose.ui.graphics.ImageBitmap
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
Expand All @@ -10,11 +11,16 @@ import com.d83t.bpm.presentation.di.IoDispatcher
import com.d83t.bpm.presentation.di.MainDispatcher
import com.d83t.bpm.presentation.util.convertBitmapToWebpFile
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SignUpViewModel @Inject constructor(
Expand All @@ -37,6 +43,17 @@ class SignUpViewModel @Inject constructor(
}
}

private fun getBundle(): Bundle? {
return savedStateHandle.get<Bundle>(SignUpActivity.KEY_BUNDLE)
}

val kakaoUserInfo: Pair<Long, String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
}
}
Expand All @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand All @@ -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))
}
Expand Down
8 changes: 8 additions & 0 deletions presentation/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tab" />

<View
android:layout_width="0dp"
android:layout_height="1dp"
android:background="@color/gray_10"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/tab"/>

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/pager"
android:layout_width="match_parent"
Expand Down

0 comments on commit e9ad361

Please sign in to comment.