From ef5beb67a7f82f61bbf248f785eefa31fcb2de70 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Nov 2022 21:24:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/association/AddToBookshelfDialog.kt | 24 +++--- .../main/res/layout/activity_book_info.xml | 2 +- .../res/layout/dialog_add_to_bookshelf.xml | 84 ++++++++++++++----- 3 files changed, 78 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt b/app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt index a6b62439e..144806c20 100644 --- a/app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt +++ b/app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt @@ -18,10 +18,7 @@ import io.legado.app.databinding.DialogAddToBookshelfBinding import io.legado.app.exception.NoStackTraceException import io.legado.app.model.webBook.WebBook import io.legado.app.ui.book.read.ReadBookActivity -import io.legado.app.utils.NetworkUtils -import io.legado.app.utils.setLayout -import io.legado.app.utils.startActivity -import io.legado.app.utils.toastOnUi +import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshelf) { @@ -59,6 +56,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe viewModel.loadStateLiveData.observe(this) { if (it) { binding.rotateLoading.show() + binding.bookInfo.invisible() } else { binding.rotateLoading.hide() } @@ -68,6 +66,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe dismiss() } viewModel.load(bookUrl) { + binding.bookInfo.visible() binding.tvName.text = it.name binding.tvAuthor.text = it.author binding.tvOrigin.text = it.originName @@ -77,18 +76,20 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe } binding.tvOk.setOnClickListener { viewModel.saveBook { - dismiss() + it?.let { + dismiss() + } ?: toastOnUi(R.string.no_book) } } binding.tvRead.setOnClickListener { viewModel.saveBook { - viewModel.book?.let { + it?.let { startActivity { putExtra("bookUrl", it.bookUrl) putExtra("inBookshelf", false) } - } - dismiss() + dismiss() + } ?: toastOnUi(R.string.no_book) } } } @@ -139,11 +140,12 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe } } - fun saveBook(finally: () -> Unit) { + fun saveBook(success: (book: Book?) -> Unit) { execute { book?.save() - }.onFinally { - finally.invoke() + book + }.onSuccess { + success.invoke(it) } } diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml index 7dbccbbdc..28a870568 100644 --- a/app/src/main/res/layout/activity_book_info.xml +++ b/app/src/main/res/layout/activity_book_info.xml @@ -139,7 +139,7 @@ + android:layout_height="wrap_content" + xmlns:tools="http://schemas.android.com/tools"> - + android:layout_marginHorizontal="16dp" + android:visibility="invisible" + app:layout_constraintTop_toBottomOf="@id/tv_title"> - + + + + + + + + + + + - + app:layout_constraintTop_toTopOf="@id/book_info" + app:layout_constraintBottom_toBottomOf="@+id/book_info" />