From b541ed2e2eac8a87d06faee9ad6aa16c2cd2bdff Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 13 Aug 2019 21:26:38 +0800 Subject: [PATCH] up --- app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt | 2 +- .../io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 7 +++++-- app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt | 2 +- .../java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt | 5 +---- .../io/legado/app/ui/sourceedit/SourceEditViewModel.kt | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index ddc2fdc1b..5270d3c5f 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -29,7 +29,7 @@ interface BookSourceDao { val allEnabled: List @Query("select * from book_sources where bookSourceUrl = :key") - fun findByKey(key: String): BookSource? + fun getBookSource(key: String): BookSource? @Query("select count(*) from book_sources") fun allCount(): Int 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 99f495040..a146bf845 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 @@ -3,6 +3,7 @@ package io.legado.app.ui.main.bookshelf 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.data.entities.BookGroup class BookshelfViewModel(application: Application) : BaseViewModel(application) { @@ -23,8 +24,10 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun upChapterList() { 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) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt b/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt index d27ba5dc9..fed906c6b 100644 --- a/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt @@ -19,7 +19,7 @@ class ReadViewModel(application: Application) : BaseViewModel(application) { book = App.db.bookDao().getBook(bookUrl) book?.let { book -> if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { - bookSource = App.db.bookSourceDao().findByKey(book.origin) + bookSource = App.db.bookSourceDao().getBookSource(book.origin) if (bookSource == null) { } diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt index 6d5689ad4..6873a30cb 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt @@ -3,11 +3,8 @@ package io.legado.app.ui.sourcedebug import android.app.Application import io.legado.app.App 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.SourceDebug -import io.legado.app.utils.postEvent class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { @@ -19,7 +16,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S sourceUrl?.let { //优先使用这个,不会抛出异常 execute { - val bookSource = App.db.bookSourceDao().findByKey(sourceUrl) + val bookSource = App.db.bookSourceDao().getBookSource(sourceUrl) bookSource?.let { webBook = WebBook(it) } } } diff --git a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt index e65cc5c94..90b72305c 100644 --- a/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourceedit/SourceEditViewModel.kt @@ -14,7 +14,7 @@ class SourceEditViewModel(application: Application) : BaseViewModel(application) fun setBookSource(key: String) { launch(IO) { - App.db.bookSourceDao().findByKey(key)?.let { + App.db.bookSourceDao().getBookSource(key)?.let { sourceLiveData.postValue(it) } ?: sourceLiveData.postValue(BookSource()) }