Download: change status parameter to downloadStatus

We want an installStatus parameter as well to enqueue installations as well

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-01-16 18:22:46 +05:30
parent 9b5fd56540
commit a3591406b2
8 changed files with 19 additions and 23 deletions

View File

@@ -59,7 +59,7 @@ open class PackageManagerReceiver : BroadcastReceiver() {
EventBus.getDefault().post(InstallEvent(packageName, ""))
downloadWorkerUtil.downloadsList.filter { it.isNotEmpty() }.firstOrNull()
?.find { it.packageName == packageName && it.status == DownloadStatus.COMPLETED }
?.find { it.packageName == packageName && it.downloadStatus == DownloadStatus.COMPLETED }
?.let {
notifyInstallation(context, it)
if (Preferences.getBoolean(context, PREFERENCE_AUTO_DELETE)) {

View File

@@ -19,7 +19,7 @@ data class Download(
val iconURL: String,
val size: Long,
val id: Int,
var status: DownloadStatus,
var downloadStatus: DownloadStatus,
var progress: Int,
var speed: Long,
var timeRemaining: Long,
@@ -28,7 +28,7 @@ data class Download(
var fileList: List<File>,
val sharedLibs: List<SharedLib>
) : Parcelable {
val isFinished get() = status in DownloadStatus.finished
val isFinished get() = downloadStatus in DownloadStatus.finished
companion object {
fun fromApp(app: App): Download {

View File

@@ -283,7 +283,7 @@ class DownloadWorker @AssistedInject constructor(
}
download.apply {
this.status = DownloadStatus.DOWNLOADING
this.downloadStatus = DownloadStatus.DOWNLOADING
this.progress = progress
this.speed = downloadInfo.speed
this.timeRemaining = bytesRemaining / speed * 1000
@@ -313,8 +313,8 @@ class DownloadWorker @AssistedInject constructor(
// Update database for all status except downloading which is handled onProgress
if (status != DownloadStatus.DOWNLOADING) {
download.apply {
this.status = status
if (download.status == DownloadStatus.COMPLETED) this.progress = 100
this.downloadStatus = status
if (download.downloadStatus == DownloadStatus.COMPLETED) this.progress = 100
}
downloadDao.update(download)
}

View File

@@ -54,8 +54,8 @@ class DownloadWorkerUtil @Inject constructor(
downloadDao.downloads()
.collectLatest { list ->
// Check and trigger next download in queue, if any
if (!list.any { it.status == DownloadStatus.DOWNLOADING }) {
val enqueuedDownloads = list.filter { it.status == DownloadStatus.QUEUED }
if (!list.any { it.downloadStatus == DownloadStatus.DOWNLOADING }) {
val enqueuedDownloads = list.filter { it.downloadStatus == DownloadStatus.QUEUED }
enqueuedDownloads.firstOrNull()?.let {
try {
if (context.isIgnoringBatteryOptimizations() || CommonUtil.inForeground()) {
@@ -83,8 +83,8 @@ class DownloadWorkerUtil @Inject constructor(
Log.i(TAG, "Cancelling download for $packageName")
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
downloadsList.filter { it.isNotEmpty() }.firstOrNull()
?.find { it.packageName == packageName && it.status == DownloadStatus.QUEUED }
?.let { downloadDao.update(it.copy(status = DownloadStatus.CANCELLED)) }
?.find { it.packageName == packageName && it.downloadStatus == DownloadStatus.QUEUED }
?.let { downloadDao.update(it.copy(downloadStatus = DownloadStatus.CANCELLED)) }
}
suspend fun clearDownload(packageName: String, versionCode: Int) {
@@ -102,8 +102,8 @@ class DownloadWorkerUtil @Inject constructor(
suspend fun cancelAll(downloads: Boolean = true, updates: Boolean = true) {
// Cancel all enqueued downloads first to avoid triggering re-download
downloadsList.value.filter { it.status == DownloadStatus.QUEUED }.forEach {
downloadDao.update(it.copy(status = DownloadStatus.CANCELLED))
downloadsList.value.filter { it.downloadStatus == DownloadStatus.QUEUED }.forEach {
downloadDao.update(it.copy(downloadStatus = DownloadStatus.CANCELLED))
}
val workManager = WorkManager.getInstance(context)

View File

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

View File

@@ -33,9 +33,6 @@ import com.aurora.store.data.room.download.Download
import com.aurora.store.databinding.ViewDownloadBinding
import com.aurora.store.util.CommonUtil.getDownloadSpeedString
import com.aurora.store.util.CommonUtil.getETAString
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.lang.reflect.Modifier
import java.util.Locale
@ModelView(
@@ -75,7 +72,7 @@ class DownloadView : RelativeLayout {
}
B.txtTitle.text = download.displayName
B.txtStatus.text = download.status.name
B.txtStatus.text = download.downloadStatus.name
.lowercase(Locale.getDefault())
.replaceFirstChar {
if (it.isLowerCase()) {
@@ -97,7 +94,7 @@ class DownloadView : RelativeLayout {
download.speed
)
when (download.status) {
when (download.downloadStatus) {
DownloadStatus.DOWNLOADING, DownloadStatus.QUEUED -> {
B.txtSpeed.visibility = VISIBLE
B.txtEta.visibility = VISIBLE

View File

@@ -108,9 +108,9 @@ class AppUpdateView : RelativeLayout {
fun download(download: Download?) {
if (download != null) {
/*Inflate Download details*/
B.btnAction.updateState(download.status)
B.btnAction.updateState(download.downloadStatus)
B.progressDownload.isIndeterminate = download.progress < 1
when (download.status) {
when (download.downloadStatus) {
DownloadStatus.QUEUED -> {
B.progressDownload.progress = 0
B.progressDownload.show()

View File

@@ -25,7 +25,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
@@ -246,10 +245,10 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
.collectLatest { downloadsList ->
val download = downloadsList.find { it.packageName == app.packageName }
download?.let {
downloadStatus = it.status
downloadStatus = it.downloadStatus
if (it.isFinished) flip(0) else flip(1)
when (it.status) {
when (it.downloadStatus) {
DownloadStatus.QUEUED -> {
updateProgress(it.progress)
}