isVolume为true时目录突出显示;isVolume为true且chapterUrl为空时,以标题代替chapterUrl,不解析正文规则,直接返回空白

pull/1511/head
Xwite 3 years ago
parent 4e151ca303
commit 9fd1edcd3f
  1. 11
      app/src/main/java/io/legado/app/lib/theme/ThemeUtils.kt
  2. 15
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  3. 2
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  5. 15
      app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt
  6. 1
      app/src/main/res/layout/item_chapter_list.xml

@ -2,6 +2,7 @@ package io.legado.app.lib.theme
import android.content.Context
import androidx.annotation.AttrRes
import android.graphics.drawable.Drawable
/**
* @author Aidan Follestad (afollestad)
@ -31,4 +32,14 @@ object ThemeUtils {
a.recycle()
}
}
@JvmOverloads
fun resolveDrawable(context: Context, @AttrRes attr: Int): Drawable? {
val a = context.theme.obtainStyledAttributes(intArrayOf(attr))
return try {
a.getDrawable(0)
} finally {
a.recycle()
}
}
}

@ -177,6 +177,7 @@ object BookChapterList {
val vipRule = analyzeRule.splitSourceRule(tocRule.isVip)
val payRule = analyzeRule.splitSourceRule(tocRule.isPay)
val upTimeRule = analyzeRule.splitSourceRule(tocRule.updateTime)
val isVolumeRule = analyzeRule.splitSourceRule(tocRule.isVolume)
elements.forEachIndexed { index, item ->
scope.ensureActive()
analyzeRule.setContent(item)
@ -185,9 +186,19 @@ object BookChapterList {
bookChapter.title = analyzeRule.getString(nameRule)
bookChapter.url = analyzeRule.getString(urlRule)
bookChapter.tag = analyzeRule.getString(upTimeRule)
val isVolume = analyzeRule.getString(isVolumeRule)
bookChapter.isVolume = false
if (isVolume.isNotEmpty() && !isVolume.matches(falseRegex)) {
bookChapter.isVolume = true
}
if (bookChapter.url.isEmpty()) {
bookChapter.url = baseUrl
Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代")
if (bookChapter.isVolume) {
bookChapter.url = bookChapter.title
Debug.log(bookSource.bookSourceUrl, "目录${index}(Volume)未获取到url,使用章节标题替代")
} else {
bookChapter.url = baseUrl
Debug.log(bookSource.bookSourceUrl, "目录${index}未获取到url,使用baseUrl替代")
}
}
if (bookChapter.title.isNotEmpty()) {
val isVip = analyzeRule.getString(vipRule)

@ -261,6 +261,8 @@ object WebBook {
Debug.log(bookSource.bookSourceUrl, "⇒正文规则为空,使用章节链接:${bookChapter.url}")
return bookChapter.url
}
//章节名为卷名时 且 章节url没获取到,返回空白
if(bookChapter.isVolume && bookChapter.url == bookChapter.title) return ""
return if (bookChapter.url == book.bookUrl && !book.tocHtml.isNullOrEmpty()) {
BookContent.analyzeContent(
scope = scope,

@ -566,6 +566,7 @@ object ChapterProvider {
tPaint.typeface = titleFont
tPaint.textSize = with(ReadBookConfig) { textSize + titleSize }.sp.toFloat()
tPaint.isAntiAlias = true
//to do:卷名的标题排版
val cPaint = TextPaint()
cPaint.color = ReadBookConfig.textColor
cPaint.letterSpacing = ReadBookConfig.letterSpacing

@ -9,10 +9,12 @@ import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.BookChapter
import io.legado.app.databinding.ItemChapterListBinding
import io.legado.app.lib.theme.accentColor
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.ThemeUtils
import io.legado.app.help.AppConfig
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.visible
class ChapterListAdapter(context: Context, val callback: Callback) :
RecyclerAdapter<BookChapter, ItemChapterListBinding>(context) {
@ -30,6 +32,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
&& oldItem.isPay == newItem.isPay
&& oldItem.title == newItem.title
&& oldItem.tag == newItem.tag
&& oldItem.isVolume == newItem.isVolume
}
}
@ -54,7 +57,15 @@ class ChapterListAdapter(context: Context, val callback: Callback) :
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText))
}
tvChapterName.text = item.getDisplayTitle()
if (!item.tag.isNullOrEmpty()) {
if (item.isVolume) {
//卷名,如第一卷 突出显示
tvChapterItem.setBackgroundColor(context.getCompatColor(R.color.btn_bg_press))
} else {
//普通章节 保持不变
tvChapterItem.setBackground(ThemeUtils.resolveDrawable(context, android.R.attr.selectableItemBackground))
}
if (!item.tag.isNullOrEmpty() && !item.isVolume) {
//卷名不显示tag(更新时间规则)
tvTag.text = item.tag
tvTag.visible()
}

@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/tv_chapter_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"

Loading…
Cancel
Save