mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
refactor: enable http logging in debug builds
This commit is contained in:
parent
c1c4a0218d
commit
e04b07d4ff
@ -126,6 +126,7 @@ dependencies {
|
|||||||
|
|
||||||
/* Retrofit and Kotlinx Serialization */
|
/* Retrofit and Kotlinx Serialization */
|
||||||
implementation(libs.square.retrofit)
|
implementation(libs.square.retrofit)
|
||||||
|
implementation(libs.logging.interceptor)
|
||||||
implementation(libs.kotlinx.serialization)
|
implementation(libs.kotlinx.serialization)
|
||||||
implementation(libs.kotlinx.datetime)
|
implementation(libs.kotlinx.datetime)
|
||||||
implementation(libs.kotlinx.serialization.retrofit)
|
implementation(libs.kotlinx.serialization.retrofit)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.github.libretube.api
|
package com.github.libretube.api
|
||||||
|
|
||||||
|
import com.github.libretube.BuildConfig
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
import com.github.libretube.helpers.PreferenceHelper
|
||||||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.create
|
import retrofit2.create
|
||||||
|
|
||||||
@ -28,10 +31,13 @@ object RetrofitInstance {
|
|||||||
private val kotlinxConverterFactory = JsonHelper.json
|
private val kotlinxConverterFactory = JsonHelper.json
|
||||||
.asConverterFactory("application/json".toMediaType())
|
.asConverterFactory("application/json".toMediaType())
|
||||||
|
|
||||||
|
private val httpClient by lazy { buildClient() }
|
||||||
|
|
||||||
val api by resettableLazy(lazyMgr) {
|
val api by resettableLazy(lazyMgr) {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(apiUrl)
|
.baseUrl(apiUrl)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
|
.client(httpClient)
|
||||||
.addConverterFactory(kotlinxConverterFactory)
|
.addConverterFactory(kotlinxConverterFactory)
|
||||||
.build()
|
.build()
|
||||||
.create<PipedApi>()
|
.create<PipedApi>()
|
||||||
@ -41,6 +47,7 @@ object RetrofitInstance {
|
|||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(authUrl)
|
.baseUrl(authUrl)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
|
.client(httpClient)
|
||||||
.addConverterFactory(kotlinxConverterFactory)
|
.addConverterFactory(kotlinxConverterFactory)
|
||||||
.build()
|
.build()
|
||||||
.create<PipedApi>()
|
.create<PipedApi>()
|
||||||
@ -50,8 +57,23 @@ object RetrofitInstance {
|
|||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(apiUrl)
|
.baseUrl(apiUrl)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
|
.client(httpClient)
|
||||||
.addConverterFactory(kotlinxConverterFactory)
|
.addConverterFactory(kotlinxConverterFactory)
|
||||||
.build()
|
.build()
|
||||||
.create<ExternalApi>()
|
.create<ExternalApi>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildClient(): OkHttpClient {
|
||||||
|
val httpClient = OkHttpClient().newBuilder()
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
val loggingInterceptor = HttpLoggingInterceptor().apply {
|
||||||
|
level = HttpLoggingInterceptor.Level.BASIC
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.addInterceptor(loggingInterceptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
return httpClient.build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,18 @@ import coil.ImageLoader
|
|||||||
import coil.disk.DiskCache
|
import coil.disk.DiskCache
|
||||||
import coil.request.CachePolicy
|
import coil.request.CachePolicy
|
||||||
import coil.request.ImageRequest
|
import coil.request.ImageRequest
|
||||||
|
import com.github.libretube.BuildConfig
|
||||||
import com.github.libretube.api.CronetHelper
|
import com.github.libretube.api.CronetHelper
|
||||||
import com.github.libretube.constants.PreferenceKeys
|
import com.github.libretube.constants.PreferenceKeys
|
||||||
import com.github.libretube.extensions.toAndroidUri
|
import com.github.libretube.extensions.toAndroidUri
|
||||||
import com.github.libretube.extensions.toAndroidUriOrNull
|
import com.github.libretube.extensions.toAndroidUriOrNull
|
||||||
import com.github.libretube.util.DataSaverMode
|
import com.github.libretube.util.DataSaverMode
|
||||||
import java.io.File
|
|
||||||
import java.nio.file.Path
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Path
|
||||||
|
|
||||||
object ImageHelper {
|
object ImageHelper {
|
||||||
lateinit var imageLoader: ImageLoader
|
lateinit var imageLoader: ImageLoader
|
||||||
@ -32,9 +35,22 @@ object ImageHelper {
|
|||||||
fun initializeImageLoader(context: Context) {
|
fun initializeImageLoader(context: Context) {
|
||||||
val maxCacheSize = PreferenceHelper.getString(PreferenceKeys.MAX_IMAGE_CACHE, "128")
|
val maxCacheSize = PreferenceHelper.getString(PreferenceKeys.MAX_IMAGE_CACHE, "128")
|
||||||
|
|
||||||
|
val httpClient = OkHttpClient().newBuilder()
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
val loggingInterceptor = HttpLoggingInterceptor().apply {
|
||||||
|
level = HttpLoggingInterceptor.Level.BASIC
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient.addInterceptor(loggingInterceptor)
|
||||||
|
}
|
||||||
|
|
||||||
imageLoader = ImageLoader.Builder(context)
|
imageLoader = ImageLoader.Builder(context)
|
||||||
.callFactory(CronetHelper.callFactory)
|
.callFactory(CronetHelper.callFactory)
|
||||||
.crossfade(true)
|
.crossfade(true)
|
||||||
|
.okHttpClient {
|
||||||
|
httpClient.build()
|
||||||
|
}
|
||||||
.apply {
|
.apply {
|
||||||
if (maxCacheSize.isEmpty()) {
|
if (maxCacheSize.isEmpty()) {
|
||||||
diskCachePolicy(CachePolicy.DISABLED)
|
diskCachePolicy(CachePolicy.DISABLED)
|
||||||
|
@ -6,6 +6,7 @@ kotlin = "1.9.23"
|
|||||||
ksp = "1.9.23-1.0.19"
|
ksp = "1.9.23-1.0.19"
|
||||||
lifecycle = "2.7.0"
|
lifecycle = "2.7.0"
|
||||||
constraintlayout = "2.1.4"
|
constraintlayout = "2.1.4"
|
||||||
|
loggingInterceptor = "4.12.0"
|
||||||
material = "1.11.0"
|
material = "1.11.0"
|
||||||
navigation = "2.7.7"
|
navigation = "2.7.7"
|
||||||
preference = "1.2.1"
|
preference = "1.2.1"
|
||||||
@ -43,6 +44,7 @@ androidx-fragment = { group = "androidx.fragment", name = "fragment-ktx", versio
|
|||||||
gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
|
gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" }
|
||||||
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||||
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }
|
||||||
|
logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "loggingInterceptor" }
|
||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||||
androidx-navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigation" }
|
androidx-navigation-fragment = { group = "androidx.navigation", name = "navigation-fragment-ktx", version.ref = "navigation" }
|
||||||
androidx-navigation-ui = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigation" }
|
androidx-navigation-ui = { group = "androidx.navigation", name = "navigation-ui-ktx", version.ref = "navigation" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user