This commit is contained in:
Horis
2024-07-07 13:24:11 +08:00
parent c6bb853624
commit 7d01189288
5 changed files with 39 additions and 4 deletions
@@ -2,7 +2,12 @@ package io.legado.app.data.entities
import android.content.Context import android.content.Context
import android.os.Parcelable 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.R
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@@ -99,6 +104,11 @@ data class SearchBook(
} }
} }
fun releaseHtmlData() {
infoHtml = null
tocHtml = null
}
fun toBook() = Book( fun toBook() = Book(
name = name, name = name,
author = author, author = author,
@@ -244,6 +244,11 @@ fun Book.isLocalModified(): Boolean {
return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime
} }
fun Book.releaseHtmlData() {
infoHtml = null
tocHtml = null
}
fun Book.isSameNameAuthor(other: Any?): Boolean { fun Book.isSameNameAuthor(other: Any?): Boolean {
if (other is BaseBook) { if (other is BaseBook) {
return name == other.name && author == other.author 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) WebBook.searchBookAwait(it, searchKey, searchPage)
} }
}.onEach { items -> }.onEach { items ->
for (book in items) {
book.releaseHtmlData()
}
appDb.searchBookDao.insert(*items.toTypedArray()) appDb.searchBookDao.insert(*items.toTypedArray())
mergeItems(items, precision) mergeItems(items, precision)
currentCoroutineContext().ensureActive() currentCoroutineContext().ensureActive()
@@ -18,10 +18,12 @@ import io.legado.app.data.entities.SearchBook
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.book.BookHelp import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.ContentProcessor 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.AppConfig
import io.legado.app.help.config.SourceConfig import io.legado.app.help.config.SourceConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.internString
import io.legado.app.utils.mapParallelSafe import io.legado.app.utils.mapParallelSafe
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
@@ -87,6 +89,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
searchCallback = object : SourceCallback { searchCallback = object : SourceCallback {
override fun searchSuccess(searchBook: SearchBook) { override fun searchSuccess(searchBook: SearchBook) {
searchBook.releaseHtmlData()
appDb.searchBookDao.insert(searchBook) appDb.searchBookDao.insert(searchBook)
when { when {
screenKey.isEmpty() -> searchBooks.add(searchBook) screenKey.isEmpty() -> searchBooks.add(searchBook)
@@ -227,13 +230,15 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
private suspend fun search(source: BookSource) { private suspend fun search(source: BookSource) {
val resultBooks = WebBook.searchBookAwait(source, name) val resultBooks = WebBook.searchBookAwait(source, name)
resultBooks.forEach { searchBook -> resultBooks.filter { searchBook ->
if (searchBook.name != name) { if (searchBook.name != name) {
return@forEach return@filter false
} }
if (AppConfig.changeSourceCheckAuthor && !searchBook.author.contains(author)) { if (AppConfig.changeSourceCheckAuthor && !searchBook.author.contains(author)) {
return@forEach return@filter false
} }
true
}.forEach { searchBook ->
when { when {
AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc || AppConfig.changeSourceLoadWordCount -> { AppConfig.changeSourceLoadInfo || AppConfig.changeSourceLoadToc || AppConfig.changeSourceLoadWordCount -> {
loadBookInfo(source, searchBook.toBook()) loadBookInfo(source, searchBook.toBook())
@@ -261,8 +266,12 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
private suspend fun loadBookToc(source: BookSource, book: Book) { private suspend fun loadBookToc(source: BookSource, book: Book) {
val chapters = WebBook.getChapterListAwait(source, book).getOrThrow() val chapters = WebBook.getChapterListAwait(source, book).getOrThrow()
for (chapter in chapters) {
chapter.internString()
}
tocMap[book.bookUrl] = chapters tocMap[book.bookUrl] = chapters
bookMap[book.bookUrl] = book bookMap[book.bookUrl] = book
book.releaseHtmlData()
if (AppConfig.changeSourceLoadWordCount) { if (AppConfig.changeSourceLoadWordCount) {
loadBookWordCount(source, book, chapters) loadBookWordCount(source, book, chapters)
} else { } 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()
}