pull/1759/head
kunfei 3 years ago
parent 465f61da80
commit d5e7d05e47
  1. 12
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 16
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -270,7 +270,7 @@ class BookInfoActivity :
showDialogFragment( showDialogFragment(
ChangeCoverDialog(it.name, it.author) ChangeCoverDialog(it.name, it.author)
) )
} } ?: toastOnUi("Book is null")
} }
ivCover.setOnLongClickListener { ivCover.setOnLongClickListener {
viewModel.bookData.value?.getDisplayCover()?.let { path -> viewModel.bookData.value?.getDisplayCover()?.let { path ->
@ -281,7 +281,7 @@ class BookInfoActivity :
tvRead.setOnClickListener { tvRead.setOnClickListener {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
readBook(it) readBook(it)
} } ?: toastOnUi("Book is null")
} }
tvShelf.setOnClickListener { tvShelf.setOnClickListener {
if (viewModel.inBookshelf) { if (viewModel.inBookshelf) {
@ -297,10 +297,12 @@ class BookInfoActivity :
startActivity<BookSourceEditActivity> { startActivity<BookSourceEditActivity> {
putExtra("sourceUrl", it.origin) putExtra("sourceUrl", it.origin)
} }
} } ?: toastOnUi("Book is null")
} }
tvChangeSource.setOnClickListener { tvChangeSource.setOnClickListener {
showDialogFragment(ChangeBookSourceDialog(viewModel.name, viewModel.author)) viewModel.bookData.value?.let { book ->
showDialogFragment(ChangeBookSourceDialog(book.name, book.author))
} ?: toastOnUi("Book is null")
} }
tvTocView.setOnClickListener { tvTocView.setOnClickListener {
if (!viewModel.inBookshelf) { if (!viewModel.inBookshelf) {
@ -318,7 +320,7 @@ class BookInfoActivity :
showDialogFragment( showDialogFragment(
GroupSelectDialog(it.group) GroupSelectDialog(it.group)
) )
} } ?: toastOnUi("Book is null")
} }
tvAuthor.setOnClickListener { tvAuthor.setOnClickListener {
startActivity<SearchActivity> { startActivity<SearchActivity> {

@ -27,8 +27,6 @@ import kotlinx.coroutines.Dispatchers.IO
class BookInfoViewModel(application: Application) : BaseViewModel(application) { class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val bookData = MutableLiveData<Book>() val bookData = MutableLiveData<Book>()
val chapterListData = MutableLiveData<List<BookChapter>>() val chapterListData = MutableLiveData<List<BookChapter>>()
var name = ""
var author = ""
var durChapterIndex = 0 var durChapterIndex = 0
var inBookshelf = false var inBookshelf = false
var bookSource: BookSource? = null var bookSource: BookSource? = null
@ -36,22 +34,22 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {
name = intent.getStringExtra("name") ?: "" val name = intent.getStringExtra("name") ?: ""
author = intent.getStringExtra("author") ?: "" val author = intent.getStringExtra("author") ?: ""
val bookUrl = intent.getStringExtra("bookUrl") ?: "" val bookUrl = intent.getStringExtra("bookUrl") ?: ""
appDb.bookDao.getBook(name, author)?.let { appDb.bookDao.getBook(name, author)?.let {
inBookshelf = true inBookshelf = true
setBook(it) upBook(it)
return@execute return@execute
} }
if (bookUrl.isNotBlank()) { if (bookUrl.isNotBlank()) {
appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let { appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let {
setBook(it) upBook(it)
return@execute return@execute
} }
} }
appDb.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { appDb.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let {
setBook(it) upBook(it)
return@execute return@execute
} }
throw NoStackTraceException("未找到书籍") throw NoStackTraceException("未找到书籍")
@ -65,12 +63,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val name = intent.getStringExtra("name") ?: "" val name = intent.getStringExtra("name") ?: ""
val author = intent.getStringExtra("author") ?: "" val author = intent.getStringExtra("author") ?: ""
appDb.bookDao.getBook(name, author)?.let { book -> appDb.bookDao.getBook(name, author)?.let { book ->
setBook(book) upBook(book)
} }
} }
} }
private fun setBook(book: Book) { private fun upBook(book: Book) {
execute { execute {
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
bookData.postValue(book) bookData.postValue(book)

Loading…
Cancel
Save