v3.36:未读 RSS 角标去重统计、阅读页空行与字号行距优化

This commit is contained in:
XIGE
2026-11-27 07:51:37 +08:00
parent 4612ddd77e
commit 681d6a8cad
5 changed files with 150 additions and 19 deletions

View File

@@ -1,5 +1,13 @@
# 变更记录
## 2026-11-27 · v3.36(versionCode 57)
- 修复信息角标(未读 RSS 数)虚高:服务端 `total / pages` 是跨站去重前口径、越界页会回落为最后一页返回同一批条目,统计改为按 id 去重,并在空页或页号被钳回时立即停止。
- 未读统计缓存窗口由 10 分钟缩短为 60 秒,从阅读页返回首页时自动校正角标,读完文章后不再挂着旧数字。
- 修复阅读页多余空行:清理只含硬换行标记(反斜杠)的行、带空格的空行;列表项之间不再留空行(避免 Markwon 按松散列表放大行距);围栏代码块与 4 空格缩进代码块原样保留。
- 正文字号 15sp → 16sp,行距改为 4dp / 1.4;块间距 10dp → 8dp,段与段、图与文之间不再出现“空两行”的观感。
- 标题字号倍数微调为 1.45 / 1.3 / 1.18 / 1.08 / 1.02 / 1,代码字号 13sp → 14sp,列表缩进 16dp → 18dp。
## 2026-11-26 · v3.35(versionCode 56)
- 修复 RSS 文章「净化后没有排版、正文糊成一片」:按行净化时不再删除段落空行,代码块先占位再逐行处理,保留缩进。

View File

@@ -1314,5 +1314,8 @@ class HomeActivity : AppCompatActivity() {
refreshMailList()
refreshMailBadge()
}
// 从阅读页回来:信息角标按本地已读变更校正。缓存刚被 adjustUnread 改过时直接命中,
// 过期(60 秒)则重新扫描,读完文章后角标不会一直挂着旧数字。
if (current != TAB_MAIL) refreshRssBadge(force = false)
}
}

View File

