DownloadWorker: Only update appropriate status field on status change

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-02-17 15:04:37 +05:30
parent b35f6e0f1d
commit 3c25626a75
2 changed files with 5 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.aurora.store.data.model.DownloadStatus
import kotlinx.coroutines.flow.Flow
@Dao
@@ -16,6 +17,9 @@ interface DownloadDao {
@Update
suspend fun update(download: Download)
@Query("UPDATE download SET downloadStatus=:downloadStatus WHERE packageName=:packageName")
suspend fun updateStatus(packageName: String, downloadStatus: DownloadStatus)
@Query("SELECT * FROM download")
fun downloads(): Flow<List<Download>>

View File

@@ -307,11 +307,7 @@ class DownloadWorker @AssistedInject constructor(
private suspend fun notifyStatus(status: DownloadStatus, dID: Int = -1) {
// Update database for all status except downloading which is handled onProgress
if (status != DownloadStatus.DOWNLOADING) {
download.apply {
this.downloadStatus = status
if (download.downloadStatus == DownloadStatus.COMPLETED) this.progress = 100
}
downloadDao.update(download)
downloadDao.updateStatus(download.packageName, status)
}
if (status == DownloadStatus.CANCELLED) return