DownloadHelper: Fetch all downloads when doing operations
Depending upon flow isn't reliable as subscription change due to lifecycle Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -110,9 +110,7 @@ class DownloadHelper @Inject constructor(
|
|||||||
suspend fun cancelDownload(packageName: String) {
|
suspend fun cancelDownload(packageName: String) {
|
||||||
Log.i(TAG, "Cancelling download for $packageName")
|
Log.i(TAG, "Cancelling download for $packageName")
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
|
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
|
||||||
downloadsList.filter { it.isNotEmpty() }.firstOrNull()
|
downloadDao.updateStatus(packageName, DownloadStatus.CANCELLED)
|
||||||
?.find { it.packageName == packageName }
|
|
||||||
?.let { downloadDao.updateStatus(packageName, DownloadStatus.CANCELLED) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -141,7 +139,7 @@ class DownloadHelper @Inject constructor(
|
|||||||
* Clears finished downloads and their downloaded files
|
* Clears finished downloads and their downloaded files
|
||||||
*/
|
*/
|
||||||
suspend fun clearFinishedDownloads() {
|
suspend fun clearFinishedDownloads() {
|
||||||
downloadsList.value.filter { it.isFinished }.forEach {
|
downloadDao.downloads().firstOrNull()?.filter { it.isFinished }?.forEach {
|
||||||
clearDownload(it.packageName, it.versionCode)
|
clearDownload(it.packageName, it.versionCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,8 +150,10 @@ class DownloadHelper @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
suspend fun cancelAll(updatesOnly: Boolean = false) {
|
suspend fun cancelAll(updatesOnly: Boolean = false) {
|
||||||
// Cancel all enqueued downloads first to avoid triggering re-download
|
// Cancel all enqueued downloads first to avoid triggering re-download
|
||||||
downloadsList.value.filter { it.downloadStatus == DownloadStatus.QUEUED }
|
downloadDao.downloads().firstOrNull()
|
||||||
.filter { if (updatesOnly) it.isInstalled else true }.forEach {
|
?.filter { it.downloadStatus == DownloadStatus.QUEUED }
|
||||||
|
?.filter { if (updatesOnly) it.isInstalled else true }
|
||||||
|
?.forEach {
|
||||||
downloadDao.updateStatus(it.packageName, DownloadStatus.CANCELLED)
|
downloadDao.updateStatus(it.packageName, DownloadStatus.CANCELLED)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user