-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f2cad1
commit 8fb5b4e
Showing
35 changed files
with
664 additions
and
42 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
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,11 @@ | ||
package com.hmh.hamyeonham.common.qualifier | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Secured | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Unsecured |
11 changes: 11 additions & 0 deletions
11
core/common/src/main/java/com/zucchini/qualifier/Interceptor.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,11 @@ | ||
package com.hmh.hamyeonham.common.qualifier | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Log | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Auth |
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,7 @@ | ||
package com.hmh.hamyeonham.common.qualifier | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Kakao |
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 @@ | ||
/build |
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,86 @@ | ||
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties | ||
import com.zucchini.buildsrc.Constants | ||
|
||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
kotlin("kapt") | ||
id("kotlin-parcelize") | ||
id("dagger.hilt.android.plugin") | ||
kotlin("plugin.serialization") version Versions.kotlinVersion | ||
|
||
} | ||
|
||
android { | ||
namespace = "com.zucchini.core.network" | ||
compileSdk = Constants.compileSdk | ||
|
||
defaultConfig { | ||
minSdk = Constants.minSdk | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = Versions.javaVersion | ||
targetCompatibility = Versions.javaVersion | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = true | ||
} | ||
buildTypes { | ||
debug { | ||
buildConfigField( | ||
"String", | ||
"BASE_URL", | ||
gradleLocalProperties(rootDir).getProperty("base.url"), | ||
) | ||
} | ||
release { | ||
buildConfigField( | ||
"String", | ||
"BASE_URL", | ||
gradleLocalProperties(rootDir).getProperty("base.url"), | ||
) | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro", | ||
) | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core:common")) | ||
|
||
KotlinDependencies.run { | ||
implementation(kotlin) | ||
implementation(coroutines) | ||
implementation(jsonSerialization) | ||
} | ||
|
||
ThirdPartyDependencies.run { | ||
implementation(platform(okHttpBom)) | ||
implementation(okHttp) | ||
implementation(okHttpLoggingInterceptor) | ||
implementation(retrofit) | ||
implementation(retrofitJsonConverter) | ||
implementation(timber) | ||
implementation(ossLicense) | ||
} | ||
|
||
AndroidXDependencies.run { | ||
implementation(hilt) | ||
implementation(workManager) | ||
implementation(hiltWorkManager) | ||
} | ||
|
||
KaptDependencies.run { | ||
kapt(hiltCompiler) | ||
kapt(hiltWorkManagerCompiler) | ||
kapt(hiltAndroidCompiler) | ||
|
||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
core/network/src/main/java/com/sample/network/di/DevelopersModule.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,19 @@ | ||
package com.sample.network.di | ||
|
||
import com.hmh.hamyeonham.common.qualifier.Unsecured | ||
import com.sample.network.service.DevelopersService | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import retrofit2.create | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DevelopersModule { | ||
@Provides | ||
@Singleton | ||
fun provideDevelopersApi(@Unsecured retrofit: Retrofit): DevelopersService = retrofit.create() | ||
} |
118 changes: 118 additions & 0 deletions
118
core/network/src/main/java/com/sample/network/di/NetModule.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,118 @@ | ||
package com.sample.network.di | ||
|
||
import com.hmh.hamyeonham.common.qualifier.Auth | ||
import com.hmh.hamyeonham.common.qualifier.Log | ||
import com.hmh.hamyeonham.common.qualifier.Secured | ||
import com.hmh.hamyeonham.common.qualifier.Unsecured | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import com.zucchini.core.network.BuildConfig | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.Authenticator | ||
import okhttp3.Interceptor | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Singleton | ||
|
||
private const val baseUrl = BuildConfig.BASE_URL | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object NetModule { | ||
@Provides | ||
@Singleton | ||
fun provideJson(): Json = Json { | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
fun provideJsonConverterFactory(json: Json): Converter.Factory { | ||
return json.asConverterFactory("application/json".toMediaType()) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
@Log | ||
fun provideLoggingInterceptor(): Interceptor = | ||
HttpLoggingInterceptor().setLevel( | ||
if (BuildConfig.DEBUG) { | ||
HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
HttpLoggingInterceptor.Level.NONE | ||
}, | ||
) | ||
|
||
// @Singleton | ||
// @Provides | ||
// @Auth | ||
// fun provideAuthInterceptor(interceptor: AuthInterceptor): Interceptor = interceptor | ||
|
||
@Singleton | ||
@Provides | ||
@Secured | ||
fun provideOkHttpClient( | ||
@Log logInterceptor: Interceptor, | ||
@Auth authInterceptor: Interceptor, | ||
authenticator: Authenticator, | ||
): OkHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(logInterceptor) | ||
.addInterceptor(authInterceptor) | ||
.authenticator(authenticator) | ||
.connectTimeout(60, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(15, TimeUnit.SECONDS) | ||
.build() | ||
|
||
@Singleton | ||
@Provides | ||
@Unsecured | ||
fun provideOkHttpClientNotNeededAuth( | ||
@Log logInterceptor: Interceptor, | ||
): OkHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(logInterceptor) | ||
.connectTimeout(60, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(15, TimeUnit.SECONDS) | ||
.build() | ||
|
||
@Singleton | ||
@Provides | ||
@Secured | ||
fun provideRetrofit( | ||
@Secured client: OkHttpClient, | ||
converterFactory: Converter.Factory, | ||
): Retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.client(client) | ||
.addConverterFactory(converterFactory) | ||
.build() | ||
|
||
@Singleton | ||
@Provides | ||
@Unsecured | ||
fun provideRetrofitNotNeededAuth( | ||
@Unsecured client: OkHttpClient, | ||
converterFactory: Converter.Factory, | ||
): Retrofit = Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.client(client) | ||
.addConverterFactory(converterFactory) | ||
.build() | ||
|
||
// @Module | ||
// @InstallIn(SingletonComponent::class) | ||
// interface Binder { | ||
// @Binds | ||
// @Singleton | ||
// fun provideAuthenticator(authenticator: Authenticator): Authenticator | ||
// } | ||
} |
19 changes: 19 additions & 0 deletions
19
core/network/src/main/java/com/sample/network/di/ProjectsModule.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,19 @@ | ||
package com.sample.network.di | ||
|
||
import com.hmh.hamyeonham.common.qualifier.Unsecured | ||
import com.sample.network.service.ProjectsService | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
import retrofit2.create | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ProjectsModule { | ||
@Provides | ||
@Singleton | ||
fun provideProjectsApi(@Unsecured retrofit: Retrofit): ProjectsService = retrofit.create() | ||
} |
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.