@@ -16,17 +16,17 @@ class MdThemePlugin(private val context: Context) : AbstractMarkwonPlugin() {
override fun configureTheme(builder: MarkwonTheme.Builder) {
builder
// # / ## / ### ... 字号逐级递减
.headingTextSizeMultipliers(floatArrayOf(1.5f, 1.32f, 1.2f, 1.1f, 1.05f, 1f))
// # / ## / ### ... 字号逐级递减(正文 16sp 起算,h1 约 23sp)
.headingTextSizeMultipliers(floatArrayOf(1.45f, 1.3f, 1.18f, 1.08f, 1.02f, 1f))
.headingBreakHeight((1 * d).toInt())
.headingBreakColor(ContextCompat.getColor(context, R.color.divider))
// 行内代码与代码块
.codeBackgroundColor(ContextCompat.getColor(context, R.color.input_bg))
.codeTextColor(ContextCompat.getColor(context, R.color.text))
.codeTextSize((13 * d).toInt())
.codeTextSize((14 * d).toInt())
.codeBlockBackgroundColor(ContextCompat.getColor(context, R.color.input_bg))
.codeBlockTextColor(ContextCompat.getColor(context, R.color.text))
.codeBlockTextSize((13 * d).toInt())
.codeBlockTextSize((14 * d).toInt())
.codeBlockMargin((8 * d).toInt())
// 引用条用品牌橙,分割线用主题分隔色,链接可点击
.blockQuoteColor(ContextCompat.getColor(context, R.color.brand))
@@ -34,10 +34,10 @@ class MdThemePlugin(private val context: Context) : AbstractMarkwonPlugin() {
.thematicBreakColor(ContextCompat.getColor(context, R.color.divider))
.thematicBreakHeight((1 * d).toInt())
.linkColor(ContextCompat.getColor(context, R.color.brand))
// 块级间距:标题、列表、代码块、引用与段落之间留白,
// 默认几乎贴在一起,长文读起来像一块砖
.blockMargin((10 * d).toInt())
// 块级间距:8dp 是「段落看得出分开、又不至于像空了两行」的折中值,
// 之前 10dp 再叠加逐段 TextView 的边距,视觉上就是满屏空白
.blockMargin((8 * d).toInt())
// 列表标记与文字的缩进,避免 "-" 贴着正文左边缘
.bulletWidth((16 * d).toInt())
.bulletWidth((18 * d).toInt())
}
}

View File

@@ -426,6 +426,58 @@ class ReaderActivity : AppCompatActivity() {
return s
}
/** 列表行(无序 / 有序),用于判断两行之间该不该留空行 */
private fun isListLine(line: String): Boolean =
line.startsWith("- ") || line.startsWith("* ") || line.startsWith("+ ") ||
Regex("^\\d+[.)]\\s").containsMatchIn(line)
/**
* 空行收尾。
*
* Markwon 把每个空行都当成块边界(并叠加 blockMargin),所以「空两行」在阅读页
* 会变成明显的空白段,读起来一句一断。多余空行有三个来源:
* 1. `</div><br><p>` 这类相邻写法会还原出一行只有反斜杠的硬换行标记;
* 2. 块闭合之间夹着源码空白,形成「带空格的空行」,`\n{3,}` 正则匹配不到;
* 3. 列表项之间留空行,Markwon 按松散列表把行距整体放大。
*
* 缩进 4 空格以上的行原样保留(Typecho 正文里的缩进代码块 / 子列表靠它),
* 围栏代码块内也原样保留。
*/
private fun tidyBlank(src: String): String {
val out = ArrayList<String>(src.length / 8 + 8)
var inFence = false
var pendingBlank = false
src.lines().forEach { rawLine ->
val line = rawLine.trimEnd()
val bare = line.trimStart()
if (bare.startsWith("```")) {
inFence = !inFence
if (pendingBlank && out.isNotEmpty()) out.add("")
pendingBlank = false
out.add(bare)
return@forEach
}
if (inFence) {
out.add(line)
return@forEach
}
val text = line.trim()
if (text.isEmpty() || text == "\\") {
if (out.isNotEmpty()) pendingBlank = true
return@forEach
}
if (pendingBlank) {
val prev = out.lastOrNull().orEmpty()
if (!(isListLine(prev) && isListLine(text))) out.add("")
pendingBlank = false
}
val indent = line.length - bare.length
// 缩进代码块/子列表保缩进;其余按源码缩进剥掉,避免被当成代码块
out.add(if (indent >= 4) line else text)
}
return out.joinToString("\n").trim()
}
/** 渲染:文字段走 Markwon,FlexPhoto 图组横排,独立图片铺满整行 */
private fun render(markdown: String) {
var raw = if (markdown.contains("<!--markdown-->")) markdown.replace("<!--markdown-->", "")
@@ -434,6 +486,8 @@ class ReaderActivity : AppCompatActivity() {
raw = raw.replace(Regex("\\{map-\\d+\\}", RegexOption.IGNORE_CASE), "")
// 正文混写 HTML 支持:<p>/<br>/<img>/<strong>/<h2> 等转成 Markdown,其余标签剥掉
raw = htmlToMarkdownLite(raw)
// 空行收尾:Markwon 把每个空行都当块边界,空行一多就成了「一句一断」
raw = tidyBlank(raw)
// 站里标题常写成 "#标题"(# 后无空格,CommonMark 不识别),补上空格;代码块内不动
raw = ensureHeadingSpaces(raw)
var body = normalizeFlexTokens(raw)
@@ -469,10 +523,10 @@ class ReaderActivity : AppCompatActivity() {
private fun addTextSegment(text: String) {
if (text.isBlank()) return
val tv = TextView(this).apply {
textSize = 15f
// 正文 16sp + 1.4 倍行高:中文长文按 15sp/1.25 排,段落一多就糊成一片
textSize = 16f
setTextColor(ContextCompat.getColor(context, R.color.text))
// 正文字距放宽一点:15sp 的中文正文按 1.0 行距排,段落一多就糊成一片
setLineSpacing(dp(7).toFloat(), 1.25f)
setLineSpacing(dp(4).toFloat(), 1.4f)
movementMethod = LinkMovementMethod.getInstance()
}
markwon.setMarkdown(tv, text)
@@ -481,7 +535,7 @@ class ReaderActivity : AppCompatActivity() {
LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
).apply { topMargin = dp(10) },
).apply { topMargin = dp(8) },
)
}
@@ -561,7 +615,7 @@ class ReaderActivity : AppCompatActivity() {
LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
).apply { topMargin = dp(10) },
).apply { topMargin = dp(8) },
)
loadFullWidth(resolved, iv)
}

View File

