diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b78154..a752259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # 变更记录 +## 2026-11-27 · v3.39(versionCode 60) + +- 阅读页代码块改为独立代码卡:左侧行号、语法高亮、内容可横向滚动,顶部标注语言;长按整段复制。 +- 新增本地语法高亮 `CodeHighlight`:一趟扫描识别注释(`//`、`#`、`/* */`)、字符串(含三引号跨行)、数字、关键字、注解与函数调用;配色分深浅两套并跟随夜间模式。未引入 Prism4j,不增加依赖和包体。 +- 行号与代码放进同一个 TextView:中文注释回退字体导致行高变化时也不会错位半行。 +- `RssApi` 从 `
` 提取语言标注,随围栏代码块一起带到阅读页。
+- bluehe.cn(sujian 主题)按站点规则取正文容器 `.song`:页头封面、标题、发布时间、分类/阅读量/评论数,以及文末版权许可、继续阅读、上一篇下一篇不再混进正文。
+- 站点页面的「分类 · 阅读 · 评论」提取后补进顶栏 meta 行,正文里不再重复。
+- 修复 `a` 标签内只包一张图(灯箱)时整块被丢弃、正文配图跟着消失的问题(HTML 转 Markdown 与阅读页 HTML 兜底两处)。
+- 噪音区块补充 `nextnav` / `prevnext` / `keepreading` / `post-pic` 等命名,`pagination2` 这类带序号的按前缀匹配;行级过滤补充「继续阅读 · KEEP READING」「许可:」「CC BY」「本文原创」和日期打头的 meta 行。
+- 顶栏菜单文案:「查看原文」改为「原文」,「作者主页」改为「主页」。
+- AI 摘要框的标签最多显示三个(AI 返回顺序即重要性)。
+- 修复浅色模式下图片放大后顶部留一条白:对话框窗口压黑、内容延伸到系统栏并隐藏状态栏,深浅色都是整屏黑底。
+
## 2026-11-27 · v3.38(versionCode 59)
- 阅读页右上角「查看原文」改为「更多」,点开是下拉菜单:查看原文、作者主页(没有原文链接时该项不出现)。
diff --git a/src/main/java/com/shitoucuo/postpad/CodeHighlight.kt b/src/main/java/com/shitoucuo/postpad/CodeHighlight.kt
new file mode 100644
index 0000000..c240f53
--- /dev/null
+++ b/src/main/java/com/shitoucuo/postpad/CodeHighlight.kt
@@ -0,0 +1,226 @@
+package com.shitoucuo.postpad
+
+import android.text.Spannable
+import android.text.SpannableStringBuilder
+import android.text.style.ForegroundColorSpan
+
+/**
+ * 代码块语法高亮。
+ *
+ * 没有引 Prism4j:它要额外依赖 + 每种语言一个定义包,离线构建拿不到、包体也要涨几 MB。
+ * 这里一趟扫描覆盖日常阅读会遇到的大部分代码(C 系 / Java / Kotlin / JS / TS /
+ * Python / Go / Rust / Shell / SQL / JSON / 配置片段):注释、字符串、数字、
+ * 关键字、注解各有颜色,认不出的按正文色。
+ *
+ * 配色分深浅两套并由调用方传入:深色底上用亮色、浅色底上用深色,
+ * 固定一套配色总有一半场景是糊的。
+ */
+object CodeHighlight {
+
+ class Palette(
+ val keyword: Int,
+ val string: Int,
+ val comment: Int,
+ val number: Int,
+ val annotation: Int,
+ val function: Int,
+ )
+
+ /** 浅色底:深色字 + 高对比强调色(参考 GitHub Light) */
+ val LIGHT = Palette(
+ keyword = 0xFF8250DF.toInt(),
+ string = 0xFF0A7D33.toInt(),
+ comment = 0xFF7A828E.toInt(),
+ number = 0xFFB35900.toInt(),
+ annotation = 0xFFB25F35.toInt(),
+ function = 0xFF0550AE.toInt(),
+ )
+
+ /** 深色底:近白字 + 提亮的强调色(参考 One Dark) */
+ val DARK = Palette(
+ keyword = 0xFFC792EA.toInt(),
+ string = 0xFF9ECE6A.toInt(),
+ comment = 0xFF6F7784.toInt(),
+ number = 0xFFE0AF68.toInt(),
+ annotation = 0xFFD4814F.toInt(),
+ function = 0xFF7DCFFF.toInt(),
+ )
+
+ /** C 系预处理指令:`#include` 不是注释 */
+ private val PREPROC = listOf(
+ "include", "define", "undef", "ifdef", "ifndef", "endif", "pragma", "error", "import",
+ )
+
+ private val KEYWORDS = setOf(
+ // 通用 / C 系
+ "if", "else", "for", "while", "do", "switch", "case", "default", "break", "continue",
+ "return", "goto", "try", "catch", "finally", "throw", "throws", "new", "delete", "this",
+ "super", "null", "nil", "true", "false", "void", "static", "const", "constexpr", "final",
+ "abstract", "interface", "class", "struct", "enum", "union", "typedef", "namespace",
+ "using", "public", "private", "protected", "internal", "extends", "implements",
+ "instanceof", "typeof", "sizeof", "extern", "volatile", "synchronized", "transient",
+ "native", "package", "import", "export", "from", "as", "and", "or", "not", "is", "in",
+ // Kotlin / Java / C# / Swift / TS
+ "fun", "val", "var", "when", "out", "object", "data", "sealed", "companion", "init",
+ "suspend", "inline", "reified", "lateinit", "by", "override", "open", "operator",
+ "infix", "tailrec", "crossinline", "noinline", "typealias", "where", "field",
+ "let", "run", "apply", "also", "with", "async", "await", "yield", "function", "def",
+ "lambda", "string", "int", "long", "float", "double", "bool", "boolean", "char", "byte",
+ "short", "unsigned", "undefined", "never", "any", "unknown", "readonly", "declare",
+ "type", "keyof", "readonly", "override", "get", "set", "of",
+ // Python / Ruby / Lua / Shell
+ "elif", "except", "raise", "pass", "self", "cls", "global", "nonlocal", "assert", "del",
+ "None", "True", "False", "end", "then", "fi", "esac", "done", "local", "source",
+ "echo", "print", "require", "include_once", "elseif", "unless", "until",
+ // Go / Rust
+ "func", "defer", "go", "chan", "select", "range", "impl", "mut", "pub", "crate", "match",
+ "loop", "unsafe", "dyn", "trait", "use", "mod", "ref", "Some", "Ok", "Err", "fn",
+ // SQL
+ "select", "from", "where", "insert", "update", "delete", "join", "group", "order",
+ "limit", "create", "table", "alter", "drop", "index", "values", "into", "set",
+ )
+
+ /**
+ * 逐行高亮。
+ *
+ * 按行返回是为了让调用方在每行前面接行号——行号与代码放进同一个 TextView,
+ * 中文注释回退字体时也不会出现「行号比代码高半行」的错位。
+ * 块注释与三引号字符串的状态跨行传递,所以这里由同一个 Lexer 顺序处理。
+ */
+ fun highlightLines(code: String, palette: Palette): List {
+ val lexer = Lexer(palette)
+ return code.split('\n').map { lexer.line(it) }
+ }
+
+ private class Lexer(private val p: Palette) {
+
+ private var inBlockComment = false
+ private var tripleQuote: String? = null
+
+ fun line(src: String): CharSequence {
+ val out = SpannableStringBuilder(src)
+ var i = 0
+ val n = src.length
+ while (i < n) {
+ // 上一行遗留的块注释
+ if (inBlockComment) {
+ val end = src.indexOf("*/", i)
+ if (end < 0) {
+ mark(out, i, n, p.comment)
+ return out
+ }
+ mark(out, i, end + 2, p.comment)
+ inBlockComment = false
+ i = end + 2
+ continue
+ }
+ // 上一行遗留的三引号字符串
+ val pendingQuote = tripleQuote
+ if (pendingQuote != null) {
+ val end = src.indexOf(pendingQuote, i)
+ if (end < 0) {
+ mark(out, i, n, p.string)
+ return out
+ }
+ mark(out, i, end + 3, p.string)
+ tripleQuote = null
+ i = end + 3
+ continue
+ }
+
+ val c = src[i]
+ // 块注释开头
+ if (c == '/' && i + 1 < n && src[i + 1] == '*') {
+ val end = src.indexOf("*/", i + 2)
+ if (end < 0) {
+ mark(out, i, n, p.comment)
+ inBlockComment = true
+ return out
+ }
+ mark(out, i, end + 2, p.comment)
+ i = end + 2
+ continue
+ }
+ // 行注释
+ if (c == '/' && i + 1 < n && src[i + 1] == '/') {
+ mark(out, i, n, p.comment)
+ return out
+ }
+ // 三引号字符串(Kotlin """ / Python '''):允许跨行
+ if ((c == '"' || c == '\'') && i + 2 < n && src[i + 1] == c && src[i + 2] == c) {
+ val q = StringBuilder().append(c).append(c).append(c).toString()
+ val end = src.indexOf(q, i + 3)
+ if (end < 0) {
+ mark(out, i, n, p.string)
+ tripleQuote = q
+ return out
+ }
+ mark(out, i, end + 3, p.string)
+ i = end + 3
+ continue
+ }
+ // 普通字符串
+ if (c == '"' || c == '\'' || c == '`') {
+ var j = i + 1
+ while (j < n) {
+ if (src[j] == '\\' && j + 1 < n) {
+ j += 2
+ continue
+ }
+ if (src[j] == c) {
+ j++
+ break
+ }
+ j++
+ }
+ mark(out, i, j, p.string)
+ i = j
+ continue
+ }
+ // # 注释 / 预处理指令(只在行首或空白后生效,避免切到 a#b)
+ if (c == '#' && (i == 0 || src[i - 1].isWhitespace())) {
+ val rest = src.substring(i + 1).trimStart()
+ if (PREPROC.any { rest.startsWith(it) }) {
+ mark(out, i, n, p.annotation)
+ } else {
+ mark(out, i, n, p.comment)
+ }
+ return out
+ }
+ // 数字
+ if (c.isDigit() && (i == 0 || !(src[i - 1].isLetterOrDigit() || src[i - 1] == '_'))) {
+ var j = i
+ while (j < n && (src[j].isLetterOrDigit() || src[j] == '.' || src[j] == '_')) j++
+ mark(out, i, j, p.number)
+ i = j
+ continue
+ }
+ // 标识符 / 关键字 / 函数名 / 注解
+ if (c.isLetter() || c == '_' || c == '@' || c == '$') {
+ var j = if (c == '@') i + 1 else i
+ while (j < n && (src[j].isLetterOrDigit() || src[j] == '_' || src[j] == '$')) j++
+ val word = src.substring(if (c == '@') i + 1 else i, j)
+ when {
+ c == '@' -> mark(out, i, j, p.annotation)
+ word in KEYWORDS -> mark(out, i, j, p.keyword)
+ // 后面紧跟左括号:函数 / 方法调用
+ j < n && src[j] == '(' -> mark(out, i, j, p.function)
+ }
+ i = if (j > i) j else i + 1
+ continue
+ }
+ i++
+ }
+ return out
+ }
+
+ private fun mark(out: SpannableStringBuilder, start: Int, end: Int, color: Int) {
+ if (end > start && start >= 0) {
+ out.setSpan(
+ ForegroundColorSpan(color), start, end,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
+ )
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/shitoucuo/postpad/ReaderActivity.kt b/src/main/java/com/shitoucuo/postpad/ReaderActivity.kt
index 15de322..fc02edb 100644
--- a/src/main/java/com/shitoucuo/postpad/ReaderActivity.kt
+++ b/src/main/java/com/shitoucuo/postpad/ReaderActivity.kt
@@ -1,21 +1,30 @@
package com.shitoucuo.postpad
+import android.content.ClipData
+import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
+import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Outline
+import android.graphics.Typeface
+import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.app.Dialog
+import android.text.Spannable
+import android.text.SpannableStringBuilder
import android.text.method.LinkMovementMethod
+import android.text.style.ForegroundColorSpan
import android.util.LruCache
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.ViewOutlineProvider
import android.widget.ArrayAdapter
+import android.widget.HorizontalScrollView
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ListView
@@ -26,6 +35,9 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
+import androidx.core.view.WindowCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.lifecycleScope
import io.noties.markwon.Markwon
import io.noties.markwon.image.ImagesPlugin
@@ -63,6 +75,9 @@ class ReaderActivity : AppCompatActivity() {
private var metaAuthor: String = ""
private var metaDate: Long = 0L
+ /** 站点页面上的补充元信息(分类 · 阅读 · 评论),原文抓到后才有 */
+ private var metaExtra: String = ""
+
/** 来源站点信息:作者主页按站点过滤,并用站点首页做「打开网站」 */
private var siteUrl: String = ""
private var urlId: Long = 0L
@@ -217,6 +232,11 @@ class ReaderActivity : AppCompatActivity() {
metaAuthor = article.author
renderMeta()
}
+ // 分类 / 阅读量 / 评论数同样收进顶栏,正文里不再重复
+ if (article.metaExtra.isNotBlank()) {
+ metaExtra = article.metaExtra
+ renderMeta()
+ }
val body = stripLeadingNoise(article.markdown.ifBlank { excerpt })
renderWithBrief(body.ifBlank { excerpt.ifBlank { "(原文里没有抓到正文)" } })
} catch (e: Exception) {
@@ -245,6 +265,11 @@ class ReaderActivity : AppCompatActivity() {
if (isNotEmpty()) append(" · ")
append(formatDate(metaDate))
}
+ // 分类 · 阅读 · 评论:站点详情页才有的信息,补在最后
+ if (metaExtra.isNotBlank()) {
+ if (isNotEmpty()) append(" · ")
+ append(metaExtra)
+ }
}
tvMeta.text = text
tvMeta.visibility = if (text.isBlank()) View.GONE else View.VISIBLE
@@ -366,7 +391,7 @@ class ReaderActivity : AppCompatActivity() {
.trim()
.length
- /** AI 给的标签优先,再并上条目自带的,去重后最多 8 个 */
+ /** AI 给的标签优先,再并上条目自带的,去重后最多 3 个 */
private fun mergeTags(aiTags: List): List {
val out = ArrayList()
(aiTags + itemTags).forEach { raw ->
@@ -374,7 +399,8 @@ class ReaderActivity : AppCompatActivity() {
if (tag.isEmpty() || tag.length > 14) return@forEach
if (out.none { it.equals(tag, true) }) out.add(tag)
}
- return out.take(8)
+ // 摘要框只放最重要的三个:AI 返回的顺序就是重要性,条目自带标签补在后面
+ return out.take(3)
}
private fun requestBrief() {
@@ -665,11 +691,20 @@ class ReaderActivity : AppCompatActivity() {
.replace(Regex("<(em|i)\\b[^>]*>", RegexOption.IGNORE_CASE), "*")
.replace(Regex("(em|i)\\s*>", RegexOption.IGNORE_CASE), "*")
.replace(Regex("]*>", RegexOption.IGNORE_CASE), "\n> ")
- // 链接
+ // 链接:只包着一张图的(灯箱),链接没有文字,直接留内层,别把图吃掉
s = Regex(
"]*href\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>([\\s\\S]*?)",
RegexOption.IGNORE_CASE,
- ).replace(s) { m -> "[${m.groupValues[2]}](${m.groupValues[1]})" }
+ ).replace(s) { m ->
+ val inner = m.groupValues[2]
+ val text = inner.replace(Regex("<[^>]*>"), "").trim()
+ when {
+ text.isNotEmpty() -> "[$text](${m.groupValues[1]})"
+ inner.contains("![") || Regex("
+ inner
+ else -> ""
+ }
+ }
// 剩余未知标签一律剥掉(含自闭合),正文不再露出 之类
s = s.replace(Regex("?[a-zA-Z][^>]*>"), "")
s = s.replace(Regex("\\n{3,}"), "\n\n")
@@ -743,6 +778,9 @@ class ReaderActivity : AppCompatActivity() {
raw = tidyBlank(raw)
// 站里标题常写成 "#标题"(# 后无空格,CommonMark 不识别),补上空格;代码块内不动
raw = ensureHeadingSpaces(raw)
+ // 代码块单独成卡(行号 + 高亮):先抽成占位符,剩下的文字段才交给 Markwon
+ val codeBlocks = ArrayList()
+ raw = extractCodeBlocks(raw, codeBlocks)
var body = normalizeFlexTokens(raw)
// 收集文末引用定义行(站里的定义行带前导空格),供引用式图片解析
val refs = Regex("(?m)^\\s*\\[([^\\]]+)\\]:\\s*(\\S+)")
@@ -759,20 +797,145 @@ class ReaderActivity : AppCompatActivity() {
// 删掉引用定义行(文末 [1]: url 之类),不在正文里显示图片地址
body = body.replace(Regex("(?m)^\\s*\\[[^\\]]+\\]:\\s*\\S+.*$"), "")
bodyContainer.removeAllViews()
- val tokenRe = Regex("%%(FLEXP|IMG)%%\\s*([\\s\\S]*?)\\s*%%/\\1%%")
+ val tokenRe = Regex("%%(FLEXP|IMG)%%\\s*([\\s\\S]*?)\\s*%%/\\1%%|%%CODE(\\d+)%%")
var last = 0
for (m in tokenRe.findAll(body)) {
addTextSegment(body.substring(last, m.range.first).trim())
- val urls = m.groupValues[2].lines().map { it.trim() }.filter { it.isNotEmpty() }
- when (m.groupValues[1]) {
- "IMG" -> urls.forEach { addFullImage(it) }
- else -> if (urls.isNotEmpty()) addFlexPhotoRow(urls)
+ val codeIndex = m.groupValues[3]
+ if (codeIndex.isNotEmpty()) {
+ codeBlocks.getOrNull(codeIndex.toIntOrNull() ?: -1)
+ ?.let { addCodeBlock(it.lang, it.code) }
+ } else {
+ val urls = m.groupValues[2].lines().map { it.trim() }.filter { it.isNotEmpty() }
+ when (m.groupValues[1]) {
+ "IMG" -> urls.forEach { addFullImage(it) }
+ else -> if (urls.isNotEmpty()) addFlexPhotoRow(urls)
+ }
}
last = m.range.last + 1
}
addTextSegment(body.substring(last).trim())
}
+ /** 抽出来的围栏代码块:语言标注 + 原始代码 */
+ private class CodeBlock(val lang: String, val code: String)
+
+ /**
+ * 把 ``` 围栏代码块换成 `%%CODEn%%` 占位符。
+ *
+ * 交给 Markwon 渲染只能得到一段等宽文字,没有行号也没有高亮;
+ * 抽出来是为了按代码卡单独排版(行号列 + 高亮 + 横向滚动)。
+ * 围栏必须整行,正文里行内的反引号不会被误抽。
+ */
+ private fun extractCodeBlocks(markdown: String, sink: MutableList): String =
+ Regex("(?m)^[ \\t]*```([^\\n`]*)\\n([\\s\\S]*?)^[ \\t]*```[ \\t]*$").replace(markdown) { m ->
+ val code = m.groupValues[2].trimEnd('\n')
+ if (code.isBlank()) {
+ ""
+ } else {
+ sink.add(CodeBlock(m.groupValues[1].trim(), code))
+ "\n%%CODE${sink.size - 1}%%\n"
+ }
+ }
+
+ /**
+ * 代码卡:顶部语言标注 + 行号 + 语法高亮,内容可横向滚动。
+ *
+ * 行号与代码放进同一个 TextView:中文注释回退字体时行高会变,
+ * 两个 TextView 并排就一定会错位半行,合成一个文本永远不会错。
+ */
+ private fun addCodeBlock(lang: String, code: String) {
+ if (code.isBlank()) return
+ val dark = isNightMode()
+ val palette = if (dark) CodeHighlight.DARK else CodeHighlight.LIGHT
+ val card = LinearLayout(this).apply {
+ orientation = LinearLayout.VERTICAL
+ setBackgroundResource(R.drawable.bg_code_card)
+ clipToOutline = true
+ }
+ if (lang.isNotBlank() && lang.length <= 16) {
+ val label = TextView(this).apply {
+ text = lang.lowercase()
+ textSize = 10f
+ letterSpacing = 0.08f
+ setTextColor(ContextCompat.getColor(context, R.color.code_lang))
+ setPadding(dp(14), dp(9), dp(14), 0)
+ }
+ card.addView(label)
+ }
+ val body = TextView(this).apply {
+ typeface = Typeface.MONOSPACE
+ textSize = 12.5f
+ includeFontPadding = false
+ setLineSpacing(0f, 1.42f)
+ setTextColor(ContextCompat.getColor(context, R.color.code_text))
+ text = buildCodeText(code, palette)
+ setPadding(dp(14), dp(10), dp(14), dp(12))
+ // 长按整段复制:代码卡里拖选很容易选到行号,整段复制更实用
+ setOnLongClickListener {
+ val cm = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
+ cm.setPrimaryClip(ClipData.newPlainText("code", code))
+ toast("代码已复制")
+ true
+ }
+ }
+ val scroll = HorizontalScrollView(this).apply {
+ isHorizontalScrollBarEnabled = false
+ isFillViewport = true
+ addView(
+ body,
+ ViewGroup.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ),
+ )
+ }
+ card.addView(
+ scroll,
+ LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ),
+ )
+ bodyContainer.addView(
+ card,
+ LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ).apply {
+ topMargin = dp(10)
+ bottomMargin = dp(2)
+ },
+ )
+ }
+
+ /** 行号 + 高亮代码拼成一段 Spannable,行号用弱化色右对齐 */
+ private fun buildCodeText(code: String, palette: CodeHighlight.Palette): CharSequence {
+ val lines = code.split('\n')
+ val highlights = CodeHighlight.highlightLines(code, palette)
+ val linenoColor = ContextCompat.getColor(this, R.color.code_lineno)
+ val width = lines.size.toString().length
+ val sb = SpannableStringBuilder()
+ lines.forEachIndexed { index, _ ->
+ val gutter = (index + 1).toString().padStart(width, ' ') + " "
+ val start = sb.length
+ sb.append(gutter)
+ sb.setSpan(
+ ForegroundColorSpan(linenoColor), start, sb.length,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
+ )
+ sb.append(highlights.getOrElse(index) { "" })
+ if (index < lines.size - 1) sb.append('\n')
+ }
+ return sb
+ }
+
+ /** 当前是否深色:代码高亮配色跟主题走,不是写死一套 */
+ private fun isNightMode(): Boolean {
+ val mode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
+ return mode == Configuration.UI_MODE_NIGHT_YES
+ }
+
private fun addTextSegment(text: String) {
if (text.isBlank()) return
val tv = TextView(this).apply {
@@ -989,6 +1152,23 @@ class ReaderActivity : AppCompatActivity() {
),
)
dialog.show()
+ /* 看图要整屏纯黑。Dialog 的 window 默认不会盖住状态栏,浅色主题下顶上就
+ 留一条白(「顶部一片空白、不是全黑」的来源)。这里把 window 背景压黑、
+ 内容延伸到系统栏,再直接把状态栏隐藏,深色浅色都是同一块黑底。 */
+ dialog.window?.let { w ->
+ w.setBackgroundDrawable(ColorDrawable(Color.BLACK))
+ w.navigationBarColor = Color.BLACK
+ WindowCompat.setDecorFitsSystemWindows(w, false)
+ w.setLayout(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ )
+ WindowInsetsControllerCompat(w, w.decorView).apply {
+ hide(WindowInsetsCompat.Type.statusBars())
+ systemBarsBehavior =
+ WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
+ }
+ }
val url = urls[index]
// 全屏查看按屏幕长边采样即可;原实现 targetSize=0 解原图,
// 一张 4000×3000 的照片就是 48MB,连开两张低端机必崩。
diff --git a/src/main/java/com/shitoucuo/postpad/RssApi.kt b/src/main/java/com/shitoucuo/postpad/RssApi.kt
index 6800f12..30b3898 100644
--- a/src/main/java/com/shitoucuo/postpad/RssApi.kt
+++ b/src/main/java/com/shitoucuo/postpad/RssApi.kt
@@ -231,23 +231,26 @@ object RssApi {
suspend fun article(link: String): Article = withContext(Dispatchers.IO) {
if (!link.startsWith("http", true)) return@withContext Article("")
val html = fetchPage(link)
+ /* 页面上的补充元信息(分类 / 阅读量 / 评论数):顶栏已经有来源、作者、日期,
+ 这几项站点各不相同,只能按站点从页面里取,取不到就空着。 */
+ val extra = extractMetaExtra(html, link)
/* 纯前端渲染的站点(Vue / React 单页应用)HTML 里只有一个挂载点
``,正文由 JS 在浏览器里拼出来,直接抓 HTML 永远是空壳。
这类站点通常仍开放 /feed/,而 content:encoded 里就是全文——
从自家 RSS 取是站点公开提供的渠道,不用碰它的接口签名。 */
if (isSpaShell(html)) {
val full = feedFullText(link)
- if (full.isNotBlank()) return@withContext Article(full)
+ if (full.isNotBlank()) return@withContext Article(full, "", extra)
}
val author = extractAuthor(html)
- val main = selectMainContent(html)
+ val main = selectMainContent(html, link)
val markdown = pruneNoiseLines(htmlToMarkdown(flexPhotoTokens(pruneNoiseBlocks(main))))
// 正文短得不像文章(空壳站、或正文容器没被认出来):再试一次 feed 全文
if (markdown.length < 80) {
val full = feedFullText(link)
- if (full.isNotBlank()) return@withContext Article(full, author)
+ if (full.isNotBlank()) return@withContext Article(full, author, extra)
}
- Article(markdown, author)
+ Article(markdown, author, extra)
}
private fun fetchPage(url: String): String {
@@ -441,7 +444,12 @@ object RssApi {
}
/** 原文正文与作者 */
- data class Article(val markdown: String, val author: String = "")
+ data class Article(
+ val markdown: String,
+ val author: String = "",
+ /** 页面上额外的元信息(分类 · 阅读 · 评论),顶栏补在日期后面 */
+ val metaExtra: String = "",
+ )
/**
* 作者提取:优先结构化数据(meta / JSON-LD),再退到 class="author" 之类。
@@ -483,7 +491,7 @@ object RssApi {
* 或者在 header 里放一条摘要式 article;取「最长」能稳定命中真正的正文。
* 选中正文容器后,页头、页脚、侧栏、目录、标签云、评论、版权在结构上就已经不在里面了。
*/
- private fun selectMainContent(html: String): String {
+ private fun selectMainContent(html: String, link: String): String {
val s = html
.replace(Regex("