txt均分目录添加开关

This commit is contained in:
Xwite
2022-02-07 18:36:03 +08:00
parent 668d0b8c3f
commit 71cd6aec20
11 changed files with 42 additions and 2 deletions
@@ -160,6 +160,14 @@ data class Book(
config().reSegment = reSegment
}
fun getLimitContentLength(): Boolean {
return config().limitContentLength
}
fun setLimitContentLength(limitContentLength: Boolean) {
config().limitContentLength = limitContentLength
}
fun getPageAnim(): Int {
return config().pageAnim
}
@@ -270,6 +278,7 @@ data class Book(
var reverseToc: Boolean = false,
var pageAnim: Int = -1,
var reSegment: Boolean = false,
var limitContentLength: Boolean = true, //txt规则解析目录时超过规定的最大字数时均分txt
var imageStyle: String? = null,
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
var delTag: Long = 0L,//去除标签
@@ -47,6 +47,7 @@ class TextFile(private val book: Book) {
private val maxLengthWithNoToc = 10 * 1024
//使用正则划分目录,每个章节的最大允许长度
private val maxLengthWithToc = 102400
private val limitContentLength = book.getLimitContentLength()
private val tocRules = arrayListOf<Pattern>()
private var charset: Charset = book.fileCharset()
@@ -128,7 +129,7 @@ class TextFile(private val book: Book) {
val chapterContent = blockContent.substring(seekPos, chapterStart)
val chapterLength = chapterContent.toByteArray(charset).size
val lastStart = toc.lastOrNull()?.start ?: curOffset
if (curOffset + chapterLength - lastStart > maxLengthWithToc) {
if (limitContentLength && curOffset + chapterLength - lastStart > maxLengthWithToc) {
bis.close()
return analyze()
}
@@ -118,12 +118,16 @@ class BookInfoActivity :
override fun onMenuOpened(featureId: Int, menu: Menu): Boolean {
menu.findItem(R.id.menu_can_update)?.isChecked =
viewModel.bookData.value?.canUpdate ?: true
menu.findItem(R.id.menu_limit_content_length)?.isChecked =
viewModel.bookData.value?.getLimitContentLength() ?: false
menu.findItem(R.id.menu_login)?.isVisible =
!viewModel.bookSource?.loginUrl.isNullOrBlank()
menu.findItem(R.id.menu_set_source_variable)?.isVisible =
viewModel.bookSource != null
menu.findItem(R.id.menu_set_book_variable)?.isVisible =
viewModel.bookSource != null
menu.findItem(R.id.menu_limit_content_length)?.isVisible =
viewModel.bookSource == null
return super.onMenuOpened(featureId, menu)
}
@@ -183,6 +187,14 @@ class BookInfoActivity :
}
R.id.menu_clear_cache -> viewModel.clearCache()
R.id.menu_log -> showDialogFragment<AppLogDialog>()
R.id.menu_limit_content_length -> {
upLoading(true)
viewModel.bookData.value?.let {
it.setLimitContentLength(!item.isChecked)
viewModel.loadBookInfo(it, false)
}
if (item.isChecked) longToastOnUi(R.string.need_more_time_load_content)
}
}
return super.onCompatOptionsItemSelected(item)
}