feat: 优化代码

pull/105/head
kunfei 5 years ago
parent 708b25624f
commit c2f314cf99
  1. 3
      app/src/main/java/io/legado/app/service/DownloadService.kt

@ -18,6 +18,7 @@ import io.legado.app.model.WebBook
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.isActive
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.util.concurrent.Executors import java.util.concurrent.Executors
@ -93,12 +94,14 @@ class DownloadService : BaseService() {
private fun download() { private fun download() {
val task = Coroutine.async(this, context = searchPool) { val task = Coroutine.async(this, context = searchPool) {
downloadMap.forEach { entry -> downloadMap.forEach { entry ->
if (!isActive) return@async
if (!finalMap.containsKey(entry.key)) { if (!finalMap.containsKey(entry.key)) {
val book = App.db.bookDao().getBook(entry.key) ?: return@async val book = App.db.bookDao().getBook(entry.key) ?: return@async
val bookSource = val bookSource =
App.db.bookSourceDao().getBookSource(book.origin) ?: return@async App.db.bookSourceDao().getBookSource(book.origin) ?: return@async
val webBook = WebBook(bookSource) val webBook = WebBook(bookSource)
entry.value.forEach { chapter -> entry.value.forEach { chapter ->
if (!isActive) return@async
if (!BookHelp.hasContent(book, chapter)) { if (!BookHelp.hasContent(book, chapter)) {
webBook.getContent(book, chapter, scope = this, context = searchPool) webBook.getContent(book, chapter, scope = this, context = searchPool)
.onStart { .onStart {

Loading…
Cancel
Save