前台启动失败自动重试;属性图标视觉高度统一;统计标题简化(v0.11)

This commit is contained in:
XIGE
2026-11-29 10:34:46 +08:00
parent ddb4eb56e2
commit af01be6958
5 changed files with 29 additions and 9 deletions

View File

@@ -101,6 +101,9 @@ class TimerService : Service() {
if (TimerCore.running && !TimerCore.countUp) startTicker() else stopTicker()
}
/** EMUI 偶发拒绝前台启动时的自愈重试标记:只重试一次,避免无限循环 */
private var fgRetried = false
private fun startForegroundCompat() {
val notification = Notif.buildOngoing(this)
// 必须显式传类型:specialUse 是 Android 14 才引入的,
@@ -115,10 +118,22 @@ class TimerService : Service() {
}
runCatching {
startForeground(Notif.ID_ONGOING, notification, type)
}.recoverCatching {
// 显式类型被拒时退回两参版本再试一次(读清单组合类型)
startForeground(Notif.ID_ONGOING, notification)
}.onSuccess {
fgRetried = false
}.onFailure {
// 前台服务被系统拒绝(省电策略/权限)时退化为普通服务,
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。
stopSelf()
// EMUI 偶发拒绝(省电策略/启动节奏):延迟半秒自动重试一次,
// 用户就不用"反复开关几次 APP"才能看到状态栏图标了;仍失败才放弃
if (!fgRetried) {
fgRetried = true
handler.postDelayed({ startForegroundCompat() }, 500L)
} else {
// 前台服务被系统拒绝时退化为普通服务,
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。
stopSelf()
}
}
}

View File

@@ -373,6 +373,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
}
companion object {
const val VERSION = "0.10"
const val VERSION = "0.11"
}
}

View File

@@ -87,7 +87,8 @@ class TaskAdapter(
// 标题右侧的属性图标,未完成与已完成都显示:
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
// 紧急度五角星 → 随时上箭头。
// 用 spannable 保证图标紧贴标题而不是被推到行尾。
// 各字形在字体里的字面尺寸不同:五角星 0.95、圆圈数字字面偏大缩到 0.85、
// 上箭头字面偏小放到 1.1,三者视觉高度一致,不再一宽一高。
val title = SpannableStringBuilder(task.title)
val (badge, badgeColor) = when (task.priority) {
@@ -100,7 +101,7 @@ class TaskAdapter(
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
title.length - badge.length, title.length, 0
)
title.setSpan(RelativeSizeSpan(0.95f), title.length - badge.length, title.length, 0)
title.setSpan(RelativeSizeSpan(0.85f), title.length - badge.length, title.length, 0)
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
val (stars, starColor) = when (task.urgency) {
@@ -122,7 +123,7 @@ class TaskAdapter(
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)),
title.length - 2, title.length, 0
)
title.setSpan(RelativeSizeSpan(0.95f), title.length - 2, title.length, 0)
title.setSpan(RelativeSizeSpan(1.1f), title.length - 2, title.length, 0)
}
tvTitle.text = title