优化
This commit is contained in:
@@ -245,6 +245,14 @@ data class Book(
|
||||
return config.delTag and tag == tag
|
||||
}
|
||||
|
||||
fun addDelTag(tag: Long) {
|
||||
config.delTag = config.delTag and tag
|
||||
}
|
||||
|
||||
fun removeDelTag(tag: Long) {
|
||||
config.delTag = config.delTag and tag.inv()
|
||||
}
|
||||
|
||||
fun getFolderName(): String {
|
||||
folderName?.let {
|
||||
return it
|
||||
|
||||
@@ -67,6 +67,10 @@ class EpubFile(var book: Book) {
|
||||
override fun upBookInfo(book: Book) {
|
||||
return getEFile(book).upBookInfo()
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
eFile = null
|
||||
}
|
||||
}
|
||||
|
||||
private var mCharset: Charset = Charset.defaultCharset()
|
||||
@@ -182,11 +186,11 @@ class EpubFile(var book: Book) {
|
||||
}
|
||||
it.attr("src", absSrc)
|
||||
}
|
||||
var html = elements.outerHtml()
|
||||
val tag = Book.rubyTag
|
||||
if (book.getDelTag(tag)) {
|
||||
html = html.replace("<ruby>\\s?([\\u4e00-\\u9fa5])\\s?.*?</ruby>".toRegex(), "$1")
|
||||
elements.select("rp, rt").remove()
|
||||
}
|
||||
val html = elements.outerHtml()
|
||||
return HtmlFormatter.formatKeepImg(html)
|
||||
}
|
||||
|
||||
@@ -242,12 +246,7 @@ class EpubFile(var book: Book) {
|
||||
val tag = Book.hTag
|
||||
if (book.getDelTag(tag)) {
|
||||
bodyElement.run {
|
||||
getElementsByTag("h1").remove()
|
||||
getElementsByTag("h2").remove()
|
||||
getElementsByTag("h3").remove()
|
||||
getElementsByTag("h4").remove()
|
||||
getElementsByTag("h5").remove()
|
||||
getElementsByTag("h6").remove()
|
||||
select("h1, h2, h3, h4, h5, h6").remove()
|
||||
//getElementsMatchingOwnText(chapter.title)?.remove()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ class TextFile(private val book: Book) {
|
||||
companion object {
|
||||
private val padRegex = "^[\\n\\s]+".toRegex()
|
||||
private const val bufferSize = 8 * 1024 * 1024
|
||||
private var bufferStart = -1
|
||||
private var bufferEnd = -1
|
||||
var txtBuffer: ByteArray? = null
|
||||
var bufferStart = -1
|
||||
var bufferEnd = -1
|
||||
var bookUrl = ""
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
|
||||
@@ -40,6 +40,7 @@ import io.legado.app.lib.theme.accentColor
|
||||
import io.legado.app.model.ReadAloud
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
||||
import io.legado.app.model.localBook.EpubFile
|
||||
import io.legado.app.receiver.TimeBatteryReceiver
|
||||
import io.legado.app.service.BaseReadAloudService
|
||||
import io.legado.app.ui.about.AppLogDialog
|
||||
@@ -332,6 +333,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
R.id.menu_group_on_line -> item.isVisible = onLine
|
||||
R.id.menu_group_local -> item.isVisible = !onLine
|
||||
R.id.menu_group_text -> item.isVisible = book.isLocalTxt
|
||||
R.id.menu_group_epub -> item.isVisible = book.isEpub
|
||||
else -> when (item.itemId) {
|
||||
R.id.menu_enable_replace -> item.isChecked = book.getUseReplaceRule()
|
||||
R.id.menu_re_segment -> item.isChecked = book.getReSegment()
|
||||
@@ -341,6 +343,8 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
}
|
||||
|
||||
R.id.menu_reverse_content -> item.isVisible = onLine
|
||||
R.id.menu_del_ruby_tag -> item.isChecked = book.getDelTag(Book.rubyTag)
|
||||
R.id.menu_del_h_tag -> item.isChecked = book.getDelTag(Book.hTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,9 +409,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
upContent()
|
||||
} else {
|
||||
ReadBook.book?.let {
|
||||
ReadBook.clearTextChapter()
|
||||
binding.readView.upContent()
|
||||
viewModel.refreshContentAll(it)
|
||||
refreshContentDur(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -418,6 +420,7 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
R.id.menu_update_toc -> ReadBook.book?.let {
|
||||
if (it.isEpub) {
|
||||
BookHelp.clearCache(it)
|
||||
EpubFile.clear()
|
||||
}
|
||||
loadChapterList(it)
|
||||
}
|
||||
@@ -425,16 +428,36 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
R.id.menu_enable_replace -> changeReplaceRuleState()
|
||||
R.id.menu_re_segment -> ReadBook.book?.let {
|
||||
it.setReSegment(!it.getReSegment())
|
||||
menu?.findItem(R.id.menu_re_segment)?.isChecked = it.getReSegment()
|
||||
item.isChecked = it.getReSegment()
|
||||
ReadBook.loadContent(false)
|
||||
}
|
||||
|
||||
R.id.menu_enable_review -> {
|
||||
AppConfig.enableReview = !AppConfig.enableReview
|
||||
menu?.findItem(R.id.menu_enable_review)?.isChecked = AppConfig.enableReview
|
||||
item.isChecked = AppConfig.enableReview
|
||||
ReadBook.loadContent(false)
|
||||
}
|
||||
|
||||
R.id.menu_del_ruby_tag -> ReadBook.book?.let {
|
||||
item.isChecked = !item.isChecked
|
||||
if (item.isChecked) {
|
||||
it.addDelTag(Book.rubyTag)
|
||||
} else {
|
||||
it.removeDelTag(Book.rubyTag)
|
||||
}
|
||||
refreshContentDur(it)
|
||||
}
|
||||
|
||||
R.id.menu_del_h_tag -> ReadBook.book?.let {
|
||||
item.isChecked = !item.isChecked
|
||||
if (item.isChecked) {
|
||||
it.addDelTag(Book.hTag)
|
||||
} else {
|
||||
it.removeDelTag(Book.hTag)
|
||||
}
|
||||
refreshContentDur(it)
|
||||
}
|
||||
|
||||
R.id.menu_page_anim -> showPageAnimConfig {
|
||||
binding.readView.upPageAnim()
|
||||
ReadBook.loadContent(false)
|
||||
@@ -491,6 +514,12 @@ class ReadBookActivity : BaseReadBookActivity(),
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun refreshContentDur(book: Book) {
|
||||
ReadBook.curTextChapter = null
|
||||
binding.readView.upContent()
|
||||
viewModel.refreshContentDur(book)
|
||||
}
|
||||
|
||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||
return onCompatOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user