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