Skip to content

Commit

Permalink
[fix/google_login]: 계정 없을 때 one tap Exception 수정
Browse files Browse the repository at this point in the history
AccountManager로 getAccounts하면 API 23이후로 계정 정보를 넘겨주지 않는 문제가 발생했습니다.
그래서 One Tap 동작에서 발생하는 Exception을 try catch로 잡아서 이후 계정 등록 하도록 넘겼습니다.
  • Loading branch information
dogdduddy committed Sep 7, 2023
1 parent 06261fd commit 53dac12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions presentation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package="org.gdsc.presentation">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 53dac12

Please sign in to comment.