Browse Source

[BuildMeta] introduce BuildType and remove Network related code from BuildMeta

test/jme/compound-poc
ganfra 1 year ago
parent
commit
df29b1dd8e
  1. 14
      app/src/main/kotlin/io/element/android/x/di/AppModule.kt
  2. 3
      libraries/core/build.gradle.kts
  3. 6
      libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt
  4. 23
      libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildType.kt
  5. 13
      libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt

14
app/src/main/kotlin/io/element/android/x/di/AppModule.kt

@ -25,6 +25,7 @@ import dagger.Module @@ -25,6 +25,7 @@ import dagger.Module
import dagger.Provides
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.core.meta.BuildType
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.ApplicationContext
@ -38,7 +39,6 @@ import kotlinx.coroutines.Dispatchers @@ -38,7 +39,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.plus
import okhttp3.logging.HttpLoggingInterceptor
import java.io.File
import java.util.concurrent.Executors
@ -64,8 +64,15 @@ object AppModule { @@ -64,8 +64,15 @@ object AppModule {
@Provides
@SingleIn(AppScope::class)
fun providesBuildMeta(@ApplicationContext context: Context) = BuildMeta(
isDebug = BuildConfig.DEBUG,
fun providesBuildType(): BuildType {
return BuildType.valueOf(BuildConfig.BUILD_TYPE.uppercase())
}
@Provides
@SingleIn(AppScope::class)
fun providesBuildMeta(@ApplicationContext context: Context, buildType: BuildType) = BuildMeta(
isDebuggable = BuildConfig.DEBUG,
buildType = buildType,
applicationName = context.getString(R.string.app_name),
applicationId = BuildConfig.APPLICATION_ID,
lowPrivacyLoggingEnabled = false, // TODO EAx Config.LOW_PRIVACY_LOG_ENABLE,
@ -75,7 +82,6 @@ object AppModule { @@ -75,7 +82,6 @@ object AppModule {
gitBranchName = "TODO", // BuildConfig.GIT_BRANCH_NAME,
flavorDescription = "TODO", // BuildConfig.FLAVOR_DESCRIPTION,
flavorShortDescription = "TODO", // BuildConfig.SHORT_FLAVOR_DESCRIPTION,
okHttpLoggingLevel = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.BASIC,
)
@Provides

3
libraries/core/build.gradle.kts

@ -29,9 +29,6 @@ java { @@ -29,9 +29,6 @@ java {
dependencies {
implementation(libs.coroutines.core)
implementation(platform(libs.network.okhttp.bom))
implementation("com.squareup.okhttp3:logging-interceptor")
testImplementation(libs.test.junit)
testImplementation(libs.test.truth)
}

6
libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt

@ -16,10 +16,9 @@ @@ -16,10 +16,9 @@
package io.element.android.libraries.core.meta
import okhttp3.logging.HttpLoggingInterceptor
data class BuildMeta(
val isDebug: Boolean,
val buildType: BuildType,
val isDebuggable: Boolean,
val applicationName: String,
val applicationId: String,
val lowPrivacyLoggingEnabled: Boolean,
@ -29,5 +28,4 @@ data class BuildMeta( @@ -29,5 +28,4 @@ data class BuildMeta(
val gitBranchName: String,
val flavorDescription: String,
val flavorShortDescription: String,
val okHttpLoggingLevel: HttpLoggingInterceptor.Level,
)

23
libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildType.kt

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.core.meta
enum class BuildType {
RELEASE,
NIGHTLY,
DEBUG
}

13
libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt

@ -22,11 +22,11 @@ import dagger.Provides @@ -22,11 +22,11 @@ import dagger.Provides
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.di.AppScope
import io.element.android.libraries.di.SingleIn
import io.element.android.libraries.network.interceptors.FormattedJsonHttpLogger
import okhttp3.OkHttpClient
import okhttp3.Protocol
import io.element.android.libraries.network.interceptors.FormattedJsonHttpLogger
import java.util.concurrent.TimeUnit
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
@Module
@ContributesTo(AppScope::class)
@ -35,9 +35,14 @@ object NetworkModule { @@ -35,9 +35,14 @@ object NetworkModule {
@Provides
@JvmStatic
fun providesHttpLoggingInterceptor(buildMeta: BuildMeta): HttpLoggingInterceptor {
val logger = FormattedJsonHttpLogger(buildMeta.okHttpLoggingLevel)
val loggingLevel = if (buildMeta.isDebuggable) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.BASIC
}
val logger = FormattedJsonHttpLogger(loggingLevel)
val interceptor = HttpLoggingInterceptor(logger)
interceptor.level = buildMeta.okHttpLoggingLevel
interceptor.level = loggingLevel
return interceptor
}

Loading…
Cancel
Save