From eea8dae17cbb2c3ed4a3a02dae09e5b0c8dbe247 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 28 Dec 2019 20:10:01 +0800 Subject: [PATCH] up --- .../io/legado/app/service/DownloadService.kt | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 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 a1042b4d6..7383f691b 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -23,6 +23,18 @@ class DownloadService : BaseService() { private var tasks: ArrayList> = arrayListOf() private val handler = Handler() private var runnable: Runnable = Runnable { upDownload() } + private val notificationBuilder by lazy { + val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) + .setSmallIcon(R.drawable.ic_download) + .setOngoing(true) + .setContentTitle(getString(R.string.download_offline)) + builder.addAction( + R.drawable.ic_stop_black_24dp, + getString(R.string.cancel), + IntentHelp.servicePendingIntent(this, Action.stop) + ) + builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + } override fun onCreate() { super.onCreate() @@ -97,17 +109,8 @@ class DownloadService : BaseService() { * 更新通知 */ private fun updateNotification(content: String) { - val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) - .setSmallIcon(R.drawable.ic_download) - .setOngoing(true) - .setContentTitle(getString(R.string.download_offline)) - .setContentText(content) - builder.addAction( - R.drawable.ic_stop_black_24dp, - getString(R.string.cancel), - IntentHelp.servicePendingIntent(this, Action.stop) - ) - builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + val builder = notificationBuilder + builder.setContentText(content) val notification = builder.build() startForeground(AppConst.notificationIdDownload, notification) }