From 2ddc3952674f137783751d57d845ed6e3fa8a6c1 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 19 Dec 2024 21:49:50 +0530 Subject: [PATCH] Added OkHttpDownloader in Fetch. --- .../kotlin/plugin/AllProjectConfigurer.kt | 2 +- .../core/di/modules/DownloaderModule.kt | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt index af3f44a66..570800a3d 100644 --- a/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt +++ b/buildSrc/src/main/kotlin/plugin/AllProjectConfigurer.kt @@ -228,7 +228,7 @@ class AllProjectConfigurer { kapt(Libs.roomCompiler) implementation(Libs.tracing) implementation(Libs.fetch) - // implementation(Libs.fetchOkhttp) + implementation(Libs.fetchOkhttp) } } } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt index c11528aaa..e81c75ba0 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/di/modules/DownloaderModule.kt @@ -21,17 +21,23 @@ import android.content.Context import com.tonyodev.fetch2.Fetch import com.tonyodev.fetch2.FetchConfiguration import com.tonyodev.fetch2.FetchNotificationManager +import com.tonyodev.fetch2okhttp.OkHttpDownloader import dagger.Module import dagger.Provides +import okhttp3.OkHttpClient import org.kiwix.kiwixmobile.core.BuildConfig import org.kiwix.kiwixmobile.core.dao.DownloadRoomDao +import org.kiwix.kiwixmobile.core.data.remote.BasicAuthInterceptor import org.kiwix.kiwixmobile.core.data.remote.KiwixService import org.kiwix.kiwixmobile.core.downloader.DownloadRequester import org.kiwix.kiwixmobile.core.downloader.Downloader import org.kiwix.kiwixmobile.core.downloader.DownloaderImpl import org.kiwix.kiwixmobile.core.downloader.downloadManager.DownloadManagerRequester import org.kiwix.kiwixmobile.core.downloader.downloadManager.FetchDownloadNotificationManager +import org.kiwix.kiwixmobile.core.utils.CONNECT_TIME_OUT +import org.kiwix.kiwixmobile.core.utils.READ_TIME_OUT import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil +import java.util.concurrent.TimeUnit import javax.inject.Singleton @Module @@ -61,29 +67,29 @@ object DownloaderModule { @Singleton fun provideFetchConfiguration( context: Context, - // okHttpDownloader: OkHttpDownloader, + okHttpDownloader: OkHttpDownloader, fetchNotificationManager: FetchNotificationManager ): FetchConfiguration = FetchConfiguration.Builder(context).apply { setDownloadConcurrentLimit(5) enableLogging(BuildConfig.DEBUG) enableRetryOnNetworkGain(true) - // setHttpDownloader(okHttpDownloader) + setHttpDownloader(okHttpDownloader) preAllocateFileOnCreation(false) setNotificationManager(fetchNotificationManager) }.build().also(Fetch.Impl::setDefaultInstanceConfiguration) - // @Provides - // @Singleton - // fun provideOkHttpDownloader() = OkHttpDownloader( - // OkHttpClient.Builder() - // .connectTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES) - // .readTimeout(READ_TIME_OUT, TimeUnit.MINUTES) - // .addInterceptor(BasicAuthInterceptor()) - // .followRedirects(true) - // .followSslRedirects(true) - // .build() - // ) + @Provides + @Singleton + fun provideOkHttpDownloader() = OkHttpDownloader( + OkHttpClient.Builder() + .connectTimeout(CONNECT_TIME_OUT, TimeUnit.MINUTES) + .readTimeout(READ_TIME_OUT, TimeUnit.MINUTES) + .addInterceptor(BasicAuthInterceptor()) + .followRedirects(true) + .followSslRedirects(true) + .build() + ) @Provides @Singleton