diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 7f2b7ecd2..af0f706fe 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -11,6 +11,10 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2022/12/12** + +* 正文添加移除重复标题开关,针对单个章节,默认开启,极个别特殊情况章节开头和标题一样但是不是标题 + **2022/12/10** * 更新cronet: 108.0.5359.79 diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index ba194112c..3b0e3176b 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -144,7 +144,8 @@ data class BookChapter( } @Suppress("unused") - fun getFileName(): String = String.format("%05d-%s.nb", index, MD5Utils.md5Encode16(title)) + fun getFileName(suffix: String = "nb"): String = + String.format("%05d-%s.%s", index, MD5Utils.md5Encode16(title), suffix) @Suppress("unused") fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title)) diff --git a/app/src/main/java/io/legado/app/help/book/BookHelp.kt b/app/src/main/java/io/legado/app/help/book/BookHelp.kt index 6681c7d67..885ce274d 100644 --- a/app/src/main/java/io/legado/app/help/book/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/BookHelp.kt @@ -282,6 +282,41 @@ object BookHelp { ).delete() } + /** + * 设置是否禁用正文的去除重复标题,针对单个章节 + */ + fun setRemoveSameTitle(book: Book, bookChapter: BookChapter, removeSameTitle: Boolean) { + if (removeSameTitle) { + val path = FileUtils.getPath( + downloadDir, + cacheFolderName, + book.getFolderName(), + bookChapter.getFileName(".nr") + ) + File(path).delete() + } else { + FileUtils.createFileIfNotExist( + downloadDir, + cacheFolderName, + book.getFolderName(), + bookChapter.getFileName(".nr") + ) + } + } + + /** + * 获取是否去除重复标题 + */ + fun removeSameTitle(book: Book, bookChapter: BookChapter): Boolean { + val path = FileUtils.getPath( + downloadDir, + cacheFolderName, + book.getFolderName(), + bookChapter.getFileName(".nr") + ) + return !File(path).exists() + } + /** * 格式化书名 */ diff --git a/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt index c03848d09..0baa4938f 100644 --- a/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt @@ -84,12 +84,16 @@ class ContentProcessor private constructor( var sameTitleRemoved = false if (content != "null") { //去除重复标题 - try { + if (BookHelp.removeSameTitle(book, chapter)) try { val name = Pattern.quote(book.name) val title = Pattern.quote(chapter.title) - val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex() - mContent = mContent.replace(titleRegex, "") - sameTitleRemoved = true + val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*" + val matcher = Pattern.compile(titleRegex) + .matcher(mContent) + if (matcher.find()) { + mContent = mContent.substring(matcher.end()) + sameTitleRemoved = true + } } catch (e: Exception) { AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 08bd71c78..540cc7756 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -43,9 +43,6 @@ object ReadBook : CoroutineScope by MainScope() { private val readRecord = ReadRecord() var readStartTime: Long = System.currentTimeMillis() - /* 跳转历史记录 */ - var bookProgressHistory: List? = null - /* 跳转进度前进度记录 */ var lastBookPress: BookProgress? = null @@ -274,7 +271,9 @@ object ReadBook : CoroutineScope by MainScope() { } /** - * 加载章节内容 + * 加载当前章节和前后一章内容 + * @param resetPageOffset 滚动阅读是否重置滚动位置 + * @param success 当前章节加载完成回调 */ fun loadContent(resetPageOffset: Boolean, success: (() -> Unit)? = null) { loadContent(durChapterIndex, resetPageOffset = resetPageOffset) { @@ -284,6 +283,13 @@ object ReadBook : CoroutineScope by MainScope() { loadContent(durChapterIndex - 1, resetPageOffset = resetPageOffset) } + /** + * 加载章节内容 + * @param index 章节序号 + * @param upContent 是否更新视图 + * @param resetPageOffset 滚动阅读是否重置滚动位置 + * @param success 加载完成回调 + */ fun loadContent( index: Int, upContent: Boolean = true, @@ -308,6 +314,9 @@ object ReadBook : CoroutineScope by MainScope() { } } + /** + * 下载正文 + */ private fun download(index: Int) { if (index < 0) return if (index > chapterSize - 1) { @@ -332,6 +341,9 @@ object ReadBook : CoroutineScope by MainScope() { } } + /** + * 下载正文 + */ private fun download( scope: CoroutineScope, chapter: BookChapter, diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index d242519bb..7371ce1c8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -404,10 +404,7 @@ class ReadBookActivity : BaseReadBookActivity(), sureSyncProgress(progress) } } - R.id.menu_same_title_removed -> { - val chapterUrl = ReadBook.curTextChapter?.url - MD5Utils.md5Encode(chapterUrl) - } + R.id.menu_same_title_removed -> viewModel.reverseRemoveSameTitle() R.id.menu_help -> showReadMenuHelp() } return super.onCompatOptionsItemSelected(item) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 3509021eb..fa2e820c4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -33,7 +33,6 @@ import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.ui.book.searchContent.SearchResult import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch import java.io.File import java.io.FileInputStream import java.io.FileNotFoundException @@ -429,6 +428,25 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2) } + /** + * 翻转删除重复标题 + */ + fun reverseRemoveSameTitle() { + execute { + val book = ReadBook.book + val textChapter = ReadBook.curTextChapter + if (book != null && textChapter != null) { + BookHelp.setRemoveSameTitle( + book, textChapter.chapter, !textChapter.sameTitleRemoved + ) + ReadBook.loadContent(ReadBook.durChapterIndex) + } + } + } + + /** + * 刷新图片 + */ fun refreshImage(src: String) { execute { ReadBook.book?.let { book -> @@ -441,6 +459,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } + /** + * 保存图片 + */ @Suppress("BlockingMethodInNonBlockingContext") fun saveImage(src: String?, uri: Uri) { src ?: return diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index 0de1c6fb2..79b06fcbf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -469,7 +469,7 @@ class ReadMenu @JvmOverloads constructor( binding.tvChapterName.text = it.title binding.tvChapterName.visible() if (!ReadBook.isLocalBook) { - binding.tvChapterUrl.text = it.url + binding.tvChapterUrl.text = it.chapter.getAbsoluteURL() binding.tvChapterUrl.visible() } else { binding.tvChapterUrl.gone() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt index 731ef2c1a..4bed6cd61 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities import androidx.annotation.Keep +import io.legado.app.data.entities.BookChapter import kotlin.math.min /** @@ -10,9 +11,9 @@ import kotlin.math.min @Keep @Suppress("unused") data class TextChapter( + val chapter: BookChapter, val position: Int, val title: String, - val url: String, val pages: List, val chaptersSize: Int, val sameTitleRemoved: Boolean, diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index ff20b4680..48fb62a1a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -216,8 +216,8 @@ object ChapterProvider { } return TextChapter( + bookChapter, bookChapter.index, displayTitle, - bookChapter.getAbsoluteURL(), textPages, chapterSize, bookContent.sameTitleRemoved, bookChapter.isVip, bookChapter.isPay diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 415d7beeb..8bf1b60a3 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1060,5 +1060,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index fc9c86cf6..9225dded7 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1063,5 +1063,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7c4837391..df488a6f2 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1063,5 +1063,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 40ce00005..bccff78de 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1060,5 +1060,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index be56c70cd..737f59774 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1062,5 +1062,5 @@ 顯示上次更新時間 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index c600b7b31..e0b1668c2 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1062,5 +1062,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d60f51ed2..ac7e91e04 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1063,5 +1063,5 @@ 显示上次更新时间 刷新列表 分隔线颜色 - 移除了重复标题 + 移除重复标题