From 824212fccfcd1e16420abcc7874355f13b803666 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Fri, 26 Jan 2024 17:54:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/DownloadService.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index e88505ac1..343ddcc1f 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -200,7 +200,8 @@ class DownloadService : BaseService() { downloadInfo.notificationId, "${downloadInfo.fileName} $status", max, - progress + progress, + downloadInfo.startTime ) } } while (cursor.moveToNext()) @@ -241,9 +242,10 @@ class DownloadService : BaseService() { notificationId: Int, content: String, max: Int, - progress: Int + progress: Int, + startTime: Long ) { - val notification = NotificationCompat.Builder(this, AppConst.channelIdDownload) + val notificationBuilder = NotificationCompat.Builder(this, AppConst.channelIdDownload) .setSmallIcon(R.drawable.ic_download) .setSubText(getString(R.string.action_download)) .setContentTitle(content) @@ -258,16 +260,19 @@ class DownloadService : BaseService() { } ) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setProgress(max, progress, false) .setGroup(groupKey) - .build() - notificationManager.notify(notificationId, notification) + .setWhen(startTime) + if (progress < max) { + notificationBuilder.setProgress(max, progress, false) + } + notificationManager.notify(notificationId, notificationBuilder.build()) } private data class DownloadInfo( val url: String, val fileName: String, - val notificationId: Int + val notificationId: Int, + val startTime: Long = System.currentTimeMillis() ) -} \ No newline at end of file +}