mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-17 19:35:36 -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(
|
LibraryAdapter(
|
||||||
LibraryDelegate.BookDelegate(bookUtils, ::onBookItemClick),
|
LibraryDelegate.BookDelegate(bookUtils, ::onBookItemClick),
|
||||||
LibraryDelegate.DownloadDelegate {
|
LibraryDelegate.DownloadDelegate {
|
||||||
dialogShower.show(
|
if (it.downloadState.toReadableState(requireActivity()).contains("Failed")) {
|
||||||
KiwixDialog.YesNoDialog.StopDownload,
|
if (isNotConnected) {
|
||||||
{ downloader.cancelDownload(it.downloadId) }
|
noInternetSnackbar()
|
||||||
)
|
} else {
|
||||||
|
downloader.retryDownload(it.downloadId)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dialogShower.show(
|
||||||
|
KiwixDialog.YesNoDialog.StopDownload,
|
||||||
|
{ downloader.cancelDownload(it.downloadId) }
|
||||||
|
)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
LibraryDelegate.DividerDelegate
|
LibraryDelegate.DividerDelegate
|
||||||
)
|
)
|
||||||
|
@ -99,6 +99,9 @@ sealed class LibraryViewHolder<in T : LibraryListItem>(containerView: View) :
|
|||||||
downloadProgress.progress = item.progress
|
downloadProgress.progress = item.progress
|
||||||
stop.setOnClickListener { clickAction.invoke(item) }
|
stop.setOnClickListener { clickAction.invoke(item) }
|
||||||
downloadState.text = item.downloadState.toReadableState(containerView.context)
|
downloadState.text = item.downloadState.toReadableState(containerView.context)
|
||||||
|
if (item.downloadState.toReadableState(containerView.context).contains("Failed")) {
|
||||||
|
clickAction.invoke(item)
|
||||||
|
}
|
||||||
eta.text = item.readableEta
|
eta.text = item.readableEta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,5 @@ import org.kiwix.kiwixmobile.core.downloader.model.DownloadRequest
|
|||||||
interface DownloadRequester {
|
interface DownloadRequester {
|
||||||
fun enqueue(downloadRequest: DownloadRequest): Long
|
fun enqueue(downloadRequest: DownloadRequest): Long
|
||||||
fun cancel(downloadId: Long)
|
fun cancel(downloadId: Long)
|
||||||
|
fun retryDownload(downloadId: Long)
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,5 @@ import org.kiwix.kiwixmobile.core.entity.LibraryNetworkEntity
|
|||||||
interface Downloader {
|
interface Downloader {
|
||||||
fun download(book: LibraryNetworkEntity.Book)
|
fun download(book: LibraryNetworkEntity.Book)
|
||||||
fun cancelDownload(downloadId: Long)
|
fun cancelDownload(downloadId: Long)
|
||||||
|
fun retryDownload(downloadId: Long)
|
||||||
}
|
}
|
||||||
|
@ -49,4 +49,8 @@ class DownloaderImpl @Inject constructor(
|
|||||||
override fun cancelDownload(downloadId: Long) {
|
override fun cancelDownload(downloadId: Long) {
|
||||||
downloadRequester.cancel(downloadId)
|
downloadRequester.cancel(downloadId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun retryDownload(downloadId: Long) {
|
||||||
|
downloadRequester.retryDownload(downloadId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,10 @@ class FetchDownloadRequester @Inject constructor(
|
|||||||
override fun cancel(downloadId: Long) {
|
override fun cancel(downloadId: Long) {
|
||||||
fetch.delete(downloadId.toInt())
|
fetch.delete(downloadId.toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun retryDownload(downloadId: Long) {
|
||||||
|
fetch.retry(downloadId.toInt())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DownloadRequest.toFetchRequest(sharedPreferenceUtil: SharedPreferenceUtil) =
|
private fun DownloadRequest.toFetchRequest(sharedPreferenceUtil: SharedPreferenceUtil) =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user