修复负数计时回归:前台服务类型按版本显式选型;重要度改圆圈数字;置顶改上箭头(v0.10)
This commit is contained in:
@@ -103,11 +103,18 @@ class TimerService : Service() {
|
||||
|
||||
private fun startForegroundCompat() {
|
||||
val notification = Notif.buildOngoing(this)
|
||||
// 必须显式传类型:specialUse 是 Android 14 才引入的,
|
||||
// Android 12/13 不认识清单里的这个类型位,两参版本(读清单)会被拒绝,
|
||||
// 服务起不来 → 每秒 tick 停掉 → 息屏后到点无人结算,通知滚成负数。
|
||||
// <34 用 dataSync(Android 12 原生支持,行为与历史版本一致);
|
||||
// >=34 用 specialUse 规避 dataSync 的 24 小时 6 小时累计上限。
|
||||
val type = if (android.os.Build.VERSION.SDK_INT >= 34) {
|
||||
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
|
||||
} else {
|
||||
android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
}
|
||||
runCatching {
|
||||
// 两参版本会读清单里声明的前台服务类型(specialUse)。
|
||||
// 不用三参 + SPECIAL_USE:该类型 Android 14 才引入,
|
||||
// 在 P30 的 Android 12 上传进去会直接抛 IllegalArgumentException。
|
||||
startForeground(Notif.ID_ONGOING, notification)
|
||||
startForeground(Notif.ID_ONGOING, notification, type)
|
||||
}.onFailure {
|
||||
// 前台服务被系统拒绝(省电策略/权限)时退化为普通服务,
|
||||
// 计时本身仍在 TimerCore 里走,只是通知可能不显示。
|
||||
|
||||
@@ -373,6 +373,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "0.9"
|
||||
const val VERSION = "0.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,21 +85,22 @@ class TaskAdapter(
|
||||
val ctx = itemView.context
|
||||
|
||||
// 标题右侧的属性图标,未完成与已完成都显示:
|
||||
// 重要度竖线(高3/中2/低1,颜色与紧急度同色系)→ 紧急度五角星 → 随时图钉。
|
||||
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
||||
// 紧急度五角星 → 随时上箭头。
|
||||
// 用 spannable 保证图标紧贴标题而不是被推到行尾。
|
||||
val title = SpannableStringBuilder(task.title)
|
||||
|
||||
val (bars, barColor) = when (task.priority) {
|
||||
2 -> " ▏▏▏" to R.color.urgent_high
|
||||
1 -> " ▏▏" to R.color.urgent_mid
|
||||
else -> " ▏" to R.color.urgent_low
|
||||
val (badge, badgeColor) = when (task.priority) {
|
||||
2 -> " ③" to R.color.urgent_high
|
||||
1 -> " ②" to R.color.urgent_mid
|
||||
else -> " ①" to R.color.urgent_low
|
||||
}
|
||||
title.append(bars)
|
||||
title.append(badge)
|
||||
title.setSpan(
|
||||
android.text.style.ForegroundColorSpan(ctx.col(barColor)),
|
||||
title.length - bars.length, title.length, 0
|
||||
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
||||
title.length - badge.length, title.length, 0
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - bars.length, title.length, 0)
|
||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - badge.length, title.length, 0)
|
||||
|
||||
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
|
||||
val (stars, starColor) = when (task.urgency) {
|
||||
@@ -114,9 +115,14 @@ class TaskAdapter(
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
|
||||
|
||||
// 「随时」任务:标题后带置顶图钉,列表里排在未完成最前面
|
||||
// 「随时」任务:标题后带品牌蓝上箭头表示置顶,列表里排在未完成最前面
|
||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||
title.append(" 📌")
|
||||
title.append(" ↑")
|
||||
title.setSpan(
|
||||
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)
|
||||
}
|
||||
|
||||
tvTitle.text = title
|
||||
|
||||
Reference in New Issue
Block a user