pull/1174/head
gedoor 3 years ago
parent 9906247ba7
commit bf661560f0
  1. 13
      app/src/main/java/io/legado/app/help/IntentHelp.kt
  2. 25
      app/src/main/java/io/legado/app/service/DownloadService.kt
  3. 4
      app/src/main/java/io/legado/app/service/WebService.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 <reified T> 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 <reified T> 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)
}
}

@ -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<DownloadService>(
this,
IntentAction.play,
bundleOf("downloadId" to downloadId)
)
IntentHelp.servicePendingIntent<DownloadService>(this, IntentAction.play) {
putExtra("downloadId", downloadId)
}
)
notificationBuilder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
IntentHelp.servicePendingIntent<DownloadService>(
this,
IntentAction.stop,
bundleOf("downloadId" to downloadId)
)
IntentHelp.servicePendingIntent<DownloadService>(this, IntentAction.stop) {
putExtra("downloadId", downloadId)
}
)
notificationBuilder.setDeleteIntent(
IntentHelp.servicePendingIntent<DownloadService>(
this,
IntentAction.stop,
bundleOf("downloadId" to downloadId)
)
IntentHelp.servicePendingIntent<DownloadService>(this, IntentAction.stop) {
putExtra("downloadId", downloadId)
}
)
notificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
notificationBuilder.setContentText(content)

@ -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<MainActivity>(this, "webService")
)
builder.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),

Loading…
Cancel
Save