From 9d41b7e81922194c4a371cfa193c9f2074a9f284 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 13 Nov 2022 15:50:10 +0530 Subject: [PATCH] refactor(di): migrate OkHttp module to core --- core/build.gradle.kts | 5 +++++ .../msfjarvis/claw/core}/injection/OkHttpModule.kt | 8 ++++---- .../claw/core}/network/DelegatingSocketFactory.kt | 2 +- .../dev/msfjarvis/claw/core}/network/NapierLogger.kt | 2 +- .../claw/core}/network/UserAgentInterceptor.kt | 11 ++--------- 5 files changed, 13 insertions(+), 15 deletions(-) rename {android/src/main/kotlin/dev/msfjarvis/claw/android => core/src/main/kotlin/dev/msfjarvis/claw/core}/injection/OkHttpModule.kt (89%) rename {android/src/main/kotlin/dev/msfjarvis/claw/android => core/src/main/kotlin/dev/msfjarvis/claw/core}/network/DelegatingSocketFactory.kt (97%) rename {android/src/main/kotlin/dev/msfjarvis/claw/android => core/src/main/kotlin/dev/msfjarvis/claw/core}/network/NapierLogger.kt (92%) rename {android/src/main/kotlin/dev/msfjarvis/claw/android => core/src/main/kotlin/dev/msfjarvis/claw/core}/network/UserAgentInterceptor.kt (64%) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 55a62388..d04926e6 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -13,10 +13,15 @@ plugins { alias(libs.plugins.anvil) } +anvil { generateDaggerFactories.set(true) } + android { namespace = "dev.msfjarvis.claw.core" } dependencies { + api(libs.okhttp.loggingInterceptor) implementation(projects.diScopes) implementation(libs.dagger) implementation(libs.javax.inject) + implementation(libs.napier) + implementation(libs.okhttp.core) } diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/injection/OkHttpModule.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt similarity index 89% rename from android/src/main/kotlin/dev/msfjarvis/claw/android/injection/OkHttpModule.kt rename to core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt index 89a45d04..8de8351c 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/injection/OkHttpModule.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/injection/OkHttpModule.kt @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -package dev.msfjarvis.claw.android.injection +package dev.msfjarvis.claw.core.injection import android.content.Context import android.net.TrafficStats @@ -13,9 +13,9 @@ import dagger.Binds import dagger.Module import dagger.Provides import dagger.multibindings.IntoSet -import dev.msfjarvis.claw.android.network.DelegatingSocketFactory -import dev.msfjarvis.claw.android.network.NapierLogger -import dev.msfjarvis.claw.android.network.UserAgentInterceptor +import dev.msfjarvis.claw.core.network.DelegatingSocketFactory +import dev.msfjarvis.claw.core.network.NapierLogger +import dev.msfjarvis.claw.core.network.UserAgentInterceptor import dev.msfjarvis.claw.injection.scopes.AppScope import java.net.Socket import javax.net.SocketFactory diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/DelegatingSocketFactory.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/DelegatingSocketFactory.kt similarity index 97% rename from android/src/main/kotlin/dev/msfjarvis/claw/android/network/DelegatingSocketFactory.kt rename to core/src/main/kotlin/dev/msfjarvis/claw/core/network/DelegatingSocketFactory.kt index bb1b1865..5fa336f7 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/DelegatingSocketFactory.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/DelegatingSocketFactory.kt @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -package dev.msfjarvis.claw.android.network +package dev.msfjarvis.claw.core.network import java.net.InetAddress import java.net.Socket diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/NapierLogger.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/NapierLogger.kt similarity index 92% rename from android/src/main/kotlin/dev/msfjarvis/claw/android/network/NapierLogger.kt rename to core/src/main/kotlin/dev/msfjarvis/claw/core/network/NapierLogger.kt index 7aa71509..b965850a 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/NapierLogger.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/NapierLogger.kt @@ -4,7 +4,7 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -package dev.msfjarvis.claw.android.network +package dev.msfjarvis.claw.core.network import io.github.aakira.napier.Napier import javax.inject.Inject diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/UserAgentInterceptor.kt b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt similarity index 64% rename from android/src/main/kotlin/dev/msfjarvis/claw/android/network/UserAgentInterceptor.kt rename to core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt index 4ef3cdc1..3468561c 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/network/UserAgentInterceptor.kt +++ b/core/src/main/kotlin/dev/msfjarvis/claw/core/network/UserAgentInterceptor.kt @@ -4,9 +4,8 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT. */ -package dev.msfjarvis.claw.android.network +package dev.msfjarvis.claw.core.network -import dev.msfjarvis.claw.android.BuildConfig import javax.inject.Inject import okhttp3.Interceptor import okhttp3.Response @@ -14,12 +13,6 @@ import okhttp3.Response /** An OkHttp [Interceptor] that adds a recognizable User-Agent header to all network requests. */ class UserAgentInterceptor @Inject constructor() : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { - return chain.proceed( - chain - .request() - .newBuilder() - .header("User-Agent", "Claw-Android/${BuildConfig.VERSION_NAME}/msfjarvis") - .build() - ) + return chain.proceed(chain.request().newBuilder().header("User-Agent", "Claw-Android").build()) } }