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() {