Download: Rename and simplify column status parameter

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-10-09 17:20:58 +08:00
parent 0274027f4d
commit 0167ddbb92
7 changed files with 17 additions and 19 deletions

View File

@@ -118,10 +118,10 @@ fun DownloadComposable(
overflow = TextOverflow.Ellipsis overflow = TextOverflow.Ellipsis
) )
Text( Text(
text = stringResource(download.downloadStatus.localized), text = stringResource(download.status.localized),
style = MaterialTheme.typography.bodySmall style = MaterialTheme.typography.bodySmall
) )
AnimatedContent(targetState = download.downloadStatus) { status -> AnimatedContent(targetState = download.status) { status ->
Text( Text(
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
text = if (status in DownloadStatus.running) { text = if (status in DownloadStatus.running) {

View File

@@ -2,8 +2,6 @@ package com.aurora.store.data.helper
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.work.Data import androidx.work.Data
import androidx.work.ExistingWorkPolicy import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder import androidx.work.OneTimeWorkRequestBuilder
@@ -20,7 +18,6 @@ import com.aurora.store.data.work.DownloadWorker
import com.aurora.store.util.PathUtil import com.aurora.store.util.PathUtil
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@@ -66,8 +63,8 @@ class DownloadHelper @Inject constructor(
private fun observeDownloads() { private fun observeDownloads() {
downloadDao.downloads().onEach { list -> downloadDao.downloads().onEach { list ->
try { try {
if (list.none { it.downloadStatus == DownloadStatus.DOWNLOADING }) { if (list.none { it.status == DownloadStatus.DOWNLOADING }) {
list.find { it.downloadStatus == DownloadStatus.QUEUED } list.find { it.status == DownloadStatus.QUEUED }
?.let { queuedDownload -> ?.let { queuedDownload ->
Log.i(TAG, "Enqueued download worker for ${queuedDownload.packageName}") Log.i(TAG, "Enqueued download worker for ${queuedDownload.packageName}")
trigger(queuedDownload) trigger(queuedDownload)
@@ -151,7 +148,7 @@ 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
downloadDao.downloads().firstOrNull() downloadDao.downloads().firstOrNull()
?.filter { it.downloadStatus == DownloadStatus.QUEUED } ?.filter { it.status == DownloadStatus.QUEUED }
?.filter { if (updatesOnly) it.isInstalled else true } ?.filter { if (updatesOnly) it.isInstalled else true }
?.forEach { ?.forEach {
downloadDao.updateStatus(it.packageName, DownloadStatus.CANCELLED) downloadDao.updateStatus(it.packageName, DownloadStatus.CANCELLED)

View File

@@ -2,7 +2,7 @@ package com.aurora.store.data.room.download
import android.content.Context import android.content.Context
import android.os.Parcelable import android.os.Parcelable
import androidx.compose.ui.platform.LocalContext import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import com.aurora.gplayapi.data.models.App import com.aurora.gplayapi.data.models.App
@@ -25,7 +25,8 @@ data class Download(
val iconURL: String, val iconURL: String,
val size: Long, val size: Long,
val id: Int, val id: Int,
var downloadStatus: DownloadStatus, @ColumnInfo("downloadStatus")
var status: DownloadStatus,
var progress: Int, var progress: Int,
var speed: Long, var speed: Long,
var timeRemaining: Long, var timeRemaining: Long,
@@ -36,9 +37,9 @@ data class Download(
val targetSdk: Int = 1, val targetSdk: Int = 1,
val downloadedAt: Long = 0 val downloadedAt: Long = 0
) : Parcelable { ) : Parcelable {
val isFinished get() = downloadStatus in DownloadStatus.finished val isFinished get() = status in DownloadStatus.finished
val isRunning get() = downloadStatus in DownloadStatus.running val isRunning get() = status in DownloadStatus.running
private val isSuccessful get() = downloadStatus == DownloadStatus.COMPLETED private val isSuccessful get() = status == DownloadStatus.COMPLETED
companion object { companion object {
fun fromApp(app: App): Download { fun fromApp(app: App): Download {
@@ -97,7 +98,7 @@ data class Download(
iconURL = externalApk.iconURL, iconURL = externalApk.iconURL,
size = 0, size = 0,
id = 0, id = 0,
downloadStatus = DownloadStatus.QUEUED, status = DownloadStatus.QUEUED,
progress = 0, progress = 0,
speed = 0L, speed = 0L,
timeRemaining = 0L, timeRemaining = 0L,

View File

@@ -396,7 +396,7 @@ class DownloadWorker @AssistedInject constructor(
exception: Exception? = null exception: Exception? = null
) { ) {
// Update status in database // Update status in database
download.downloadStatus = status download.status = status
downloadDao.updateStatus(download.packageName, status) downloadDao.updateStatus(download.packageName, status)
when (status) { when (status) {

View File

@@ -111,7 +111,7 @@ object NotificationUtil {
false false
) )
when (download.downloadStatus) { when (download.status) {
DownloadStatus.CANCELLED -> { DownloadStatus.CANCELLED -> {
builder.setSmallIcon(R.drawable.ic_download_cancel) builder.setSmallIcon(R.drawable.ic_download_cancel)
builder.setContentText(context.getString(R.string.download_canceled)) builder.setContentText(context.getString(R.string.download_canceled))

View File

@@ -102,8 +102,8 @@ class AppUpdateView @JvmOverloads constructor(
@ModelProp @ModelProp
fun download(download: Download?) { fun download(download: Download?) {
if (download != null) { if (download != null) {
binding.btnAction.updateState(download.downloadStatus) binding.btnAction.updateState(download.status)
when (download.downloadStatus) { when (download.status) {
DownloadStatus.VERIFYING, DownloadStatus.VERIFYING,
DownloadStatus.QUEUED -> { DownloadStatus.QUEUED -> {
binding.progressDownload.isIndeterminate = true binding.progressDownload.isIndeterminate = true

View File

@@ -117,7 +117,7 @@ class DetailsMicroGFragment : BaseFragment<FragmentDetailsMicrogBinding>() {
} }
microGViewModel.download.filterNotNull().onEach { microGViewModel.download.filterNotNull().onEach {
when (it.downloadStatus) { when (it.status) {
DownloadStatus.DOWNLOADING -> updateProgressBar(visible = true, it.progress) DownloadStatus.DOWNLOADING -> updateProgressBar(visible = true, it.progress)
DownloadStatus.FAILED -> updateProgressBar(visible = false, 0) DownloadStatus.FAILED -> updateProgressBar(visible = false, 0)
DownloadStatus.QUEUED -> updateProgressBar(visible = true, -1) DownloadStatus.QUEUED -> updateProgressBar(visible = true, -1)