pull/2633/head
kunfei 2 years ago
parent d26323714f
commit 236b545ab4
  1. 4
      app/src/main/assets/updateLog.md
  2. 3
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  3. 35
      app/src/main/java/io/legado/app/help/book/BookHelp.kt
  4. 12
      app/src/main/java/io/legado/app/help/book/ContentProcessor.kt
  5. 20
      app/src/main/java/io/legado/app/model/ReadBook.kt
  6. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  7. 23
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  9. 3
      app/src/main/java/io/legado/app/ui/book/read/page/entities/TextChapter.kt
  10. 2
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  11. 2
      app/src/main/res/values-es-rES/strings.xml
  12. 2
      app/src/main/res/values-ja-rJP/strings.xml
  13. 2
      app/src/main/res/values-pt-rBR/strings.xml
  14. 2
      app/src/main/res/values-zh-rHK/strings.xml
  15. 2
      app/src/main/res/values-zh-rTW/strings.xml
  16. 2
      app/src/main/res/values-zh/strings.xml
  17. 2
      app/src/main/res/values/strings.xml

@ -11,6 +11,10 @@
* 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。 * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则或简繁转换出现问题。
* 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源!
**2022/12/12**
* 正文添加移除重复标题开关,针对单个章节,默认开启,极个别特殊情况章节开头和标题一样但是不是标题
**2022/12/10** **2022/12/10**
* 更新cronet: 108.0.5359.79 * 更新cronet: 108.0.5359.79

@ -144,7 +144,8 @@ data class BookChapter(
} }
@Suppress("unused") @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") @Suppress("unused")
fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title)) fun getFontName(): String = String.format("%05d-%s.ttf", index, MD5Utils.md5Encode16(title))

@ -282,6 +282,41 @@ object BookHelp {
).delete() ).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()
}
/** /**
* 格式化书名 * 格式化书名
*/ */

