优化
This commit is contained in:
@@ -2,7 +2,12 @@ package io.legado.app.data.entities
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Parcelable
|
||||
import androidx.room.*
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Ignore
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import io.legado.app.R
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.utils.GSON
|
||||
@@ -99,6 +104,11 @@ data class SearchBook(
|
||||
}
|
||||
}
|
||||
|
||||
fun releaseHtmlData() {
|
||||
infoHtml = null
|
||||
tocHtml = null
|
||||
}
|
||||
|
||||
fun toBook() = Book(
|
||||
name = name,
|
||||
author = author,
|
||||
|
||||
@@ -244,6 +244,11 @@ fun Book.isLocalModified(): Boolean {
|
||||
return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime
|
||||
}
|
||||
|
||||
fun Book.releaseHtmlData() {
|
||||
infoHtml = null
|
||||
tocHtml = null
|
||||
}
|
||||
|
||||
fun Book.isSameNameAuthor(other: Any?): Boolean {
|
||||
if (other is BaseBook) {
|
||||
return name == other.name && author == other.author
|
||||
|
||||
@@ -87,6 +87,9 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
WebBook.searchBookAwait(it, searchKey, searchPage)
|
||||
}
|
||||
}.onEach { items ->
|
||||
for (book in items) {
|
||||
book.releaseHtmlData()
|
||||
}
|
||||
appDb.searchBookDao.insert(*items.toTypedArray())
|
||||
mergeItems(items, precision)
|
||||
currentCoroutineContext().ensureActive()
|
||||
|
||||
@@ -18,10 +18,12 @@ import io.legado.app.data.entities.SearchBook
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.book.ContentProcessor
|
||||
import io.legado.app.help.book.releaseHtmlData
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.SourceConfig
|
||||
import io.legado.app.help.coroutine.Coroutine
|
||||
import io.legado.app.model.webBook.WebBook
|
||||
import io.legado.app.utils.internString
|
||||
import io.legado.app.utils.mapParallelSafe
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.CancellationException
|
||||
@@ -87,6 +89,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
searchCallback = object : SourceCallback {
|
||||
|
||||
override fun searchSuccess(searchBook: SearchBook) {
|
||||
searchBook.releaseHtmlData()
|
||||
appDb.searchBookDao.insert(searchBook)
|
||||
when {
|
||||
screenKey.isEmpty() -> searchBooks.add(searchBook)
|
||||
@@ -227,13 +230,15 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
|
||||
private suspend fun search(source: BookSource) {
|
||||
val resultBooks = WebBook.searchBookAwait(source, name)
|
||||
resultBooks.forEach { searchBook ->
|
||||
resultBooks.filter { searchBook ->
|
||||
if (searchBook.name != name) {
|
||||
return@forEach
|
||||
return@filter false
|
||||
}
|
||||
if (AppConfig.changeSourceCheckAuthor && !searchBook.author.contains(author)) {
|
||||
return@forEach
|
||||
return@filter false
|
||||
}
|
||||
true
|
||||
}.forEach { searchBook ->
|
||||
when {
|
||||
AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc || AppConfig.changeSourceLoadWordCount -> {
|
||||
loadBookInfo(source, searchBook.toBook())
|
||||
@@ -261,8 +266,12 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
|
||||
|
||||
private suspend fun loadBookToc(source: BookSource, book: Book) {
|
||||
val chapters = WebBook.getChapterListAwait(source, book).getOrThrow()
|
||||
for (chapter in chapters) {
|
||||
chapter.internString()
|
||||
}
|
||||
tocMap[book.bookUrl] = chapters
|
||||
bookMap[book.bookUrl] = book
|
||||
book.releaseHtmlData()
|
||||
if (AppConfig.changeSourceLoadWordCount) {
|
||||
loadBookWordCount(source, book, chapters)
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
|
||||
fun BookChapter.internString() {
|
||||
title = title.intern()
|
||||
bookUrl = bookUrl.intern()
|
||||
}
|
||||
Reference in New Issue
Block a user