pull/2533/head
kunfei 2 years ago
parent 05472a9c71
commit bc758d6a20
  1. 29
      app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt
  2. 2
      app/src/main/java/io/legado/app/ui/association/OnLineImportActivity.kt
  3. 58
      app/src/main/res/layout/dialog_add_to_bookshelf.xml

@ -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<Boolean>()
val loadErrorLiveData = MutableLiveData<String>()
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()
}
}
}
}

@ -74,7 +74,7 @@ class OnLineImportActivity :
viewModel.importReadConfig(bytes, this::finallyDialog)
}
"/addToBookshelf" -> showDialogFragment(
AddToBookshelfDialog(url)
AddToBookshelfDialog(url, true)
)
"/importonline" -> when (it.host) {
"booksource" -> showDialogFragment(

@ -1,22 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_menu"
android:elevation="5dp"
android:theme="?attr/actionBarStyle"
app:displayHomeAsUp="false"
app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/add_book_url"
app:titleTextAppearance="@style/ToolbarTitle" />
android:padding="16dp"
android:text="@string/add_book_url"
android:textColor="@color/primaryText"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:minLines="3"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rotate_loading"
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_message"
app:layout_constraintBottom_toBottomOf="@+id/tv_message" />
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/ok"
app:layout_constraintTop_toBottomOf="@+id/tv_message"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
<TextView
android:id="@+id/tv_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/cancel"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/tv_ok" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save