From bf661560f0216842bcbff5ccde8b862b483f16e4 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 26 Jul 2021 22:25:09 +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 --- .../java/io/legado/app/help/IntentHelp.kt | 13 +++------- .../io/legado/app/service/DownloadService.kt | 25 +++++++------------ .../java/io/legado/app/service/WebService.kt | 4 +++ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index 10e1c53ac..64192b124 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -3,7 +3,6 @@ package io.legado.app.help import android.app.PendingIntent import android.content.Context import android.content.Intent -import android.os.Bundle import io.legado.app.R import io.legado.app.utils.toastOnUi @@ -37,26 +36,22 @@ object IntentHelp { inline fun servicePendingIntent( context: Context, action: String, - bundle: Bundle? = null + configIntent: Intent.() -> Unit = {} ): PendingIntent? { val intent = Intent(context, T::class.java) intent.action = action - bundle?.let { - intent.putExtras(bundle) - } + configIntent.invoke(intent) return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } inline fun activityPendingIntent( context: Context, action: String, - bundle: Bundle? = null + configIntent: Intent.() -> Unit = {} ): PendingIntent? { val intent = Intent(context, T::class.java) intent.action = action - bundle?.let { - intent.putExtras(bundle) - } + configIntent.invoke(intent) return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } } \ No newline at end of file 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 156f9eccf..d3c7af5ef 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -11,7 +11,6 @@ import android.os.Handler import android.os.Looper import androidx.core.app.NotificationCompat import androidx.core.content.FileProvider -import androidx.core.os.bundleOf import io.legado.app.R import io.legado.app.base.BaseService import io.legado.app.constant.AppConst @@ -152,27 +151,21 @@ class DownloadService : BaseService() { .setOngoing(true) .setContentTitle(getString(R.string.action_download)) notificationBuilder.setContentIntent( - IntentHelp.servicePendingIntent( - this, - IntentAction.play, - bundleOf("downloadId" to downloadId) - ) + IntentHelp.servicePendingIntent(this, IntentAction.play) { + putExtra("downloadId", downloadId) + } ) notificationBuilder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.cancel), - IntentHelp.servicePendingIntent( - this, - IntentAction.stop, - bundleOf("downloadId" to downloadId) - ) + IntentHelp.servicePendingIntent(this, IntentAction.stop) { + putExtra("downloadId", downloadId) + } ) notificationBuilder.setDeleteIntent( - IntentHelp.servicePendingIntent( - this, - IntentAction.stop, - bundleOf("downloadId" to downloadId) - ) + IntentHelp.servicePendingIntent(this, IntentAction.stop) { + putExtra("downloadId", downloadId) + } ) notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) notificationBuilder.setContentText(content) diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 910e76497..2f9afe931 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -10,6 +10,7 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.constant.PreferKey import io.legado.app.help.IntentHelp +import io.legado.app.ui.main.MainActivity import io.legado.app.utils.* import io.legado.app.web.HttpServer import io.legado.app.web.WebSocketServer @@ -113,6 +114,9 @@ class WebService : BaseService() { .setOngoing(true) .setContentTitle(getString(R.string.web_service)) .setContentText(notificationContent) + .setContentIntent( + IntentHelp.activityPendingIntent(this, "webService") + ) builder.addAction( R.drawable.ic_stop_black_24dp, getString(R.string.cancel),