前台启动失败自动重试;属性图标视觉高度统一;统计标题简化(v0.11)
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# 变更记录
|
# 变更记录
|
||||||
|
|
||||||
|
## 2026-11-29 · 前台启动失败自动重试;属性图标视觉高度统一;统计标题简化(v0.11)
|
||||||
|
|
||||||
|
- 同步源码更新 4 个文件(新增/修改 4,删除 0)。
|
||||||
|
|
||||||
## 2026-11-29 · 修复负数计时回归:前台服务类型按版本显式选型;重要度改圆圈数字;置顶改上箭头(v0.10)
|
## 2026-11-29 · 修复负数计时回归:前台服务类型按版本显式选型;重要度改圆圈数字;置顶改上箭头(v0.10)
|
||||||
|
|
||||||
- 修复 v0.7 引入的负数计时回归:specialUse 是 Android 14 才引入的 FGS 类型,Android 12/13 不认识清单里的这个位,startForeground 被拒 → 服务自杀 → 每秒 tick 停止 + 进程失去前台保活,息屏后到点无人结算,通知 Chronometer 滚成负数。修复:manifest 声明 dataSync|specialUse 双类型(补回 FOREGROUND_SERVICE_DATA_SYNC 权限),startForeground 三参按系统版本显式选型——<34 用 dataSync(恢复 Android 12 原行为),>=34 用 specialUse(规避 dataSync 6 小时累计上限)
|
- 修复 v0.7 引入的负数计时回归:specialUse 是 Android 14 才引入的 FGS 类型,Android 12/13 不认识清单里的这个位,startForeground 被拒 → 服务自杀 → 每秒 tick 停止 + 进程失去前台保活,息屏后到点无人结算,通知 Chronometer 滚成负数。修复:manifest 声明 dataSync|specialUse 双类型(补回 FOREGROUND_SERVICE_DATA_SYNC 权限),startForeground 三参按系统版本显式选型——<34 用 dataSync(恢复 Android 12 原行为),>=34 用 specialUse(规避 dataSync 6 小时累计上限)
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ class TimerService : Service() {
|
|||||||
if (TimerCore.running && !TimerCore.countUp) startTicker() else stopTicker()
|
if (TimerCore.running && !TimerCore.countUp) startTicker() else stopTicker()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** EMUI 偶发拒绝前台启动时的自愈重试标记:只重试一次,避免无限循环 */
|
||||||
|
private var fgRetried = false
|
||||||
|
|
||||||
private fun startForegroundCompat() {
|
private fun startForegroundCompat() {
|
||||||
val notification = Notif.buildOngoing(this)
|
val notification = Notif.buildOngoing(this)
|
||||||
// 必须显式传类型:specialUse 是 Android 14 才引入的,
|
// 必须显式传类型:specialUse 是 Android 14 才引入的,
|
||||||
@@ -115,10 +118,22 @@ class TimerService : Service() {
|
|||||||
}
|
}
|
||||||
runCatching {
|
runCatching {
|
||||||
startForeground(Notif.ID_ONGOING, notification, type)
|
startForeground(Notif.ID_ONGOING, notification, type)
|
||||||
|
}.recoverCatching {
|
||||||
|
// 显式类型被拒时退回两参版本再试一次(读清单组合类型)
|
||||||
|
startForeground(Notif.ID_ONGOING, notification)
|
||||||
|
}.onSuccess {
|
||||||
|
fgRetried = false
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
// 前台服务被系统拒绝(省电策略/权限)时退化为普通服务,
|
// EMUI 偶发拒绝(省电策略/启动节奏):延迟半秒自动重试一次,
|
||||||
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。
|
// 用户就不用"反复开关几次 APP"才能看到状态栏图标了;仍失败才放弃
|
||||||
stopSelf()
|
if (!fgRetried) {
|
||||||
|
fgRetried = true
|
||||||
|
handler.postDelayed({ startForegroundCompat() }, 500L)
|
||||||
|
} else {
|
||||||
|
// 前台服务被系统拒绝时退化为普通服务,
|
||||||
|
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -373,6 +373,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val VERSION = "0.10"
|
const val VERSION = "0.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ class TaskAdapter(
|
|||||||
// 标题右侧的属性图标,未完成与已完成都显示:
|
// 标题右侧的属性图标,未完成与已完成都显示:
|
||||||
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
||||||
// 紧急度五角星 → 随时上箭头。
|
// 紧急度五角星 → 随时上箭头。
|
||||||
// 用 spannable 保证图标紧贴标题而不是被推到行尾。
|
// 各字形在字体里的字面尺寸不同:五角星 0.95、圆圈数字字面偏大缩到 0.85、
|
||||||
|
// 上箭头字面偏小放到 1.1,三者视觉高度一致,不再一宽一高。
|
||||||
val title = SpannableStringBuilder(task.title)
|
val title = SpannableStringBuilder(task.title)
|
||||||
|
|
||||||
val (badge, badgeColor) = when (task.priority) {
|
val (badge, badgeColor) = when (task.priority) {
|
||||||
@@ -100,7 +101,7 @@ class TaskAdapter(
|
|||||||
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
||||||
title.length - badge.length, title.length, 0
|
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) {
|
val (stars, starColor) = when (task.urgency) {
|
||||||
@@ -122,7 +123,7 @@ class TaskAdapter(
|
|||||||
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)),
|
android.text.style.ForegroundColorSpan(ctx.col(R.color.brand)),
|
||||||
title.length - 2, title.length, 0
|
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
|
tvTitle.text = title
|
||||||
|
|||||||
@@ -145,8 +145,8 @@
|
|||||||
<string name="completed_tasks">完成任务</string>
|
<string name="completed_tasks">完成任务</string>
|
||||||
<string name="goal_progress">今日目标%1$d%%</string>
|
<string name="goal_progress">今日目标%1$d%%</string>
|
||||||
<string name="goal_short">%1$dM</string>
|
<string name="goal_short">%1$dM</string>
|
||||||
<string name="trend_title">专注趋势</string>
|
<string name="trend_title">趋势</string>
|
||||||
<string name="heatmap_title">专注频率</string>
|
<string name="heatmap_title">频率</string>
|
||||||
<string name="distribution_title">项目分布</string>
|
<string name="distribution_title">项目分布</string>
|
||||||
<string name="task_distribution_title">任务分布</string>
|
<string name="task_distribution_title">任务分布</string>
|
||||||
<string name="task_share">任务占比</string>
|
<string name="task_share">任务占比</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user