Download: Rename and simplify column status parameter
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -118,10 +118,10 @@ fun DownloadComposable(
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = stringResource(download.downloadStatus.localized),
|
||||
text = stringResource(download.status.localized),
|
||||
style = MaterialTheme.typography.bodySmall
|
||||
)
|
||||
AnimatedContent(targetState = download.downloadStatus) { status ->
|
||||
AnimatedContent(targetState = download.status) { status ->
|
||||
Text(
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
text = if (status in DownloadStatus.running) {
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.aurora.store.data.helper
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.paging.Pager
|
||||
import androidx.paging.PagingConfig
|
||||
import androidx.work.Data
|
||||
import androidx.work.ExistingWorkPolicy
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
@@ -20,7 +18,6 @@ import com.aurora.store.data.work.DownloadWorker
|
||||
import com.aurora.store.util.PathUtil
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@@ -66,8 +63,8 @@ class DownloadHelper @Inject constructor(
|
||||
private fun observeDownloads() {
|
||||
downloadDao.downloads().onEach { list ->
|
||||
try {
|
||||
if (list.none { it.downloadStatus == DownloadStatus.DOWNLOADING }) {
|
||||
list.find { it.downloadStatus == DownloadStatus.QUEUED }
|
||||
if (list.none { it.status == DownloadStatus.DOWNLOADING }) {
|
||||
list.find { it.status == DownloadStatus.QUEUED }
|
||||
?.let { queuedDownload ->
|
||||
Log.i(TAG, "Enqueued download worker for ${queuedDownload.packageName}")
|
||||
trigger(queuedDownload)
|
||||
@@ -151,7 +148,7 @@ class DownloadHelper @Inject constructor(
|
||||
suspend fun cancelAll(updatesOnly: Boolean = false) {
|
||||
// Cancel all enqueued downloads first to avoid triggering re-download
|
||||
downloadDao.downloads().firstOrNull()
|
||||
?.filter { it.downloadStatus == DownloadStatus.QUEUED }
|
||||
?.filter { it.status == DownloadStatus.QUEUED }
|
||||
?.filter { if (updatesOnly) it.isInstalled else true }
|
||||
?.forEach {
|
||||
downloadDao.updateStatus(it.packageName, DownloadStatus.CANCELLED)
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.aurora.store.data.room.download
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Parcelable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.aurora.gplayapi.data.models.App
|
||||
@@ -25,7 +25,8 @@ data class Download(
|
||||
val iconURL: String,
|
||||
val size: Long,
|
||||
val id: Int,
|
||||
var downloadStatus: DownloadStatus,
|
||||
@ColumnInfo("downloadStatus")
|
||||
var status: DownloadStatus,
|
||||
var progress: Int,
|
||||
var speed: Long,
|
||||
var timeRemaining: Long,
|
||||
@@ -36,9 +37,9 @@ data class Download(
|
||||
val targetSdk: Int = 1,
|
||||
val downloadedAt: Long = 0
|
||||
) : Parcelable {
|
||||
val isFinished get() = downloadStatus in DownloadStatus.finished
|
||||
val isRunning get() = downloadStatus in DownloadStatus.running
|
||||
private val isSuccessful get() = downloadStatus == DownloadStatus.COMPLETED
|
||||
val isFinished get() = status in DownloadStatus.finished
|
||||
val isRunning get() = status in DownloadStatus.running
|
||||
private val isSuccessful get() = status == DownloadStatus.COMPLETED
|
||||
|
||||
companion object {
|
||||
fun fromApp(app: App): Download {
|
||||
@@ -97,7 +98,7 @@ data class Download(
|
||||
iconURL = externalApk.iconURL,
|
||||
size = 0,
|
||||
id = 0,
|
||||
downloadStatus = DownloadStatus.QUEUED,
|
||||
status = DownloadStatus.QUEUED,
|
||||
progress = 0,
|
||||
speed = 0L,
|
||||
timeRemaining = 0L,
|
||||
|
||||
@@ -396,7 +396,7 @@ class DownloadWorker @AssistedInject constructor(
|
||||
exception: Exception? = null
|
||||
) {
|
||||
// Update status in database
|
||||
download.downloadStatus = status
|
||||
download.status = status
|
||||
downloadDao.updateStatus(download.packageName, status)
|
||||
|
||||
when (status) {
|
||||
|
||||
@@ -111,7 +111,7 @@ object NotificationUtil {
|
||||
false
|
||||
)
|
||||
|
||||
when (download.downloadStatus) {
|
||||
when (download.status) {
|
||||
DownloadStatus.CANCELLED -> {
|
||||
builder.setSmallIcon(R.drawable.ic_download_cancel)
|
||||
builder.setContentText(context.getString(R.string.download_canceled))
|
||||
|
||||
@@ -102,8 +102,8 @@ class AppUpdateView @JvmOverloads constructor(
|
||||
@ModelProp
|
||||
fun download(download: Download?) {
|
||||
if (download != null) {
|
||||
binding.btnAction.updateState(download.downloadStatus)
|
||||
when (download.downloadStatus) {
|
||||
binding.btnAction.updateState(download.status)
|
||||
when (download.status) {
|
||||
DownloadStatus.VERIFYING,
|
||||
DownloadStatus.QUEUED -> {
|
||||
binding.progressDownload.isIndeterminate = true
|
||||
|
||||
@@ -117,7 +117,7 @@ class DetailsMicroGFragment : BaseFragment<FragmentDetailsMicrogBinding>() {
|
||||
}
|
||||
|
||||
microGViewModel.download.filterNotNull().onEach {
|
||||
when (it.downloadStatus) {
|
||||
when (it.status) {
|
||||
DownloadStatus.DOWNLOADING -> updateProgressBar(visible = true, it.progress)
|
||||
DownloadStatus.FAILED -> updateProgressBar(visible = false, 0)
|
||||
DownloadStatus.QUEUED -> updateProgressBar(visible = true, -1)
|
||||
|
||||
Reference in New Issue
Block a user