mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 19:05:27 -04:00
Retry strategy if download failed due to network fluctuation
This commit is contained in:
parent
0472b2c5ff
commit
90cb76839c
@ -106,10 +106,18 @@ class OnlineLibraryFragment : BaseFragment(), FragmentActivityExtensions {
|
||||
LibraryAdapter(
|
||||
LibraryDelegate.BookDelegate(bookUtils, ::onBookItemClick),
|
||||
LibraryDelegate.DownloadDelegate {
|
||||
dialogShower.show(
|
||||
KiwixDialog.YesNoDialog.StopDownload,
|
||||
{ downloader.cancelDownload(it.downloadId) }
|
||||
)
|
||||
if (it.downloadState.toReadableState(requireActivity()).contains("Failed")) {
|
||||
if (isNotConnected) {
|
||||
noInternetSnackbar()
|
||||
} else {
|
||||
downloader.retryDownload(it.downloadId)
|
||||
}
|
||||
} else {
|
||||
dialogShower.show(
|
||||
KiwixDialog.YesNoDialog.StopDownload,
|
||||
{ downloader.cancelDownload(it.downloadId) }
|
||||
)
|
||||
}
|
||||
},
|
||||
LibraryDelegate.DividerDelegate
|
||||
)
|
||||
|
@ -99,6 +99,9 @@ sealed class LibraryViewHolder<in T : LibraryListItem>(containerView: View) :
|
||||
downloadProgress.progress = item.progress
|
||||
stop.setOnClickListener { clickAction.invoke(item) }
|
||||
downloadState.text = item.downloadState.toReadableState(containerView.context)
|
||||
if (item.downloadState.toReadableState(containerView.context).contains("Failed")) {
|
||||
clickAction.invoke(item)
|
||||
}
|
||||
eta.text = item.readableEta
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,5 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadRequest
|
||||
interface DownloadRequester {
|
||||
fun enqueue(downloadRequest: DownloadRequest): Long
|
||||
fun cancel(downloadId: Long)
|
||||
fun retryDownload(downloadId: Long)
|
||||
}
|
||||
|
@ -22,4 +22,5 @@ import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
||||
interface Downloader {
|
||||
fun download(book: LibraryNetworkEntity.Book)
|
||||
fun cancelDownload(downloadId: Long)
|
||||
fun retryDownload(downloadId: Long)
|
||||
}
|
||||
|
@ -49,4 +49,8 @@ class DownloaderImpl @Inject constructor(
|
||||
override fun cancelDownload(downloadId: Long) {
|
||||
downloadRequester.cancel(downloadId)
|
||||
}
|
||||
|
||||
override fun retryDownload(downloadId: Long) {
|
||||
downloadRequester.retryDownload(downloadId)
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,10 @@ class FetchDownloadRequester @Inject constructor(
|
||||
override fun cancel(downloadId: Long) {
|
||||
fetch.delete(downloadId.toInt())
|
||||
}
|
||||
|
||||
override fun retryDownload(downloadId: Long) {
|
||||
fetch.retry(downloadId.toInt())
|
||||
}
|
||||
}
|
||||
|
||||
private fun DownloadRequest.toFetchRequest(sharedPreferenceUtil: SharedPreferenceUtil) =
|
||||
|
Loading…
x
Reference in New Issue
Block a user