更新章节是检查是否有目录url

pull/862/head
gedoor 4 years ago
parent e254932ae7
commit bfa9df9b48
  1. 39
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt

@ -14,7 +14,6 @@ import io.legado.app.model.webBook.WebBook
import io.legado.app.service.help.CacheBook import io.legado.app.service.help.CacheBook
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@ -76,28 +75,28 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
postEvent(EventBus.UP_BOOK, book.bookUrl) postEvent(EventBus.UP_BOOK, book.bookUrl)
} }
appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource -> appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource ->
val webBook = WebBook(bookSource) execute(context = upTocPool) {
webBook.getChapterList(this, book, context = upTocPool) val webBook = WebBook(bookSource)
.timeout(60000) if (book.tocUrl.isBlank()) {
.onSuccess(IO) { webBook.getBookInfoAwait(this, book)
appDb.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*it.toTypedArray())
if (AppConfig.preDownload) {
cacheBook(webBook, book)
}
} }
.onError { val toc = webBook.getChapterListAwait(this, book)
it.printStackTrace() appDb.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray())
if (AppConfig.preDownload) {
cacheBook(webBook, book)
} }
.onFinally { }.onError {
synchronized(this) { it.printStackTrace()
bookMap.remove(bookEntry.key) }.onFinally {
updateList.remove(book.bookUrl) synchronized(this) {
postEvent(EventBus.UP_BOOK, book.bookUrl) bookMap.remove(bookEntry.key)
upNext() updateList.remove(book.bookUrl)
} postEvent(EventBus.UP_BOOK, book.bookUrl)
upNext()
} }
}
} ?: synchronized(this) { } ?: synchronized(this) {
bookMap.remove(bookEntry.key) bookMap.remove(bookEntry.key)
updateList.remove(book.bookUrl) updateList.remove(book.bookUrl)

Loading…
Cancel
Save