优化
This commit is contained in:
@@ -186,11 +186,6 @@
|
|||||||
android:name=".ui.about.AboutActivity"
|
android:name=".ui.about.AboutActivity"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:screenOrientation="behind" />
|
android:screenOrientation="behind" />
|
||||||
<!-- 捐赠界面 -->
|
|
||||||
<activity
|
|
||||||
android:name=".ui.about.DonateActivity"
|
|
||||||
android:launchMode="singleTask"
|
|
||||||
android:screenOrientation="behind" />
|
|
||||||
<!-- 书源管理 -->
|
<!-- 书源管理 -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.book.source.manage.BookSourceActivity"
|
android:name=".ui.book.source.manage.BookSourceActivity"
|
||||||
@@ -432,7 +427,9 @@
|
|||||||
<service android:name=".service.TTSReadAloudService" />
|
<service android:name=".service.TTSReadAloudService" />
|
||||||
<service android:name=".service.HttpReadAloudService" />
|
<service android:name=".service.HttpReadAloudService" />
|
||||||
<service android:name=".service.AudioPlayService" />
|
<service android:name=".service.AudioPlayService" />
|
||||||
<service android:name=".service.DownloadService" />
|
<service
|
||||||
|
android:name=".service.DownloadService"
|
||||||
|
android:exported="" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".receiver.MediaButtonReceiver"
|
android:name=".receiver.MediaButtonReceiver"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.legado.app.service
|
package io.legado.app.service
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.DownloadManager
|
import android.app.DownloadManager
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -39,9 +40,13 @@ class DownloadService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
registerReceiver(downloadReceiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
|
registerReceiver(
|
||||||
|
downloadReceiver,
|
||||||
|
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
@@ -55,6 +60,7 @@ class DownloadService : BaseService() {
|
|||||||
intent.getStringExtra("url"),
|
intent.getStringExtra("url"),
|
||||||
intent.getStringExtra("fileName")
|
intent.getStringExtra("fileName")
|
||||||
)
|
)
|
||||||
|
|
||||||
IntentAction.play -> {
|
IntentAction.play -> {
|
||||||
val id = intent.getLongExtra("downloadId", 0)
|
val id = intent.getLongExtra("downloadId", 0)
|
||||||
if (completeDownloads.contains(id)) {
|
if (completeDownloads.contains(id)) {
|
||||||
@@ -63,6 +69,7 @@ class DownloadService : BaseService() {
|
|||||||
toastOnUi("未完成,下载的文件夹Download")
|
toastOnUi("未完成,下载的文件夹Download")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IntentAction.stop -> {
|
IntentAction.stop -> {
|
||||||
val downloadId = intent.getLongExtra("downloadId", 0)
|
val downloadId = intent.getLongExtra("downloadId", 0)
|
||||||
removeDownload(downloadId)
|
removeDownload(downloadId)
|
||||||
@@ -177,6 +184,7 @@ class DownloadService : BaseService() {
|
|||||||
successDownload(id)
|
successDownload(id)
|
||||||
getString(R.string.download_success)
|
getString(R.string.download_success)
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
|
DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
|
||||||
else -> getString(R.string.unknown_state)
|
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.epub.EpubWriterProcessor
|
||||||
import me.ag2s.epublib.util.ResourceUtil
|
import me.ag2s.epublib.util.ResourceUtil
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
import splitties.systemservices.notificationManager
|
||||||
import java.io.BufferedOutputStream
|
import java.io.BufferedOutputStream
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -87,6 +88,7 @@ class ExportBookService : BaseService() {
|
|||||||
val epubScope: String? = null
|
val epubScope: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val groupKey = "${appCtx.packageName}.exportBook"
|
||||||
private val handler = buildMainHandler()
|
private val handler = buildMainHandler()
|
||||||
private val waitExportBooks = linkedMapOf<String, ExportConfig>()
|
private val waitExportBooks = linkedMapOf<String, ExportConfig>()
|
||||||
private var exportJob: Job? = null
|
private var exportJob: Job? = null
|
||||||
@@ -125,26 +127,34 @@ class ExportBookService : BaseService() {
|
|||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
override fun upNotification() {
|
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)
|
val notification = NotificationCompat.Builder(this, AppConst.channelIdDownload)
|
||||||
.setSmallIcon(R.drawable.ic_export)
|
.setSmallIcon(R.drawable.ic_export)
|
||||||
.setContentTitle(getString(R.string.export_book))
|
.setContentTitle(getString(R.string.export_book))
|
||||||
.setContentIntent(activityPendingIntent<CacheActivity>("cacheActivity"))
|
.setContentIntent(activityPendingIntent<CacheActivity>("cacheActivity"))
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setContentText(notificationContent)
|
.setContentText(notificationContent)
|
||||||
|
.setDeleteIntent(servicePendingIntent<ExportBookService>(IntentAction.stop))
|
||||||
|
.setGroup(groupKey)
|
||||||
if (exportJob?.isActive == true) {
|
if (exportJob?.isActive == true) {
|
||||||
|
notification.setOngoing(true)
|
||||||
notification.addAction(
|
notification.addAction(
|
||||||
R.drawable.ic_stop_black_24dp,
|
R.drawable.ic_stop_black_24dp,
|
||||||
getString(R.string.cancel),
|
getString(R.string.cancel),
|
||||||
servicePendingIntent<ExportBookService>(IntentAction.stop)
|
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() {
|
private fun export() {
|
||||||
@@ -154,7 +164,7 @@ class ExportBookService : BaseService() {
|
|||||||
val entry = waitExportBooks.firstNotNullOfOrNull { it }
|
val entry = waitExportBooks.firstNotNullOfOrNull { it }
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
notificationContent = "导出完成"
|
notificationContent = "导出完成"
|
||||||
upNotification()
|
upExportNotification()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val bookUrl = entry.key
|
val bookUrl = entry.key
|
||||||
@@ -171,7 +181,7 @@ class ExportBookService : BaseService() {
|
|||||||
book.name,
|
book.name,
|
||||||
waitExportBooks.size
|
waitExportBooks.size
|
||||||
)
|
)
|
||||||
upNotification()
|
upExportNotification()
|
||||||
if (exportConfig.type == "epub") {
|
if (exportConfig.type == "epub") {
|
||||||
if (exportConfig.epubScope.isNullOrBlank()) {
|
if (exportConfig.epubScope.isNullOrBlank()) {
|
||||||
exportEPUB(exportConfig.path, book)
|
exportEPUB(exportConfig.path, book)
|
||||||
|
|||||||
Reference in New Issue
Block a user