Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

구글 로그인 - google token 가져오기 #107

Merged
merged 10 commits into from
Nov 16, 2023
4 changes: 3 additions & 1 deletion .github/workflows/android-pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ jobs:
env:
DEBUG_KEYSTORE: ${{ secrets.DEBUG_KEYSTORE }}
KEYSTORE_PROPERTIES: ${{ secrets.KEYSTORE_PROPERTIES }}
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: |
echo "$DEBUG_KEYSTORE" | base64 -d > keystore.properties
echo "$KEYSTORE_PROPERTIES" > keystore.properties
echo "$LOCAL_PROPERTIES" > local.properties
./gradlew testDebugUnitTest --stacktrace

- name: Publish Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: "**/test-results/**/*.xml"
files: "**/test-results/**/*.xml"
11 changes: 11 additions & 0 deletions android/feature/login/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import java.util.Properties
import java.io.FileInputStream

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("catchytape.android.feature")
}

val localPropertiesFile = rootProject.file("local.properties")
val localProperties = Properties()
localProperties.load(FileInputStream(localPropertiesFile))

android {
namespace = "com.ohdodok.catchytape.feature.login"

defaultConfig {

buildConfigField("String", "GOOGLE_SERVER_ID", localProperties["google.server.id"] as String)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
Expand All @@ -24,6 +32,9 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
}
}

dependencies {
Expand Down
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)
.requestEmail()
.requestIdToken(BuildConfig.GOOGLE_SERVER_ID)
youlalala marked this conversation as resolved.
Show resolved Hide resolved
.build()

private val googleLoginLauncher: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if(result.resultCode == Activity.RESULT_OK){
youlalala marked this conversation as resolved.
Show resolved Hide resolved
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 mGoogleSignInClient = GoogleSignIn.getClient(requireContext(), gso)
youlalala marked this conversation as resolved.
Show resolved Hide resolved
googleLoginLauncher.launch(mGoogleSignInClient.signInIntent)
}
}
}
}
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.Waiting)
youlalala marked this conversation as resolved.
Show resolved Hide resolved
val uiState: StateFlow<LoginUiState> = _uiState.asStateFlow()

private val _events = 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
}
Loading