Use cronet call factory for api requests.

This commit is contained in:
Kavin 2022-07-21 19:06:15 +05:30
parent 9193c86e54
commit 1f78d4d2c5
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
3 changed files with 9 additions and 0 deletions

View File

@ -89,5 +89,6 @@ dependencies {
coreLibraryDesugaring libs.desugaring
implementation libs.cronet.embedded
implementation libs.cronet.okhttp
implementation libs.gson
}

View File

@ -1,5 +1,6 @@
package com.github.libretube.util
import com.google.net.cronet.okhttptransport.CronetCallFactory
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
@ -7,9 +8,13 @@ object RetrofitInstance {
lateinit var url: String
lateinit var authUrl: String
val lazyMgr = resettableManager()
private val callFactory: CronetCallFactory =
CronetCallFactory.newBuilder(CronetHelper.getCronetEngine())
.build()
val api: PipedApi by resettableLazy(lazyMgr) {
Retrofit.Builder()
.baseUrl(url)
.callFactory(callFactory)
.addConverterFactory(JacksonConverterFactory.create())
.build()
.create(PipedApi::class.java)
@ -17,6 +22,7 @@ object RetrofitInstance {
val authApi: PipedApi by resettableLazy(lazyMgr) {
Retrofit.Builder()
.baseUrl(authUrl)
.callFactory(callFactory)
.addConverterFactory(JacksonConverterFactory.create())
.build()
.create(PipedApi::class.java)

View File

@ -16,6 +16,7 @@ jacksonAnnotations = "2.13.3"
mobileffmpeg = "4.5.1.LTS"
desugaring = "1.1.5"
cronetEmbedded = "101.4951.41"
cronetOkHttp = "0.1.0"
leakcanary = "2.8.1"
gson = "2.9.0"
@ -41,5 +42,6 @@ mobileffmpeg = { group = "com.arthenica", name = "ffmpeg-kit-min", version.ref =
desugaring = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "desugaring" }
exoplayer-extension-cronet = { group = "com.google.android.exoplayer", name = "extension-cronet", version.ref = "exoplayer" }
cronet-embedded = { group = "org.chromium.net", name = "cronet-embedded", version.ref = "cronetEmbedded" }
cronet-okhttp = { group = "com.google.net.cronet", name = "cronet-okhttp", version.ref = "cronetOkHttp" }
square-leakcanary = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" }
gson = { group = "com.google.code.gson", name="gson", version.ref = "gson"}