make network module simplier and remove firebase perf plugin, because google sucks
This commit is contained in:
parent
7d9b44baa2
commit
c61e37c3b4
|
|
@ -1,10 +1,11 @@
|
|||
plugins {
|
||||
id(Plugins.ANDROID_APP_PLUGIN_WITH_DEFAULT_CONFIG)
|
||||
id(Plugins.FIREBASE_CRASH)
|
||||
id(Plugins.FIREBASE_PERF)
|
||||
id(Plugins.GOOGLE_SERVICES)
|
||||
}
|
||||
|
||||
val customEndpoint: String? = System.getenv("CUSTOM_ENDPOINT")?.takeIf(String::isNotBlank)
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
addConfig(SigningConfig.Test)
|
||||
|
|
@ -32,6 +33,13 @@ android {
|
|||
TestPanelFlavour.DIMENSION_NAME
|
||||
)
|
||||
|
||||
addFlavour(ApiFlavour.MockDev, customEndpoint)
|
||||
addFlavour(ApiFlavour.TouchinTest, customEndpoint)
|
||||
addFlavour(ApiFlavour.CustomerProd, customEndpoint)
|
||||
|
||||
addFlavour(SSLPinningFlavour.OFF)
|
||||
addFlavour(SSLPinningFlavour.ON)
|
||||
|
||||
productFlavors {
|
||||
create(ProguardFlavour.NO_OBFUSCATE) {
|
||||
dimension = ProguardFlavour.DIMENSION_NAME
|
||||
|
|
@ -49,13 +57,6 @@ android {
|
|||
))
|
||||
}
|
||||
|
||||
addEmptyFlavour(ApiFlavour.MockDev)
|
||||
addEmptyFlavour(ApiFlavour.TouchinTest)
|
||||
addEmptyFlavour(ApiFlavour.CustomerProd)
|
||||
|
||||
addEmptyFlavour(SSLPinningFlavour.OFF)
|
||||
addEmptyFlavour(SSLPinningFlavour.ON)
|
||||
|
||||
addEmptyFlavour(TestPanelFlavour.OFF)
|
||||
addEmptyFlavour(TestPanelFlavour.ON)
|
||||
}
|
||||
|
|
@ -89,6 +90,7 @@ dependencies {
|
|||
coreNetwork()
|
||||
leakCanary()
|
||||
sharedPrefs()
|
||||
chucker()
|
||||
implementation(Library.FIREBASE_ANAL)
|
||||
implementation(Library.FIREBASE_CRASH)
|
||||
implementation(Library.FIREBASE_PERF)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package ru.touchin.template
|
|||
import me.vponomarenko.injectionmanager.IHasComponent
|
||||
import me.vponomarenko.injectionmanager.x.XInjectionManager
|
||||
import ru.touchin.roboswag.navigation_base.TouchinApp
|
||||
import ru.touchin.template.core_prefs.PreferencesModule
|
||||
import ru.touchin.template.di.ApplicationComponent
|
||||
import ru.touchin.template.di.DaggerApplicationComponent
|
||||
|
||||
|
|
@ -20,8 +19,7 @@ class App : TouchinApp(), IHasComponent<ApplicationComponent> {
|
|||
}
|
||||
|
||||
override fun getComponent(): ApplicationComponent = DaggerApplicationComponent
|
||||
.builder()
|
||||
.preferencesModule(PreferencesModule(this))
|
||||
.build()
|
||||
.factory()
|
||||
.create(this)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package ru.touchin.template.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.BindsInstance
|
||||
import dagger.Component
|
||||
import ru.terrakok.cicerone.Router
|
||||
import ru.touchin.mvi_test.feature_login.LoginDeps
|
||||
|
|
@ -13,6 +14,7 @@ import javax.inject.Singleton
|
|||
|
||||
@Singleton
|
||||
@Component(modules = [
|
||||
ApplicationModule::class,
|
||||
PreferencesModule::class,
|
||||
MainNavigationModule::class,
|
||||
NetworkModule::class,
|
||||
|
|
@ -27,4 +29,9 @@ interface ApplicationComponent : LoginDeps {
|
|||
|
||||
fun inject(activity: SingleActivity)
|
||||
|
||||
@Component.Factory
|
||||
interface Factory {
|
||||
fun create(@BindsInstance context: Context): ApplicationComponent
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,28 @@
|
|||
package ru.touchin.template.di
|
||||
|
||||
import android.content.Context
|
||||
import com.chuckerteam.chucker.api.ChuckerInterceptor
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.Interceptor
|
||||
import ru.touchin.mvitest.network.di.ApiUrl
|
||||
import ru.touchin.mvitest.network.di.ChuckInterceptor
|
||||
import ru.touchin.mvitest.network.di.WithSslPinning
|
||||
import ru.touchin.template.BuildConfig
|
||||
|
||||
@Module
|
||||
class ApplicationModule {
|
||||
|
||||
@Provides
|
||||
@ApiUrl
|
||||
fun provideApiUrl() = BuildConfig.API_URL
|
||||
|
||||
@Provides
|
||||
@WithSslPinning
|
||||
fun providePluggerForSsl() = BuildConfig.WithSSLPinning
|
||||
|
||||
@Provides
|
||||
@ChuckInterceptor
|
||||
fun provideChucker(context: Context): Interceptor = ChuckerInterceptor(context)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ buildscript {
|
|||
classpath(kotlin("gradle-plugin", version = Version.KOTLIN))
|
||||
classpath("com.google.gms:google-services:${Version.GOOGLE_SERVICES_PLUGIN}")
|
||||
classpath("com.google.firebase:firebase-crashlytics-gradle:${Version.FIREBASE_CRASH_PLUGIN}")
|
||||
classpath("com.google.firebase:perf-plugin:${Version.FIREBASE_PERF_PLUGIN}")
|
||||
classpath("com.vanniktech:gradle-dependency-graph-generator-plugin:0.5.0")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ object Plugins {
|
|||
|
||||
const val GOOGLE_SERVICES = "com.google.gms.google-services"
|
||||
const val FIREBASE_CRASH = "com.google.firebase.crashlytics"
|
||||
const val FIREBASE_PERF = "com.google.firebase.firebase-perf"
|
||||
|
||||
const val DEPENDENCY_GRAPH = "com.vanniktech.dependency.graph.generator"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import com.android.build.gradle.LibraryExtension
|
||||
import com.android.build.gradle.BaseExtension
|
||||
|
||||
sealed class ApiFlavour(
|
||||
val name: String,
|
||||
|
|
@ -26,7 +26,7 @@ sealed class ApiFlavour(
|
|||
|
||||
}
|
||||
|
||||
fun LibraryExtension.addFlavour(flavour: ApiFlavour, customEndpoint: String?) {
|
||||
fun BaseExtension.addFlavour(flavour: ApiFlavour, customEndpoint: String?) {
|
||||
productFlavors {
|
||||
create(flavour.name) {
|
||||
dimension = flavour.dimensionName
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import org.gradle.api.NamedDomainObjectContainer
|
||||
|
||||
fun NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.BuildType>.addBuildType(type: BuildType) {
|
||||
fun NamedDomainObjectContainer<com.android.build.gradle.internal.dsl.BuildType>.addBuildType(
|
||||
type: BuildType
|
||||
) {
|
||||
getByName(type.name) {
|
||||
isMinifyEnabled = type.isMinifyEnabled
|
||||
isShrinkResources = type.isShrinkResources
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import com.android.build.gradle.LibraryExtension
|
||||
import com.android.build.gradle.BaseExtension
|
||||
|
||||
sealed class SSLPinningFlavour(
|
||||
val name: String,
|
||||
|
|
@ -9,18 +9,18 @@ sealed class SSLPinningFlavour(
|
|||
const val DIMENSION_NAME = "sslPinning"
|
||||
}
|
||||
|
||||
object OFF: SSLPinningFlavour(
|
||||
object OFF : SSLPinningFlavour(
|
||||
name = "withoutSSLPinning",
|
||||
withSslPinning = true
|
||||
)
|
||||
|
||||
object ON: SSLPinningFlavour(
|
||||
object ON : SSLPinningFlavour(
|
||||
name = "withSSLPinning",
|
||||
withSslPinning = true
|
||||
)
|
||||
}
|
||||
|
||||
fun LibraryExtension.addFlavour(flavour: SSLPinningFlavour) {
|
||||
fun BaseExtension.addFlavour(flavour: SSLPinningFlavour) {
|
||||
productFlavors {
|
||||
create(flavour.name) {
|
||||
dimension = flavour.dimensionName
|
||||
|
|
|
|||
|
|
@ -2,31 +2,12 @@ plugins {
|
|||
id(Plugins.ANDROID_LIB_PLUGIN_WITH_DEFAULT_CONFIG)
|
||||
}
|
||||
|
||||
val customEndpoint: String? = System.getenv("CUSTOM_ENDPOINT")?.takeIf(String::isNotBlank)
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
rootProject.extensions.add("pathToApiSchemes", "$rootDir/common/api")
|
||||
rootProject.extensions.add("applicationId", AndroidConfig.TEST_APP_ID)
|
||||
}
|
||||
|
||||
flavorDimensions(
|
||||
ApiFlavour.DIMENSION_NAME,
|
||||
SSLPinningFlavour.DIMENSION_NAME,
|
||||
TestPanelFlavour.DIMENSION_NAME
|
||||
)
|
||||
|
||||
addFlavour(ApiFlavour.MockDev, customEndpoint)
|
||||
addFlavour(ApiFlavour.TouchinTest, customEndpoint)
|
||||
addFlavour(ApiFlavour.CustomerProd, customEndpoint)
|
||||
|
||||
addFlavour(SSLPinningFlavour.OFF)
|
||||
addFlavour(SSLPinningFlavour.ON)
|
||||
|
||||
productFlavors {
|
||||
addEmptyFlavour(TestPanelFlavour.OFF)
|
||||
addEmptyFlavour(TestPanelFlavour.ON)
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
|
@ -34,7 +15,6 @@ dependencies {
|
|||
dagger()
|
||||
moshi()
|
||||
coroutines()
|
||||
chucker()
|
||||
}
|
||||
|
||||
//afterEvaluate {
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ package ru.touchin.mvitest.network.di
|
|||
import javax.inject.Qualifier
|
||||
|
||||
@Qualifier
|
||||
annotation class DefaultPageSize
|
||||
annotation class ApiUrl
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package ru.touchin.mvitest.network.di
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
@Qualifier
|
||||
annotation class ChuckInterceptor
|
||||
|
|
@ -3,6 +3,8 @@ package ru.touchin.mvitest.network.di
|
|||
import com.squareup.moshi.Moshi
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import okhttp3.CertificatePinner
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
|
|
@ -21,8 +23,12 @@ class NetworkModule {
|
|||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun providePublicClient(exceptionsInterceptor: ExceptionsInterceptor): OkHttpClient =
|
||||
buildPublicClient(exceptionsInterceptor)
|
||||
fun providePublicClient(
|
||||
exceptionsInterceptor: ExceptionsInterceptor,
|
||||
@ChuckInterceptor chuckerInterceptor: Interceptor,
|
||||
@WithSslPinning withSslPinning: Boolean
|
||||
): OkHttpClient =
|
||||
buildPublicClient(exceptionsInterceptor, chuckerInterceptor, withSslPinning)
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
|
|
@ -30,26 +36,34 @@ class NetworkModule {
|
|||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun provideRetrofit(client: OkHttpClient, moshi: Moshi) = buildRetrofitInstance(client, moshi)
|
||||
fun provideRetrofit(client: OkHttpClient, moshi: Moshi, @ApiUrl apiUrl: String) = buildRetrofitInstance(client, moshi, apiUrl)
|
||||
|
||||
private fun buildMoshi() = Moshi.Builder()
|
||||
.build()
|
||||
|
||||
private fun buildRetrofitInstance(client: OkHttpClient, moshi: Moshi): Retrofit = Retrofit.Builder()
|
||||
.baseUrl(BuildConfig.API_URL)
|
||||
private fun buildRetrofitInstance(client: OkHttpClient, moshi: Moshi, apiUrl: String): Retrofit = Retrofit.Builder()
|
||||
.baseUrl(apiUrl)
|
||||
.client(client)
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.build()
|
||||
|
||||
private fun buildPublicClient(exceptionsInterceptor: ExceptionsInterceptor): OkHttpClient = OkHttpClient.Builder()
|
||||
private fun buildPublicClient(
|
||||
exceptionsInterceptor: ExceptionsInterceptor,
|
||||
chuckerInterceptor: Interceptor,
|
||||
withSslPinning: Boolean
|
||||
): OkHttpClient = OkHttpClient.Builder()
|
||||
.apply {
|
||||
connectTimeout(TIMEOUT, TimeUnit.SECONDS)
|
||||
readTimeout(TIMEOUT, TimeUnit.SECONDS)
|
||||
writeTimeout(TIMEOUT, TimeUnit.SECONDS)
|
||||
addInterceptor(exceptionsInterceptor)
|
||||
addInterceptor(chuckerInterceptor)
|
||||
if (BuildConfig.DEBUG) {
|
||||
addNetworkInterceptor(HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY })
|
||||
}
|
||||
if (withSslPinning) {
|
||||
certificatePinner(CertificatePinner.DEFAULT)
|
||||
}
|
||||
}.build()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package ru.touchin.mvitest.network.di
|
||||
|
||||
import javax.inject.Qualifier
|
||||
|
||||
@Qualifier
|
||||
annotation class WithSslPinning
|
||||
|
|
@ -10,7 +10,7 @@ import ru.touchin.roboswag.core.observables.storable.NonNullStorable
|
|||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class PreferencesModule(private val context: Context) {
|
||||
class PreferencesModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
|
|
|||
Loading…
Reference in New Issue