diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index bb3f60f1c..e3ab2f6a0 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -186,11 +186,6 @@
android:name=".ui.about.AboutActivity"
android:launchMode="singleTask"
android:screenOrientation="behind" />
-
-
-
+
{
val id = intent.getLongExtra("downloadId", 0)
if (completeDownloads.contains(id)) {
@@ -63,6 +69,7 @@ class DownloadService : BaseService() {
toastOnUi("未完成,下载的文件夹Download")
}
}
+
IntentAction.stop -> {
val downloadId = intent.getLongExtra("downloadId", 0)
removeDownload(downloadId)
@@ -177,6 +184,7 @@ class DownloadService : BaseService() {
successDownload(id)
getString(R.string.download_success)
}
+
DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
else -> getString(R.string.unknown_state)
}
diff --git a/app/src/main/java/io/legado/app/service/ExportBookService.kt b/app/src/main/java/io/legado/app/service/ExportBookService.kt
index 1159dc9f9..c5d0c28c5 100644
--- a/app/src/main/java/io/legado/app/service/ExportBookService.kt
+++ b/app/src/main/java/io/legado/app/service/ExportBookService.kt
@@ -63,6 +63,7 @@ import me.ag2s.epublib.epub.EpubWriter
import me.ag2s.epublib.epub.EpubWriterProcessor
import me.ag2s.epublib.util.ResourceUtil
import splitties.init.appCtx
+import splitties.systemservices.notificationManager
import java.io.BufferedOutputStream
import java.io.ByteArrayOutputStream
import java.io.File
@@ -87,6 +88,7 @@ class ExportBookService : BaseService() {
val epubScope: String? = null
)
+ private val groupKey = "${appCtx.packageName}.exportBook"
private val handler = buildMainHandler()
private val waitExportBooks = linkedMapOf()
private var exportJob: Job? = null
@@ -125,26 +127,34 @@ class ExportBookService : BaseService() {
@SuppressLint("MissingPermission")
override fun upNotification() {
+ val notification = NotificationCompat.Builder(this, AppConst.channelIdDownload)
+ .setSmallIcon(R.drawable.ic_export)
+ .setContentTitle(getString(R.string.export_book))
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
+ .setContentText(notificationContent)
+ .setGroup(groupKey)
+ .setGroupSummary(true)
+ startForeground(AppConst.notificationIdExport, notification.build())
+ }
+
+ private fun upExportNotification() {
val notification = NotificationCompat.Builder(this, AppConst.channelIdDownload)
.setSmallIcon(R.drawable.ic_export)
.setContentTitle(getString(R.string.export_book))
.setContentIntent(activityPendingIntent("cacheActivity"))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentText(notificationContent)
+ .setDeleteIntent(servicePendingIntent(IntentAction.stop))
+ .setGroup(groupKey)
if (exportJob?.isActive == true) {
+ notification.setOngoing(true)
notification.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
servicePendingIntent(IntentAction.stop)
)
- } else {
- notification.addAction(
- R.drawable.ic_stop_black_24dp,
- getString(R.string.close),
- servicePendingIntent(IntentAction.stop)
- )
}
- startForeground(AppConst.notificationIdExport, notification.build())
+ notificationManager.notify(AppConst.notificationIdExport, notification.build())
}
private fun export() {
@@ -154,7 +164,7 @@ class ExportBookService : BaseService() {
val entry = waitExportBooks.firstNotNullOfOrNull { it }
if (entry == null) {
notificationContent = "导出完成"
- upNotification()
+ upExportNotification()
return
}
val bookUrl = entry.key
@@ -171,7 +181,7 @@ class ExportBookService : BaseService() {
book.name,
waitExportBooks.size
)
- upNotification()
+ upExportNotification()
if (exportConfig.type == "epub") {
if (exportConfig.epubScope.isNullOrBlank()) {
exportEPUB(exportConfig.path, book)