Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/src/main/java/com/paw/key/data/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.paw.key.data.di

import android.content.ContentResolver
import android.content.Context
import androidx.credentials.CredentialManager
import com.paw.key.BuildConfig
import dagger.Module
import dagger.Provides
Expand All @@ -26,4 +27,12 @@ object AppModule {
fun provideContentResolver(@ApplicationContext context: Context): ContentResolver {
return context.contentResolver
}

@Provides
@Singleton
fun provideCredentialManager(
@ApplicationContext context: Context
): CredentialManager {
return CredentialManager.create(context)
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/paw/key/data/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.paw.key.data.di

import com.paw.key.data.local.datasource.UserLocalDataSource
import com.paw.key.data.local.datasourceimpl.UserLocalDataSourceImpl
import com.paw.key.data.remote.datasource.datasourceimpl.AuthRemoteDataSourceImpl
import com.paw.key.data.remote.datasource.datasourceimpl.GoogleAuthDataSourceImpl
import com.paw.key.data.remote.datasource.login.AuthRemoteDataSource
import com.paw.key.data.remote.datasource.login.GoogleAuthDataSource
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindsUserDatasource(
userLocalDataSourceImpl: UserLocalDataSourceImpl
) : UserLocalDataSource

@Binds
@Singleton
abstract fun bindsAuthDatasource(
authRemoteDataSourceImpl: AuthRemoteDataSourceImpl
) : AuthRemoteDataSource

@Binds
@Singleton
abstract fun bindsGoogleDataSource(
googleAuthDataSourceImpl: GoogleAuthDataSourceImpl
) : GoogleAuthDataSource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.paw.key.data.local.datasource

interface UserLocalDataSource {
suspend fun saveTokens(accessToken: String, refreshToken: String)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.paw.key.data.local.datasourceimpl

import android.content.Context
import com.paw.key.core.util.UserDataStore
import com.paw.key.data.local.datasource.UserLocalDataSource
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class UserLocalDataSourceImpl @Inject constructor(
@ApplicationContext private val context: Context
) : UserLocalDataSource {

override suspend fun saveTokens(accessToken: String, refreshToken: String) {
UserDataStore.saveAcessToken(context, accessToken)
UserDataStore.saveRefreshToken(context, refreshToken)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.paw.key.data.repositoryimpl.login

import android.content.Context
import com.paw.key.core.util.UserDataStore
import com.paw.key.core.util.suspendRunCatching
import com.paw.key.data.dto.response.LoginResponseDto
import com.paw.key.data.local.datasource.UserLocalDataSource
import com.paw.key.data.remote.datasource.login.AuthRemoteDataSource
import com.paw.key.data.remote.datasource.login.GoogleAuthDataSource
import com.paw.key.domain.repository.login.AuthRepository
Expand All @@ -12,7 +12,7 @@ import javax.inject.Inject
class AuthRepositoryImpl @Inject constructor(
private val authRemoteDataSource: AuthRemoteDataSource,
private val googleAuthDataSource: GoogleAuthDataSource,
private val context: Context
private val userLocalDataSource: UserLocalDataSource
) : AuthRepository {

override suspend fun signInWithGoogle(context: Context): Result<String> =
Expand All @@ -22,14 +22,11 @@ class AuthRepositoryImpl @Inject constructor(
suspendRunCatching {
val loginResponse = authRemoteDataSource.login(providerToken, provider).data

UserDataStore.saveAcessToken(
context = context,
token = loginResponse.AccessToken
)
UserDataStore.saveRefreshToken(
context = context,
token = loginResponse.RefreshToken
userLocalDataSource.saveTokens(
accessToken = loginResponse.AccessToken,
refreshToken = loginResponse.RefreshToken
)

loginResponse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import androidx.lifecycle.ViewModel
import com.paw.key.domain.repository.login.AuthRepository
import com.paw.key.presentation.ui.login.state.LoginSideEffect
import com.paw.key.presentation.ui.login.state.LoginState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor(
private val authRepository: AuthRepository,
) : ViewModel() {
Expand Down