Skip to content

Commit

Permalink
Merge pull request #107 from boostcampwm2023/android/feature/login
Browse files Browse the repository at this point in the history
구글 로그인 - google token 가져오기
  • Loading branch information
youlalala authored Nov 16, 2023
2 parents b05d69c + 11f7c3a commit 178fe30
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 9 deletions.
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"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AndroidFeaturePlugin : Plugin<Project> {
with(pluginManager) {
apply("catchytape.android.library")
apply("catchytape.android.hilt")
apply("androidx.navigation.safeargs.kotlin")
}

extensions.configure<LibraryExtension> {
Expand Down
1 change: 1 addition & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ plugins {
alias(libs.plugins.org.jetbrains.kotlin.jvm) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.navigation.safe.args) apply false
}
true // Needed to make the Suppress annotation work for the plugins block
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.appbar.MaterialToolbar


abstract class BaseFragment<VB : ViewDataBinding>(
@LayoutRes private val layoutId: Int
) : Fragment() {
Expand Down
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_CLIENT_ID", localProperties["google.client.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)
.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)
}
}
}
}
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
}
4 changes: 2 additions & 2 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ kotlinx-serialization-converter = { module = "com.jakewharton.retrofit:retrofit2

timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" }


[plugins]
com-android-application = { id = "com.android.application", version.ref = "agp" }
com-android-library = { id = "com.android.library", version.ref = "agp" }
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
navigation-safe-args = { id = "androidx.navigation.safeargs.kotlin", version.ref = "navigation" }

0 comments on commit 178fe30

Please sign in to comment.