-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from boostcampwm2023/android/feature/login
구글 로그인 - google token 가져오기
- Loading branch information
Showing
8 changed files
with
72 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletions
30
android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
package com.ohdodok.catchytape.feature.login | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import androidx.fragment.app.viewModels | ||
import androidx.navigation.fragment.findNavController | ||
import com.google.android.gms.auth.api.signin.GoogleSignIn | ||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions | ||
import com.ohdodok.catchytape.core.ui.BaseFragment | ||
import com.ohdodok.catchytape.feature.login.databinding.FragmentLoginBinding | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
|
||
@AndroidEntryPoint | ||
class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login) { | ||
|
||
private val viewModel: LoginViewModel by viewModels() | ||
|
||
private val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) | ||
.requestIdToken(BuildConfig.GOOGLE_CLIENT_ID) | ||
.build() | ||
|
||
private val googleLoginLauncher: ActivityResultLauncher<Intent> = | ||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | ||
if (result.resultCode == Activity.RESULT_OK) { | ||
val task = GoogleSignIn.getSignedInAccountFromIntent(result.data) | ||
viewModel.login(task.result.idToken, task.result.email) | ||
} | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.viewModel = viewModel | ||
setUpGoogleLoginBtn() | ||
} | ||
|
||
// TODO : Nickname Fragment Test 를 위한 코드로 추후 변경 해야함 | ||
private fun setUpGoogleLoginBtn() { | ||
binding.btnGoogleLogin.setOnClickListener { | ||
findNavController().navigate(R.id.action_login_fragment_to_nickname_fragment) | ||
val googleSignInClient = GoogleSignIn.getClient(requireContext(), gso) | ||
googleLoginLauncher.launch(googleSignInClient.signInIntent) | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
android/feature/login/src/main/java/com/ohdodok/catchytape/feature/login/LoginViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,36 @@ | ||
package com.ohdodok.catchytape.feature.login | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
class LoginViewModel : ViewModel() { | ||
|
||
private val _uiState: MutableStateFlow<LoginUiState> = MutableStateFlow(LoginUiState.Waiting) | ||
val uiState: StateFlow<LoginUiState> = _uiState.asStateFlow() | ||
|
||
private val _events: MutableSharedFlow<LoginEvent> = MutableSharedFlow<LoginEvent>() | ||
val events: SharedFlow<LoginEvent> = _events.asSharedFlow() | ||
|
||
fun login(token: String?, email: String?) { | ||
// 서버 통신 예정 | ||
} | ||
} | ||
|
||
|
||
// TODO : 서버 연결 후 수정 될 예정 | ||
sealed class LoginUiState{ | ||
data object Waiting : LoginUiState() | ||
data object Success : LoginUiState() | ||
data object Failure : LoginUiState() | ||
} | ||
|
||
// TODO : 서버 연결 후 수정 될 예정 | ||
sealed interface LoginEvent { | ||
data object NavigateToHome : LoginEvent | ||
data object NavigateToNickName : LoginEvent | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters