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

Feat/week07-xml #34

Open
wants to merge 18 commits into
base: feat/week06-xml-challenge
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
id 'androidx.navigation.safeargs.kotlin'
id 'com.google.devtools.ksp'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.0'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

Properties properties = new Properties()
Expand Down Expand Up @@ -48,7 +50,7 @@ android {

dependencies {
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
Expand All @@ -58,18 +60,21 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
implementation "androidx.recyclerview:recyclerview:1.3.2"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.1'
ksp 'androidx.room:room-compiler:2.6.1'
implementation 'androidx.room:room-common:2.6.1'
implementation 'androidx.room:room-ktx:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.11.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0'
implementation(platform'com.squareup.okhttp3:okhttp-bom:4.10.0')
implementation'com.squareup.okhttp3:okhttp'
implementation'com.squareup.okhttp3:logging-interceptor'
implementation 'com.github.bumptech.glide:glide:4.16.0'
implementation 'com.jakewharton:process-phoenix:3.0.0'

implementation "com.google.dagger:hilt-android:2.51.1"
kapt "com.google.dagger:hilt-android-compiler:2.51.1"
}
41 changes: 0 additions & 41 deletions app/src/main/java/com/sopt/now/ServiceLocator.kt

This file was deleted.

22 changes: 3 additions & 19 deletions app/src/main/java/com/sopt/now/SoptApp.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
package com.sopt.now

import android.app.Application
import android.content.Context
import dagger.hilt.android.HiltAndroidApp

class SoptApp : Application() {
lateinit var serviceLocator: ServiceLocator

companion object {
@Volatile
private lateinit var instance: SoptApp

fun applicationContext(): Context {
return instance.applicationContext
}
}

override fun onCreate() {
super.onCreate()
instance = this
serviceLocator = ServiceLocator(applicationContext)
}
}
@HiltAndroidApp
class SoptApp : Application()
58 changes: 11 additions & 47 deletions app/src/main/java/com/sopt/now/data/UserRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,15 @@ import com.sopt.now.network.response.ResponseDto
import com.sopt.now.network.response.ResponseInfoDto
import retrofit2.Response

class UserRepository(
private val localDataSource: UserLocalDataSource,
private val remoteDataSource: UserRemoteDataSource
) {
fun setUserLoggedIn(loggedIn: Boolean) {
localDataSource.setUserLoggedIn(loggedIn)
}

fun isUserLoggedIn(): Boolean {
return localDataSource.isUserLoggedIn()
}

fun logoutUser() {
localDataSource.logoutUser()
}

fun saveUserData(user: User) {
localDataSource.saveUserData(user)
}

fun updateUserPassword(newPassword: String) {
localDataSource.updateUserPassword(newPassword)
}

fun setMemberId(memberId: String) {
localDataSource.setMemberId(memberId)
}

fun getMemberId(): String? {
return localDataSource.getMemberId()
}

suspend fun signUp(request: RequestSignUpDto): Response<ResponseDto> {
return remoteDataSource.signUp(request)
}

suspend fun login(request: RequestLoginDto): Response<ResponseDto> {
return remoteDataSource.login(request)
}

suspend fun getUserInfo(): Response<ResponseInfoDto> {
return remoteDataSource.getUserInfo()
}

suspend fun changePassword(request: RequestChangePasswordDto): Response<ResponseDto> {
return remoteDataSource.changePassword(request)
}
interface UserRepository {
fun setUserLoggedIn(loggedIn: Boolean)
fun isUserLoggedIn(): Boolean
fun logoutUser()
fun saveUserData(user: User)
fun updateUserPassword(newPassword: String)
fun setMemberId(memberId: String)
suspend fun signUp(request: RequestSignUpDto): Response<ResponseDto>
suspend fun login(request: RequestLoginDto): Response<ResponseDto>
suspend fun getUserInfo(): Response<ResponseInfoDto>
suspend fun changePassword(request: RequestChangePasswordDto): Response<ResponseDto>
}
54 changes: 54 additions & 0 deletions app/src/main/java/com/sopt/now/data/UserRepositoryImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.sopt.now.data

import com.sopt.now.network.request.RequestChangePasswordDto
import com.sopt.now.network.request.RequestLoginDto
import com.sopt.now.network.request.RequestSignUpDto
import com.sopt.now.network.response.ResponseDto
import com.sopt.now.network.response.ResponseInfoDto
import retrofit2.Response
import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(
private val localDataSource: UserLocalDataSource,
private val remoteDataSource: UserRemoteDataSource
) : UserRepository {
override fun setUserLoggedIn(loggedIn: Boolean) {
localDataSource.setUserLoggedIn(loggedIn)
}

override fun isUserLoggedIn(): Boolean {
return localDataSource.isUserLoggedIn()
}

override fun logoutUser() {
localDataSource.logoutUser()
}

override fun saveUserData(user: User) {
localDataSource.saveUserData(user)
}

override fun updateUserPassword(newPassword: String) {
localDataSource.updateUserPassword(newPassword)
}

override fun setMemberId(memberId: String) {
localDataSource.setMemberId(memberId)
}

override suspend fun signUp(request: RequestSignUpDto): Response<ResponseDto> {
return remoteDataSource.signUp(request)
}

override suspend fun login(request: RequestLoginDto): Response<ResponseDto> {
return remoteDataSource.login(request)
}

override suspend fun getUserInfo(): Response<ResponseInfoDto> {
return remoteDataSource.getUserInfo()
}

override suspend fun changePassword(request: RequestChangePasswordDto): Response<ResponseDto> {
return remoteDataSource.changePassword(request)
}
}
105 changes: 105 additions & 0 deletions app/src/main/java/com/sopt/now/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.sopt.now.di

import android.content.Context
import android.content.SharedPreferences
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.now.BuildConfig
import com.sopt.now.data.UserLocalDataSource
import com.sopt.now.data.UserRemoteDataSource
import com.sopt.now.data.UserRepository
import com.sopt.now.data.UserRepositoryImpl
import com.sopt.now.data.friend.FriendDao
import com.sopt.now.data.friend.FriendDatabase
import com.sopt.now.data.friend.FriendsRepository
import com.sopt.now.data.friend.OfflineFriendsRepository
import com.sopt.now.network.HeaderInterceptor
import com.sopt.now.network.service.AuthService
import com.sopt.now.network.service.FollowerService
import com.sopt.now.network.service.ServicePool
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object AppModule {

@Provides
@Singleton
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences =
context.getSharedPreferences("SaveLogin", Context.MODE_PRIVATE)

@Provides
@Singleton
fun provideHeaderInterceptor(
@ApplicationContext context: Context,
sharedPreferences: SharedPreferences
): HeaderInterceptor = HeaderInterceptor(context, sharedPreferences)


@Provides
@Singleton
fun provideOkHttpClient(headerInterceptor: HeaderInterceptor): OkHttpClient {
return OkHttpClient.Builder()
.addInterceptor(headerInterceptor)
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.build()
}

@Provides
@Singleton
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.AUTH_BASE_URL)
.client(okHttpClient)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

@Provides
@Singleton
fun provideAuthService(retrofit: Retrofit): AuthService = retrofit.create(AuthService::class.java)

@Provides
@Singleton
fun provideFollowerService(retrofit: Retrofit): FollowerService = retrofit.create(FollowerService::class.java)


@Provides
@Singleton
fun provideServicePool(
authService: AuthService,
followerService: FollowerService
): ServicePool = ServicePool(authService, followerService)

@Provides
@Singleton
fun provideUserLocalDataSource(sharedPreferences: SharedPreferences): UserLocalDataSource =
UserLocalDataSource(sharedPreferences)

@Provides
@Singleton
fun provideUserRemoteDataSource(servicePool: ServicePool): UserRemoteDataSource =
UserRemoteDataSource(servicePool.authService)

@Provides
@Singleton
fun provideFriendDao(@ApplicationContext context: Context) =
FriendDatabase.getDatabase(context).friendDao()

@Provides
@Singleton
fun provideFriendsRepository(friendDao: FriendDao): FriendsRepository =
OfflineFriendsRepository(friendDao)
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/sopt/now/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sopt.now.di

import com.sopt.now.data.UserRepository
import com.sopt.now.data.UserRepositoryImpl
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 RepositoryModule {

@Binds
@Singleton
abstract fun bindUserRepository(
impl: UserRepositoryImpl
): UserRepository
}
Loading