From 3651422291bb1036610f794ccf52de5960b5f1bd Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 6 Dec 2019 11:49:40 +0800 Subject: [PATCH] up --- .../ui/book/info/edit/BookInfoEditActivity.kt | 27 ++++++++++++------- .../book/info/edit/BookInfoEditViewModel.kt | 10 +++---- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 0361c462d..297951b40 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -8,11 +8,11 @@ import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book +import io.legado.app.help.ImageLoader import io.legado.app.ui.changecover.ChangeCoverDialog import io.legado.app.utils.getViewModel import kotlinx.android.synthetic.main.activity_book_info_edit.* import org.jetbrains.anko.sdk27.listeners.onClick -import org.jetbrains.anko.toast class BookInfoEditActivity : VMBaseActivity(R.layout.activity_book_info_edit), @@ -55,6 +55,15 @@ class BookInfoEditActivity : tie_book_author.setText(book.author) tie_cover_url.setText(book.getDisplayCover()) tie_book_intro.setText(book.getDisplayIntro()) + upCover() + } + + private fun upCover() { + viewModel.book?.getDisplayCover()?.let { + ImageLoader.load(this, it) + .centerCrop() + .into(iv_cover) + } } private fun saveData() { @@ -64,18 +73,16 @@ class BookInfoEditActivity : val customCoverUrl = tie_cover_url.text?.toString() book.customCoverUrl = if (customCoverUrl == book.coverUrl) null else customCoverUrl book.customIntro = tie_book_intro.text?.toString() - viewModel.saveBook(book, - success = { - setResult(Activity.RESULT_OK) - finish() - }, - error = { - toast(it) - }) + viewModel.saveBook(book) { + setResult(Activity.RESULT_OK) + finish() + } } } override fun coverChangeTo(coverUrl: String) { - + viewModel.book?.customCoverUrl = coverUrl + tie_cover_url.setText(coverUrl) + upCover() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt index a947719cd..66602c1d7 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt @@ -7,25 +7,23 @@ import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book class BookInfoEditViewModel(application: Application) : BaseViewModel(application) { - + var book: Book? = null val bookData = MutableLiveData() - fun loadBook(bookUrl: String) { execute { - App.db.bookDao().getBook(bookUrl)?.let { + book = App.db.bookDao().getBook(bookUrl) + book?.let { bookData.postValue(it) } } } - fun saveBook(book: Book, success: (() -> Unit)?, error: ((msg: String) -> Unit)?) { + fun saveBook(book: Book, success: (() -> Unit)?) { execute { App.db.bookDao().insert(book) }.onSuccess { success?.invoke() - }.onError { - error?.invoke(it.localizedMessage) } } } \ No newline at end of file