优化
This commit is contained in:
@@ -93,7 +93,6 @@ class ExportBookService : BaseService() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
private val groupKey = "${appCtx.packageName}.exportBook"
|
private val groupKey = "${appCtx.packageName}.exportBook"
|
||||||
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
|
||||||
private var notificationContentText = appCtx.getString(R.string.service_starting)
|
private var notificationContentText = appCtx.getString(R.string.service_starting)
|
||||||
@@ -111,6 +110,8 @@ class ExportBookService : BaseService() {
|
|||||||
epubScope = intent.getStringExtra("epubScope")
|
epubScope = intent.getStringExtra("epubScope")
|
||||||
)
|
)
|
||||||
waitExportBooks[bookUrl] = exportConfig
|
waitExportBooks[bookUrl] = exportConfig
|
||||||
|
exportMsg[bookUrl] = getString(R.string.export_wait)
|
||||||
|
postEvent(EventBus.EXPORT_BOOK, bookUrl)
|
||||||
export()
|
export()
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
@@ -163,18 +164,15 @@ class ExportBookService : BaseService() {
|
|||||||
if (exportJob?.isActive == true) {
|
if (exportJob?.isActive == true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val entry = waitExportBooks.firstNotNullOfOrNull { it }
|
exportJob = lifecycleScope.launch(IO) {
|
||||||
if (entry == null) {
|
while (true) {
|
||||||
|
val (bookUrl, exportConfig) = waitExportBooks.entries.firstOrNull() ?: let {
|
||||||
notificationContentText = "导出完成"
|
notificationContentText = "导出完成"
|
||||||
upExportNotification()
|
upExportNotification()
|
||||||
return
|
return@launch
|
||||||
}
|
}
|
||||||
val bookUrl = entry.key
|
|
||||||
val exportConfig = entry.value
|
|
||||||
if (exportProgress.contains(bookUrl)) return
|
|
||||||
exportProgress[bookUrl] = 0
|
exportProgress[bookUrl] = 0
|
||||||
waitExportBooks.remove(bookUrl)
|
waitExportBooks.remove(bookUrl)
|
||||||
exportJob = lifecycleScope.launch(IO) {
|
|
||||||
val book = appDb.bookDao.getBook(bookUrl)
|
val book = appDb.bookDao.getBook(bookUrl)
|
||||||
try {
|
try {
|
||||||
book ?: throw NoStackTraceException("获取${bookUrl}书籍出错")
|
book ?: throw NoStackTraceException("获取${bookUrl}书籍出错")
|
||||||
@@ -188,8 +186,10 @@ class ExportBookService : BaseService() {
|
|||||||
if (exportConfig.epubScope.isNullOrBlank()) {
|
if (exportConfig.epubScope.isNullOrBlank()) {
|
||||||
exportEPUB(exportConfig.path, book)
|
exportEPUB(exportConfig.path, book)
|
||||||
} else {
|
} else {
|
||||||
CustomExporter(paresScope(exportConfig.epubScope), exportConfig.epubSize)
|
CustomExporter(
|
||||||
.export(exportConfig.path, book)
|
paresScope(exportConfig.epubScope),
|
||||||
|
exportConfig.epubSize
|
||||||
|
).export(exportConfig.path, book)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
export(exportConfig.path, book)
|
export(exportConfig.path, book)
|
||||||
@@ -202,8 +202,6 @@ class ExportBookService : BaseService() {
|
|||||||
exportProgress.remove(bookUrl)
|
exportProgress.remove(bookUrl)
|
||||||
postEvent(EventBus.EXPORT_BOOK, bookUrl)
|
postEvent(EventBus.EXPORT_BOOK, bookUrl)
|
||||||
}
|
}
|
||||||
handler.post {
|
|
||||||
export()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1127,4 +1127,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1130,4 +1130,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1130,4 +1130,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1126,4 +1126,5 @@ Còn </string>
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1127,4 +1127,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1129,4 +1129,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1129,4 +1129,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1130,4 +1130,5 @@
|
|||||||
<string name="export_md">导出(MD)</string>
|
<string name="export_md">导出(MD)</string>
|
||||||
<string name="change_source_delay">换源间隔</string>
|
<string name="change_source_delay">换源间隔</string>
|
||||||
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
<string name="open_book_info_by_click_title">点击书名打开详情</string>
|
||||||
|
<string name="export_wait">等待导出</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user