From bdfb60c4867b4cebc483fbcdf2edb6b75ed00064 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Dec 2019 20:33:15 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/dao/BookDao.kt | 3 ++ .../io/legado/app/ui/main/MainViewModel.kt | 51 +++++++++---------- .../ui/main/bookshelf/BookshelfViewModel.kt | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index c2bce5278..42e76ddd6 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -32,6 +32,9 @@ interface BookDao { @Query("SELECT * FROM books WHERE bookUrl = :bookUrl") fun getBook(bookUrl: String): Book? + @get:Query("SELECT * FROM books where origin <> '${BookType.local}' and type = 0") + val webBooks: List + @get:Query("SELECT * FROM books where origin <> '${BookType.local}' and canUpdate = 1") val hasUpdateBooks: List diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 3bb9df417..647b0bac2 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -3,7 +3,6 @@ package io.legado.app.ui.main import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.constant.BookType import io.legado.app.constant.Bus import io.legado.app.model.WebBook import io.legado.app.utils.postEvent @@ -16,34 +15,32 @@ class MainViewModel(application: Application) : BaseViewModel(application) { fun upChapterList() { execute { App.db.bookDao().hasUpdateBooks.forEach { book -> - if (book.origin != BookType.local) { - if (!updateList.contains(book.bookUrl)) { - App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - synchronized(this) { - updateList.add(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) - } - WebBook(bookSource).getChapterList(book) - .timeout(300000) - .onSuccess(IO) { - synchronized(this) { - updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) - } - it?.let { - App.db.bookDao().update(book) - App.db.bookChapterDao().delByBook(book.bookUrl) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } + if (!updateList.contains(book.bookUrl)) { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + synchronized(this) { + updateList.add(book.bookUrl) + postEvent(Bus.UP_BOOK, book.bookUrl) + } + WebBook(bookSource).getChapterList(book) + .timeout(300000) + .onSuccess(IO) { + synchronized(this) { + updateList.remove(book.bookUrl) + postEvent(Bus.UP_BOOK, book.bookUrl) } - .onError { - synchronized(this) { - updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) - } - it.printStackTrace() + it?.let { + App.db.bookDao().update(book) + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) } - } + } + .onError { + synchronized(this) { + updateList.remove(book.bookUrl) + postEvent(Bus.UP_BOOK, book.bookUrl) + } + it.printStackTrace() + } } } delay(50) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 806cff675..7f116694e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -35,7 +35,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun downloadAll() { execute { - App.db.bookDao().hasUpdateBooks.forEach { book -> + App.db.bookDao().webBooks.forEach { book -> Download.start(context, book.bookUrl, book.durChapterIndex, book.totalChapterNum) } }