From 53dac124ac1e505509aab763159ad3529045f497 Mon Sep 17 00:00:00 2001 From: DOGDDUDDY Date: Thu, 7 Sep 2023 23:07:57 +0900 Subject: [PATCH] =?UTF-8?q?[fix/google=5Flogin]:=20=EA=B3=84=EC=A0=95=20?= =?UTF-8?q?=EC=97=86=EC=9D=84=20=EB=95=8C=20one=20tap=20Exception=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AccountManager로 getAccounts하면 API 23이후로 계정 정보를 넘겨주지 않는 문제가 발생했습니다. 그래서 One Tap 동작에서 발생하는 Exception을 try catch로 잡아서 이후 계정 등록 하도록 넘겼습니다. --- presentation/src/main/AndroidManifest.xml | 1 + .../gdsc/presentation/login/LoginFragment.kt | 32 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/presentation/src/main/AndroidManifest.xml b/presentation/src/main/AndroidManifest.xml index dec514fc..3fe252c6 100644 --- a/presentation/src/main/AndroidManifest.xml +++ b/presentation/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ package="org.gdsc.presentation"> + diff --git a/presentation/src/main/java/org/gdsc/presentation/login/LoginFragment.kt b/presentation/src/main/java/org/gdsc/presentation/login/LoginFragment.kt index 6ab0892b..fdf1a686 100644 --- a/presentation/src/main/java/org/gdsc/presentation/login/LoginFragment.kt +++ b/presentation/src/main/java/org/gdsc/presentation/login/LoginFragment.kt @@ -3,6 +3,8 @@ package org.gdsc.presentation.login import android.app.Activity import android.content.Intent import android.os.Bundle +import android.provider.Settings +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View @@ -16,10 +18,12 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.activityViewModels import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController +import com.google.android.gms.common.api.ApiException import kotlinx.coroutines.launch import org.gdsc.domain.model.response.UserLoginAction import org.gdsc.presentation.R import org.gdsc.presentation.databinding.FragmentLoginBinding +import org.gdsc.presentation.utils.repeatWhenUiStarted import org.gdsc.presentation.view.LoginManager import org.gdsc.presentation.view.MainActivity @@ -45,15 +49,24 @@ class LoginFragment : Fragment() { setLoginButton() } - // TODO: 가입 여부 확인 후 가입되어있으면 메인 화면으로 그렇지 않으면 가입 화면으로 이동 private fun setLoginButton() { binding.googleLoginBtnTemplate.setOnClickListener { + viewLifecycleOwner.lifecycleScope.launch { - startForResult.launch( - IntentSenderRequest.Builder(loginManager.signInIntent(requireActivity())) - .build() - ) + try { + startForResult.launch( + IntentSenderRequest.Builder(loginManager.signInIntent(requireActivity())) + .build() + ) + } catch (e: ApiException) { + Log.e("Login","ApiException $e") + showGoogleAccountRegistrationPrompt() + } catch (e: Exception) { + Log.e("Login", "setLoginButton Exception $e") + } } +// showGoogleAccountRegistrationPrompt() + } binding.googleLoginBtnText.text = context?.getString(R.string.continue_with_google) @@ -62,7 +75,16 @@ class LoginFragment : Fragment() { binding.appleLoginBtn.setOnClickListener { Toast.makeText(requireContext(), "준비중입니다.", Toast.LENGTH_SHORT).show() } + } + + private fun showGoogleAccountRegistrationPrompt() { + (context as Activity).runOnUiThread { + Toast.makeText(requireContext(), "구글 계정을 등록해주세요.", Toast.LENGTH_SHORT).show() + } + val intent = Intent(Settings.ACTION_ADD_ACCOUNT) + intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, arrayOf("com.google")) + startActivity(intent) } override fun onDestroyView() {