pull/32/head
kunfei 5 years ago
parent 68aeaa5ecb
commit 1989e36902
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
  2. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  3. 17
      app/src/main/java/io/legado/app/ui/read/ReadViewModel.kt

@ -16,6 +16,8 @@ interface BookChapterDao {
@Query("select * from chapters where bookUrl = :bookUrl and `index` = :index") @Query("select * from chapters where bookUrl = :bookUrl and `index` = :index")
fun getChapter(bookUrl: String, index: Int): BookChapter? 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) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookChapter: BookChapter) fun insert(vararg bookChapter: BookChapter)

@ -30,6 +30,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE `name` in (:names)") @Query("SELECT * FROM books WHERE `name` in (:names)")
fun findByName(vararg names: String): List<Book> fun findByName(vararg names: String): List<Book>
@Query("select * from books where bookUrl = :bookUrl")
fun getBook(bookUrl: String): Book?
@get:Query("SELECT bookUrl FROM books") @get:Query("SELECT bookUrl FROM books")
val allBookUrls: List<String> val allBookUrls: List<String>

@ -2,19 +2,32 @@ package io.legado.app.ui.read
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
class ReadViewModel(application: Application) : BaseViewModel(application) { class ReadViewModel(application: Application) : BaseViewModel(application) {
val bookData = MutableLiveData<Book>() var book: Book? = null
var bookSource: BookSource? = null
fun initData(intent: Intent) { fun initData(intent: Intent) {
val bookUrl = intent.getStringExtra("bookUrl") val bookUrl = intent.getStringExtra("bookUrl")
if (!bookUrl.isNullOrEmpty()) { 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) {
} }
} }
}
}
}
}
} }
Loading…
Cancel
Save