mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Use cronet with coil.
This commit is contained in:
parent
56b7a8e5cc
commit
f0ab7888fb
@ -25,6 +25,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import coil.ImageLoader
|
||||
import com.github.libretube.Globals
|
||||
import com.github.libretube.PIPED_API_URL
|
||||
import com.github.libretube.R
|
||||
@ -69,6 +70,9 @@ class MainActivity : AppCompatActivity() {
|
||||
startService(Intent(this, ClosingService::class.java))
|
||||
|
||||
CronetHelper.initCronet(this.applicationContext)
|
||||
ConnectionHelper.imageLoader = ImageLoader.Builder(this.applicationContext)
|
||||
.callFactory(CronetHelper.callFactory)
|
||||
.build()
|
||||
|
||||
RetrofitInstance.url =
|
||||
PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, PIPED_API_URL)!!
|
||||
|
@ -3,6 +3,7 @@ package com.github.libretube.util
|
||||
import android.content.Context
|
||||
import android.net.ConnectivityManager
|
||||
import android.widget.ImageView
|
||||
import coil.ImageLoader
|
||||
import coil.load
|
||||
import com.github.libretube.Globals
|
||||
|
||||
@ -37,11 +38,13 @@ object ConnectionHelper {
|
||||
return connectivityManager.activeNetworkInfo?.isConnected ?: false
|
||||
}
|
||||
|
||||
lateinit var imageLoader: ImageLoader
|
||||
|
||||
// load an image from a url into an imageView
|
||||
fun loadImage(url: String?, target: ImageView) {
|
||||
// only load the image if the data saver mode is disabled
|
||||
if (!Globals.DATA_SAVER_MODE_ENABLED) {
|
||||
target.load(url)
|
||||
target.load(url, imageLoader)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,20 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import android.content.Context
|
||||
import com.google.net.cronet.okhttptransport.CronetCallFactory
|
||||
import org.chromium.net.CronetEngine
|
||||
|
||||
class CronetHelper {
|
||||
companion object {
|
||||
private lateinit var engine: CronetEngine
|
||||
lateinit var callFactory: CronetCallFactory
|
||||
|
||||
fun initCronet(context: Context) {
|
||||
this.engine = CronetEngine.Builder(context)
|
||||
.enableBrotli(true)
|
||||
.build()
|
||||
callFactory = CronetCallFactory.newBuilder(this.engine)
|
||||
.build()
|
||||
}
|
||||
|
||||
fun getCronetEngine(): CronetEngine {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.libretube.util
|
||||
|
||||
import com.google.net.cronet.okhttptransport.CronetCallFactory
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.jackson.JacksonConverterFactory
|
||||
|
||||
@ -8,13 +7,10 @@ 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)
|
||||
.callFactory(CronetHelper.callFactory)
|
||||
.addConverterFactory(JacksonConverterFactory.create())
|
||||
.build()
|
||||
.create(PipedApi::class.java)
|
||||
@ -22,7 +18,7 @@ object RetrofitInstance {
|
||||
val authApi: PipedApi by resettableLazy(lazyMgr) {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(authUrl)
|
||||
.callFactory(callFactory)
|
||||
.callFactory(CronetHelper.callFactory)
|
||||
.addConverterFactory(JacksonConverterFactory.create())
|
||||
.build()
|
||||
.create(PipedApi::class.java)
|
||||
|
Loading…
Reference in New Issue
Block a user