From bc758d6a20a20096c7a53c9cca5f3a65afc55036 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 6 Nov 2022 18:24:34 +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 | 29 +++++++++- .../ui/association/OnLineImportActivity.kt | 2 +- .../res/layout/dialog_add_to_bookshelf.xml | 58 ++++++++++++++----- 3 files changed, 72 insertions(+), 17 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 6fbf12678..3b63907f6 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 @@ -53,13 +53,26 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe return } viewModel.loadStateLiveData.observe(this) { - //todo + if (it) { + binding.rotateLoading.show() + } else { + binding.rotateLoading.hide() + } } viewModel.loadErrorLiveData.observe(this) { - //todo + toastOnUi(it) + dismiss() } viewModel.load(bookUrl) { - //todo + binding.tvMessage + } + binding.tvCancel.setOnClickListener { + dismiss() + } + binding.tvOk.setOnClickListener { + viewModel.saveBook { + dismiss() + } } } @@ -67,6 +80,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe val loadStateLiveData = MutableLiveData() val loadErrorLiveData = MutableLiveData() + var book: Book? = null fun load(bookUrl: String, success: (book: Book) -> Unit) { execute { @@ -99,6 +113,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe AppLog.put("添加书籍 ${bookUrl} 出错", it) loadErrorLiveData.postValue(it.localizedMessage) }.onSuccess { + book = it success.invoke(it) }.onStart { loadStateLiveData.postValue(true) @@ -107,6 +122,14 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe } } + fun saveBook(finally: () -> Unit) { + execute { + book?.save() + }.onFinally { + finally.invoke() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt index bed546b4b..3d6e9bd45 100644 --- a/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt @@ -74,7 +74,7 @@ class OnLineImportActivity : viewModel.importReadConfig(bytes, this::finallyDialog) } "/addToBookshelf" -> showDialogFragment( - AddToBookshelfDialog(url) + AddToBookshelfDialog(url, true) ) "/importonline" -> when (it.host) { "booksource" -> showDialogFragment( diff --git a/app/src/main/res/layout/dialog_add_to_bookshelf.xml b/app/src/main/res/layout/dialog_add_to_bookshelf.xml index c82bd527b..88bef49aa 100644 --- a/app/src/main/res/layout/dialog_add_to_bookshelf.xml +++ b/app/src/main/res/layout/dialog_add_to_bookshelf.xml @@ -1,22 +1,54 @@ + android:layout_height="wrap_content"> - + android:padding="16dp" + android:text="@string/add_book_url" + android:textColor="@color/primaryText" + android:textSize="16sp" + android:textStyle="bold" + app:layout_constraintTop_toTopOf="parent" /> + + + + + + + \ No newline at end of file