From 9b2f733c993b822763459190e2cac09eaa784162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Sun, 23 Apr 2023 20:25:07 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[FIX]=20signUp=20=EC=84=B1=EB=B3=84,=20?= =?UTF-8?q?=EB=82=98=EC=9D=B4,=20=EC=97=B0=EB=A0=B9=EB=8C=80=20=EB=B9=88?= =?UTF-8?q?=20=EA=B0=92=20=EB=93=A4=EC=96=B4=EA=B0=80=EB=8A=94=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/havit/di/ServiceModule.kt | 12 ++++ .../sopt/havit/ui/sign/KakaoLoginService.kt | 56 ++++++++++--------- .../org/sopt/havit/ui/sign/SignInViewModel.kt | 21 ++++--- .../havit/ui/sign/SplashWithSignActivity.kt | 28 ++-------- 4 files changed, 60 insertions(+), 57 deletions(-) diff --git a/app/src/main/java/org/sopt/havit/di/ServiceModule.kt b/app/src/main/java/org/sopt/havit/di/ServiceModule.kt index 81d5df00a..d5b8affee 100644 --- a/app/src/main/java/org/sopt/havit/di/ServiceModule.kt +++ b/app/src/main/java/org/sopt/havit/di/ServiceModule.kt @@ -1,10 +1,14 @@ package org.sopt.havit.di +import android.content.Context import dagger.Module import dagger.Provides import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import org.sopt.havit.data.api.HavitApi +import org.sopt.havit.data.local.HavitAuthLocalPreferences +import org.sopt.havit.ui.sign.KakaoLoginService import retrofit2.Retrofit import javax.inject.Singleton @@ -15,4 +19,12 @@ object ServiceModule { @Singleton fun provideHavitService(retrofit: Retrofit): HavitApi = retrofit.create(HavitApi::class.java) + + @Provides + @Singleton + fun provideKakaoLoginService( + @ApplicationContext context: Context, + preference: HavitAuthLocalPreferences + ): KakaoLoginService = + KakaoLoginService(context, preference) } diff --git a/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt b/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt index b7e3d985b..41395b9c0 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt @@ -5,6 +5,7 @@ import android.util.Log import com.kakao.sdk.auth.model.OAuthToken import com.kakao.sdk.auth.model.Prompt import com.kakao.sdk.user.UserApiClient +import com.kakao.sdk.user.model.User import dagger.hilt.android.qualifiers.ActivityContext import org.sopt.havit.data.local.HavitAuthLocalPreferences import javax.inject.Inject @@ -23,23 +24,6 @@ class KakaoLoginService @Inject constructor( ) } - private fun getKakaoUserInfo() { - UserApiClient.instance.me { user, error -> - if (error != null) { - Log.d("TAG", "사용자 정보 요청 실패", error) - } else if (user != null) { - Log.d("TAG", "사용자 정보 요청 성공") - val age = user.kakaoAccount?.ageRange.toString().split("_") - - preferences.userEmail = user.kakaoAccount?.email.toString() - preferences.userGender = user.kakaoAccount?.gender.toString() - preferences.userAge = (age[1].toInt() + age[2].toInt()) / 2 - preferences.userNickName = user.kakaoAccount?.profile?.nickname ?: "" - - } - } - } - fun setKakaoLogin(kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit) { if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) { UserApiClient.instance.loginWithKakaoTalk( @@ -54,7 +38,7 @@ class KakaoLoginService @Inject constructor( } } - fun getUserNeedNewScopes() { + fun getUserNeedNewScopes(isGetUserInfo: (Boolean) -> Unit) { UserApiClient.instance.me { user, error -> if (error != null) { Log.d("TAG", "사용자 정보 요청 실패", error) @@ -72,22 +56,42 @@ class KakaoLoginService @Inject constructor( if (scopes.isNotEmpty()) { Log.d("TAG", "사용자에게 추가 동의를 받아야 합니다.") // scope 목록을 전달하여 카카오 로그인 요청 - UserApiClient.instance.loginWithNewScopes( - context, - scopes - ) { _, error -> + UserApiClient.instance.loginWithNewScopes(context, scopes) { token, error -> if (error != null) { - Log.d("TAG", "사용자 추가 동의 실패", error) + Log.e("TAG", "사용자 추가 동의 실패", error) } else { + Log.d("TAG", "allowed scopes: ${token!!.scopes}") + // 사용자 정보 재요청 - getKakaoUserInfo() + UserApiClient.instance.me { user, error -> + if (error != null) { + Log.e("TAG", "사용자 정보 요청 실패", error) + isGetUserInfo(false) + } else if (user != null) { + Log.i("TAG", "사용자 정보 요청 성공") + getUserInfo(user) + isGetUserInfo(true) + } + } } } + } else { - getKakaoUserInfo() + getUserInfo(user) + isGetUserInfo(true) } } } } -} \ No newline at end of file + private fun getUserInfo(user: User) { + val age = user.kakaoAccount?.ageRange.toString().split("_") + + preferences.userEmail = user.kakaoAccount?.email.toString() + preferences.userGender = user.kakaoAccount?.gender.toString() + preferences.userAge = (age[1].toInt() + age[2].toInt()) / 2 + preferences.userNickName = user.kakaoAccount?.profile?.nickname ?: "" + } + + +} diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt index 512b07785..1b217dec0 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt @@ -17,7 +17,8 @@ import javax.inject.Inject @HiltViewModel class SignInViewModel @Inject constructor( - private val authRepository: AuthRepository + private val authRepository: AuthRepository, + private val kakaoLoginService: KakaoLoginService ) : ViewModel() { companion object { @@ -33,9 +34,6 @@ class SignInViewModel @Inject constructor( private var _isAlreadyUser = MutableLiveData>() var isAlreadyUser: LiveData> = _isAlreadyUser - private var _isNeedScopes = MutableLiveData>() - var isNeedScopes: LiveData> = _isNeedScopes - private var _accessToken = MutableLiveData() var accessToken: LiveData = _accessToken @@ -46,17 +44,26 @@ class SignInViewModel @Inject constructor( private val _kakaoToken = MutableLiveData() - val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> + private val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> if (error != null) { _isSuccessKakaoLogin.value = Event(false) } else if (token != null) { Log.d("TAG", "카카오계정으로 로그인 성공 ${token.accessToken}") setKakaoToken(token.accessToken) - _isNeedScopes.value = Event(true) - _isSuccessKakaoLogin.value = Event(true) + kakaoLoginService.getUserNeedNewScopes { + _isSuccessKakaoLogin.value = Event(it) + } } } + fun setKakaoLogin() { + kakaoLoginService.setKakaoLogin(kakaoLoginCallback) + } + + fun setKakaoWithAccountLogin() { + kakaoLoginService.setLoginWithAccount(kakaoLoginCallback) + } + fun setLoginGuideVisibility(boolean: Boolean) { loginGuidVisibility.value = boolean diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt index d6b482566..2b4b9ff7d 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt @@ -7,7 +7,6 @@ import android.view.animation.Animation import android.view.animation.AnimationUtils import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels -import com.kakao.sdk.user.UserApiClient import dagger.hilt.android.AndroidEntryPoint import org.sopt.havit.MainActivity import org.sopt.havit.R @@ -28,10 +27,6 @@ import kotlin.properties.Delegates class SplashWithSignActivity : BaseBindingActivity(R.layout.activity_splash_with_sign) { - - @Inject - lateinit var kakaoLoginService: KakaoLoginService - @Inject lateinit var preference: HavitSharedPreference @@ -57,26 +52,21 @@ class SplashWithSignActivity : setContentView(binding.root) binding.main = signInViewModel initFcmToken() - initSuccessKakaoLoginOserver() + initSuccessKakaoLoginObserver() initWhereSplashComesFrom() setLoginGuideIfFromShare() setSplashView() setListeners() isAlreadyUserObserver() - isNeedScopesObserver() } private fun initFcmToken() { signInViewModel.initFcmToken() } - private fun initSuccessKakaoLoginOserver() { + private fun initSuccessKakaoLoginObserver() { signInViewModel.isSuccessKakaoLogin.observe(this, EventObserver { if (it) signInViewModel.getSignIn() - else UserApiClient.instance.loginWithKakaoAccount( - this, - callback = signInViewModel.kakaoLoginCallback - ) }) } @@ -142,14 +132,10 @@ class SplashWithSignActivity : setAutoLogin() } binding.btnKakaoLogin.setOnSinglePostClickListener { - kakaoLoginService.setKakaoLogin( - signInViewModel.kakaoLoginCallback - ) + signInViewModel.setKakaoLogin() } binding.tvAnotherLogin.setOnClickListener { - kakaoLoginService.setLoginWithAccount( - signInViewModel.kakaoLoginCallback - ) + signInViewModel.setKakaoWithAccountLogin() } } @@ -165,12 +151,6 @@ class SplashWithSignActivity : ) } - private fun isNeedScopesObserver() { - signInViewModel.isNeedScopes.observe(this) { - kakaoLoginService.getUserNeedNewScopes() - } - } - private fun isAlreadyUserObserver() { signInViewModel.isAlreadyUser.observe( this, From 8043a8bb49ad1b26e2f526ee526d442844d150d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Sun, 23 Apr 2023 21:31:16 +0900 Subject: [PATCH 2/4] [CHORE] version code, name v1.0.4 -> v1.0.5 (#835) --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9d1c672c0..50b8d3bf9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -19,8 +19,8 @@ android { applicationId "org.sopt.havit" minSdk 23 targetSdk 31 - versionCode 104 - versionName "1.0.4" + versionCode 105 + versionName "1.0.5" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField("String", "HAVIT_BASE_URL_DEV", properties["HAVIT_BASE_URL_DEV"]) buildConfigField("String", "HAVIT_BASE_URL_PROD", properties["HAVIT_BASE_URL_PROD"]) From 3406089188b7ec4e656114a23ea00d36ddaef722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Sun, 23 Apr 2023 23:58:27 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[FIX]=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B3=84=EC=A0=95=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20=EC=95=88=EB=90=9C=20=EA=B2=BD=EC=9A=B0=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC=20(#836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/sopt/havit/di/ServiceModule.kt | 11 ----------- .../sopt/havit/ui/sign/KakaoLoginService.kt | 2 -- .../org/sopt/havit/ui/sign/SignInViewModel.kt | 18 ++++-------------- .../havit/ui/sign/SplashWithSignActivity.kt | 16 ++++++++++++---- 4 files changed, 16 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/sopt/havit/di/ServiceModule.kt b/app/src/main/java/org/sopt/havit/di/ServiceModule.kt index d5b8affee..688e29f07 100644 --- a/app/src/main/java/org/sopt/havit/di/ServiceModule.kt +++ b/app/src/main/java/org/sopt/havit/di/ServiceModule.kt @@ -1,14 +1,10 @@ package org.sopt.havit.di -import android.content.Context import dagger.Module import dagger.Provides import dagger.hilt.InstallIn -import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.components.SingletonComponent import org.sopt.havit.data.api.HavitApi -import org.sopt.havit.data.local.HavitAuthLocalPreferences -import org.sopt.havit.ui.sign.KakaoLoginService import retrofit2.Retrofit import javax.inject.Singleton @@ -20,11 +16,4 @@ object ServiceModule { fun provideHavitService(retrofit: Retrofit): HavitApi = retrofit.create(HavitApi::class.java) - @Provides - @Singleton - fun provideKakaoLoginService( - @ApplicationContext context: Context, - preference: HavitAuthLocalPreferences - ): KakaoLoginService = - KakaoLoginService(context, preference) } diff --git a/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt b/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt index 41395b9c0..e2fe95eb6 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/KakaoLoginService.kt @@ -14,8 +14,6 @@ class KakaoLoginService @Inject constructor( @ActivityContext private val context: Context, private val preferences: HavitAuthLocalPreferences ) { - - fun setLoginWithAccount(kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit) { UserApiClient.instance.loginWithKakaoAccount( context, diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt index 1b217dec0..6701655ce 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt @@ -17,8 +17,7 @@ import javax.inject.Inject @HiltViewModel class SignInViewModel @Inject constructor( - private val authRepository: AuthRepository, - private val kakaoLoginService: KakaoLoginService + private val authRepository: AuthRepository ) : ViewModel() { companion object { @@ -44,26 +43,17 @@ class SignInViewModel @Inject constructor( private val _kakaoToken = MutableLiveData() - private val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> + val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> if (error != null) { _isSuccessKakaoLogin.value = Event(false) + Log.d("TAG", "카카오계정으로 로그인 실패 ${error}") } else if (token != null) { Log.d("TAG", "카카오계정으로 로그인 성공 ${token.accessToken}") + _isSuccessKakaoLogin.value = Event(true) setKakaoToken(token.accessToken) - kakaoLoginService.getUserNeedNewScopes { - _isSuccessKakaoLogin.value = Event(it) - } } } - fun setKakaoLogin() { - kakaoLoginService.setKakaoLogin(kakaoLoginCallback) - } - - fun setKakaoWithAccountLogin() { - kakaoLoginService.setLoginWithAccount(kakaoLoginCallback) - } - fun setLoginGuideVisibility(boolean: Boolean) { loginGuidVisibility.value = boolean diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt index 2b4b9ff7d..3aab6d971 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt @@ -5,6 +5,7 @@ import android.content.Intent import android.os.Bundle import android.view.animation.Animation import android.view.animation.AnimationUtils +import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint @@ -30,6 +31,9 @@ class SplashWithSignActivity : @Inject lateinit var preference: HavitSharedPreference + @Inject + lateinit var kakaoLoginService: KakaoLoginService + private val signInViewModel: SignInViewModel by viewModels() private var isFromShare by Delegates.notNull() @@ -65,8 +69,12 @@ class SplashWithSignActivity : } private fun initSuccessKakaoLoginObserver() { - signInViewModel.isSuccessKakaoLogin.observe(this, EventObserver { - if (it) signInViewModel.getSignIn() + signInViewModel.isSuccessKakaoLogin.observe(this, EventObserver { isSuccess -> + if (isSuccess) { + kakaoLoginService.getUserNeedNewScopes { isGetUserInfo -> + if (isGetUserInfo) signInViewModel.getSignIn() + } + } }) } @@ -132,10 +140,10 @@ class SplashWithSignActivity : setAutoLogin() } binding.btnKakaoLogin.setOnSinglePostClickListener { - signInViewModel.setKakaoLogin() + kakaoLoginService.setKakaoLogin(signInViewModel.kakaoLoginCallback) } binding.tvAnotherLogin.setOnClickListener { - signInViewModel.setKakaoWithAccountLogin() + kakaoLoginService.setLoginWithAccount(signInViewModel.kakaoLoginCallback) } } From b6b2dacbf96f3692526059e452bb18a7f0c5f8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A1=E1=86=AB=E1=84=82=E1=85=A1=E1=84=8B?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= Date: Mon, 24 Apr 2023 01:02:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EA=B3=84=EC=A0=95=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20=EC=95=88=EB=90=9C=20=EA=B2=BD=EC=9A=B0=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EC=B2=98=EB=A6=AC=20(#836)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt | 4 +++- .../java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt index 6701655ce..9d3e6bc2e 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SignInViewModel.kt @@ -45,7 +45,9 @@ class SignInViewModel @Inject constructor( val kakaoLoginCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> if (error != null) { - _isSuccessKakaoLogin.value = Event(false) + if (error.toString().contains("statusCode=302")) { + _isSuccessKakaoLogin.value = Event(false) + } Log.d("TAG", "카카오계정으로 로그인 실패 ${error}") } else if (token != null) { Log.d("TAG", "카카오계정으로 로그인 성공 ${token.accessToken}") diff --git a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt index 3aab6d971..87c1bbac7 100644 --- a/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt +++ b/app/src/main/java/org/sopt/havit/ui/sign/SplashWithSignActivity.kt @@ -5,7 +5,6 @@ import android.content.Intent import android.os.Bundle import android.view.animation.Animation import android.view.animation.AnimationUtils -import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels import dagger.hilt.android.AndroidEntryPoint @@ -74,6 +73,8 @@ class SplashWithSignActivity : kakaoLoginService.getUserNeedNewScopes { isGetUserInfo -> if (isGetUserInfo) signInViewModel.getSignIn() } + } else { + kakaoLoginService.setLoginWithAccount(signInViewModel.kakaoLoginCallback) } }) }