NotificationUtil: Use download object available from parcel

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-05-21 18:06:25 +05:30
parent e338146e9e
commit a655358e47
2 changed files with 18 additions and 21 deletions

View File

@@ -26,7 +26,6 @@ import android.content.pm.PackageInstaller
import android.util.Log
import androidx.core.content.IntentCompat
import com.aurora.extensions.runOnUiThread
import com.aurora.gplayapi.data.models.App
import com.aurora.store.R
import com.aurora.store.data.event.InstallerEvent
import com.aurora.store.data.installer.AppInstaller
@@ -58,10 +57,10 @@ class InstallerStatusReceiver : BroadcastReceiver() {
val extra = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE)
val download = IntentCompat.getParcelableExtra(
intent, EXTRA_DOWNLOAD, Download::class.java
)
)!!
// If package was successfully installed, exit after notifying user and doing cleanup
if (status == PackageInstaller.STATUS_SUCCESS && download != null) {
if (status == PackageInstaller.STATUS_SUCCESS) {
// No post-install steps for shared libraries
if (PackageUtil.isSharedLibrary(context, packageName)) return
@@ -77,20 +76,20 @@ class InstallerStatusReceiver : BroadcastReceiver() {
promptUser(intent, context)
} else {
postStatus(status, packageName, extra, context)
notifyUser(context, packageName, status)
notifyUser(context, download, status)
}
}
}
private fun notifyUser(context: Context, packageName: String, status: Int) {
private fun notifyUser(context: Context, download: Download, status: Int) {
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notification = NotificationUtil.getInstallerStatusNotification(
context,
App(packageName),
download,
AppInstaller.getErrorString(context, status)
)
notificationManager.notify(packageName.hashCode(), notification)
notificationManager.notify(download.packageName.hashCode(), notification)
}
private fun promptUser(intent: Intent, context: Context) {

View File

@@ -8,10 +8,8 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.os.Build
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
@@ -27,7 +25,6 @@ import com.aurora.store.R
import com.aurora.store.data.activity.InstallActivity
import com.aurora.store.data.model.DownloadStatus
import com.aurora.store.data.room.download.Download
import java.net.URL
import java.util.UUID
object NotificationUtil {
@@ -170,17 +167,18 @@ object NotificationUtil {
.build()
}
fun getInstallerStatusNotification(context: Context, app: App, content: String?): Notification {
val builder =
NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ALERT).apply {
color = context.getStyledAttributeColor(R.color.colorAccent)
setSmallIcon(R.drawable.ic_install)
setContentTitle(app.displayName)
setContentText(content)
setContentIntent(getContentIntentForDetails(context, app.packageName))
setSubText(app.packageName)
}
return builder.build()
fun getInstallerStatusNotification(
context: Context,
download: Download,
content: String?
): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ALERT)
.setSmallIcon(R.drawable.ic_install)
.setColor(context.getStyledAttributeColor(R.color.colorAccent))
.setContentTitle(download.displayName)
.setContentText(content)
.setContentIntent(getContentIntentForDetails(context, download.packageName))
.build()
}
fun getOngoingUpdateNotification(context: Context): Notification {