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

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

Loading…
Cancel
Save