diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt index 7f42d74d8..20d233149 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt @@ -16,6 +16,8 @@ interface BookChapterDao { @Query("select * from chapters where bookUrl = :bookUrl and `index` = :index") fun getChapter(bookUrl: String, index: Int): BookChapter? + @Query("select count(url) from chapters where bookUrl = :bookUrl") + fun getChapterCount(bookUrl: String): Int @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookChapter: BookChapter) 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 670ed6b6c..58bd7a36c 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 @@ -30,6 +30,9 @@ interface BookDao { @Query("SELECT * FROM books WHERE `name` in (:names)") fun findByName(vararg names: String): List + @Query("select * from books where bookUrl = :bookUrl") + fun getBook(bookUrl: String): Book? + @get:Query("SELECT bookUrl FROM books") val allBookUrls: List 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 4528e2d1a..d27ba5dc9 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 @@ -2,18 +2,31 @@ package io.legado.app.ui.read import android.app.Application import android.content.Intent -import androidx.lifecycle.MutableLiveData +import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookSource class ReadViewModel(application: Application) : BaseViewModel(application) { - val bookData = MutableLiveData() + var book: Book? = null + var bookSource: BookSource? = null fun initData(intent: Intent) { val bookUrl = intent.getStringExtra("bookUrl") if (!bookUrl.isNullOrEmpty()) { + execute { + book = App.db.bookDao().getBook(bookUrl) + book?.let { book -> + if (App.db.bookChapterDao().getChapterCount(bookUrl) == 0) { + bookSource = App.db.bookSourceDao().findByKey(book.origin) + if (bookSource == null) { + } + } + } + + } } }