This commit is contained in:
Horis 2024-01-26 17:54:11 +08:00
parent d1064c5b4c
commit 824212fccf

View File

@ -200,7 +200,8 @@ class DownloadService : BaseService() {
downloadInfo.notificationId, downloadInfo.notificationId,
"${downloadInfo.fileName} $status", "${downloadInfo.fileName} $status",
max, max,
progress progress,
downloadInfo.startTime
) )
} }
} while (cursor.moveToNext()) } while (cursor.moveToNext())
@ -241,9 +242,10 @@ class DownloadService : BaseService() {
notificationId: Int, notificationId: Int,
content: String, content: String,
max: Int, 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) .setSmallIcon(R.drawable.ic_download)
.setSubText(getString(R.string.action_download)) .setSubText(getString(R.string.action_download))
.setContentTitle(content) .setContentTitle(content)
@ -258,16 +260,19 @@ class DownloadService : BaseService() {
} }
) )
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setProgress(max, progress, false)
.setGroup(groupKey) .setGroup(groupKey)
.build() .setWhen(startTime)
notificationManager.notify(notificationId, notification) if (progress < max) {
notificationBuilder.setProgress(max, progress, false)
}
notificationManager.notify(notificationId, notificationBuilder.build())
} }
private data class DownloadInfo( private data class DownloadInfo(
val url: String, val url: String,
val fileName: String, val fileName: String,
val notificationId: Int val notificationId: Int,
val startTime: Long = System.currentTimeMillis()
) )
} }