feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 974a2a3b2f
commit 6294c92982
  1. 6
      app/src/main/java/io/legado/app/help/BookHelp.kt
  2. 2
      app/src/main/java/io/legado/app/model/webBook/BookContent.kt
  3. 1
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  4. 5
      app/src/main/java/io/legado/app/ui/book/read/page/ContentTextView.kt

@ -247,7 +247,6 @@ object BookHelp {
content: String,
enableReplace: Boolean
): String {
var c = content
synchronized(this) {
if (enableReplace && (bookName != name || bookOrigin != origin)) {
replaceRules = if (origin.isNullOrEmpty()) {
@ -257,6 +256,7 @@ object BookHelp {
}
}
}
var c = content
for (item in replaceRules) {
item.pattern.let {
if (it.isNotEmpty()) {
@ -268,9 +268,7 @@ object BookHelp {
}
}
}
if (!content.substringBefore("\n").contains(title)) {
c = title + "\n" + c
}
c = "$title\n$c"
when (AppConfig.chineseConverterType) {
1 -> c = ZhConvertBootstrap.newInstance().toSimple(c)
2 -> c = ZhConvertBootstrap.newInstance().toTraditional(c)

@ -37,7 +37,7 @@ object BookContent {
val nextUrlList = arrayListOf(baseUrl)
val contentRule = bookSource.getContentRule()
var contentData = analyzeContent(body, contentRule, book, bookChapter, bookSource, baseUrl)
content.append(contentData.content)
content.append(contentData.content.replace(bookChapter.title, ""))
if (contentData.nextUrl.size == 1) {
var nextUrl = contentData.nextUrl[0]
val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty())

@ -111,6 +111,7 @@ object ChapterProvider {
durY = joinBody(text, durY, textPages, pageLines, pageLengths, stringBuilder)
}
}
textPages.last().text = stringBuilder.toString()
if (pageLines.size < textPages.size) {
pageLines.add(textPages.last().textLines.size)
}

@ -16,7 +16,6 @@ import io.legado.app.utils.getPrefBoolean
class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private val maxScrollOffset = 100f
private val selectedPaint by lazy {
Paint().apply {
color = context.getCompatColor(R.color.btn_bg_press_2)
@ -30,6 +29,10 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at
private var selectLineEnd = 0
private var selectCharEnd = 0
private var textPage: TextPage? = null
//滚动参数
private val maxScrollOffset = 100f
private val pageOffset = 0f
private val isLastPage = false
init {
activityCallBack = activity as CallBack

Loading…
Cancel
Save