pull/32/head
kunfei 5 years ago
parent e2582c9452
commit d48741fb52
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 12
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -30,6 +30,9 @@ interface BookDao {
@Query("select * from books where bookUrl = :bookUrl")
fun getBook(bookUrl: String): Book?
@Query("select * from books order by durChapterTime desc limit 1")
fun getLastReadBook(): Book?
@get:Query("SELECT bookUrl FROM books")
val allBookUrls: List<String>

@ -36,11 +36,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
private val loadingLock = "loadingLock"
fun initData(intent: Intent) {
execute {
inBookshelf = intent.getBooleanExtra("inBookshelf", true)
val bookUrl = intent.getStringExtra("bookUrl")
if (!bookUrl.isNullOrEmpty()) {
execute {
App.db.bookDao().getBook(bookUrl)?.let { book ->
val book = if (!bookUrl.isNullOrEmpty()) {
App.db.bookDao().getBook(bookUrl)
} else {
App.db.bookDao().getLastReadBook()
}
book?.let {
durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local
@ -64,8 +68,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
chapterListFinish.postValue(true)
}
}
}
}
}

Loading…
Cancel
Save