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:
@@ -59,7 +59,7 @@ open class PackageManagerReceiver : BroadcastReceiver() {
|
|||||||
EventBus.getDefault().post(InstallEvent(packageName, ""))
|
EventBus.getDefault().post(InstallEvent(packageName, ""))
|
||||||
|
|
||||||
downloadWorkerUtil.downloadsList.filter { it.isNotEmpty() }.firstOrNull()
|
downloadWorkerUtil.downloadsList.filter { it.isNotEmpty() }.firstOrNull()
|
||||||
?.find { it.packageName == packageName && it.status == DownloadStatus.COMPLETED }
|
?.find { it.packageName == packageName && it.downloadStatus == DownloadStatus.COMPLETED }
|
||||||
?.let {
|
?.let {
|
||||||
notifyInstallation(context, it)
|
notifyInstallation(context, it)
|
||||||
if (Preferences.getBoolean(context, PREFERENCE_AUTO_DELETE)) {
|
if (Preferences.getBoolean(context, PREFERENCE_AUTO_DELETE)) {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ data class Download(
|
|||||||
val iconURL: String,
|
val iconURL: String,
|
||||||
val size: Long,
|
val size: Long,
|
||||||
val id: Int,
|
val id: Int,
|
||||||
var status: DownloadStatus,
|
var downloadStatus: DownloadStatus,
|
||||||
var progress: Int,
|
var progress: Int,
|
||||||
var speed: Long,
|
var speed: Long,
|
||||||
var timeRemaining: Long,
|
var timeRemaining: Long,
|
||||||
@@ -28,7 +28,7 @@ data class Download(
|
|||||||
var fileList: List<File>,
|
var fileList: List<File>,
|
||||||
val sharedLibs: List<SharedLib>
|
val sharedLibs: List<SharedLib>
|
||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
val isFinished get() = status in DownloadStatus.finished
|
val isFinished get() = downloadStatus in DownloadStatus.finished
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromApp(app: App): Download {
|
fun fromApp(app: App): Download {
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
download.apply {
|
download.apply {
|
||||||
this.status = DownloadStatus.DOWNLOADING
|
this.downloadStatus = DownloadStatus.DOWNLOADING
|
||||||
this.progress = progress
|
this.progress = progress
|
||||||
this.speed = downloadInfo.speed
|
this.speed = downloadInfo.speed
|
||||||
this.timeRemaining = bytesRemaining / speed * 1000
|
this.timeRemaining = bytesRemaining / speed * 1000
|
||||||
@@ -313,8 +313,8 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
// 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 {
|
download.apply {
|
||||||
this.status = status
|
this.downloadStatus = status
|
||||||
if (download.status == DownloadStatus.COMPLETED) this.progress = 100
|
if (download.downloadStatus == DownloadStatus.COMPLETED) this.progress = 100
|
||||||
}
|
}
|
||||||
downloadDao.update(download)
|
downloadDao.update(download)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ class DownloadWorkerUtil @Inject constructor(
|
|||||||
downloadDao.downloads()
|
downloadDao.downloads()
|
||||||
.collectLatest { list ->
|
.collectLatest { list ->
|
||||||
// Check and trigger next download in queue, if any
|
// Check and trigger next download in queue, if any
|
||||||
if (!list.any { it.status == DownloadStatus.DOWNLOADING }) {
|
if (!list.any { it.downloadStatus == DownloadStatus.DOWNLOADING }) {
|
||||||
val enqueuedDownloads = list.filter { it.status == DownloadStatus.QUEUED }
|
val enqueuedDownloads = list.filter { it.downloadStatus == DownloadStatus.QUEUED }
|
||||||
enqueuedDownloads.firstOrNull()?.let {
|
enqueuedDownloads.firstOrNull()?.let {
|
||||||
try {
|
try {
|
||||||
if (context.isIgnoringBatteryOptimizations() || CommonUtil.inForeground()) {
|
if (context.isIgnoringBatteryOptimizations() || CommonUtil.inForeground()) {
|
||||||
@@ -83,8 +83,8 @@ class DownloadWorkerUtil @Inject constructor(
|
|||||||
Log.i(TAG, "Cancelling download for $packageName")
|
Log.i(TAG, "Cancelling download for $packageName")
|
||||||
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
|
WorkManager.getInstance(context).cancelAllWorkByTag("$PACKAGE_NAME:$packageName")
|
||||||
downloadsList.filter { it.isNotEmpty() }.firstOrNull()
|
downloadsList.filter { it.isNotEmpty() }.firstOrNull()
|
||||||
?.find { it.packageName == packageName && it.status == DownloadStatus.QUEUED }
|
?.find { it.packageName == packageName && it.downloadStatus == DownloadStatus.QUEUED }
|
||||||
?.let { downloadDao.update(it.copy(status = DownloadStatus.CANCELLED)) }
|
?.let { downloadDao.update(it.copy(downloadStatus = DownloadStatus.CANCELLED)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun clearDownload(packageName: String, versionCode: Int) {
|
suspend fun clearDownload(packageName: String, versionCode: Int) {
|
||||||
@@ -102,8 +102,8 @@ class DownloadWorkerUtil @Inject constructor(
|
|||||||
|
|
||||||
suspend fun cancelAll(downloads: Boolean = true, updates: Boolean = true) {
|
suspend fun cancelAll(downloads: Boolean = true, updates: Boolean = true) {
|
||||||
// Cancel all enqueued downloads first to avoid triggering re-download
|
// Cancel all enqueued downloads first to avoid triggering re-download
|
||||||
downloadsList.value.filter { it.status == DownloadStatus.QUEUED }.forEach {
|
downloadsList.value.filter { it.downloadStatus == DownloadStatus.QUEUED }.forEach {
|
||||||
downloadDao.update(it.copy(status = DownloadStatus.CANCELLED))
|
downloadDao.update(it.copy(downloadStatus = DownloadStatus.CANCELLED))
|
||||||
}
|
}
|
||||||
|
|
||||||
val workManager = WorkManager.getInstance(context)
|
val workManager = WorkManager.getInstance(context)
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ object NotificationUtil {
|
|||||||
builder.setContentIntent(getContentIntentForDownloads(context))
|
builder.setContentIntent(getContentIntentForDownloads(context))
|
||||||
builder.setLargeIcon(largeIcon)
|
builder.setLargeIcon(largeIcon)
|
||||||
|
|
||||||
when (download.status) {
|
when (download.downloadStatus) {
|
||||||
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))
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ import com.aurora.store.data.room.download.Download
|
|||||||
import com.aurora.store.databinding.ViewDownloadBinding
|
import com.aurora.store.databinding.ViewDownloadBinding
|
||||||
import com.aurora.store.util.CommonUtil.getDownloadSpeedString
|
import com.aurora.store.util.CommonUtil.getDownloadSpeedString
|
||||||
import com.aurora.store.util.CommonUtil.getETAString
|
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
|
import java.util.Locale
|
||||||
|
|
||||||
@ModelView(
|
@ModelView(
|
||||||
@@ -75,7 +72,7 @@ class DownloadView : RelativeLayout {
|
|||||||
}
|
}
|
||||||
B.txtTitle.text = download.displayName
|
B.txtTitle.text = download.displayName
|
||||||
|
|
||||||
B.txtStatus.text = download.status.name
|
B.txtStatus.text = download.downloadStatus.name
|
||||||
.lowercase(Locale.getDefault())
|
.lowercase(Locale.getDefault())
|
||||||
.replaceFirstChar {
|
.replaceFirstChar {
|
||||||
if (it.isLowerCase()) {
|
if (it.isLowerCase()) {
|
||||||
@@ -97,7 +94,7 @@ class DownloadView : RelativeLayout {
|
|||||||
download.speed
|
download.speed
|
||||||
)
|
)
|
||||||
|
|
||||||
when (download.status) {
|
when (download.downloadStatus) {
|
||||||
DownloadStatus.DOWNLOADING, DownloadStatus.QUEUED -> {
|
DownloadStatus.DOWNLOADING, DownloadStatus.QUEUED -> {
|
||||||
B.txtSpeed.visibility = VISIBLE
|
B.txtSpeed.visibility = VISIBLE
|
||||||
B.txtEta.visibility = VISIBLE
|
B.txtEta.visibility = VISIBLE
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ class AppUpdateView : RelativeLayout {
|
|||||||
fun download(download: Download?) {
|
fun download(download: Download?) {
|
||||||
if (download != null) {
|
if (download != null) {
|
||||||
/*Inflate Download details*/
|
/*Inflate Download details*/
|
||||||
B.btnAction.updateState(download.status)
|
B.btnAction.updateState(download.downloadStatus)
|
||||||
B.progressDownload.isIndeterminate = download.progress < 1
|
B.progressDownload.isIndeterminate = download.progress < 1
|
||||||
when (download.status) {
|
when (download.downloadStatus) {
|
||||||
DownloadStatus.QUEUED -> {
|
DownloadStatus.QUEUED -> {
|
||||||
B.progressDownload.progress = 0
|
B.progressDownload.progress = 0
|
||||||
B.progressDownload.show()
|
B.progressDownload.show()
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import android.content.ActivityNotFoundException
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
@@ -246,10 +245,10 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
|||||||
.collectLatest { downloadsList ->
|
.collectLatest { downloadsList ->
|
||||||
val download = downloadsList.find { it.packageName == app.packageName }
|
val download = downloadsList.find { it.packageName == app.packageName }
|
||||||
download?.let {
|
download?.let {
|
||||||
downloadStatus = it.status
|
downloadStatus = it.downloadStatus
|
||||||
|
|
||||||
if (it.isFinished) flip(0) else flip(1)
|
if (it.isFinished) flip(0) else flip(1)
|
||||||
when (it.status) {
|
when (it.downloadStatus) {
|
||||||
DownloadStatus.QUEUED -> {
|
DownloadStatus.QUEUED -> {
|
||||||
updateProgress(it.progress)
|
updateProgress(it.progress)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user