This commit is contained in:
Horis
2025-02-02 10:02:37 +08:00
parent 55f04ed001
commit d7ce5580cb
4 changed files with 41 additions and 50 deletions

View File

@@ -240,7 +240,7 @@ class EpubFile(var book: Book) {
it.attr("src", it.attr("xlink:href"))
}
bodyElement.select("img").forEach {
val src = it.attr("src").encodeURI()
val src = it.attr("src").trim().encodeURI()
val href = res.href.encodeURI()
val resolvedHref = URLDecoder.decode(URI(href).resolve(src).toString(), "UTF-8")
it.attr("src", resolvedHref)

View File

@@ -19,8 +19,13 @@ import io.legado.app.databinding.DialogAddToBookshelfBinding
import io.legado.app.exception.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.webBook.WebBook
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.*
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.utils.GSON
import io.legado.app.utils.NetworkUtils
import io.legado.app.utils.fromJsonObject
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
/**
@@ -66,7 +71,6 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
viewModel.loadStateLiveData.observe(this) {
if (it) {
binding.rotateLoading.visible()
binding.bookInfo.invisible()
} else {
binding.rotateLoading.gone()
}
@@ -76,32 +80,18 @@ 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
viewModel.saveSearchBook(it) {
startActivity<BookInfoActivity> {
putExtra("name", it.name)
putExtra("author", it.author)
putExtra("bookUrl", it.bookUrl)
}
dismiss()
}
}
binding.tvCancel.setOnClickListener {
dismiss()
}
binding.tvOk.setOnClickListener {
viewModel.saveBook {
it?.let {
dismiss()
} ?: toastOnUi(R.string.no_book)
}
}
binding.tvRead.setOnClickListener {
viewModel.saveBook {
it?.let {
startActivity<ReadBookActivity> {
putExtra("bookUrl", it.bookUrl)
putExtra("inBookshelf", false)
}
dismiss()
} ?: toastOnUi(R.string.no_book)
}
}
}
class ViewModel(application: Application) : BaseViewModel(application) {
@@ -168,12 +158,13 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
}.getOrNull()
}
fun saveBook(success: (book: Book?) -> Unit) {
fun saveSearchBook(book: Book, success: () -> Unit) {
execute {
book?.save()
book
val searchBook = book.toSearchBook()
appDb.searchBookDao.insert(searchBook)
searchBook
}.onSuccess {
success.invoke(it)
success.invoke()
}
}

View File

@@ -106,8 +106,9 @@
android:paddingBottom="3dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:scrollbars="none">
@@ -115,8 +116,6 @@
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:includeFontPadding="false"
android:singleLine="true"
android:text="@string/book_name"
@@ -126,8 +125,9 @@
</HorizontalScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="6dp"
android:scrollbars="none">
@@ -135,8 +135,6 @@
android:id="@+id/lb_kind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone" />
</HorizontalScrollView>

View File

@@ -1,9 +1,9 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools">
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_title"
@@ -38,10 +38,10 @@
android:contentDescription="@string/author"
android:paddingRight="2dp"
android:src="@drawable/ic_author"
app:tint="@color/tv_text_summary"
app:layout_constraintBottom_toBottomOf="@+id/tv_author"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_author"
app:layout_constraintBottom_toBottomOf="@+id/tv_author"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
@@ -61,10 +61,10 @@
android:contentDescription="@string/origin_format"
android:paddingRight="2dp"
android:src="@drawable/ic_web_outline"
app:tint="@color/tv_text_summary"
app:layout_constraintBottom_toBottomOf="@+id/tv_origin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_origin"
app:layout_constraintBottom_toBottomOf="@+id/tv_origin"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
@@ -84,10 +84,10 @@
android:id="@+id/rotate_loading"
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="@+id/book_info"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/book_info"
app:layout_constraintBottom_toBottomOf="@+id/book_info" />
app:layout_constraintTop_toTopOf="@id/book_info" />
<io.legado.app.ui.widget.text.AccentTextView
android:id="@+id/tv_ok"
@@ -95,9 +95,10 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/ok"
app:layout_constraintTop_toBottomOf="@+id/book_info"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/book_info" />
<TextView
android:id="@+id/tv_cancel"
@@ -115,7 +116,8 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/reading"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>