Files
FocusBox/src/main/java/com/focusbox/app/util/Percent.kt
XIGE 9eacf7d87b v3.18 按审查报告修缺陷:口径统一、生命周期补漏、读数与百分比修正
- 项目时长/次数改为按任务当前项目统计,与统计页分布一致
- 进度条不再把重复任务跑一轮算成完成
- 清空数据补清 t_task/t_project 等并解绑内存任务
- 进程被杀补记同时写完成记录;结束本轮清空暂存备注
- 通知「结束」先前台化再 stopSelf
- 正计时锁屏读数按需刷新;悬浮窗 addView 失败先 removeView
- 百分比统一 <1%、分布卡加大下界、清空后刷新专注页
- 删除死代码与 41 个未引用字符串,计时状态一次落盘
2026-12-02 10:59:52 +08:00

19 lines
663 B
Kotlin
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.focusbox.app.util
import kotlin.math.roundToInt
/**
* 占比文案。环上的小字与环下方的明细必须共用这一个实现。
*
* 两处各写一套取整会打架:环上原来 `roundToInt().coerceAtLeast(1)` 把 0.6% 写成 1%,
* 明细里判 `pct < 1` 写成「<1%」,同一块切片在两个地方显示两个数,
* 看上去就像"排第 7 的牵了线、前 6 反而没牵"。
*
* 规则:四舍五入;不足 1% 统一写「<1%」。
*/
fun percentText(part: Int, total: Int): String {
if (total <= 0) return "0%"
val pct = part * 100.0 / total
return if (pct < 1.0) "<1%" else "${pct.roundToInt()}%"
}