mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
优化
This commit is contained in:
parent
504b56f61b
commit
ef5beb67a7
@ -18,10 +18,7 @@ import io.legado.app.databinding.DialogAddToBookshelfBinding
|
|||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.model.webBook.WebBook
|
import io.legado.app.model.webBook.WebBook
|
||||||
import io.legado.app.ui.book.read.ReadBookActivity
|
import io.legado.app.ui.book.read.ReadBookActivity
|
||||||
import io.legado.app.utils.NetworkUtils
|
import io.legado.app.utils.*
|
||||||
import io.legado.app.utils.setLayout
|
|
||||||
import io.legado.app.utils.startActivity
|
|
||||||
import io.legado.app.utils.toastOnUi
|
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshelf) {
|
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) {
|
viewModel.loadStateLiveData.observe(this) {
|
||||||
if (it) {
|
if (it) {
|
||||||
binding.rotateLoading.show()
|
binding.rotateLoading.show()
|
||||||
|
binding.bookInfo.invisible()
|
||||||
} else {
|
} else {
|
||||||
binding.rotateLoading.hide()
|
binding.rotateLoading.hide()
|
||||||
}
|
}
|
||||||
@ -68,6 +66,7 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
viewModel.load(bookUrl) {
|
viewModel.load(bookUrl) {
|
||||||
|
binding.bookInfo.visible()
|
||||||
binding.tvName.text = it.name
|
binding.tvName.text = it.name
|
||||||
binding.tvAuthor.text = it.author
|
binding.tvAuthor.text = it.author
|
||||||
binding.tvOrigin.text = it.originName
|
binding.tvOrigin.text = it.originName
|
||||||
@ -77,18 +76,20 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
|||||||
}
|
}
|
||||||
binding.tvOk.setOnClickListener {
|
binding.tvOk.setOnClickListener {
|
||||||
viewModel.saveBook {
|
viewModel.saveBook {
|
||||||
|
it?.let {
|
||||||
dismiss()
|
dismiss()
|
||||||
|
} ?: toastOnUi(R.string.no_book)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.tvRead.setOnClickListener {
|
binding.tvRead.setOnClickListener {
|
||||||
viewModel.saveBook {
|
viewModel.saveBook {
|
||||||
viewModel.book?.let {
|
it?.let {
|
||||||
startActivity<ReadBookActivity> {
|
startActivity<ReadBookActivity> {
|
||||||
putExtra("bookUrl", it.bookUrl)
|
putExtra("bookUrl", it.bookUrl)
|
||||||
putExtra("inBookshelf", false)
|
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 {
|
execute {
|
||||||
book?.save()
|
book?.save()
|
||||||
}.onFinally {
|
book
|
||||||
finally.invoke()
|
}.onSuccess {
|
||||||
|
success.invoke(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@
|
|||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="18sp"
|
android:layout_width="18sp"
|
||||||
android:layout_height="18sp"
|
android:layout_height="18sp"
|
||||||
android:contentDescription="@string/origin_format"
|
android:contentDescription="@string/author"
|
||||||
android:paddingRight="2dp"
|
android:paddingRight="2dp"
|
||||||
android:src="@drawable/ic_author"
|
android:src="@drawable/ic_author"
|
||||||
app:tint="@color/tv_text_summary"
|
app:tint="@color/tv_text_summary"
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_title"
|
android:id="@+id/tv_title"
|
||||||
@ -15,26 +16,69 @@
|
|||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:id="@+id/book_info"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="16dp"
|
||||||
|
android:visibility="invisible"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tv_title">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_name"
|
android:id="@+id/tv_name"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="16dp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tv_title" />
|
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
|
<TextView
|
||||||
android:id="@+id/tv_author"
|
android:id="@+id/tv_author"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="16dp"
|
android:layout_marginLeft="2dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tv_name" />
|
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
|
<TextView
|
||||||
android:id="@+id/tv_origin"
|
android:id="@+id/tv_origin"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingHorizontal="16dp"
|
android:layout_marginLeft="2dp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tv_author" />
|
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>
|
||||||
|
|
||||||
|
|
||||||
<io.legado.app.ui.widget.anima.RotateLoading
|
<io.legado.app.ui.widget.anima.RotateLoading
|
||||||
android:id="@+id/rotate_loading"
|
android:id="@+id/rotate_loading"
|
||||||
@ -42,8 +86,8 @@
|
|||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@id/tv_name"
|
app:layout_constraintTop_toTopOf="@id/book_info"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tv_origin" />
|
app:layout_constraintBottom_toBottomOf="@+id/book_info" />
|
||||||
|
|
||||||
<io.legado.app.ui.widget.text.AccentTextView
|
<io.legado.app.ui.widget.text.AccentTextView
|
||||||
android:id="@+id/tv_ok"
|
android:id="@+id/tv_ok"
|
||||||
@ -51,7 +95,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/ok"
|
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_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent" />
|
app:layout_constraintRight_toRightOf="parent" />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user