pull/2533/head
kunfei 2 years ago
parent 504b56f61b
commit ef5beb67a7
  1. 24
      app/src/main/java/io/legado/app/ui/association/AddToBookshelfDialog.kt
  2. 2
      app/src/main/res/layout/activity_book_info.xml
  3. 84
      app/src/main/res/layout/dialog_add_to_bookshelf.xml

@ -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<ReadBookActivity> {
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)
}
}

@ -139,7 +139,7 @@
<ImageView
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/origin_format"
android:contentDescription="@string/author"
android:paddingRight="2dp"
android:src="@drawable/ic_author"
app:tint="@color/tv_text_summary"

@ -2,7 +2,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="wrap_content">
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/tv_title"
@ -15,26 +16,69 @@
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_name"
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/book_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
android:layout_marginHorizontal="16dp"
android:visibility="invisible"
app:layout_constraintTop_toBottomOf="@id/tv_title">
<TextView
android:id="@+id/tv_author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
app:layout_constraintTop_toBottomOf="@+id/tv_name" />
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_author"
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/author"
android:paddingRight="2dp"
android:src="@drawable/ic_author"
app:tint="@color/tv_text_summary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_author"
app:layout_constraintBottom_toBottomOf="@+id/tv_author"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
app:layout_constraintLeft_toRightOf="@+id/iv_author"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="@+id/iv_origin"
android:layout_width="18sp"
android:layout_height="18sp"
android:contentDescription="@string/origin_format"
android:paddingRight="2dp"
android:src="@drawable/ic_web_outline"
app:tint="@color/tv_text_summary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_origin"
app:layout_constraintBottom_toBottomOf="@+id/tv_origin"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_origin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
app:layout_constraintLeft_toRightOf="@+id/iv_origin"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_author"
tools:ignore="RtlHardcoded" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tv_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="16dp"
app:layout_constraintTop_toBottomOf="@+id/tv_author" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rotate_loading"
@ -42,8 +86,8 @@
android:layout_height="48dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_name"
app:layout_constraintBottom_toBottomOf="@+id/tv_origin" />
app:layout_constraintTop_toTopOf="@id/book_info"
app:layout_constraintBottom_toBottomOf="@+id/book_info" />
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_ok"
@ -51,7 +95,7 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/ok"
app:layout_constraintTop_toBottomOf="@+id/tv_origin"
app:layout_constraintTop_toBottomOf="@+id/book_info"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />

Loading…
Cancel
Save