From 1989e36902329236d08ec44f18085b331dac5e82 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 10 Aug 2019 11:08:11 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/BookChapterDao.kt | 2 ++ .../main/java/io/legado/app/data/dao/BookDao.kt | 3 +++ .../java/io/legado/app/ui/read/ReadViewModel.kt | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) 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) { + } + } + } + + } } }