v3.18 按审查报告修缺陷:口径统一、生命周期补漏、读数与百分比修正
- 项目时长/次数改为按任务当前项目统计,与统计页分布一致 - 进度条不再把重复任务跑一轮算成完成 - 清空数据补清 t_task/t_project 等并解绑内存任务 - 进程被杀补记同时写完成记录;结束本轮清空暂存备注 - 通知「结束」先前台化再 stopSelf - 正计时锁屏读数按需刷新;悬浮窗 addView 失败先 removeView - 百分比统一 <1%、分布卡加大下界、清空后刷新专注页 - 删除死代码与 41 个未引用字符串,计时状态一次落盘
This commit is contained in:
@@ -14,7 +14,15 @@ object Dates {
|
||||
private val hmFmt = SimpleDateFormat("HH:mm", Locale.CHINA)
|
||||
private val hmsFmt = SimpleDateFormat("HH:mm:ss", Locale.CHINA)
|
||||
|
||||
fun dayKey(ms: Long): String = keyFmt.format(Date(ms))
|
||||
/**
|
||||
* SimpleDateFormat 不是线程安全的。
|
||||
* 目前这些格式化全在主线程调用,但一旦挪到后台(通知、统计异步化)就会静默出错,
|
||||
* 所以统一走加锁的薄封装,成本只有一次监视器进出。
|
||||
*/
|
||||
private fun format(f: SimpleDateFormat, ms: Long): String =
|
||||
synchronized(f) { f.format(Date(ms)) }
|
||||
|
||||
fun dayKey(ms: Long): String = format(keyFmt, ms)
|
||||
|
||||
fun dayStart(ms: Long): Long {
|
||||
val c = Calendar.getInstance()
|
||||
@@ -26,7 +34,8 @@ object Dates {
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
fun dayStartOfKey(key: String): Long = keyFmt.parse(key)?.time ?: 0L
|
||||
fun dayStartOfKey(key: String): Long =
|
||||
synchronized(keyFmt) { keyFmt.parse(key)?.time } ?: 0L
|
||||
|
||||
fun todayStart(): Long = dayStart(System.currentTimeMillis())
|
||||
|
||||
@@ -91,12 +100,22 @@ object Dates {
|
||||
return c.timeInMillis
|
||||
}
|
||||
|
||||
/** 12:30 这种时钟显示;不足 10 分钟显示 09:30 两位分 */
|
||||
/**
|
||||
* 计时读数。不足 1 小时是 mm:ss,满 1 小时自动变 h:mm:ss。
|
||||
*
|
||||
* 原来固定按分:秒输出,正计时到 90 分钟会显示成 90:00,两小时就是三位数,
|
||||
* 把圆环和锁屏的固定排版挤变形(锁屏那套排版是写死 dp 的,不能自适应)。
|
||||
*/
|
||||
fun clock(ms: Long): String {
|
||||
val total = (ms / 1000).coerceAtLeast(0)
|
||||
val m = total / 60
|
||||
val h = total / 3600
|
||||
val m = total % 3600 / 60
|
||||
val s = total % 60
|
||||
return String.format(Locale.US, "%02d:%02d", m, s)
|
||||
return if (h > 0) {
|
||||
String.format(Locale.US, "%d:%02d:%02d", h, m, s)
|
||||
} else {
|
||||
String.format(Locale.US, "%02d:%02d", m, s)
|
||||
}
|
||||
}
|
||||
|
||||
/** 45m / 2h10m / 12.5h,统计里统一用这个口径 */
|
||||
@@ -123,19 +142,10 @@ object Dates {
|
||||
return if (m == 0) "${h}h" else "${h}h ${m}m"
|
||||
}
|
||||
|
||||
/** 图表坐标轴用的短格式:2h / 45m */
|
||||
fun shortDuration(seconds: Int): String {
|
||||
if (seconds <= 0) return "0"
|
||||
val minutes = seconds / 60
|
||||
if (minutes < 60) return "${minutes}m"
|
||||
val h = minutes / 60f
|
||||
return if (h >= 10) "${h.toInt()}h" else String.format(Locale.US, "%.1fh", h)
|
||||
}
|
||||
|
||||
fun md(ms: Long): String = mdFmt.format(Date(ms))
|
||||
fun mdLong(ms: Long): String = mdFmt2.format(Date(ms))
|
||||
fun hm(ms: Long): String = hmFmt.format(Date(ms))
|
||||
fun hms(ms: Long): String = hmsFmt.format(Date(ms))
|
||||
fun md(ms: Long): String = format(mdFmt, ms)
|
||||
fun mdLong(ms: Long): String = format(mdFmt2, ms)
|
||||
fun hm(ms: Long): String = format(hmFmt, ms)
|
||||
fun hms(ms: Long): String = format(hmsFmt, ms)
|
||||
|
||||
/** 周五 / 周一 */
|
||||
fun weekday(ms: Long): String {
|
||||
|
||||
18
src/main/java/com/focusbox/app/util/Percent.kt
Normal file
18
src/main/java/com/focusbox/app/util/Percent.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
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()}%"
|
||||
}
|
||||
@@ -215,17 +215,76 @@ object Prefs {
|
||||
get() = sp.getBoolean("ui_filter_expanded", false)
|
||||
set(v) = sp.edit().putBoolean("ui_filter_expanded", v).apply()
|
||||
|
||||
/**
|
||||
* 计时状态的批量落盘:TimerCore 每次状态变更要写十几个字段,
|
||||
* 逐个属性 setter 会走十几次 Editor.apply()(十几次磁盘写入);
|
||||
* 这里合成一次提交,语义完全相同。
|
||||
*/
|
||||
fun saveTimer(
|
||||
mode: Int,
|
||||
running: Boolean,
|
||||
countUp: Boolean,
|
||||
totalMs: Long,
|
||||
remainingMs: Long,
|
||||
endAt: Long,
|
||||
endElapsed: Long,
|
||||
clockOffset: Long,
|
||||
pauseReason: String,
|
||||
roundNotes: String,
|
||||
pauseStartAt: Long,
|
||||
pauseTaskId: Long,
|
||||
startedAt: Long,
|
||||
taskId: Long,
|
||||
projectId: Long,
|
||||
round: Int,
|
||||
accumMs: Long,
|
||||
) {
|
||||
sp.edit()
|
||||
.putInt("t_mode", mode)
|
||||
.putBoolean("t_running", running)
|
||||
.putBoolean("t_countup", countUp)
|
||||
.putLong("t_total", totalMs)
|
||||
.putLong("t_remaining", remainingMs)
|
||||
.putLong("t_end", endAt)
|
||||
.putLong("t_end_elapsed", endElapsed)
|
||||
.putLong("t_clock_offset", clockOffset)
|
||||
.putString("t_pause_reason", pauseReason)
|
||||
.putString("t_round_notes", roundNotes)
|
||||
.putLong("t_pause_start", pauseStartAt)
|
||||
.putLong("t_pause_task", pauseTaskId)
|
||||
.putLong("t_started", startedAt)
|
||||
.putLong("t_task", taskId)
|
||||
.putLong("t_project", projectId)
|
||||
.putInt("t_round", round)
|
||||
.putLong("t_accum", accumMs)
|
||||
.apply()
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空所有数据时复位计时状态。
|
||||
*
|
||||
* 必须连任务绑定一起清:只清运行态的话,TimerCore 内存里的 taskId 和这里的
|
||||
* t_task / t_project / t_total 都还指着已经被删掉的行,下一轮专注写出来的
|
||||
* session 立刻变成「未关联记录」。
|
||||
*/
|
||||
fun clearTimer() {
|
||||
sp.edit()
|
||||
.putInt("t_mode", 0)
|
||||
.putBoolean("t_running", false)
|
||||
.putBoolean("t_countup", false)
|
||||
.putLong("t_total", 0L)
|
||||
.putLong("t_remaining", 0L)
|
||||
.putLong("t_end", 0L)
|
||||
.putLong("t_end_elapsed", 0L)
|
||||
.putLong("t_clock_offset", 0L)
|
||||
.putString("t_pause_reason", "")
|
||||
.putString("t_round_notes", "")
|
||||
.putLong("t_pause_start", 0L)
|
||||
.putLong("t_pause_task", 0L)
|
||||
.putLong("t_started", 0L)
|
||||
.putLong("t_task", 0L)
|
||||
.putLong("t_project", 0L)
|
||||
.putInt("t_round", 0)
|
||||
.putLong("t_accum", 0L)
|
||||
.apply()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user