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 f9d02b541..5b6353d67 100644
--- a/app/src/main/java/io/legado/app/service/ExportBookService.kt
+++ b/app/src/main/java/io/legado/app/service/ExportBookService.kt
@@ -93,7 +93,6 @@ class ExportBookService : BaseService() {
)
private val groupKey = "${appCtx.packageName}.exportBook"
- private val handler = buildMainHandler()
private val waitExportBooks = linkedMapOf()
private var exportJob: Job? = null
private var notificationContentText = appCtx.getString(R.string.service_starting)
@@ -111,6 +110,8 @@ class ExportBookService : BaseService() {
epubScope = intent.getStringExtra("epubScope")
)
waitExportBooks[bookUrl] = exportConfig
+ exportMsg[bookUrl] = getString(R.string.export_wait)
+ postEvent(EventBus.EXPORT_BOOK, bookUrl)
export()
}
}.onFailure {
@@ -163,47 +164,44 @@ class ExportBookService : BaseService() {
if (exportJob?.isActive == true) {
return
}
- val entry = waitExportBooks.firstNotNullOfOrNull { it }
- if (entry == null) {
- notificationContentText = "导出完成"
- upExportNotification()
- return
- }
- val bookUrl = entry.key
- val exportConfig = entry.value
- if (exportProgress.contains(bookUrl)) return
- exportProgress[bookUrl] = 0
- waitExportBooks.remove(bookUrl)
exportJob = lifecycleScope.launch(IO) {
- val book = appDb.bookDao.getBook(bookUrl)
- try {
- book ?: throw NoStackTraceException("获取${bookUrl}书籍出错")
- notificationContentText = getString(
- R.string.export_book_notification_content,
- book.name,
- waitExportBooks.size
- )
- upExportNotification()
- if (exportConfig.type == "epub") {
- if (exportConfig.epubScope.isNullOrBlank()) {
- exportEPUB(exportConfig.path, book)
+ while (true) {
+ val (bookUrl, exportConfig) = waitExportBooks.entries.firstOrNull() ?: let {
+ notificationContentText = "导出完成"
+ upExportNotification()
+ return@launch
+ }
+ exportProgress[bookUrl] = 0
+ waitExportBooks.remove(bookUrl)
+ val book = appDb.bookDao.getBook(bookUrl)
+ try {
+ book ?: throw NoStackTraceException("获取${bookUrl}书籍出错")
+ notificationContentText = getString(
+ R.string.export_book_notification_content,
+ book.name,
+ waitExportBooks.size
+ )
+ upExportNotification()
+ if (exportConfig.type == "epub") {
+ if (exportConfig.epubScope.isNullOrBlank()) {
+ exportEPUB(exportConfig.path, book)
+ } else {
+ CustomExporter(
+ paresScope(exportConfig.epubScope),
+ exportConfig.epubSize
+ ).export(exportConfig.path, book)
+ }
} else {
- CustomExporter(paresScope(exportConfig.epubScope), exportConfig.epubSize)
- .export(exportConfig.path, book)
+ export(exportConfig.path, book)
}
- } else {
- export(exportConfig.path, book)
+ exportMsg[book.bookUrl] = getString(R.string.export_success)
+ } catch (e: Throwable) {
+ exportMsg[bookUrl] = e.localizedMessage ?: "ERROR"
+ AppLog.put("导出书籍<${book?.name ?: bookUrl}>出错", e)
+ } finally {
+ exportProgress.remove(bookUrl)
+ postEvent(EventBus.EXPORT_BOOK, bookUrl)
}
- exportMsg[book.bookUrl] = getString(R.string.export_success)
- } catch (e: Throwable) {
- exportMsg[bookUrl] = e.localizedMessage ?: "ERROR"
- AppLog.put("导出书籍<${book?.name ?: bookUrl}>出错", e)
- } finally {
- exportProgress.remove(bookUrl)
- postEvent(EventBus.EXPORT_BOOK, bookUrl)
- }
- handler.post {
- export()
}
}
}
diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml
index 64a02416e..7500824fa 100644
--- a/app/src/main/res/values-es-rES/strings.xml
+++ b/app/src/main/res/values-es-rES/strings.xml
@@ -1127,4 +1127,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml
index 1c86d0b6c..4a49f09d8 100644
--- a/app/src/main/res/values-ja-rJP/strings.xml
+++ b/app/src/main/res/values-ja-rJP/strings.xml
@@ -1130,4 +1130,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index af2703f1a..5c24dc941 100644
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -1130,4 +1130,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml
index 6f7183e50..8992615d5 100644
--- a/app/src/main/res/values-vi/strings.xml
+++ b/app/src/main/res/values-vi/strings.xml
@@ -1126,4 +1126,5 @@ Còn
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
\ No newline at end of file
diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml
index 6dca930f6..5e7be45d5 100644
--- a/app/src/main/res/values-zh-rHK/strings.xml
+++ b/app/src/main/res/values-zh-rHK/strings.xml
@@ -1127,4 +1127,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml
index 1754cd749..804cef6dd 100644
--- a/app/src/main/res/values-zh-rTW/strings.xml
+++ b/app/src/main/res/values-zh-rTW/strings.xml
@@ -1129,4 +1129,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index e88d33d01..c89a7f0b0 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -1129,4 +1129,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ed5967110..605dbe826 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1130,4 +1130,5 @@
导出(MD)
换源间隔
点击书名打开详情
+ 等待导出