-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/BCSDLab/JJBAKSA-ANDROID …
…into feature/#7-Get-kakao-login-token � Conflicts: � app/src/main/java/com/jjbaksa/jjbaksa/JjbaksaApp.kt � app/src/main/java/com/jjbaksa/jjbaksa/di/RepositoryModule.kt
- Loading branch information
Showing
29 changed files
with
469 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/jjbaksa/jjbaksa/di/DataBaseModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.jjbaksa.jjbaksa.di | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import com.jjbaksa.data.database.AppDatabase | ||
import com.jjbaksa.data.database.UserDao | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DataBaseModule { | ||
@Provides | ||
@Singleton | ||
fun provideRoomDataBase(@ApplicationContext context: Context): AppDatabase { | ||
return Room | ||
.databaseBuilder(context, AppDatabase::class.java, "MyExoPlayer.db") | ||
.allowMainThreadQueries() | ||
.build() | ||
} | ||
@Provides | ||
@Singleton | ||
fun provideVideoDao(appDatabase: AppDatabase): UserDao { | ||
return appDatabase.userDao() | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/jjbaksa/jjbaksa/di/DataSourceModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.jjbaksa.jjbaksa.di | ||
|
||
import com.jjbaksa.data.api.AuthApi | ||
import com.jjbaksa.data.api.NoAuthApi | ||
import com.jjbaksa.data.database.UserDao | ||
import com.jjbaksa.data.datasource.local.UserLocalDataSource | ||
import com.jjbaksa.data.datasource.remote.UserRemoteDataSource | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DataSourceModule { | ||
@Provides | ||
@Singleton | ||
fun provideUserRemoteDataSource(authApi: AuthApi, noAuthApi: NoAuthApi): UserRemoteDataSource { | ||
return UserRemoteDataSource(authApi, noAuthApi) | ||
} | ||
@Provides | ||
@Singleton | ||
fun provideLocalDataSource(userDao: UserDao): UserLocalDataSource { | ||
return UserLocalDataSource(userDao) | ||
} | ||
} |
186 changes: 186 additions & 0 deletions
186
app/src/main/java/com/jjbaksa/jjbaksa/di/NetworkModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package com.jjbaksa.jjbaksa.di | ||
|
||
import com.jjbaksa.data.BASE_URL | ||
import com.jjbaksa.data.api.AuthApi | ||
import com.jjbaksa.data.api.NoAuthApi | ||
import com.jjbaksa.jjbaksa.JjbaksaApp | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.Interceptor | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Qualifier | ||
import javax.inject.Singleton | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class AUTH | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class NOAUTH | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class REFRESH | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetworkModule { | ||
private val httpLoggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = if (JjbaksaApp.instance.isDebug) { | ||
HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
HttpLoggingInterceptor.Level.HEADERS | ||
} | ||
} | ||
|
||
@AUTH | ||
@Provides | ||
@Singleton | ||
fun provideAuthInterceptor(): Interceptor { | ||
return Interceptor { chain: Interceptor.Chain -> | ||
// val accessToken //todo 추후 ACCESS TOKEN 추가 | ||
val newRequest: Request = chain.request().newBuilder() | ||
// .addHeader("Authorization", "Bearer $accessToken") | ||
.build() | ||
chain.proceed(newRequest) | ||
} | ||
} | ||
// TODO 추후 Refresh 추가 | ||
/* | ||
@AUTH | ||
@Provides | ||
@Singleton | ||
fun provideTokenAuthenticator(@REFRESH refreshRetrofit: Retrofit): TokenAuthenticator { | ||
return TokenAuthenticator( | ||
KoalaApp.instance.applicationContext, | ||
refreshRetrofit | ||
) | ||
} | ||
*/ | ||
// TODO 추후 Refresh 추가 | ||
/* | ||
@REFRESH | ||
@Provides | ||
@Singleton | ||
fun provideRefreshInterceptor(): Interceptor { | ||
return Interceptor { chain: Interceptor.Chain -> | ||
val refreshToken = Hawk.get(REFRESH_TOKEN, "") | ||
val newRequest: Request = chain.request().newBuilder() | ||
.addHeader("RefreshToken", "Bearer $refreshToken") | ||
.build() | ||
chain.proceed(newRequest) | ||
} | ||
} | ||
*/ | ||
|
||
@NOAUTH | ||
@Provides | ||
@Singleton | ||
fun provideNoAuthOkHttpClient(): OkHttpClient { | ||
return OkHttpClient.Builder().apply { | ||
connectTimeout(10, TimeUnit.SECONDS) | ||
readTimeout(30, TimeUnit.SECONDS) | ||
writeTimeout(15, TimeUnit.SECONDS) | ||
addInterceptor(httpLoggingInterceptor) | ||
}.build() | ||
} | ||
// TODO 추후 Refresh 추가 | ||
/* | ||
@AUTH | ||
@Provides | ||
@Singleton | ||
fun provideAuthOkHttpClient( | ||
@AUTH authInterceptor: Interceptor, | ||
@AUTH tokenAuthenticator: TokenAuthenticator | ||
): OkHttpClient { | ||
return OkHttpClient.Builder().apply { | ||
connectTimeout(10, TimeUnit.SECONDS) | ||
readTimeout(30, TimeUnit.SECONDS) | ||
writeTimeout(15, TimeUnit.SECONDS) | ||
addInterceptor(httpLoggingInterceptor) | ||
addInterceptor(authInterceptor) | ||
authenticator(tokenAuthenticator) | ||
}.build() | ||
} | ||
*/ | ||
|
||
@REFRESH | ||
@Provides | ||
@Singleton | ||
fun provideRefreshOkHttpClient( | ||
@REFRESH refreshAuthInterceptor: Interceptor | ||
): OkHttpClient { | ||
return OkHttpClient.Builder().apply { | ||
connectTimeout(10, TimeUnit.SECONDS) | ||
readTimeout(30, TimeUnit.SECONDS) | ||
writeTimeout(15, TimeUnit.SECONDS) | ||
addInterceptor(httpLoggingInterceptor) | ||
addInterceptor(refreshAuthInterceptor) | ||
}.build() | ||
} | ||
|
||
@NOAUTH | ||
@Provides | ||
@Singleton | ||
fun provideNoAuthRetrofit(@NOAUTH okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
@AUTH | ||
@Provides | ||
@Singleton | ||
fun provideAuthRetrofit(@AUTH okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
@REFRESH | ||
@Provides | ||
@Singleton | ||
fun provideRefreshRetrofit(@REFRESH okHttpClient: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.client(okHttpClient) | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.build() | ||
} | ||
|
||
@NOAUTH | ||
@Provides | ||
@Singleton | ||
fun provideNoAuthApi(@NOAUTH retrofit: Retrofit): NoAuthApi { | ||
return retrofit.create(NoAuthApi::class.java) | ||
} | ||
|
||
@AUTH | ||
@Provides | ||
@Singleton | ||
fun provideAuthApi(@AUTH retrofit: Retrofit): AuthApi { | ||
return retrofit.create(AuthApi::class.java) | ||
} | ||
|
||
@REFRESH | ||
@Provides | ||
@Singleton | ||
fun provideRefreshApi(@REFRESH retrofit: Retrofit): AuthApi { | ||
return retrofit.create(AuthApi::class.java) | ||
} | ||
} |
19 changes: 16 additions & 3 deletions
19
app/src/main/java/com/jjbaksa/jjbaksa/di/RepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.jjbaksa.jjbaksa.di | ||
|
||
object UseCaseModule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.