pull/1161/head
gedoor 3 years ago
parent 13f32499b4
commit 05cd5e24cd
  1. 14
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -32,12 +32,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) {
execute {
ReadBook.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
intent.getStringExtra("bookUrl")?.let {
appDb.bookDao.getBook(it)?.let { book ->
initBook(book)
}
} ?: appDb.bookDao.lastReadBook?.let {
initBook(it)
val bookUrl = intent.getStringExtra("bookUrl")
val book = when {
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
else -> appDb.bookDao.getBook(bookUrl)
} ?: ReadBook.book
when {
book != null -> initBook(book)
else -> ReadBook.upMsg(context.getString(R.string.no_book))
}
}.onFinally {
ReadBook.saveRead()

Loading…
Cancel
Save