@@ -144,7 +144,9 @@ object RssApi {
/** 扫描页数上限:服务端 pages 异常时不要无限请求(100 条/页,足够覆盖上万条) */
private const val MAX_SCAN_PAGES = 30
private const val UNREAD_TTL_MS = 10 * 60_000L
/** 统计结果复用窗口:本地已读变更会即时调整缓存值,这里只防抖动,
* 不能设长——设成 10 分钟时,缓存里残留的旧数字会一直挂在角标上。 */
private const val UNREAD_TTL_MS = 60_000L
/**
* 全部 RSS 条目中未读的数量。
@@ -164,10 +166,21 @@ object RssApi {
var page = 1
var pages = 1
var unread = 0
/* 服务端的 total / pages 是「跨站去重前」的口径,比列表实际能翻到的条数略大
(见 RssUnion Front::getFeeds 的注释)。页码越界时它会把 page 回落成最后一页,
于是同一批条目会被第二次、第三次返回——不去重就会把同一篇未读重复累加,
用户把文章全读完、角标却还挂着数字,正是这么来的。 */
val seenIds = HashSet<Long>()
while (page <= pages && page <= MAX_SCAN_PAGES) {
val result = items(prefs, page, pageSize = 100)
pages = result.pages
// 空页:没有更多数据可扫
if (result.items.isEmpty()) break
// 服务端把越界页钳回了别的页号(返回的 page 与请求不一致):已经到底,再翻就是重复
if (result.page != page) break
result.items.forEach { item ->
// 同一 id 只算一次,防止服务端重复返回时重复计数
if (!seenIds.add(item.id)) return@forEach
val id = item.id.toString()
// 本地删除过的条目不再计入未读,否则删掉后角标数字还挂着。
// 键与首页一致,都带 "rss:" 前缀(文章的 cid 可能与之同号)
@@ -581,10 +594,10 @@ object RssApi {
// 末尾的分隔线没有意义,去掉
out = out.replace(Regex("(?:\\n\\s*(?:-{3,}|\\*{3,}|_{3,})\\s*)+$"), "")
// 按行过滤会留下「只含反斜杠的硬换行行」「带空格的空行」,统一在这里收掉
out = tidyMarkdown(out)
codeList.forEachIndexed { i, code -> out = out.replace("\u0000C$i\u0000", code) }
return out
.replace(Regex("[ \t]+\n"), "\n")
.replace(Regex("\n{3,}"), "\n\n")
.trim()
}
/**
@@ -715,8 +728,61 @@ object RssApi {
}
// 收拢:行尾空白、行首缩进(代码块已占位)、连续空行
s = s.replace(Regex("[ \\t]+\\n"), "\n")
s = s.lines().joinToString("\n") { it.trim() }
return s.replace(Regex("\\n{3,}"), "\n\n").trim()
return tidyMarkdown(s)
}
/** 列表行(无序 / 有序),用于判断两行之间该不该留空行 */
private fun isListLine(line: String): Boolean =
line.startsWith("- ") || line.startsWith("* ") || line.startsWith("+ ") ||
Regex("^\\d+[.)]\\s").containsMatchIn(line)
/**
* 收尾整理:清掉占位符还原过程中产生的「无内容行」。
*
* 多余空行有三个来源,光靠 `\n{3,}` 正则压不住:
* 1. 块级标签收尾处 `</div><br><p>` 会还原出一行只有反斜杠的硬换行标记,
* 渲染出来就是一行空白;
* 2. 相邻块闭合之间夹着源码空白,形成「带空格的空行」——正则按连续 `\n` 匹配不到它;
* 3. 列表项之间被塞进空行后,Markwon 会按「松散列表」把行距整体放大。
*
* 代码块(``` 围栏内)原样保留:里面的空行、缩进都是内容的一部分。
*/
private fun tidyMarkdown(src: String): String {
val out = ArrayList<String>(src.length / 8 + 8)
var inFence = false
var pendingBlank = false
src.lines().forEach { raw ->
val line = raw.trimEnd()
val bare = line.trimStart()
// 围栏行:原样输出,同时切换「代码块内」状态
if (bare.startsWith("```")) {
inFence = !inFence
if (pendingBlank && out.isNotEmpty()) out.add("")
pendingBlank = false
out.add(bare)
return@forEach
}
// 代码块内部:不 trim、不合并空行
if (inFence) {
out.add(line)
return@forEach
}
val text = line.trim()
// 纯空白行、只有硬换行标记的行,都按「空行」处理
if (text.isEmpty() || text == "\\") {
if (out.isNotEmpty()) pendingBlank = true
return@forEach
}
if (pendingBlank) {
// 列表项之间不留空行,否则 Markwon 按松散列表渲染、行距翻倍
val prev = out.lastOrNull().orEmpty()
if (!(isListLine(prev) && isListLine(text))) out.add("")
pendingBlank = false
}
// trim 掉源码缩进:4 个空格会被 Markdown 当成代码块
out.add(text)
}
return out.joinToString("\n").trim()
}
/**