优化
This commit is contained in:
@@ -240,7 +240,7 @@ class EpubFile(var book: Book) {
|
|||||||
it.attr("src", it.attr("xlink:href"))
|
it.attr("src", it.attr("xlink:href"))
|
||||||
}
|
}
|
||||||
bodyElement.select("img").forEach {
|
bodyElement.select("img").forEach {
|
||||||
val src = it.attr("src").encodeURI()
|
val src = it.attr("src").trim().encodeURI()
|
||||||
val href = res.href.encodeURI()
|
val href = res.href.encodeURI()
|
||||||
val resolvedHref = URLDecoder.decode(URI(href).resolve(src).toString(), "UTF-8")
|
val resolvedHref = URLDecoder.decode(URI(href).resolve(src).toString(), "UTF-8")
|
||||||
it.attr("src", resolvedHref)
|
it.attr("src", resolvedHref)
|
||||||
|
|||||||
@@ -19,8 +19,13 @@ import io.legado.app.databinding.DialogAddToBookshelfBinding
|
|||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
||||||
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.info.BookInfoActivity
|
||||||
import io.legado.app.utils.*
|
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
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,7 +71,6 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
|||||||
viewModel.loadStateLiveData.observe(this) {
|
viewModel.loadStateLiveData.observe(this) {
|
||||||
if (it) {
|
if (it) {
|
||||||
binding.rotateLoading.visible()
|
binding.rotateLoading.visible()
|
||||||
binding.bookInfo.invisible()
|
|
||||||
} else {
|
} else {
|
||||||
binding.rotateLoading.gone()
|
binding.rotateLoading.gone()
|
||||||
}
|
}
|
||||||
@@ -76,32 +80,18 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
|||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
viewModel.load(bookUrl) {
|
viewModel.load(bookUrl) {
|
||||||
binding.bookInfo.visible()
|
viewModel.saveSearchBook(it) {
|
||||||
binding.tvName.text = it.name
|
startActivity<BookInfoActivity> {
|
||||||
binding.tvAuthor.text = it.author
|
putExtra("name", it.name)
|
||||||
binding.tvOrigin.text = it.originName
|
putExtra("author", it.author)
|
||||||
|
putExtra("bookUrl", it.bookUrl)
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
binding.tvCancel.setOnClickListener {
|
binding.tvCancel.setOnClickListener {
|
||||||
dismiss()
|
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) {
|
class ViewModel(application: Application) : BaseViewModel(application) {
|
||||||
@@ -168,12 +158,13 @@ class AddToBookshelfDialog() : BaseDialogFragment(R.layout.dialog_add_to_bookshe
|
|||||||
}.getOrNull()
|
}.getOrNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveBook(success: (book: Book?) -> Unit) {
|
fun saveSearchBook(book: Book, success: () -> Unit) {
|
||||||
execute {
|
execute {
|
||||||
book?.save()
|
val searchBook = book.toSearchBook()
|
||||||
book
|
appDb.searchBookDao.insert(searchBook)
|
||||||
|
searchBook
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
success.invoke(it)
|
success.invoke()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,8 +106,9 @@
|
|||||||
android:paddingBottom="3dp">
|
android:paddingBottom="3dp">
|
||||||
|
|
||||||
<HorizontalScrollView
|
<HorizontalScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:layout_marginBottom="6dp"
|
android:layout_marginBottom="6dp"
|
||||||
android:scrollbars="none">
|
android:scrollbars="none">
|
||||||
|
|
||||||
@@ -115,8 +116,6 @@
|
|||||||
android:id="@+id/tv_name"
|
android:id="@+id/tv_name"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:gravity="center"
|
|
||||||
android:includeFontPadding="false"
|
android:includeFontPadding="false"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:text="@string/book_name"
|
android:text="@string/book_name"
|
||||||
@@ -126,8 +125,9 @@
|
|||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
<HorizontalScrollView
|
<HorizontalScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
android:layout_marginBottom="6dp"
|
android:layout_marginBottom="6dp"
|
||||||
android:scrollbars="none">
|
android:scrollbars="none">
|
||||||
|
|
||||||
@@ -135,8 +135,6 @@
|
|||||||
android:id="@+id/lb_kind"
|
android:id="@+id/lb_kind"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
|
||||||
android:gravity="center"
|
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
</HorizontalScrollView>
|
</HorizontalScrollView>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-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"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
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"
|
||||||
@@ -38,10 +38,10 @@
|
|||||||
android:contentDescription="@string/author"
|
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:layout_constraintBottom_toBottomOf="@+id/tv_author"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@id/tv_author"
|
app:layout_constraintTop_toTopOf="@id/tv_author"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tv_author"
|
app:tint="@color/tv_text_summary"
|
||||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -61,10 +61,10 @@
|
|||||||
android:contentDescription="@string/origin_format"
|
android:contentDescription="@string/origin_format"
|
||||||
android:paddingRight="2dp"
|
android:paddingRight="2dp"
|
||||||
android:src="@drawable/ic_web_outline"
|
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_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="@id/tv_origin"
|
app:layout_constraintTop_toTopOf="@id/tv_origin"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tv_origin"
|
app:tint="@color/tv_text_summary"
|
||||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -84,10 +84,10 @@
|
|||||||
android:id="@+id/rotate_loading"
|
android:id="@+id/rotate_loading"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/book_info"
|
||||||
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/book_info"
|
app:layout_constraintTop_toTopOf="@id/book_info" />
|
||||||
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"
|
||||||
@@ -95,9 +95,10 @@
|
|||||||
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/book_info"
|
android:visibility="invisible"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent" />
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/book_info" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_cancel"
|
android:id="@+id/tv_cancel"
|
||||||
@@ -115,7 +116,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/reading"
|
android:text="@string/reading"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
android:visibility="invisible"
|
||||||
app:layout_constraintBottom_toBottomOf="parent" />
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user