Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#294] Add Chucker library #331

Merged
merged 2 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sample-compose/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.KOTLIN_VERSION}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.KOTLINX_COROUTINES_VERSION}")

debugImplementation("com.github.chuckerteam.chucker:library:${Versions.CHUCKER_VERSION}")
releaseImplementation("com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER_VERSION}")

kapt("com.google.dagger:hilt-compiler:${Versions.HILT_VERSION}")

// Testing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package co.nimblehq.sample.compose.di.modules

import android.content.Context
import co.nimblehq.sample.compose.BuildConfig
import com.chuckerteam.chucker.api.*
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
import java.util.concurrent.*

private const val READ_TIME_OUT = 30L

Expand All @@ -16,12 +19,31 @@ private const val READ_TIME_OUT = 30L
class OkHttpClientModule {

@Provides
fun provideOkHttpClient() = OkHttpClient.Builder().apply {
fun provideOkHttpClient(
chuckerInterceptor: ChuckerInterceptor
) = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
addInterceptor(chuckerInterceptor)
readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
}
}.build()

@Provides
fun provideChuckerInterceptor(
@ApplicationContext context: Context
): ChuckerInterceptor {
val chuckerCollector = ChuckerCollector(
context = context,
showNotification = true,
retentionPeriod = RetentionManager.Period.ONE_HOUR
)

return ChuckerInterceptor.Builder(context)
.collector(chuckerCollector)
.alwaysReadResponseBody(true)
.build()
}
}
1 change: 1 addition & 0 deletions sample-compose/buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object Versions {
const val ANDROIDX_NAVIGATION_VERSION = "2.3.4"
const val ANDROIDX_SUPPORT_VERSION = "1.3.0"

const val CHUCKER_VERSION = "3.5.2"
const val COMPOSE_VERSION = "1.0.2"

const val HILT_VERSION = "2.38.1"
Expand Down
3 changes: 3 additions & 0 deletions sample-xml/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ dependencies {

debugImplementation("androidx.fragment:fragment-testing:${Versions.ANDROIDX_FRAGMENT_VERSION}")

debugImplementation("com.github.chuckerteam.chucker:library:${Versions.CHUCKER_VERSION}")
releaseImplementation("com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER_VERSION}")

// Testing
testImplementation("io.kotest:kotest-assertions-core:${Versions.TEST_KOTEST_VERSION}")
testImplementation("junit:junit:${Versions.TEST_JUNIT_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package co.nimblehq.sample.xml.di.modules

import android.content.Context
import co.nimblehq.sample.xml.BuildConfig
import com.chuckerteam.chucker.api.*
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
import java.util.concurrent.*

private const val READ_TIME_OUT = 30L

Expand All @@ -16,12 +19,31 @@ private const val READ_TIME_OUT = 30L
class OkHttpClientModule {

@Provides
fun provideOkHttpClient() = OkHttpClient.Builder().apply {
fun provideOkHttpClient(
chuckerInterceptor: ChuckerInterceptor
) = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
addInterceptor(chuckerInterceptor)
readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
}
}.build()

@Provides
fun provideChuckerInterceptor(
@ApplicationContext context: Context
): ChuckerInterceptor {
val chuckerCollector = ChuckerCollector(
context = context,
showNotification = true,
retentionPeriod = RetentionManager.Period.ONE_HOUR
)

return ChuckerInterceptor.Builder(context)
.collector(chuckerCollector)
.alwaysReadResponseBody(true)
.build()
}
}
1 change: 1 addition & 0 deletions sample-xml/buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object Versions {
const val ANDROIDX_NAVIGATION_VERSION = "2.3.4"
const val ANDROIDX_SUPPORT_VERSION = "1.3.0"

const val CHUCKER_VERSION = "3.5.2"
const val CONSTRAINT_LAYOUT_VERSION = "2.0.0-alpha3"

const val HILT_VERSION = "2.38.1"
Expand Down
3 changes: 3 additions & 0 deletions template/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ dependencies {

debugImplementation("androidx.fragment:fragment-testing:${Versions.ANDROIDX_FRAGMENT_VERSION}")

debugImplementation("com.github.chuckerteam.chucker:library:${Versions.CHUCKER_VERSION}")
releaseImplementation("com.github.chuckerteam.chucker:library-no-op:${Versions.CHUCKER_VERSION}")

// Testing
testImplementation("io.kotest:kotest-assertions-core:${Versions.TEST_KOTEST_VERSION}")
testImplementation("junit:junit:${Versions.TEST_JUNIT_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package co.nimblehq.template.di.modules

import android.content.Context
import co.nimblehq.template.BuildConfig
import com.chuckerteam.chucker.api.*
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
import java.util.concurrent.*

private const val READ_TIME_OUT = 30L

Expand All @@ -16,12 +19,31 @@ private const val READ_TIME_OUT = 30L
class OkHttpClientModule {

@Provides
fun provideOkHttpClient() = OkHttpClient.Builder().apply {
fun provideOkHttpClient(
chuckerInterceptor: ChuckerInterceptor
) = OkHttpClient.Builder().apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
addInterceptor(chuckerInterceptor)
readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
}
}.build()

@Provides
fun provideChuckerInterceptor(
@ApplicationContext context: Context
): ChuckerInterceptor {
val chuckerCollector = ChuckerCollector(
context = context,
showNotification = true,
retentionPeriod = RetentionManager.Period.ONE_HOUR
)

return ChuckerInterceptor.Builder(context)
.collector(chuckerCollector)
.alwaysReadResponseBody(true)
.build()
}
}
1 change: 1 addition & 0 deletions template/buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object Versions {
const val ANDROIDX_NAVIGATION_VERSION = "2.3.4"
const val ANDROIDX_SUPPORT_VERSION = "1.3.0"

const val CHUCKER_VERSION = "3.5.2"
const val COMPOSE_VERSION = "1.0.2"
const val CONSTRAINT_LAYOUT_VERSION = "2.0.0-alpha3"

Expand Down