diff --git a/app/src/main/java/com/github/libretube/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/activities/MainActivity.kt index 0e1b48444..c295ad3a2 100644 --- a/app/src/main/java/com/github/libretube/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/activities/MainActivity.kt @@ -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)!! diff --git a/app/src/main/java/com/github/libretube/util/ConnectionHelper.kt b/app/src/main/java/com/github/libretube/util/ConnectionHelper.kt index f6aa0875b..6f1e93bb3 100644 --- a/app/src/main/java/com/github/libretube/util/ConnectionHelper.kt +++ b/app/src/main/java/com/github/libretube/util/ConnectionHelper.kt @@ -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) } } } diff --git a/app/src/main/java/com/github/libretube/util/CronetHelper.kt b/app/src/main/java/com/github/libretube/util/CronetHelper.kt index 61bb62e75..cc50a9fa9 100644 --- a/app/src/main/java/com/github/libretube/util/CronetHelper.kt +++ b/app/src/main/java/com/github/libretube/util/CronetHelper.kt @@ -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 { diff --git a/app/src/main/java/com/github/libretube/util/RetrofitInstance.kt b/app/src/main/java/com/github/libretube/util/RetrofitInstance.kt index 5e26f0f43..c8a9eaeb7 100644 --- a/app/src/main/java/com/github/libretube/util/RetrofitInstance.kt +++ b/app/src/main/java/com/github/libretube/util/RetrofitInstance.kt @@ -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)