v3.29–v3.34:RSS 阅读页净化、批量选择与左滑、未读角标、邮件多账户聚合与排版修复
- 同步 HomeActivity/MailDetailActivity/MainActivity/ReaderActivity/RssApi 及 activity_home、activity_main 布局 - 更新 CHANGELOG 至 v3.34(versionCode 55)
This commit is contained in:
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,5 +1,20 @@
|
|||||||
# 变更记录
|
# 变更记录
|
||||||
|
|
||||||
|
## 2026-11-26 · v3.34(versionCode 55)
|
||||||
|
|
||||||
|
- RSS 阅读页深度净化:仅保留标题、作者、正文;过滤版权声明、标签、目录、分析数据、点赞评论数、文章地址、评论框与末尾分隔线,并去重顶部重复的标题/日期/分类。
|
||||||
|
- 「发文」「发博」拆分为两个独立入口,挂在发布按钮二级菜单下,移除页面顶部 tab 切换。
|
||||||
|
- HTML/框架邮件排版与深浅色优化:拆离正文与 style、限宽包裹、剥离 `color-scheme` 媒体查询并强制 `light only`、固定 viewport,避免排版错乱与暗色下发灰。
|
||||||
|
- 文章与邮件列表的选择栏、「已选 N 项」及操作按钮统一为圆角胶囊样式。
|
||||||
|
|
||||||
|
## 2026-11-26 · v3.29 – v3.33
|
||||||
|
|
||||||
|
- v3.33:左滑改为激活卡片左侧选择框;去掉左滑删除按钮与顶部「选择」入口,滑出后显示全选/设为已读/已选 N 项/删除;取消最后一项自动退出选择模式。
|
||||||
|
- v3.32:修复信息与邮件未读角标数字被裁切;新增列表项左滑删除;搜索栏下一行新增批量操作栏。
|
||||||
|
- v3.31:邮件卡片邮箱名前置(仅「全部邮箱」显示,筛选后不重复);RSS 与邮件改为点击即已读,标记与统计精准;信息/邮件菜单新增未读角标。
|
||||||
|
- v3.30:邮件首页聚合全部账户并可本地筛选,卡片显示邮箱名;修复多账户邮件串号、幽灵邮件与已读状态错乱(缓存带 UIDVALIDITY、每次同步用 `FETCH(UID FLAGS)` 校正);Markdown 图片预览失败增加内存位图兜底、URL 归一化与换 UA/Referer 重试。
|
||||||
|
- v3.29:Memos 正文图片支持点击放大,与追加图片统一横排。
|
||||||
|
|
||||||
## 2026-11-26 · 初始同步
|
## 2026-11-26 · 初始同步
|
||||||
|
|
||||||
- 同步插件源代码到新 Gitea 仓库。
|
- 同步插件源代码到新 Gitea 仓库。
|
||||||
|
|||||||
@@ -249,7 +249,14 @@ class HomeActivity : AppCompatActivity() {
|
|||||||
btnSelectAll.text = getString(
|
btnSelectAll.text = getString(
|
||||||
if (adapter.allSelected()) R.string.select_none else R.string.select_all
|
if (adapter.allSelected()) R.string.select_none else R.string.select_all
|
||||||
)
|
)
|
||||||
tvSelectedCount.text = if (count > 0) getString(R.string.selected_count, count) else ""
|
// 「已选 N 项」是一枚圆角胶囊:没有选中项时整枚隐藏,避免留一个空壳
|
||||||
|
if (count > 0) {
|
||||||
|
tvSelectedCount.text = getString(R.string.selected_count, count)
|
||||||
|
tvSelectedCount.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
tvSelectedCount.text = ""
|
||||||
|
tvSelectedCount.visibility = View.GONE
|
||||||
|
}
|
||||||
listOf(btnMarkRead, btnDeleteSelected).forEach { btn ->
|
listOf(btnMarkRead, btnDeleteSelected).forEach { btn ->
|
||||||
btn.isEnabled = count > 0
|
btn.isEnabled = count > 0
|
||||||
btn.alpha = if (btn.isEnabled) 1f else 0.45f
|
btn.alpha = if (btn.isEnabled) 1f else 0.45f
|
||||||
|
|||||||
@@ -203,6 +203,10 @@ class MailDetailActivity : AppCompatActivity() {
|
|||||||
// 邮件里常见 http 图片,放开混合内容才能显示
|
// 邮件里常见 http 图片,放开混合内容才能显示
|
||||||
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
||||||
textZoom = 100
|
textZoom = 100
|
||||||
|
// 邮件里普遍带 viewport meta:开启后按 device-width 排版,
|
||||||
|
// 否则 600px 的定宽模板会被压成两倍宽再缩回来,字小且易错位
|
||||||
|
useWideViewPort = true
|
||||||
|
loadWithOverviewMode = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,40 +233,43 @@ class MailDetailActivity : AppCompatActivity() {
|
|||||||
Configuration.UI_MODE_NIGHT_YES
|
Configuration.UI_MODE_NIGHT_YES
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTML 邮件净化:去掉脚本 / 内嵌框架,图片与表格限制在屏宽内。
|
* HTML 邮件渲染。
|
||||||
* 深色模式强制深色:所有容器背景透明、文字继承正文浅色(!important 压过邮件内联样式),
|
*
|
||||||
* 避免模板邮件在深色下仍是刺眼白块;链接用主题橙、标题近白。
|
* 排版错乱主要有三个来源,这里逐一处理:
|
||||||
* 浅色模式保留邮件原样,仅注入底色兜底。
|
* 1. **重复的文档结构**:邮件本身就是完整的 <html><head><body>,再被塞进我们的
|
||||||
|
* <body> 里就变成嵌套文档,WebView 会把 head 里的样式挪位置、body 属性失效。
|
||||||
|
* 所以先把 head / body 拆开,只取正文与其中的 <style>,再拼一份干净的骨架。
|
||||||
|
* 2. **宽表溢出**:营销邮件常用 600px 固定宽表格,超出屏宽就会横向溢出、
|
||||||
|
* 整页错位。正文包一层可换行的容器,图片与表格统一压到屏宽内。
|
||||||
|
* 3. **系统深色下的二次反色**:邮件自带 `prefers-color-scheme` 媒体查询或
|
||||||
|
* `color-scheme` meta 时,WebView 会自行反色,和我们注入的配色打架。
|
||||||
|
* 这些声明统一剥掉,配色只由这里的 CSS 决定。
|
||||||
*/
|
*/
|
||||||
private fun showHtmlMail(html: String) {
|
private fun showHtmlMail(raw: String) {
|
||||||
val dark = isDarkMode()
|
val dark = isDarkMode()
|
||||||
var s = html
|
val cleaned = raw
|
||||||
.replace(Regex("<script[\\s\\S]*?</script>", RegexOption.IGNORE_CASE), "")
|
.replace(Regex("<script[\\s\\S]*?</script>", RegexOption.IGNORE_CASE), "")
|
||||||
.replace(Regex("<script[^>]*/>", RegexOption.IGNORE_CASE), "")
|
.replace(Regex("<script[^>]*/>", RegexOption.IGNORE_CASE), "")
|
||||||
.replace(Regex("<iframe[\\s\\S]*?</iframe>", RegexOption.IGNORE_CASE), "")
|
.replace(Regex("<iframe[\\s\\S]*?</iframe>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("<object[\\s\\S]*?</object>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("<embed[^>]*>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("<link[^>]*>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("<meta[^>]*>", RegexOption.IGNORE_CASE), "")
|
||||||
.replace(Regex("<!--[\\s\\S]*?-->"), "")
|
.replace(Regex("<!--[\\s\\S]*?-->"), "")
|
||||||
val theme = buildString {
|
|
||||||
append("body{margin:0;padding:0;font-family:sans-serif;")
|
val (content, emailCss) = splitMailDocument(cleaned)
|
||||||
append("-webkit-text-size-adjust:100%;word-wrap:break-word;overflow-wrap:break-word;")
|
val page = buildString {
|
||||||
if (dark) {
|
append("<!DOCTYPE html><html><head><meta charset=\"utf-8\">")
|
||||||
append("background:#191B1F!important;color:#EFEBE4!important;}")
|
append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">")
|
||||||
// 容器背景全部拍平透明、文字一律继承,保证深色下永远可读
|
// 只按我们自己算好的配色渲染,禁止 WebView 自动加深/反色
|
||||||
append("table,td,th,tr,tbody,thead,tfoot,div,span,p,li,ul,ol,dl,dd,dt,")
|
append("<meta name=\"color-scheme\" content=\"light only\">")
|
||||||
append("section,article,figure,figcaption,header,footer,aside,blockquote,pre,code,")
|
append("<style>").append(baseMailCss()).append("</style>")
|
||||||
append("font,h1,h2,h3,h4,h5,h6,strong,b,em,i,u,small,label")
|
if (emailCss.isNotBlank()) append("<style>").append(emailCss).append("</style>")
|
||||||
append("{background-color:transparent!important;color:inherit!important;}")
|
append("<style>").append(themeMailCss(dark)).append("</style>")
|
||||||
append("a,a *{color:#D4814F!important;}")
|
append("</head><body><div class=\"pp-wrap\">")
|
||||||
append("h1,h2,h3,h4,h5,h6{color:#FAF7F1!important;}")
|
append(content)
|
||||||
} else {
|
append("</div></body></html>")
|
||||||
append("background:#FFFFFF;color:#1D1B18;}")
|
|
||||||
}
|
}
|
||||||
append("img{max-width:100%!important;height:auto!important;}")
|
|
||||||
append("table{max-width:100%!important;}")
|
|
||||||
append("pre,code{white-space:pre-wrap;max-width:100%;}")
|
|
||||||
}
|
|
||||||
val page = "<!DOCTYPE html><html><head><meta charset=\"utf-8\">" +
|
|
||||||
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=3\">" +
|
|
||||||
"<style>$theme</style></head><body>$s</body></html>"
|
|
||||||
tvBody.visibility = TextView.GONE
|
tvBody.visibility = TextView.GONE
|
||||||
webViewMail.visibility = TextView.VISIBLE
|
webViewMail.visibility = TextView.VISIBLE
|
||||||
// 底色同步:深色下滚动过冲区域也是深色
|
// 底色同步:深色下滚动过冲区域也是深色
|
||||||
@@ -272,6 +279,97 @@ class MailDetailActivity : AppCompatActivity() {
|
|||||||
webViewMail.loadDataWithBaseURL(null, page, "text/html", "utf-8", null)
|
webViewMail.loadDataWithBaseURL(null, page, "text/html", "utf-8", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把邮件拆成「正文片段」与「内联样式」两份。
|
||||||
|
*
|
||||||
|
* 邮件里的 <style> 有的是整页样式,放进我们的 head 才生效;
|
||||||
|
* head/body 外壳则必须丢掉,否则是嵌套文档。
|
||||||
|
*/
|
||||||
|
private fun splitMailDocument(html: String): Pair<String, String> {
|
||||||
|
val css = Regex("<style[^>]*>([\\s\\S]*?)</style>", RegexOption.IGNORE_CASE)
|
||||||
|
.findAll(html)
|
||||||
|
.joinToString("\n") { it.groupValues[1] }
|
||||||
|
.let { stripColorSchemeMedia(it) }
|
||||||
|
val body = Regex("<body[^>]*>([\\s\\S]*)</body>", RegexOption.IGNORE_CASE)
|
||||||
|
.find(html)?.groupValues?.get(1)
|
||||||
|
?: html.replace(Regex("<head[\\s\\S]*?</head>", RegexOption.IGNORE_CASE), "")
|
||||||
|
val content = body
|
||||||
|
.replace(Regex("<style[^>]*>[\\s\\S]*?</style>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.replace(Regex("</?(html|head|body)\\b[^>]*>", RegexOption.IGNORE_CASE), "")
|
||||||
|
.trim()
|
||||||
|
return content to css
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去掉 `@media (prefers-color-scheme: dark)` 整块。
|
||||||
|
*
|
||||||
|
* 这类规则会在系统深色时把邮件改成另一套配色,与这里注入的主题叠加后
|
||||||
|
* 常出现「浅字压浅底」;按大括号配对整段删除,剩下的 CSS 保持原样。
|
||||||
|
*/
|
||||||
|
private fun stripColorSchemeMedia(css: String): String {
|
||||||
|
var s = css
|
||||||
|
val re = Regex("@media[^{]*prefers-color-scheme[^{]*\\{", RegexOption.IGNORE_CASE)
|
||||||
|
var guard = 0
|
||||||
|
while (guard++ < 20) {
|
||||||
|
val m = re.find(s) ?: break
|
||||||
|
var depth = 1
|
||||||
|
var i = m.range.last + 1
|
||||||
|
while (i < s.length && depth > 0) {
|
||||||
|
when (s[i]) {
|
||||||
|
'{' -> depth++
|
||||||
|
'}' -> depth--
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
s = s.removeRange(m.range.first, i)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 基础排版:限宽、换行、图片与表格不溢出 */
|
||||||
|
private fun baseMailCss(): String = buildString {
|
||||||
|
append("html,body{margin:0;padding:0;}")
|
||||||
|
append("body{font-family:-apple-system,'Helvetica Neue',sans-serif;font-size:15px;")
|
||||||
|
append("line-height:1.62;-webkit-text-size-adjust:100%;")
|
||||||
|
append("word-wrap:break-word;overflow-wrap:anywhere;}")
|
||||||
|
// 横向兜底:少数顽固的定宽表格仍可能撑宽,至少让它自己滚,不把整页挤歪
|
||||||
|
append(".pp-wrap{width:100%;max-width:100%;overflow-x:auto;overflow-y:hidden;}")
|
||||||
|
append(".pp-wrap img{max-width:100%!important;height:auto!important;}")
|
||||||
|
append(".pp-wrap table{max-width:100%!important;}")
|
||||||
|
append(".pp-wrap td,.pp-wrap th{word-break:break-word;}")
|
||||||
|
append(".pp-wrap pre,.pp-wrap code{white-space:pre-wrap!important;word-break:break-word;}")
|
||||||
|
append(".pp-wrap blockquote{margin:12px 0;padding-left:12px;}")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主题配色。
|
||||||
|
*
|
||||||
|
* 深色:把所有容器背景拍平成透明(否则模板邮件一进来就是刺眼白块),
|
||||||
|
* 文字统一继承浅色,标题更亮、链接用品牌橙;边框同步调暗,避免白色分隔线。
|
||||||
|
* 浅色:保留邮件原本的配色,只给页面兜一层白底。
|
||||||
|
*/
|
||||||
|
private fun themeMailCss(dark: Boolean): String = buildString {
|
||||||
|
if (dark) {
|
||||||
|
append("html,body{background:#191B1F!important;color:#EFEBE4!important;}")
|
||||||
|
append(".pp-wrap,.pp-wrap table,.pp-wrap thead,.pp-wrap tbody,.pp-wrap tfoot,")
|
||||||
|
append(".pp-wrap tr,.pp-wrap td,.pp-wrap th,.pp-wrap div,.pp-wrap span,")
|
||||||
|
append(".pp-wrap p,.pp-wrap li,.pp-wrap ul,.pp-wrap ol,.pp-wrap dl,.pp-wrap dd,")
|
||||||
|
append(".pp-wrap section,.pp-wrap article,.pp-wrap header,.pp-wrap footer,")
|
||||||
|
append(".pp-wrap aside,.pp-wrap center,.pp-wrap blockquote,.pp-wrap pre,")
|
||||||
|
append(".pp-wrap code,.pp-wrap font,.pp-wrap label,.pp-wrap small,")
|
||||||
|
append(".pp-wrap h1,.pp-wrap h2,.pp-wrap h3,.pp-wrap h4,.pp-wrap h5,.pp-wrap h6")
|
||||||
|
append("{background-color:transparent!important;border-color:#33383F!important;}")
|
||||||
|
append(".pp-wrap{color:#EFEBE4!important;}")
|
||||||
|
append(".pp-wrap *{color:inherit!important;}")
|
||||||
|
append(".pp-wrap a,.pp-wrap a *{color:#D4814F!important;}")
|
||||||
|
append(".pp-wrap h1,.pp-wrap h2,.pp-wrap h3,.pp-wrap h4,.pp-wrap h5,.pp-wrap h6")
|
||||||
|
append("{color:#FAF7F1!important;}")
|
||||||
|
append(".pp-wrap hr{border-color:#33383F!important;}")
|
||||||
|
} else {
|
||||||
|
append("html,body{background:#FFFFFF!important;}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** 回复:引用原文,正文输入后用当前邮箱的 SMTP 直接发送 */
|
/** 回复:引用原文,正文输入后用当前邮箱的 SMTP 直接发送 */
|
||||||
private fun showReplyDialog() {
|
private fun showReplyDialog() {
|
||||||
val current = detail ?: run {
|
val current = detail ?: run {
|
||||||
|
|||||||
@@ -54,8 +54,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private lateinit var prefs: Prefs
|
private lateinit var prefs: Prefs
|
||||||
|
|
||||||
private lateinit var tabPublish: TextView
|
|
||||||
private lateinit var tabMemo: TextView
|
|
||||||
private lateinit var panelPublish: View
|
private lateinit var panelPublish: View
|
||||||
private lateinit var panelMemo: View
|
private lateinit var panelMemo: View
|
||||||
private lateinit var panelEmpty: View
|
private lateinit var panelEmpty: View
|
||||||
@@ -157,8 +155,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
btnTheme.setOnClickListener { toggleTheme() }
|
btnTheme.setOnClickListener { toggleTheme() }
|
||||||
tabPublish.setOnClickListener { showTab(TAB_PUBLISH) }
|
|
||||||
tabMemo.setOnClickListener { showTab(TAB_MEMO) }
|
|
||||||
findViewById<ImageView>(R.id.btnSettings).setOnClickListener {
|
findViewById<ImageView>(R.id.btnSettings).setOnClickListener {
|
||||||
startActivity(Intent(this, SettingsActivity::class.java))
|
startActivity(Intent(this, SettingsActivity::class.java))
|
||||||
}
|
}
|
||||||
@@ -287,8 +283,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun bindViews() {
|
private fun bindViews() {
|
||||||
tabPublish = findViewById(R.id.tabPublish)
|
|
||||||
tabMemo = findViewById(R.id.tabMemo)
|
|
||||||
panelPublish = findViewById(R.id.panelPublish)
|
panelPublish = findViewById(R.id.panelPublish)
|
||||||
panelMemo = findViewById(R.id.panelMemo)
|
panelMemo = findViewById(R.id.panelMemo)
|
||||||
panelEmpty = findViewById(R.id.panelEmpty)
|
panelEmpty = findViewById(R.id.panelEmpty)
|
||||||
@@ -534,15 +528,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val isPublish = target == TAB_PUBLISH
|
val isPublish = target == TAB_PUBLISH
|
||||||
val ready = if (isPublish) prefs.typechoReady else prefs.memosReady
|
val ready = if (isPublish) prefs.typechoReady else prefs.memosReady
|
||||||
|
|
||||||
tabPublish.setBackgroundResource(if (isPublish) R.drawable.bg_segment_on else 0)
|
|
||||||
tabMemo.setBackgroundResource(if (isPublish) 0 else R.drawable.bg_segment_on)
|
|
||||||
tabPublish.setTextColor(
|
|
||||||
color(if (isPublish) R.color.text else R.color.text_secondary)
|
|
||||||
)
|
|
||||||
tabMemo.setTextColor(
|
|
||||||
color(if (isPublish) R.color.text_secondary else R.color.text)
|
|
||||||
)
|
|
||||||
|
|
||||||
panelPublish.visibility = if (isPublish && ready) View.VISIBLE else View.GONE
|
panelPublish.visibility = if (isPublish && ready) View.VISIBLE else View.GONE
|
||||||
panelMemo.visibility = if (!isPublish && ready) View.VISIBLE else View.GONE
|
panelMemo.visibility = if (!isPublish && ready) View.VISIBLE else View.GONE
|
||||||
panelEmpty.visibility = if (ready) View.GONE else View.VISIBLE
|
panelEmpty.visibility = if (ready) View.GONE else View.VISIBLE
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private var originalUrl: String = ""
|
private var originalUrl: String = ""
|
||||||
|
|
||||||
|
/** 顶栏 meta 的三段信息:来源站点、作者、发布时间 */
|
||||||
|
private var metaSource: String = ""
|
||||||
|
private var metaAuthor: String = ""
|
||||||
|
private var metaDate: Long = 0L
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val EXTRA_KIND = "kind"
|
private const val EXTRA_KIND = "kind"
|
||||||
private const val EXTRA_ID = "id"
|
private const val EXTRA_ID = "id"
|
||||||
@@ -120,13 +125,9 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
originalUrl = intent.getStringExtra(EXTRA_LINK).orEmpty()
|
originalUrl = intent.getStringExtra(EXTRA_LINK).orEmpty()
|
||||||
|
|
||||||
tvTitle.text = title.ifBlank { getString(R.string.reader_untitled) }
|
tvTitle.text = title.ifBlank { getString(R.string.reader_untitled) }
|
||||||
tvMeta.text = buildString {
|
metaSource = source
|
||||||
if (source.isNotEmpty()) append(source)
|
metaDate = date
|
||||||
if (date > 0) {
|
renderMeta()
|
||||||
if (isNotEmpty()) append(" · ")
|
|
||||||
append(formatDate(date))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
findViewById<ImageView>(R.id.btnReaderBack).setOnClickListener { finish() }
|
findViewById<ImageView>(R.id.btnReaderBack).setOnClickListener { finish() }
|
||||||
btnOriginal.setOnClickListener {
|
btnOriginal.setOnClickListener {
|
||||||
@@ -176,8 +177,13 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
progress.visibility = TextView.VISIBLE
|
progress.visibility = TextView.VISIBLE
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
val markdown = withContext(Dispatchers.IO) { RssApi.article(originalUrl) }
|
val article = withContext(Dispatchers.IO) { RssApi.article(originalUrl) }
|
||||||
val body = stripDuplicateHeader(markdown.ifBlank { excerpt })
|
// 作者提到顶栏,正文里那条「作者:xxx」就不必再出现
|
||||||
|
if (article.author.isNotBlank()) {
|
||||||
|
metaAuthor = article.author
|
||||||
|
renderMeta()
|
||||||
|
}
|
||||||
|
val body = stripLeadingNoise(article.markdown.ifBlank { excerpt })
|
||||||
render(body.ifBlank { excerpt.ifBlank { "(原文里没有抓到正文)" } })
|
render(body.ifBlank { excerpt.ifBlank { "(原文里没有抓到正文)" } })
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// 抓不到原文时用站端摘要兜底,至少能读个大概
|
// 抓不到原文时用站端摘要兜底,至少能读个大概
|
||||||
@@ -189,37 +195,123 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原文页面的 article 标签里常带着站名标题和发布日期,
|
* 顶栏信息行:来源 · 作者 · 发布时间。
|
||||||
* 顶栏已经显示了这两样,开头再出现一遍就去掉;
|
*
|
||||||
* 开头的分类 / 标签 / 来源等 meta 行也一并清掉,只留正文。
|
* 「只留标题、作者、正文」——标题在页面最上方,作者与来源、时间收在这一行,
|
||||||
|
* 正文里就不再重复这些信息。
|
||||||
*/
|
*/
|
||||||
private fun stripDuplicateHeader(markdown: String): String {
|
private fun renderMeta() {
|
||||||
var s = markdown.trim()
|
val text = buildString {
|
||||||
val heading = Regex("^#{1,6}\\s*(.+?)[\\r\\n]+")
|
if (metaSource.isNotBlank()) append(metaSource)
|
||||||
heading.find(s)?.let { m ->
|
if (metaAuthor.isNotBlank()) {
|
||||||
val h = m.groupValues[1].trim()
|
if (isNotEmpty()) append(" · ")
|
||||||
|
append(metaAuthor)
|
||||||
|
}
|
||||||
|
if (metaDate > 0) {
|
||||||
|
if (isNotEmpty()) append(" · ")
|
||||||
|
append(formatDate(metaDate))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tvMeta.text = text
|
||||||
|
tvMeta.visibility = if (text.isBlank()) View.GONE else View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 正文开头的重复信息全部剥掉。
|
||||||
|
*
|
||||||
|
* 原文页面的 article 里常把「标题 + 日期 + 分类 + 作者」再写一遍,顶栏已经有了,
|
||||||
|
* 重复显示等于把同一段信息看两次。这里逐行往下剥,直到第一行是真正的正文:
|
||||||
|
* 重复标题(含 `# 标题`、`**标题**`、`标题 - 站点名`)、日期行、分类/标签/作者/阅读量
|
||||||
|
* 等 meta 行、头像小图、开头的分隔线都算噪音。
|
||||||
|
*/
|
||||||
|
private fun stripLeadingNoise(markdown: String): String {
|
||||||
val title = tvTitle.text.toString().trim()
|
val title = tvTitle.text.toString().trim()
|
||||||
if (title.isEmpty() || h == title || title.contains(h) || h.contains(title)) {
|
var s = markdown.trim()
|
||||||
s = s.substring(m.range.last + 1).trim()
|
var guard = 0
|
||||||
|
while (guard++ < 16) {
|
||||||
|
val lines = s.lines()
|
||||||
|
val idx = lines.indexOfFirst { it.isNotBlank() }
|
||||||
|
if (idx < 0) return ""
|
||||||
|
if (!isHeaderNoise(lines[idx].trim(), title)) break
|
||||||
|
s = lines.drop(idx + 1).joinToString("\n").trim()
|
||||||
}
|
}
|
||||||
|
// 正文中部再出现一次同名一级标题,同样是重复
|
||||||
|
s = removeRedundantH1(s, title)
|
||||||
|
return stripTrailingNoise(s)
|
||||||
}
|
}
|
||||||
// 开头的日期行:2026-06-08、2026年6月8日、2026/06/08 09:46 等,可能连续几行 meta
|
|
||||||
val dateLine = Regex("^[\\r\\n]*\\d{4}[-/年]\\d{1,2}[-/月]\\d{1,2}日?[^\\n]{0,30}[\\r\\n]+")
|
/** 这一行是不是「顶栏已经显示过」的信息 */
|
||||||
while (true) {
|
private fun isHeaderNoise(line: String, title: String): Boolean {
|
||||||
val next = dateLine.replaceFirst(s, "").trim()
|
if (line.isEmpty()) return false
|
||||||
if (next == s || next.isEmpty()) break
|
val plain = line
|
||||||
s = next
|
.replace(Regex("^#{1,6}\\s*"), "")
|
||||||
|
.replace(Regex("^\\*\\*(.*)\\*\\*$"), "$1")
|
||||||
|
.replace(Regex("^__(.*)__$"), "$1")
|
||||||
|
.replace(Regex("^\\[(.*)\\]\\([^)]*\\)$"), "$1")
|
||||||
|
.trim()
|
||||||
|
if (plain.isEmpty()) return true
|
||||||
|
if (Regex("^(?:-{3,}|\\*{3,}|_{3,})$").matches(plain)) return true
|
||||||
|
// 1) 重复标题
|
||||||
|
if (title.length >= 4) {
|
||||||
|
val t = title.lowercase()
|
||||||
|
val p = plain.lowercase()
|
||||||
|
if (p == t) return true
|
||||||
|
// 「主标题 - 站点名」「标题 | 分类」这类拼接也算重复
|
||||||
|
if (p.length <= t.length + 24 && (p.startsWith(t) || p.contains(t))) return true
|
||||||
}
|
}
|
||||||
// 开头的 meta 行:作者 / 分类 / 标签 / 来源 / 字数 / 阅读次数
|
// 2) 日期行:2026-06-08 / 2026年6月8日 / 2026/06/08 09:46
|
||||||
val metaLine = Regex(
|
if (plain.length < 70 &&
|
||||||
"^[\\r\\n]*(作者|分类|标签|来源|发布于|发表于|更新于|字数|阅读|浏览|字体大小)[::\\s][^\\n]{0,40}[\\r\\n]+",
|
Regex("^\\d{4}[-/年.]\\d{1,2}[-/月.]\\d{1,2}日?(?:[^\\n]{0,40})$").matches(plain)
|
||||||
)
|
) return true
|
||||||
while (true) {
|
// 3) 一行里既带日期又带「·」分隔的 meta(日期 · 分类 · 阅读数)
|
||||||
val next = metaLine.replaceFirst(s, "").trim()
|
if (plain.length < 90 && plain.contains('·') &&
|
||||||
if (next == s || next.isEmpty()) break
|
Regex("\\d{4}[-/年]\\d{1,2}").containsMatchIn(plain)
|
||||||
s = next
|
) return true
|
||||||
|
// 4) 分类 / 标签 / 作者 / 来源 / 字数 / 阅读
|
||||||
|
if (Regex("^(?:作者|撰文|文|分类|标签|来源|发布于|发表于|更新于|字数|阅读|浏览|编辑|责编|摄影)[::\\s].{0,40}$")
|
||||||
|
.containsMatchIn(plain)
|
||||||
|
) return true
|
||||||
|
// 5) 阅读时长 / 字数统计
|
||||||
|
if (Regex("^(?:约?\\s*\\d+\\s*分钟(?:阅读)?|\\d+\\s*字(?:数)?|阅读\\s*\\d+|\\d+\\s*阅读)$")
|
||||||
|
.matches(plain)
|
||||||
|
) return true
|
||||||
|
// 6) 头像 / 二维码小图
|
||||||
|
if (Regex("^!\\[[^\\]]*\\]\\([^)]*(?:avatar|gravatar|qrcode)[^)]*\\)$", RegexOption.IGNORE_CASE)
|
||||||
|
.matches(line)
|
||||||
|
) return true
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return s.trim()
|
|
||||||
|
/** 正文里与标题同名的一级标题直接删除 */
|
||||||
|
private fun removeRedundantH1(markdown: String, title: String): String {
|
||||||
|
if (title.isBlank()) return markdown
|
||||||
|
val t = title.lowercase()
|
||||||
|
val h1 = Regex("^#\\s+(.+)$")
|
||||||
|
return markdown.lines().filterNot { line ->
|
||||||
|
val m = h1.find(line.trim())
|
||||||
|
m != null && m.groupValues[1].trim().lowercase() == t
|
||||||
|
}.joinToString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 结尾的分隔线与「一串标签」行没有阅读价值 */
|
||||||
|
private fun stripTrailingNoise(markdown: String): String {
|
||||||
|
val s = markdown
|
||||||
|
.replace(Regex("(?:\\n\\s*(?:-{3,}|\\*{3,}|_{3,})\\s*)+$"), "")
|
||||||
|
.trimEnd()
|
||||||
|
val lines = s.lines().toMutableList()
|
||||||
|
while (lines.isNotEmpty()) {
|
||||||
|
val last = lines.last().trim()
|
||||||
|
if (last.isEmpty()) {
|
||||||
|
lines.removeAt(lines.size - 1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (Regex("^(?:#[^\\s#]+\\s*){2,}$").matches(last)) {
|
||||||
|
lines.removeAt(lines.size - 1)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return lines.joinToString("\n").trimEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.ifNotBlank(): String? = takeIf { isNotBlank() }
|
private fun String.ifNotBlank(): String? = takeIf { isNotBlank() }
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -152,60 +152,78 @@
|
|||||||
<!--
|
<!--
|
||||||
批量操作栏:平时完全隐藏,左滑卡片(或长按)激活选择后才出现。
|
批量操作栏:平时完全隐藏,左滑卡片(或长按)激活选择后才出现。
|
||||||
不再有「选择」入口按钮——左滑就是入口;左侧只留一个「完成」用于退出选择。
|
不再有「选择」入口按钮——左滑就是入口;左侧只留一个「完成」用于退出选择。
|
||||||
|
整根栏是一张圆角卡片,里面的按钮与「已选 N 项」也都是圆角胶囊,与
|
||||||
|
站点 / 邮箱那些下拉菜单同一套形态(12dp 圆角),不再是方角贴着页面底色。
|
||||||
-->
|
-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/selectionBar"
|
android:id="@+id/selectionBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@drawable/bg_card"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="10dp"
|
||||||
|
android:paddingTop="6dp"
|
||||||
|
android:paddingEnd="10dp"
|
||||||
|
android:paddingBottom="6dp"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/btnSelectDone"
|
android:id="@+id/btnSelectDone"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="30dp"
|
||||||
|
android:background="@drawable/bg_field"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:minWidth="32dp"
|
android:minWidth="40dp"
|
||||||
|
android:paddingStart="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
android:text="@string/done"
|
android:text="@string/done"
|
||||||
android:textColor="@color/brand"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12.5sp" />
|
android:textSize="12.5sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/btnSelectAll"
|
android:id="@+id/btnSelectAll"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="30dp"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="8dp"
|
||||||
android:background="@drawable/bg_field"
|
android:background="@drawable/bg_field"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:minWidth="54dp"
|
android:minWidth="48dp"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="10dp"
|
||||||
android:text="@string/select_all"
|
android:text="@string/select_all"
|
||||||
android:textColor="@color/text"
|
android:textColor="@color/text"
|
||||||
android:textSize="12.5sp" />
|
android:textSize="12.5sp" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvSelectedCount"
|
android:id="@+id/tvSelectedCount"
|
||||||
android:layout_width="0dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:layout_weight="1"
|
android:background="@drawable/bg_brand_soft"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="end"
|
android:gravity="center"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/text_tertiary"
|
android:paddingStart="8dp"
|
||||||
android:textSize="12sp" />
|
android:paddingEnd="8dp"
|
||||||
|
android:textColor="@color/brand"
|
||||||
|
android:textSize="11.5sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/btnMarkRead"
|
android:id="@+id/btnMarkRead"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="30dp"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:background="@drawable/bg_field"
|
android:background="@drawable/bg_field"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="10dp"
|
||||||
android:text="@string/mark_read"
|
android:text="@string/mark_read"
|
||||||
android:textColor="@color/text"
|
android:textColor="@color/text"
|
||||||
android:textSize="12.5sp" />
|
android:textSize="12.5sp" />
|
||||||
@@ -213,12 +231,12 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/btnDeleteSelected"
|
android:id="@+id/btnDeleteSelected"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="32dp"
|
android:layout_height="30dp"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:background="@drawable/bg_field"
|
android:background="@drawable/bg_field"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="10dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="10dp"
|
||||||
android:text="@string/delete"
|
android:text="@string/delete"
|
||||||
android:textColor="@color/danger"
|
android:textColor="@color/danger"
|
||||||
android:textSize="12.5sp" />
|
android:textSize="12.5sp" />
|
||||||
|
|||||||
@@ -48,47 +48,15 @@
|
|||||||
app:tint="@color/text_secondary" />
|
app:tint="@color/text_secondary" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- ========== 分栏切换 ========== -->
|
<!--
|
||||||
<LinearLayout
|
发文与发博是两张独立的页面,入口在首页「发布」的二级菜单里(各自带 extra_tab 进来),
|
||||||
android:layout_width="match_parent"
|
这里不再需要顶部分栏切换按钮。
|
||||||
android:layout_height="40dp"
|
-->
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:background="@drawable/bg_segment"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:padding="3dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tabPublish"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:background="@drawable/bg_segment_on"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/tab_publish"
|
|
||||||
android:textColor="@color/text"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tabMemo"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/tab_memo"
|
|
||||||
android:textColor="@color/text_secondary"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<!-- ========== 发文 ========== -->
|
<!-- ========== 发文 ========== -->
|
||||||
|
|||||||
Reference in New Issue
Block a user