This commit is contained in:
kunfei
2023-07-30 00:15:57 +08:00
parent d43d61647a
commit 9971bb5054
3 changed files with 31 additions and 16 deletions
+3 -6
View File
@@ -186,11 +186,6 @@
android:name=".ui.about.AboutActivity"
android:launchMode="singleTask"
android:screenOrientation="behind" />
<!-- 捐赠界面 -->
<activity
android:name=".ui.about.DonateActivity"
android:launchMode="singleTask"
android:screenOrientation="behind" />
<!-- 书源管理 -->
<activity
android:name=".ui.book.source.manage.BookSourceActivity"
@@ -432,7 +427,9 @@
<service android:name=".service.TTSReadAloudService" />
<service android:name=".service.HttpReadAloudService" />
<service android:name=".service.AudioPlayService" />
<service android:name=".service.DownloadService" />
<service
android:name=".service.DownloadService"
android:exported="" />
<receiver
android:name=".receiver.MediaButtonReceiver"
@@ -1,5 +1,6 @@
package io.legado.app.service
import android.annotation.SuppressLint
import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
@@ -39,9 +40,13 @@ class DownloadService : BaseService() {
}
}
@SuppressLint("UnspecifiedRegisterReceiverFlag")
override fun onCreate() {
super.onCreate()
registerReceiver(downloadReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
registerReceiver(
downloadReceiver,
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
)
}
override fun onDestroy() {
@@ -55,6 +60,7 @@ class DownloadService : BaseService() {
intent.getStringExtra("url"),
intent.getStringExtra("fileName")
)
IntentAction.play -> {
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)
}
@@ -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<String, ExportConfig>()
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>("cacheActivity"))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentText(notificationContent)
.setDeleteIntent(servicePendingIntent<ExportBookService>(IntentAction.stop))
.setGroup(groupKey)
if (exportJob?.isActive == true) {
notification.setOngoing(true)
notification.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.cancel),
servicePendingIntent<ExportBookService>(IntentAction.stop)
)
} else {
notification.addAction(
R.drawable.ic_stop_black_24dp,
getString(R.string.close),
servicePendingIntent<ExportBookService>(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)