@ -84,12 +84,16 @@ class ContentProcessor private constructor(
var sameTitleRemoved = false var sameTitleRemoved = false
if (content != "null") { if (content != "null") {
//去除重复标题 //去除重复标题
try { if (BookHelp.removeSameTitle(book, chapter)) try {
val name = Pattern.quote(book.name) val name = Pattern.quote(book.name)
val title = Pattern.quote(chapter.title) val title = Pattern.quote(chapter.title)
val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex() val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*"
mContent = mContent.replace(titleRegex, "") val matcher = Pattern.compile(titleRegex)
sameTitleRemoved = true .matcher(mContent)
if (matcher.find()) {
mContent = mContent.substring(matcher.end())
sameTitleRemoved = true
}
} catch (e: Exception) { } catch (e: Exception) {
AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) AppLog.put("去除重复标题出错\n${e.localizedMessage}", e)
} }

@ -43,9 +43,6 @@ object ReadBook : CoroutineScope by MainScope() {
private val readRecord = ReadRecord() private val readRecord = ReadRecord()
var readStartTime: Long = System.currentTimeMillis() var readStartTime: Long = System.currentTimeMillis()
/* 跳转历史记录 */
var bookProgressHistory: List<BookProgress>? = null
/* 跳转进度前进度记录 */ /* 跳转进度前进度记录 */
var lastBookPress: BookProgress? = 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) { fun loadContent(resetPageOffset: Boolean, success: (() -> Unit)? = null) {
loadContent(durChapterIndex, resetPageOffset = resetPageOffset) { loadContent(durChapterIndex, resetPageOffset = resetPageOffset) {
@ -284,6 +283,13 @@ object ReadBook : CoroutineScope by MainScope() {
loadContent(durChapterIndex - 1, resetPageOffset = resetPageOffset) loadContent(durChapterIndex - 1, resetPageOffset = resetPageOffset)
} }
/**
* 加载章节内容
* @param index 章节序号
* @param upContent 是否更新视图
* @param resetPageOffset 滚动阅读是否重置滚动位置
* @param success 加载完成回调
*/
fun loadContent( fun loadContent(
index: Int, index: Int,
upContent: Boolean = true, upContent: Boolean = true,
@ -308,6 +314,9 @@ object ReadBook : CoroutineScope by MainScope() {
} }
} }
/**
* 下载正文
*/
private fun download(index: Int) { private fun download(index: Int) {
if (index < 0) return if (index < 0) return
if (index > chapterSize - 1) { if (index > chapterSize - 1) {
@ -332,6 +341,9 @@ object ReadBook : CoroutineScope by MainScope() {
} }
} }
/**
* 下载正文
*/
private fun download( private fun download(
scope: CoroutineScope, scope: CoroutineScope,
chapter: BookChapter, chapter: BookChapter,

@ -404,10 +404,7 @@ class ReadBookActivity : BaseReadBookActivity(),
sureSyncProgress(progress) sureSyncProgress(progress)
} }
} }
R.id.menu_same_title_removed -> { R.id.menu_same_title_removed -> viewModel.reverseRemoveSameTitle()
val chapterUrl = ReadBook.curTextChapter?.url
MD5Utils.md5Encode(chapterUrl)
}
R.id.menu_help -> showReadMenuHelp() R.id.menu_help -> showReadMenuHelp()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)

@ -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.ui.book.searchContent.SearchResult
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.FileNotFoundException import java.io.FileNotFoundException
@ -429,6 +428,25 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
return arrayOf(pageIndex, lineIndex, charIndex, addLine, charIndex2) 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) { fun refreshImage(src: String) {
execute { execute {
ReadBook.book?.let { book -> ReadBook.book?.let { book ->
@ -441,6 +459,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
/**
* 保存图片
*/
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
fun saveImage(src: String?, uri: Uri) { fun saveImage(src: String?, uri: Uri) {
src ?: return src ?: return

@ -469,7 +469,7 @@ class ReadMenu @JvmOverloads constructor(
binding.tvChapterName.text = it.title binding.tvChapterName.text = it.title
binding.tvChapterName.visible() binding.tvChapterName.visible()
if (!ReadBook.isLocalBook) { if (!ReadBook.isLocalBook) {
binding.tvChapterUrl.text = it.url binding.tvChapterUrl.text = it.chapter.getAbsoluteURL()
binding.tvChapterUrl.visible() binding.tvChapterUrl.visible()
} else { } else {
binding.tvChapterUrl.gone() binding.tvChapterUrl.gone()

@ -2,6 +2,7 @@ package io.legado.app.ui.book.read.page.entities
import androidx.annotation.Keep import androidx.annotation.Keep
import io.legado.app.data.entities.BookChapter
import kotlin.math.min import kotlin.math.min
/** /**
@ -10,9 +11,9 @@ import kotlin.math.min
@Keep @Keep
@Suppress("unused") @Suppress("unused")
data class TextChapter( data class TextChapter(
val chapter: BookChapter,
val position: Int, val position: Int,
val title: String, val title: String,
val url: String,
val pages: List<TextPage>, val pages: List<TextPage>,
val chaptersSize: Int, val chaptersSize: Int,
val sameTitleRemoved: Boolean, val sameTitleRemoved: Boolean,

@ -216,8 +216,8 @@ object ChapterProvider {
} }
return TextChapter( return TextChapter(
bookChapter,
bookChapter.index, displayTitle, bookChapter.index, displayTitle,
bookChapter.getAbsoluteURL(),
textPages, chapterSize, textPages, chapterSize,
bookContent.sameTitleRemoved, bookContent.sameTitleRemoved,
bookChapter.isVip, bookChapter.isPay bookChapter.isVip, bookChapter.isPay

@ -1060,5 +1060,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1063,5 +1063,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1063,5 +1063,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1060,5 +1060,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1062,5 +1062,5 @@
<string name="show_last_update_time">顯示上次更新時間</string> <string name="show_last_update_time">顯示上次更新時間</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1062,5 +1062,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

@ -1063,5 +1063,5 @@
<string name="show_last_update_time">显示上次更新时间</string> <string name="show_last_update_time">显示上次更新时间</string>
<string name="refresh_list">刷新列表</string> <string name="refresh_list">刷新列表</string>
<string name="tip_divider_color">分隔线颜色</string> <string name="tip_divider_color">分隔线颜色</string>
<string name="same_title_removed">移除重复标题</string> <string name="same_title_removed">移除重复标题</string>
</resources> </resources>

Loading…
Cancel
Save