DownloadWorker: Only update appropriate status field on status change
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -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>>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user