Fixed downloading progress is not showing after starting the download.

This commit is contained in:
MohitMaliFtechiz 2024-07-30 15:16:10 +05:30
parent 71db5fc7d1
commit 4fb53ed5df
5 changed files with 20 additions and 8 deletions

View File

@ -115,7 +115,9 @@ abstract class DownloadRoomDao {
book = book,
file = downloadRequest.getDestinationFile(sharedPreferenceUtil).path
)
)
).also {
downloadRequester.onDownloadAdded()
}
}
}

View File

@ -24,4 +24,5 @@ interface DownloadRequester {
fun cancel(downloadId: Long)
fun retryDownload(downloadId: Long)
fun pauseResumeDownload(downloadId: Long, isPause: Boolean)
fun onDownloadAdded()
}

View File

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

View File

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

View File

@ -52,6 +52,10 @@ class FetchDownloadRequester @Inject constructor(
else
fetch.pause(downloadId.toInt())
}
override fun onDownloadAdded() {
// empty function
}
}
private fun DownloadRequest.toFetchRequest(sharedPreferenceUtil: SharedPreferenceUtil) =