优化
This commit is contained in:
@@ -111,7 +111,7 @@ object BookHelp {
|
|||||||
).writeText(content)
|
).writeText(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun saveImages(
|
suspend fun saveImages(
|
||||||
bookSource: BookSource,
|
bookSource: BookSource,
|
||||||
book: Book,
|
book: Book,
|
||||||
bookChapter: BookChapter,
|
bookChapter: BookChapter,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import io.legado.app.data.entities.BookSource
|
|||||||
import io.legado.app.exception.ConcurrentException
|
import io.legado.app.exception.ConcurrentException
|
||||||
import io.legado.app.help.book.BookHelp
|
import io.legado.app.help.book.BookHelp
|
||||||
import io.legado.app.help.book.isLocal
|
import io.legado.app.help.book.isLocal
|
||||||
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.service.CacheBookService
|
import io.legado.app.service.CacheBookService
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
@@ -247,12 +248,31 @@ object CacheBook {
|
|||||||
waitDownloadSet.remove(chapterIndex)
|
waitDownloadSet.remove(chapterIndex)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (BookHelp.hasContent(book, chapter)) {
|
if (BookHelp.hasImageContent(book, chapter)) {
|
||||||
waitDownloadSet.remove(chapterIndex)
|
waitDownloadSet.remove(chapterIndex)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
waitDownloadSet.remove(chapterIndex)
|
waitDownloadSet.remove(chapterIndex)
|
||||||
onDownloadSet.add(chapterIndex)
|
onDownloadSet.add(chapterIndex)
|
||||||
|
if (BookHelp.hasContent(book, chapter)) {
|
||||||
|
Coroutine.async {
|
||||||
|
BookHelp.getContent(book, chapter)?.let {
|
||||||
|
BookHelp.saveImages(bookSource, book, chapter, it)
|
||||||
|
}
|
||||||
|
}.onSuccess {
|
||||||
|
onSuccess(chapterIndex)
|
||||||
|
}.onError {
|
||||||
|
onPreError(chapterIndex, it)
|
||||||
|
//出现错误等待一秒后重新加入待下载列表
|
||||||
|
delay(1000)
|
||||||
|
onPostError(chapterIndex, it, chapter.title)
|
||||||
|
}.onCancel {
|
||||||
|
onCancel(chapterIndex)
|
||||||
|
}.onFinally {
|
||||||
|
onFinally()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
WebBook.getContent(
|
WebBook.getContent(
|
||||||
scope,
|
scope,
|
||||||
bookSource,
|
bookSource,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
val cacheNames = BookHelp.getChapterFiles(book)
|
val cacheNames = BookHelp.getChapterFiles(book)
|
||||||
if (cacheNames.isNotEmpty()) {
|
if (cacheNames.isNotEmpty()) {
|
||||||
appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
|
appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter ->
|
||||||
if (cacheNames.contains(chapter.getFileName())) {
|
if (cacheNames.contains(chapter.getFileName()) || chapter.isVolume) {
|
||||||
chapterCaches.add(chapter.url)
|
chapterCaches.add(chapter.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user