pull/517/head
gedoor 4 years ago
parent 65890f5d91
commit 235558ea4e
  1. 30
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt

@ -54,26 +54,26 @@ class BookInfoEditActivity :
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }
private fun initEvent() { private fun initEvent() = with(binding) {
binding.tvChangeCover.onClick { tvChangeCover.onClick {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) ChangeCoverDialog.show(supportFragmentManager, it.name, it.author)
} }
} }
binding.tvSelectCover.onClick { tvSelectCover.onClick {
selectImage() selectImage()
} }
binding.tvRefreshCover.onClick { tvRefreshCover.onClick {
viewModel.book?.customCoverUrl = binding.tieCoverUrl.text?.toString() viewModel.book?.customCoverUrl = tieCoverUrl.text?.toString()
upCover() upCover()
} }
} }
private fun upView(book: Book) { private fun upView(book: Book) = with(binding) {
binding.tieBookName.setText(book.name) tieBookName.setText(book.name)
binding.tieBookAuthor.setText(book.author) tieBookAuthor.setText(book.author)
binding.tieCoverUrl.setText(book.getDisplayCover()) tieCoverUrl.setText(book.getDisplayCover())
binding.tieBookIntro.setText(book.getDisplayIntro()) tieBookIntro.setText(book.getDisplayIntro())
upCover() upCover()
} }
@ -83,13 +83,13 @@ class BookInfoEditActivity :
} }
} }
private fun saveData() { private fun saveData() = with(binding) {
viewModel.book?.let { book -> viewModel.book?.let { book ->
book.name = binding.tieBookName.text?.toString() ?: "" book.name = tieBookName.text?.toString() ?: ""
book.author = binding.tieBookAuthor.text?.toString() ?: "" book.author = tieBookAuthor.text?.toString() ?: ""
val customCoverUrl = binding.tieCoverUrl.text?.toString() val customCoverUrl = tieCoverUrl.text?.toString()
book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl
book.customIntro = binding.tieBookIntro.text?.toString() book.customIntro = tieBookIntro.text?.toString()
viewModel.saveBook(book) { viewModel.saveBook(book) {
setResult(Activity.RESULT_OK) setResult(Activity.RESULT_OK)
finish() finish()

Loading…
Cancel
Save