pull/32/head
kunfei 5 years ago
parent d0f3702248
commit b541ed2e2e
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 7
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt
  4. 5
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt

@ -29,7 +29,7 @@ interface BookSourceDao {
val allEnabled: List<BookSource> val allEnabled: List<BookSource>
@Query("select * from book_sources where bookSourceUrl = :key") @Query("select * from book_sources where bookSourceUrl = :key")
fun findByKey(key: String): BookSource? fun getBookSource(key: String): BookSource?
@Query("select count(*) from book_sources") @Query("select count(*) from book_sources")
fun allCount(): Int fun allCount(): Int

@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf
import android.app.Application import android.app.Application
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.BookType
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
class BookshelfViewModel(application: Application) : BaseViewModel(application) { class BookshelfViewModel(application: Application) : BaseViewModel(application) {
@ -23,8 +24,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
fun upChapterList() { fun upChapterList() {
execute { execute {
App.db.bookDao().getRecentRead().map { App.db.bookDao().getRecentRead().map { book ->
if (book.origin != BookType.local) {
val bookSource = App.db.bookSourceDao().getBookSource(book.origin)
}
} }
} }
} }

@ -19,7 +19,7 @@ class ReadViewModel(application: Application) : BaseViewModel(application) {
book = App.db.bookDao().getBook(bookUrl) book = App.db.bookDao().getBook(bookUrl)
book?.let { book -> book?.let { book ->
if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) {
bookSource = App.db.bookSourceDao().findByKey(book.origin) bookSource = App.db.bookSourceDao().getBookSource(book.origin)
if (bookSource == null) { if (bookSource == null) {
} }

@ -3,11 +3,8 @@ package io.legado.app.ui.sourcedebug
import android.app.Application import android.app.Application
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.Bus
import io.legado.app.help.EventMessage
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.model.webbook.SourceDebug import io.legado.app.model.webbook.SourceDebug
import io.legado.app.utils.postEvent
class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback {
@ -19,7 +16,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S
sourceUrl?.let { sourceUrl?.let {
//优先使用这个,不会抛出异常 //优先使用这个,不会抛出异常
execute { execute {
val bookSource = App.db.bookSourceDao().findByKey(sourceUrl) val bookSource = App.db.bookSourceDao().getBookSource(sourceUrl)
bookSource?.let { webBook = WebBook(it) } bookSource?.let { webBook = WebBook(it) }
} }
} }

@ -14,7 +14,7 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application)
fun setBookSource(key: String) { fun setBookSource(key: String) {
launch(IO) { launch(IO) {
App.db.bookSourceDao().findByKey(key)?.let { App.db.bookSourceDao().getBookSource(key)?.let {
sourceLiveData.postValue(it) sourceLiveData.postValue(it)
} ?: sourceLiveData.postValue(BookSource()) } ?: sourceLiveData.postValue(BookSource())
} }

Loading…
Cancel
Save