Skip to content

Commit

Permalink
[#30] 로그인 기능 추가
Browse files Browse the repository at this point in the history
- Firebase 로그인 기능 제거 (기획 확인 됨)
- 패키지 정리
  • Loading branch information
ethan-223 committed Apr 26, 2022
1 parent 83b9c5f commit 707e226
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 73 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:29.2.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'

// Google Login
implementation 'com.google.android.gms:play-services-auth:20.1.0'

// Hilt
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moyerun.moyeorun_android.login

import com.moyerun.moyeorun_android.login.data.LoginRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.moyerun.moyeorun_android.login.data

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class LoginRepository(
private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
) {

// Todo: 모여런 서버 붙일 때 반환 타입 조정
suspend fun signIn(idToken: String): LoginResponse {
return withContext(coroutineDispatcher) {
// Todo: 모여런 서버 signIn
LoginResponse(TokenPair(Token("", ""), Token("", "")), true, "1234")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.moyerun.moyeorun_android.login.data

data class LoginResponse(
val token: TokenPair,
val isNewUser: Boolean,
val userId: String
)

data class TokenPair(
val accessToken: Token,
val refreshToken: Token
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.moyerun.moyeorun_android.login.data

data class Token(
val token: String,
val expiresIn: String
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moyerun.moyeorun_android.login
package com.moyerun.moyeorun_android.login.ui

import android.content.Intent
import android.content.IntentSender
Expand Down Expand Up @@ -69,7 +69,7 @@ class LoginActivity : AppCompatActivity() {

observeEvent(viewModel.loginEvent) {
when (it) {
LoginEvent.Success -> {
LoginEvent.RegisteredUser -> {
// Todo: 메인화면 진입
Lg.d("Login!")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.moyerun.moyeorun_android.login.ui

enum class LoginEvent {
RegisteredUser, NewUser, Error
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.moyerun.moyeorun_android.login
package com.moyerun.moyeorun_android.login.ui

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.moyerun.moyeorun_android.common.EventLiveData
import com.moyerun.moyeorun_android.common.MutableEventLiveData
import com.moyerun.moyeorun_android.login.data.LoginRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -26,12 +27,14 @@ class LoginViewModel @Inject constructor(
fun signIn(idToken: String) {
viewModelScope.launch {
_isLoading.value = true
// Todo: 반환 타입 결정 후 분기
// Todo: Firebase crashlytics userId 세팅
// Todo: SharedPreference 에 유저 메타데이터 세팅
val result = loginRepository.signIn(idToken)
if (result is LoginRepository.ApiResponse.Success) {
// Todo: Firebase crashlytics userId 세팅
_loginEvent.event = LoginEvent.Success
_loginEvent.event = if (result.isNewUser) {
LoginEvent.NewUser
} else {
_loginEvent.event = LoginEvent.Error
LoginEvent.RegisteredUser
}
_isLoading.value = false
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".login.LoginActivity">
tools:context=".login.ui.LoginActivity">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/imageview_login_logo"
Expand Down

0 comments on commit 707e226

Please sign in to comment.