This commit is contained in:
Horis
2024-08-18 21:51:53 +08:00
parent 9c7ca3e01a
commit f1ad7c848b
3 changed files with 11 additions and 8 deletions
@@ -53,6 +53,10 @@ object BookType {
@IntDef(text, updateError, audio, image, webFile, local, archive, notShelf) @IntDef(text, updateError, audio, image, webFile, local, archive, notShelf)
annotation class Type annotation class Type
/**
* 所有可以从书源转换的书籍类型
*/
const val allBookType = text or image or audio or webFile
/** /**
* 本地书籍书源标志 * 本地书籍书源标志
@@ -206,6 +206,10 @@ fun Book.removeType(@BookType.Type vararg types: Int) {
} }
} }
fun Book.removeAllBookType() {
removeType(BookType.allBookType)
}
fun Book.clearType() { fun Book.clearType() {
type = 0 type = 0
} }
@@ -235,10 +239,6 @@ fun BookSource.getBookType(): Int {
} }
} }
fun BookSource.getAllBookType(): Int {
return BookType.text or BookType.image or BookType.audio or BookType.webFile
}
fun Book.sync(oldBook: Book) { fun Book.sync(oldBook: Book) {
val curBook = appDb.bookDao.getBook(oldBook.bookUrl)!! val curBook = appDb.bookDao.getBook(oldBook.bookUrl)!!
durChapterTime = curBook.durChapterTime durChapterTime = curBook.durChapterTime
@@ -7,9 +7,8 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook 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.addType import io.legado.app.help.book.addType
import io.legado.app.help.book.getAllBookType
import io.legado.app.help.book.getBookType import io.legado.app.help.book.getBookType
import io.legado.app.help.book.removeType import io.legado.app.help.book.removeAllBookType
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.http.StrResponse import io.legado.app.help.http.StrResponse
import io.legado.app.model.Debug import io.legado.app.model.Debug
@@ -149,7 +148,7 @@ object WebBook {
book: Book, book: Book,
canReName: Boolean = true, canReName: Boolean = true,
): Book { ): Book {
book.removeType(bookSource.getAllBookType()) book.removeAllBookType()
book.addType(bookSource.getBookType()) book.addType(bookSource.getBookType())
if (!book.infoHtml.isNullOrEmpty()) { if (!book.infoHtml.isNullOrEmpty()) {
BookInfo.analyzeBookInfo( BookInfo.analyzeBookInfo(
@@ -227,7 +226,7 @@ object WebBook {
book: Book, book: Book,
runPerJs: Boolean = false runPerJs: Boolean = false
): Result<List<BookChapter>> { ): Result<List<BookChapter>> {
book.removeType(bookSource.getAllBookType()) book.removeAllBookType()
book.addType(bookSource.getBookType()) book.addType(bookSource.getBookType())
return kotlin.runCatching { return kotlin.runCatching {
if (runPerJs) { if (runPerJs) {