Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/src/main/java/io/legado/app/data/entities/Book.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.model.ReadBook
import io.legado.app.model.read.ReadingTimeState
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.IgnoredOnParcel
Expand Down Expand Up @@ -353,7 +354,7 @@ data class Book(
newBook.customIntro = customIntro
newBook.customTag = customTag
newBook.canUpdate = canUpdate
newBook.readConfig = readConfig
newBook.readConfig = readConfig?.copy(readingTimeState = null)
return newBook
}

Expand Down Expand Up @@ -402,7 +403,8 @@ data class Book(
var readSimulating: Boolean = false,
var startDate: LocalDate? = null,
var startChapter: Int? = null, // 用户设置的起始章节
var dailyChapters: Int = 3 // 用户设置的每日更新章节数
var dailyChapters: Int = 3, // 用户设置的每日更新章节数
var readingTimeState: ReadingTimeState? = null,
) : Parcelable

class Converters {
Expand All @@ -413,4 +415,4 @@ data class Book(
@TypeConverter
fun stringToReadConfig(json: String?) = GSON.fromJsonObject<ReadConfig>(json).getOrNull()
}
}
}
13 changes: 11 additions & 2 deletions app/src/main/java/io/legado/app/help/book/BookHelp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ object BookHelp {
val cachePath = FileUtils.getPath(downloadDir, cacheFolderName)

fun clearCache() {
ReadingTimeIndexManager.onAllCachesCleared()
FileUtils.delete(
FileUtils.getPath(downloadDir, cacheFolderName)
)
}

fun clearCache(book: Book) {
ReadingTimeIndexManager.onBookCacheCleared(book)
val filePath = FileUtils.getPath(downloadDir, cacheFolderName, book.getFolderName())
FileUtils.delete(filePath)
}

fun getBookCacheDirectory(book: Book): File {
return downloadDir.getFile(cacheFolderName, book.getFolderName())
}

fun updateCacheFolder(oldBook: Book, newBook: Book) {
val oldFolderName = oldBook.getFolderNameNoCache()
val newFolderName = newBook.getFolderNameNoCache()
Expand Down Expand Up @@ -180,12 +186,14 @@ object BookHelp {
) {
if (content.isEmpty()) return
//保存文本
FileUtils.createFileIfNotExist(
val contentFile = FileUtils.createFileIfNotExist(
downloadDir,
cacheFolderName,
book.getFolderName(),
bookChapter.getFileName(),
).writeText(content)
)
contentFile.writeText(content)
ReadingTimeIndexManager.onContentSaved(book, bookChapter, contentFile.length())
if (book.isOnLineTxt && AppConfig.tocCountWords) {
val wordCount = StringUtils.wordCountFormat(content.length)
bookChapter.wordCount = wordCount
Expand Down Expand Up @@ -430,6 +438,7 @@ object BookHelp {
book.getFolderName(),
bookChapter.getFileName()
).delete()
ReadingTimeIndexManager.onContentDeleted(book, bookChapter)
}

/**
Expand Down
Loading
Loading