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.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.Update
|
import androidx.room.Update
|
||||||
|
import com.aurora.store.data.model.DownloadStatus
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -16,6 +17,9 @@ interface DownloadDao {
|
|||||||
@Update
|
@Update
|
||||||
suspend fun update(download: Download)
|
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")
|
@Query("SELECT * FROM download")
|
||||||
fun downloads(): Flow<List<Download>>
|
fun downloads(): Flow<List<Download>>
|
||||||
|
|
||||||
|
|||||||
@@ -307,11 +307,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
private suspend fun notifyStatus(status: DownloadStatus, dID: Int = -1) {
|
private suspend fun notifyStatus(status: DownloadStatus, dID: Int = -1) {
|
||||||
// Update database for all status except downloading which is handled onProgress
|
// Update database for all status except downloading which is handled onProgress
|
||||||
if (status != DownloadStatus.DOWNLOADING) {
|
if (status != DownloadStatus.DOWNLOADING) {
|
||||||
download.apply {
|
downloadDao.updateStatus(download.packageName, status)
|
||||||
this.downloadStatus = status
|
|
||||||
if (download.downloadStatus == DownloadStatus.COMPLETED) this.progress = 100
|
|
||||||
}
|
|
||||||
downloadDao.update(download)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == DownloadStatus.CANCELLED) return
|
if (status == DownloadStatus.CANCELLED) return
|
||||||
|
|||||||
Reference in New Issue
Block a user