mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 14:52:13 -04:00
Fixed downloading progress is not showing after starting the download.
This commit is contained in:
parent
71db5fc7d1
commit
4fb53ed5df
@ -115,7 +115,9 @@ abstract class DownloadRoomDao {
|
||||
book = book,
|
||||
file = downloadRequest.getDestinationFile(sharedPreferenceUtil).path
|
||||
)
|
||||
)
|
||||
).also {
|
||||
downloadRequester.onDownloadAdded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,4 +24,5 @@ interface DownloadRequester {
|
||||
fun cancel(downloadId: Long)
|
||||
fun retryDownload(downloadId: Long)
|
||||
fun pauseResumeDownload(downloadId: Long, isPause: Boolean)
|
||||
fun onDownloadAdded()
|
||||
}
|
||||
|
@ -84,13 +84,17 @@ class DownloadManagerMonitor @Inject constructor(
|
||||
fun startMonitoringDownloads() {
|
||||
// Check if monitoring is already active. If it is, do nothing.
|
||||
if (monitoringDisposable?.isDisposed == false) return
|
||||
monitoringDisposable = Observable.interval(0, 5, TimeUnit.SECONDS)
|
||||
monitoringDisposable = Observable.interval(ZERO.toLong(), 5, TimeUnit.SECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(
|
||||
{
|
||||
try {
|
||||
synchronized(lock) {
|
||||
Log.e(
|
||||
"DOWNLOAD_MONITOR",
|
||||
"startMonitoringDownloads: ${downloadRoomDao.downloads().blockingFirst()}"
|
||||
)
|
||||
if (downloadRoomDao.downloads().blockingFirst().isNotEmpty()) {
|
||||
checkDownloads()
|
||||
} else {
|
||||
@ -425,7 +429,7 @@ class DownloadManagerMonitor @Inject constructor(
|
||||
downloadId: Long,
|
||||
control: Int
|
||||
): Boolean {
|
||||
Log.e("PAUSED", "pauseResumeDownloadInDownloadManagerContentResolver: $control")
|
||||
Log.e("DOWNLOAD_MONITOR", "pauseResumeDownloadInDownloadManagerContentResolver: $control")
|
||||
return try {
|
||||
// Update the status to paused/resumed in the database
|
||||
val contentValues = ContentValues().apply {
|
||||
|
@ -38,10 +38,11 @@ class DownloadManagerRequester @Inject constructor(
|
||||
) : DownloadRequester {
|
||||
override fun enqueue(downloadRequest: DownloadRequest): Long =
|
||||
downloadManager.enqueue(downloadRequest.toDownloadManagerRequest(sharedPreferenceUtil))
|
||||
.also {
|
||||
// Start monitoring downloads after enqueuing a new download request.
|
||||
downloadManagerMonitor.startMonitoringDownloads()
|
||||
}
|
||||
|
||||
override fun onDownloadAdded() {
|
||||
// Start monitoring downloads after enqueuing a new download request.
|
||||
downloadManagerMonitor.startMonitoringDownloads()
|
||||
}
|
||||
|
||||
override fun cancel(downloadId: Long) {
|
||||
downloadManagerMonitor.cancelDownload(downloadId)
|
||||
@ -65,7 +66,7 @@ class DownloadManagerRequester @Inject constructor(
|
||||
}
|
||||
}.also {
|
||||
// Start monitoring downloads after retrying.
|
||||
downloadManagerMonitor.startMonitoringDownloads()
|
||||
onDownloadAdded()
|
||||
}
|
||||
} catch (ignore: Exception) {
|
||||
Log.e(
|
||||
|
@ -52,6 +52,10 @@ class FetchDownloadRequester @Inject constructor(
|
||||
else
|
||||
fetch.pause(downloadId.toInt())
|
||||
}
|
||||
|
||||
override fun onDownloadAdded() {
|
||||
// empty function
|
||||
}
|
||||
}
|
||||
|
||||
private fun DownloadRequest.toFetchRequest(sharedPreferenceUtil: SharedPreferenceUtil) =
|
||||
|
Loading…
x
Reference in New Issue
Block a user