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