0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-11-23 19:55:11 +00:00
This commit is contained in:
X1nto 2020-06-30 12:32:51 +04:00
parent 2dacfb0616
commit b569ec6bd5
2 changed files with 9 additions and 9 deletions

View file

@ -9,9 +9,8 @@ import com.downloader.PRDownloader
class DownloadBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val tag: Int? = intent?.getIntExtra("dwnldId", 0)
val tag: Int? = intent?.getIntExtra("tag", 0)
PRDownloader.cancel(tag)
Log.d("VMNotification", "Canceled ${intent?.getIntExtra("dwnldId", 0)} download")
Log.d("VMNotification", "Canceled $tag download")
}
}

View file

@ -17,29 +17,30 @@ object NotificationHelper {
val notifChannel = NotificationChannel(
"69420",
context.getString(R.string.notif_channel_name),
NotificationManager.IMPORTANCE_LOW
NotificationManager.IMPORTANCE_HIGH
)
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(notifChannel)
}
}
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, downId: Int, context: Context) {
fun displayDownloadNotif(channel: Int, progress:Int, filename: String, tag: Int, context: Context) {
val notifBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
Notification.Builder(context, channel.toString()).setChannelId("69420")
else
Notification.Builder(context).setPriority(Notification.PRIORITY_LOW)
Notification.Builder(context).setPriority(Notification.PRIORITY_HIGH)
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java)
cancelDownload.putExtra("tag", tag)
val cancelDownload = Intent(context, DownloadBroadcastReceiver::class.java).apply {
putExtra("dwnldId", downId)
}
val cancelPendingIntent = PendingIntent.getBroadcast(context, 0, cancelDownload, PendingIntent.FLAG_UPDATE_CURRENT)
notifBuilder.apply {
setContentTitle(context.getString(R.string.app_name))
setContentText(context.getString(R.string.downloading_file, filename))
setSmallIcon(R.drawable.ic_stat_name)
setOnlyAlertOnce(true)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
addAction(Notification.Action.Builder(null, context.getString(R.string.cancel), cancelPendingIntent).build())
else