Added OkHttpDownloader in Fetch.

This commit is contained in:
MohitMaliFtechiz 2024-12-19 21:49:50 +05:30
parent 89d7b87925
commit 2ddc395267
2 changed files with 20 additions and 14 deletions

View File

@ -228,7 +228,7 @@ class AllProjectConfigurer {
kapt(Libs.roomCompiler)
implementation(Libs.tracing)
implementation(Libs.fetch)
// implementation(Libs.fetchOkhttp)
implementation(Libs.fetchOkhttp)
}
}
}

View File

@ -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