48 Commits
v2.0 ... v3.3

Author SHA1 Message Date
XIGE
ae75410e9b CHANGELOG:3.3 发布条目(去除自动计数条目) 2026-12-01 21:41:44 +08:00
XIGE
234df41f64 发布 3.3:版本号 3.3 / versionCode 70 2026-12-01 21:40:20 +08:00
XIGE
aad58da3b9 CHANGELOG:v3.15 手写条目(去除自动计数条目) 2026-12-01 21:10:17 +08:00
XIGE
0a7d5fda8c 选任务即开始、任务卡正在专注、饼图引线回归几何分侧(v3.15) 2026-12-01 21:08:29 +08:00
XIGE
ec286bcc6b CHANGELOG:v3.14 手写条目(去除自动计数条目) 2026-12-01 20:41:25 +08:00
XIGE
853186015d 项目色板20色、删除级联清理、未关联数据清理、饼图左右各三、手动完成标记(v3.14) 2026-12-01 20:40:39 +08:00
XIGE
1df122af48 CHANGELOG:v3.13 手写条目(去除自动计数条目) 2026-12-01 19:01:35 +08:00
XIGE
177c965894 饼图标注回到6条并在下方完整列出其余切片(v3.13) 2026-12-01 19:00:43 +08:00
XIGE
c9c7a79349 CHANGELOG:v3.12 手写条目(去除自动计数条目) 2026-12-01 18:32:39 +08:00
XIGE
320554381e 删除改整系列软删除、系列统计与饼图归属修正(v3.12) 2026-12-01 18:30:57 +08:00
XIGE
a1e200a1d6 CHANGELOG:v3.11 手写条目(去除自动计数条目) 2026-12-01 18:00:33 +08:00
XIGE
256ccfe1ae 饼图按系列根任务与任务当前项目归并,选择器改为立即创建(v3.11) 2026-12-01 17:59:28 +08:00
XIGE
0058efe5df CHANGELOG:v3.10 手写条目(去除自动计数条目) 2026-12-01 17:32:18 +08:00
XIGE
6989dc0c68 项目展开完成记录加开始按钮,专注页无任务改为立即创建(v3.10) 2026-12-01 17:31:24 +08:00
XIGE
43b12b1bf4 CHANGELOG:v3.9 手写条目(去除自动计数条目) 2026-12-01 16:53:20 +08:00
XIGE
fcfd167623 项目任务行恢复统计口径与完成记录对齐任务页(v3.9) 2026-12-01 16:52:28 +08:00
XIGE
44b0baacca 重复任务自动完成与项目页口径对齐(v3.8) 2026-12-01 16:28:21 +08:00
XIGE
ce48d805fc 专注选任务、任务页与项目页口径重整(v3.7) 2026-12-01 14:51:04 +08:00
XIGE
65f56490e9 修复任务图标间距与项目编辑键盘遮挡(v3.6) 2026-12-01 14:06:17 +08:00
XIGE
35a7c4a785 CHANGELOG:v3.5 手写条目(去除自动计数条目) 2026-12-01 13:42:51 +08:00
XIGE
ab8840d421 回退v3.3基线并删除内置收件箱项目(v3.5) 2026-12-01 13:42:12 +08:00
XIGE
ce4ec2cd51 项目页统计口径重构与执行入口移除(v3.4) 2026-12-01 13:18:59 +08:00
XIGE
467d34afe8 图标间距减半与逾期任务过滤(v3.3) 2026-12-01 12:54:03 +08:00
XIGE
256c0d4540 CHANGELOG:v3.2 数字去空格与完成副本去重条目(去除自动计数条目) 2026-12-01 12:33:15 +08:00
XIGE
30b385a4d9 项目页数字去空格、任务图标留间距、按session时间排除历史完成副本去重(v3.2) 2026-12-01 12:33:06 +08:00
XIGE
8a7147b299 CHANGELOG:v3.1 统计补全与完成记录折叠条目(去除自动计数条目) 2026-12-01 11:58:16 +08:00
XIGE
47294f4fcf 项目统计补累计专注分钟、展开行点开编辑删除、置顶前移并统一圆圈规格、已完成任务折叠(v3.1) 2026-12-01 11:58:05 +08:00
XIGE
8ad5441ba4 CHANGELOG:v3.0 项目列表展开任务与统计条目(去除自动计数条目) 2026-12-01 11:24:23 +08:00
XIGE
9c8e2eb534 项目列表点击就地展开任务与统计,任务页零改动(v3.0) 2026-12-01 11:24:03 +08:00
XIGE
eb3d961b0a CHANGELOG:v2.9 回退字体并删除分割线条目(去除自动计数条目) 2026-11-30 10:00:50 +08:00
XIGE
9fdecfb1b9 回退打包字体,删除横屏分割线(v2.9) 2026-11-30 10:00:37 +08:00
XIGE
a8446bcf51 CHANGELOG:v2.8 横屏时间字体SourceCodePro条目(去除自动计数条目) 2026-11-30 09:37:39 +08:00
XIGE
54df5b398c 横屏大时间换SourceCodeProBold修墨迹边距不均导致的分割线左右间隙不等(v2.8) 2026-11-30 09:37:29 +08:00
XIGE
8a1f41ca9d CHANGELOG:v2.7 删除CountdownFit回退v2.3行为条目(去除自动计数条目) 2026-11-30 09:12:28 +08:00
XIGE
4a648669ea 删除CountdownFit,LockScreenActivity/LockOverlay恢复v2.3,竖屏专注时间恢复原字号(v2.7) 2026-11-30 09:12:10 +08:00
XIGE
60fd3d1044 CHANGELOG:v2.6 回退v2.3基线与等宽缩号条目(去除自动计数条目) 2026-11-30 08:57:43 +08:00
XIGE
ed7927af1d 回退v2.3布局基线,撤销autoSize;新增CountdownFit按实测字宽把6位倒计时缩到与时钟等宽修复左右间隙不等(v2.6) 2026-11-30 08:57:32 +08:00
XIGE
2d999edc0c CHANGELOG:v2.5 autoSize防溢出条目(去除自动计数条目) 2026-11-30 08:40:27 +08:00
XIGE
4e062923ef 分割线等距修正:大时间autoSize自动缩号(40..130sp)修复6位数倒计时溢出越线,贴线对齐间隙恒24dp(v2.5) 2026-11-30 08:40:17 +08:00
XIGE
7d8995ead0 CHANGELOG:v2.4 分割线左右等距条目(去除自动计数条目) 2026-11-30 08:19:59 +08:00
XIGE
4444b18b29 分割线左右等距:左栏右对齐右栏左对齐各距线24dp,tnum等宽数字,修复系统字体数字非等宽导致的间隙不等(v2.4) 2026-11-30 08:19:49 +08:00
XIGE
11dc2825cc CHANGELOG:v2.3 分割线中列镜像对齐条目(去除自动计数条目) 2026-11-30 07:52:06 +08:00
XIGE
2dd7f8b506 分割线中列完整镜像左右两栏:三列同高同顶,线中心严格等于时间中心,修复v2.2锚点列偏矮居中失效(v2.3) 2026-11-30 07:51:44 +08:00
XIGE
3277fa5826 CHANGELOG:v2.2 分割线镜像锚点对齐条目(去除自动计数条目) 2026-11-30 01:29:39 +08:00
XIGE
00a01b3f22 分割线镜像锚点对齐:中心与左右时间文字严格重合,修复下移(v2.2) 2026-11-30 01:28:49 +08:00
XIGE
01ca852b2a CHANGELOG:v2.1 条目细化(去除自动计数条目) 2026-11-30 01:09:35 +08:00
XIGE
8e7de267a4 分割线降至92dp与时间等高;改项目时迁移系列实例与完成记录修复双项目重复;普通任务按重要+紧急总分排序,版本 2.1 2026-11-30 01:09:06 +08:00
XIGE
9305bd588b CHANGELOG:v2.0 条目细化(去除自动计数条目) 2026-11-30 00:44:43 +08:00
22 changed files with 1491 additions and 176 deletions

View File

@@ -1,8 +1,232 @@
# 变更记录 # 变更记录
## 2026-11-30 · 分割线恢复原始静态View实现高度150dp;逾期任务排在置顶之后列表最前,版本 2.0 ## 2026-12-01 · 发布 3.3:版本号 3.3 / versionCode 70
- 同步源码更新 3 个文件(新增/修改 3,删除 0)。 本次是 v3.2 之后的汇总发布,覆盖内部迭代 3.3~3.15 的全部改动:专注页选任务即开始、项目色板 20 色、项目展开系列统计、饼图归并与标注重构、删除语义调整为级联清理、未关联数据清理、手动/自动完成不计入统计等。逐条明细见下方各次记录,面向使用者的汇总说明见 Gitea Release 页面。
- 版本号:versionName 3.3 / versionCode 70(高于历史任何版本,可覆盖安装)。
- 签名:与 v3.2 相同(SHA-256 7bcbd511…cc8c83),无数据迁移。
## 2026-12-01 · 选任务即开始、任务卡正在专注、饼图引线回归几何分侧(v3.15)
- 专注页选中任务后自动开始计时(「立即创建」建完任务同样开跑),不需要再点一次开始;暂停过的走 resume,才会补写暂停原因。
- 专注进行中任务卡右侧文案由「已选任务」改为「正在专注」,整卡不可点击;本轮结束或复位后恢复可选、恢复原文案。
- 环形图撤回 v3.14 的「左右各 3 条」强制均分与三段式引线,恢复按扇区几何位置分侧、两段式引线,引线不再穿过圆环。
- 环上百分比与下方明细统一为四舍五入:修正「列表 8% 排在后面、环上 7% 反而牵了线」的显示矛盾(7.6% 原来环上写 7、列表写 8)。
## 2026-12-01 · 项目色板20色、删除级联清理、未关联数据清理、饼图左右各三、手动完成标记(v3.14)
- 项目配色 8 → 20 色:原有 8 色顺序不变,新增 12 色按色相插空(暖 6 / 冷 6);项目弹层色点改为两行平铺(每行 10 个,32dp 单元),窄屏仍可横向滑动。
- 删除任务改为物理删除整个系列(根任务 + 重复实例 + 完成记录副本),并删除这些行上的专注记录;删除项目同样连带删除项目下任务与其专注记录。删除确认文案明确提示「记录与统计一并删除,不可恢复」。
- 设置页新增「清空未关联数据」:清理查不到任务的专注记录(旧版本删任务时 task_id 被清零的残留、v3.12 软删除遗留),以及标记为已删除的任务行;弹窗显示待清理条数与合计时长。
- 统计页连续打卡文案改为「连续专注」(概览行与汇总卡两处)。
- 项目/任务饼图:环上固定标注占比最高的 6 条,其余切片全部在下方两列明细列出,不合并「其他」;引线改为左右各 3 条(按旋转分割线对半分配),并新增一段径向离开环带的引线,跨侧标注不再横穿色带。
- 累计统计口径修正:累计次数只认系列内已完成的真实专注记录,手动勾选完成与周期滚动自动完成的实例不再凭空记 1 次。
- 手动勾选完成时自动在备注追加「手动完成」,取消勾选会撤掉该标记;这类完成与自动完成一样没有专注记录,不进入饼图。
## 2026-12-01 · 饼图标注回到6条并在下方完整列出其余切片(v3.13)
- 环形图引线标注上限 8 → 6(占比最高的 6 条),撤掉「其他」合并:环按真实占比把每一块都画出来,任务不再因为被合并而在图上消失。
- 新增 `LabelDonutView.unlabeled`:没牵到线的切片(排在第 7 名之后,或扇区张角不足 3°)按占比排序暴露给调用方。
- 项目分布 / 任务分布两张卡在环下方新增两列明细列表:圆点 + 名称 /「时长 · 占比」,把全部未牵线切片逐条列出,不截断、不合并。
- 环上缝隙按切片数摊薄(`min(2.2°, 14°/n)`):切片数量多时细扇区不会被固定缝隙吃掉。
- 新增文案 `legend_meta`(`%1$s · %2$s`)。
## 2026-12-01 · 删除改整系列软删除、系列统计与饼图归属修正(v3.12)
- 项目展开任务行统计按整个系列聚合:`Store.projectTaskRows` 用递归 CTE 把根任务、重复实例、完成记录副本归到同一个 root,最近完成 / 累计专注 / 累计次数(新增 `done_cnt`)都按系列求和。重复任务每轮的专注终于算进同一个任务,不再是 0。
- 任务删除改为整系列软删除(DB v9,`tasks.deleted`):先沿 `origin_id` 向上找到系列根(兼容旧版本物理删除留下的孤儿实例),再向下级联标记根、实例、完成记录副本。行与 session 全部保留,历史专注不会变成「未关联任务」;重复任务也不会在下次启动被 `rollRepeatingTasks` 重新长出来。
- `deleteTask` 返回被隐藏的行 id,`TaskSheet` 据此解绑正在计时的任务;`rollRepeatingTasks` 跳过根任务已不存在的孤儿系列,避免启动时凭空生成新任务。
- 列表与统计入口统一补 `deleted = 0`:`tasks()`、`projects()` 计数、`projectTasks`、`projectTaskRows`、`projectCompletions`、`completedSourceIds`、`rollRepeatingTasks`、`startTargetFor`。
- 任务饼 `Store.taskSlices` 改用递归 CTE,任意深度的实例/副本都归到系列根;已删除任务仍按原名称单独成块,不再并进「未关联任务」。
- `LabelDonutView`:标注上限 6 → 8 条(每侧 4 条),牵线阈值 5° → 3°,小占比任务也能看到名称。
- 内存 SQLite 已验证:跨实例的重复任务时长合并、级联删除后无残留可滚动行、删除任务的饼图分块正常。
- 未改动:完成记录来源、任务页排序与筛选、逾期与重复规则、图标间距、锁屏实现。
- versionCode 66 / versionName 3.12,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.11。
## 2026-12-01 · 饼图按系列根任务与任务当前项目归并,选择器改为立即创建(v3.11)
- 专注页选任务弹层第二步底部的「不选择任务,直接开始」改为「立即创建」:关闭选择器后直接拉起新建任务弹层,保存成功自动选为新任务(圆环套用其专注时长)并停在专注页;取消则原状不变。
- 撤销 v3.10 对专注页主按钮的改动:主按钮恢复「开始专注」,没有任务时仍可直接开始;`no_task` 文案恢复原文案。
- 项目展开区:完成记录行不再显示开始键,开始键只保留在顶部创建任务行(仍经 `Store.startTargetFor` 找到系列中当前可计时的那一条)。
- 项目饼图归属改以任务当前所在项目为准(`t.project_id`),`sessions.project_id` 只在任务已删除时兜底,修掉「任务换项目 / 项目被删后整块落入未归类」;未归类文案统一为「未分类」。
- 任务饼图先归到系列根任务(`origin_id > 0 → origin_id`,否则自身 `_id`)再分组,名称与颜色取根任务,修掉「重复任务各周期实例、完成记录副本各自成块,同名任务被拆开、时长统计不全」。
- 已用内存 SQLite 复现验证:跨实例的重复任务时长合并为一条、换过项目的记录归到任务当前项目、删除任务后的记录落到「未关联任务」。
- 未改动:项目展开任务行 `projectTaskRows` 的统计口径、任务页与完成记录来源、重复与逾期规则、图标间距、锁屏实现。
- versionCode 65 / versionName 3.11,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.10。
## 2026-12-01 · 项目展开完成记录加开始按钮,专注页无任务改为立即创建(v3.10)
- 项目展开区两类行右侧都常驻开始键:顶部创建任务行不再因「已完成」隐藏播放键;下方完成记录行同样带开始键,点一下即重新开始该任务。
- 完成记录行(已完成的任务行)不能直接绑给计时器,否则每轮结束会再复制一份副本、`origin_id` 链条无限增长。新增 `Store.startTargetFor(taskId)`:回溯到系列根任务(`origin_id = 0`),系列里有未完成实例时取最新一条(重复任务的当前这一轮),全部完成才退回根任务本身。
- `MainActivity.startFocusFrom(taskId)` 负责解析后复用原来的 `startFocusOn(task)`:计时中切换仍被拦截并提示,空闲时自动开跑。
- 专注页不再「无任务空跑一轮」:没有任务且本轮未开始时,主按钮文案变为「立即创建」,点击直接拉起新建任务弹层;保存成功后自动选为新任务(圆环套用其专注时长)、停在专注页,取消则保持原状。
- `TaskSheet` 回调由 `() -> Unit` 改为 `(Long) -> Unit` 回传任务 id(删除回传 0),供专注页自动选中;既有调用方无需改动。
- 文案:新增「立即创建」「任务已创建,已选为当前任务」;`no_task` 改为「未选择任务 · 点开始即创建」。
- 未改动:任务页开始逻辑、项目任务与完成记录取数口径、逾期与重复规则、图标间距、项目编辑键盘适配、锁屏实现。
- versionCode 64 / versionName 3.10,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.9。
## 2026-12-01 · 项目任务行恢复统计口径、完成记录对齐任务页(v3.9)
- 项目展开顶部任务行恢复为「任务名称 + 专注时长 + 最近完成 + 累计次数/累计专注」,不再用「截止/随时」代替任务时间。
- 顶部任务行不划线、不变灰:那是「创建了就一直在」的清单,只有删除才消失,不受完成、重复影响。
- 完成记录行与任务页底部一致:任务名划线(备注不划线),meta 为「日期 周几 起-止 · 专注X」;没有真实专注时长(如自动完成)只写完成时刻。
- 专注页选任务行同样改为任务时间(专注时长),不写截止/随时、不标完成或逾期。
- 仅改 `ProjectAdapter.kt`、`FocusFragment.kt` 与 `item_project_task.xml` 注释;v3.8 的重复任务自动完成、逾期口径收窄、项目任务与完成记录来源不变。
- versionCode 63 / versionName 3.9,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.8。
## 2026-12-01 · 重复任务自动完成与项目页口径对齐(v3.8)
- 重复任务不再计逾期:任务页的「已逾期」标记与逾期分桶只对不重复任务(`repeat_type=0`)生效;`Store.tasks` 的 `includeOverdue` 过滤同步收窄,重复实例不会被当成逾期行。
- 周期滚动改为「先结束、再新建」:`rollRepeatingTasks` 在创建新周期实例前调用 `autoFinishSeries`,把该系列未完成的旧实例置为已完成,`done_at` 记本次滚动时刻,备注追加「自动完成」;不累加 `done_pomodoros`,不计入累计次数与累计时长。
- 项目完成记录改为与任务页同源:`Store.projectCompletions` 不再按 completed session 取,而是取已完成的任务行(`done_at` 倒序),并用 `origin_id` 指向关系排除被副本代表的源任务,老副本(`origin_id=0`)用 session 起止兜底排除;`ProjectCompletion.sessionId` 更名 `taskId`。
- 项目展开任务行回到「名称 + 时间」:只显示任务名称与截止时间(无截止「随时」),不再显示最近完成与累计统计;任务不按完成、逾期过滤,只有删除才消失,与专注页选任务口径一致。
- 完成记录行显示完成时刻(`完成`),有真实专注时长才追加「专注 X」,自动完成的记录备注为「自动完成」。
- 仅改 `Store.kt`、`Models.kt`、`ProjectAdapter.kt`、`TasksFragment.kt`;v3.6 图标间距、项目编辑键盘修复与 v3.7 任务页筛选默认值保持不变。
- versionCode 62 / versionName 3.8,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.7。
## 2026-12-01 · 专注选任务、任务页与项目页口径重整(v3.7)
- 专注页选任务:新增 `Store.projectTasks(projectId)`,只按项目列出用户创建的任务本体(`origin_id=0`),不按完成、逾期过滤;任务行只显示名称与截止时间(无截止显示「随时」),项目行统计改为总任务数。
- 任务页:默认状态由「未完成」改为「全部」,并对旧默认值做一次性迁移;逾期任务照常显示并排在置顶(随时)之后,其他未完成按重要+紧急排序,完成记录按完成时间倒序排在后面。取消 `finishedIds` 误伤导致的完成记录不可见问题。
- 项目页:`Store.projects()` 的待办/已完成统计改为只数项目下用户创建的任务(`origin_id=0`),排除重复系列实例与完成记录副本;`Store.projectTaskRows` 不再按逾期或完成过滤,任务创建后一直显示,只有删除才消失。
- 项目展开行:显示任务名称、截止时间(无截止「随时」)、最近完成时间、累计完成次数与累计专注时间;勾选完成且无 session 时完成次数至少记 1。
- 新增 `Store.projectCompletions(projectId)` 与 `ProjectCompletion`:完成记录按 completed session 一条一条列,任务行下方用「展开/收起完成记录(N)」控制显示,不与任务行混在一起。
- 仅改数据查询、专注选任务、任务页筛选默认值与项目页展示;v3.6 的图标间距与项目编辑键盘修复保持不变。
- versionCode 61 / versionName 3.7,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.6。
## 2026-12-01 · 修复任务图标间距与项目编辑键盘遮挡(v3.6)
- 任务页图标间距:间距与图标改为各占一个字符。此前 `IconGapSpan` 与图标 `ReplacementSpan` 套在同一字符上,后设置的图标会覆盖间距,导致标题与置顶、置顶与重要度图标视觉贴住。现在两处均保留可见空隙,间距仍为原 3 空格的一半。
- 项目编辑弹层:`ProjectSheet` 改用 `fitOnIme(root)` 的满屏容器 + 键盘顶起方案,拉起输入法时弹层整体上移,项目名称输入框与弹层边框不再被键盘遮住;同时保留点弹层外关闭。
- 仅改 `TaskAdapter.kt` 与 `ProjectSheet.kt`,任务排序、图标样式、项目统计及其他页面逻辑不变。
- versionCode 60 / versionName 3.6,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.5。
## 2026-12-01 · 回退 v3.3 基线并删除内置收件箱(v3.5)
- 源码整体回退到 v3.3(commit 467d34a),撤销 v3.4 的项目页统计口径重构、完成记录折叠与执行入口移除;任务页、专注页选任务、项目展开均恢复 v3.3 行为。
- 图标间距保持 v3.3 的「原 3 空格的一半」无字形占位:标题↔置顶圆圈、置顶↔重要度圆圈均有可见空隙,不贴住;未做二次改动。
- 删除默认内置「收件箱」项目:新库不再插入 id=1 的收件箱;DB 升到 v8,升级时只把原收件箱(id=1)下的任务与专注记录改为未分类(project_id=0),再删项目行,不删任何任务或记录。
- 未归属任务显示文案由「收件箱」改为「未分类」;`INBOX_ID` 常量保留但语义改为 0(无项目哨兵值),历史常量名不变以减小改动面。
- versionCode 59 / versionName 3.5,签名不变(7bcbd511…cc8c83),可覆盖安装 v3.4。
## 2026-12-01 · 项目页统计口径重构与执行入口移除(v3.4)
- 统计口径与展示口径统一:`Store.projects()` 的待办/已完成只数「用户创建(origin_id=0)、未删除、未逾期、非完成副本」的任务,专注时长与次数仍取 sessions;此前计数把周期滚动旧实例和完成副本也算进去,导致没有可见记录却有统计数字。
- 项目展开任务行只列用户创建且未删除、未逾期的任务(`Store.projectTaskRows` 增加 `origin_id=0`);自动滚动的周期旧实例与完成记录副本不再进入项目页。
- 新增 `Store.projectCompletions()`:完成记录直接取 sessions(completed=1),一条专注一条,备注取同一次专注的完成副本;与任务行分开,默认折叠在「展开完成记录(N)」区。
- 项目页退化为任务二级分类:移除展开行的开始按钮与点击编辑入口,任务执行与编辑统一留在任务页;仅保留创建任务、统计、完成记录三项内容。
- versionCode 58 / versionName 3.4,签名不变(7bcbd511…cc8c83),覆盖安装,无数据迁移。
## 2026-12-01 · 图标间距减半与逾期任务过滤(v3.3)
- 任务列表图标间距减半:标题↔置顶圆圈、置顶↔重要度圆圈由 3 个空格改为等宽于 3 个空格一半的空白占位,随字号等比缩放;重要度↔五角星间距不变。
- 逾期任务显示口径:任务页保持原样(逾期仍显示且排在「随时」之后);专注页选任务列表与项目卡展开均过滤「已逾期」(有截止日且早于今天零点,完成与否都算)的行。
- 修复项目展开重复:周期任务跨零点滚动生成的旧实例会沉淀为逾期行,项目展开与选任务列表不再列出;继续排除完成记录副本,仅保留未删除、非逾期的任务。
- versionCode 57 / versionName 3.3,签名不变(7bcbd511…cc8c83),覆盖安装,无数据迁移。
## 2026-12-01 · 项目页数字去空格、图标间距与完成副本去重(v3.2)
- 项目页所有数字前后空格删除:「N待办 / M已完成」「N分钟」「最近12-01·10:30完成」「累计N次M分钟」「N个项目 · M个待办」「已归档N」。任务页共用的 minutes_value 不改。
- 任务列表置顶圆圈与标题之间、置顶与重要度圆圈之间各留两个可见空格。
- 修复项目展开任务重复:DB v3 之前创建的完成记录副本 origin_id 为 0,旧排除条件只认 origin_id>0。新增按 session 起止时刻匹配(task_id 不同、start_at/end_at 与该行 created_at/done_at 一致)兜底识别并排除;周期系列实例与任务本体保留。
## 2026-12-01 · 统计补全、任务行编辑弹窗、图标对齐与完成记录折叠(v3.1)
- 项目展开行统计:在「累计 N 次」后空一格追加累计专注分钟数,只写「数字 分钟」,不加说明文案。
- 项目展开行点击复用任务页同款 `TaskSheet`,可直接编辑或删除该任务,保存/删除后刷新项目页。
- 任务列表置顶图标前移到重要度圆圈之前;重要度圆圈改为自绘圆环+数字,与置顶圆圈共用同一绘制函数(0.85 倍字号、s/10 描边),两者粗细与高度严格一致。
- 项目展开区已完成任务默认折叠,在已完成记录前新增「展开完成记录(N)/ 收起完成记录(N)」开关,避免历史记录越积越长。
- 数据层与任务页逻辑不变;versionCode 55 / versionName 3.1,签名不变。
## 2026-12-01 · 项目列表点击就地展开任务与统计(v3.0)
- 项目列表点击项目不再跳转任务页,改为就地展开该项目下的任务列表;只展开一个项目,再次点击收起。
- 口径:项目下添加过的任务只要没删除都保留(含已完成);排除每次专注生成的完成记录副本(否则一个任务重复 N 行)。
- 展开行参考任务列表但不显示分类(项目名),meta 为「单轮时长 · 最近完成时间 · 累计完成次数」;右侧保留开始按钮。
- 新增只读查询 Store.projectTaskRows + ProjectTaskStat 模型;累计次数取 done_pomodoros,最近完成取 sessions 中 completed=1 的最近 end_at,口径一致;排序沿用任务页。
- **任务页零改动**:TasksFragment / TaskAdapter / fragment_tasks / item_task / MainActivity 与 v2.9 逐字节一致,现有逻辑不变。
- versionCode 54 / versionName 3.0,签名不变(7bcbd511…cc8c83),覆盖安装,无数据迁移。
## 2026-11-30 · 回退字体改动,删除横屏分割线(v2.9)
- v2.8 打包字体在鸿蒙锁屏/悬浮窗上渲染异常(时间乱铺),按用户要求回退并移除分割线。
- layout-land 从 v2.3 提交恢复后仅删除中列(锚点+分割线+占位),删除 res/font;其余代码与 v2.3 一致。
- 最终形态:横屏左右两栏各半、时间居中、无分割线;竖屏不变。
- versionCode 53 / versionName 2.9,签名不变(7bcbd511…cc8c83),覆盖安装,无数据迁移。
## 2026-11-30 · 横屏大时间换用 Source Code Pro Bold,修分割线左右间隙不等(v2.8)
- 诊断(基于用户 4 张锁屏照片的程序实测):右间距恒 36px、左间距 20~27px 随秒数变化;数字 advance 等宽(≈95px)但"1"墨迹仅 65px → 系统字体墨迹边距不均;分割线在 advance 中点,布局本身对称无问题。间隙差来自字形墨迹:右钟以"0"开头(墨迹内缩)、左倒计时以 7/3/4/8 结尾(墨迹顶边)。
- 选型(渲染位图实测各候选字体的墨迹间隙差):Source Code Pro Bold 最优(最坏 4.9dp vs 现状 ~15dp),其"1"带衬线脚、墨迹近满宽、各数字边距最均匀。
- 改动(纯静态 XML):新增 res/font/sourcecodepro_bold.ttf;layout-land 仅给 3 个 130sp 文本(左右时间+中列锚点)加 fontFamily,其余与 v2.3 逐行一致。竖屏与 Kotlin 代码零改动。
- 版本:versionCode 52 / versionName 2.8,签名不变(7bcbd511…cc8c83),覆盖安装,无数据迁移。数字字形略有变化("1"多一个衬线脚,类翻页钟样式),字号 130sp 不变。
## 2026-11-30 · 删除 CountdownFit,竖屏恢复 v2.3 行为(v2.7)
- 起因:用户报告竖屏专注时间变小(回归)。v2.6 的 CountdownFit 等宽缩号在锁屏页与悬浮窗两条链路都接入,竖屏被波及——该工具只要倒计时文字比时钟宽几像素(鸿蒙字体数字非严格等宽时必然发生)就缩小倒计时,前提错误。
- 处理(回退):LockScreenActivity.kt、LockOverlay.kt 从 v2.3 提交 2dd7f8b 原样恢复(md5 校验一致);删除 util/CountdownFit.kt。
- 全量比对:app/src 树与 v2.3 完全一致,仅 SettingsFragment.kt 版本号字符串不同;横竖屏布局 XML 本轮零改动。
- 版本:versionCode 51 / versionName 2.7(Android 禁止 versionCode 降级,无法回退到 45),签名 SHA-256 7bcbd511…cc8c83 不变,直接覆盖安装,无数据迁移。装上后锁屏/悬浮窗行为与确认正常的 v2.3 一致。
- 横屏线与左右数字的间距问题本轮未动,待截图实测后另行处理。
## 2026-11-30 · 回退 v2.3 布局基线 + 倒计时等宽缩号(v2.6)
- 起因:v2.5 的 autoSize 方案在锁屏/悬浮窗特殊窗口上渲染异常(时间缩小居中、高度只显示约三分之一),判定 autoSize 在该链路不可靠,彻底放弃。按用户要求回退到 v2.3(确认"高度对齐成功"的版本)重新修。
- 回退:layout-land 布局从 git 提交 2dd7f8b 原样恢复,撤销 v2.4/v2.5 全部布局改动(贴线边距、match_parent、autoSize、tnum、gravity end/start)。
- 重新修「右边距离比左边大」:唯一来源是倒计时 ≥100 分钟时为 6 位数(120:00),比右侧时钟宽出一个数字。新增 util/CountdownFit:按实际字体测量(Paint.measureText)把 6 位倒计时缩到与时钟完全等宽,居中布局下左右间隙天然相等;回到 5 位立即恢复 130sp(越大越好不变)。LockScreenActivity 与 LockOverlay 两条渲染链路同时接入。
- 竖向对齐不受影响:时间列「时间+10dp+小字」整体居中,时间垂直中心=列中心−(10dp+小字)/2 与字号无关;中列锚点保持 130sp。
- 版本号不回退(Android 不允许 versionCode 降级覆盖安装):2.6 / versionCode 50。
- 改动文件:layout-land/activity_lock_screen.xml(恢复 v2.3)、LockScreenActivity.kt、LockOverlay.kt、util/CountdownFit.kt(新增)、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt2 确认 versionCode 50 / versionName 2.6,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装(可覆盖 v2.4/v2.5),无数据迁移。
## 2026-11-30 · 分割线左右等距 + autoSize 防溢出(v2.5)
- 起因:v2.4 后用户反馈「距离没变、一个屏幕装不下、需要左右滑动才能完整显示两个时间」。
- 根因(本轮钉死):倒计时 ≥100 分钟时是 6 位数(如 120:00),130sp 下宽约 410dp,超出半屏可用宽度(约 366dp);wrap_content 被压缩后文字从框左缘起画、向右溢出越过分割线——左边贴死/越线、右边 24dp,即「右边距离比左边大 + 装不下」。
- 方案:两个大时间改 match_parent 定宽 + autoSize 自动缩号(40sp..130sp)。5 位数保持 130sp 原样(「越大越好」不变);6 位数缩到刚好装下,永不溢出;文字 end/start 对齐 → 线到两边时间间隙恒为 24dp。时间列「时间+10dp+小字」整体居中,时间垂直中心=列中心−(10dp+小字)/2 与字号无关 → 一侧缩号不破坏竖向对齐。
- 视觉变化:时间从「半屏居中」改为「贴线排布」,文字向外生长,与线的距离恒定;≥100 分钟时倒计时一侧字号自动略小。
- 改动文件:layout-land/activity_lock_screen.xml、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt2 确认 versionCode 49 / versionName 2.5,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装,无数据迁移。
## 2026-11-30 · 分割线左右等距 + 等宽数字(v2.4)
- 起因:v2.3 垂直对齐成功后,用户反馈线到左右两边时间的水平间隙不相等。
- 诊断(实测而非猜测):布局左右两栏 weight 严格对称,分割线恒在正中;下载 Roboto-Bold 解析 hmtx 并用 Pillow 复核,10 个数字 advance 全部 0.5737em(等宽),`DD:DD` 恒等于 2.5771em。间隙不等只能来自系统字体(鸿蒙 HarmonyOS Sans 数字非等宽)或倒计时 ≥100 分钟时的 6 位(3.1509em)。
- 方案双保险:①左栏右对齐 + marginEnd 24dp、右栏左对齐 + marginStart 24dp——线到两边时间的布局间隙无条件恒等;②两侧大时间与锚点加 `fontFeatureSettings="tnum"`,系统字体支持时强制数字等宽、消除逐秒抖动(不支持则无副作用)。
- 视觉变化:时间从「半屏居中」改为「贴线排布」,文字向外生长,与线的距离恒定。
- 改动文件:layout-land/activity_lock_screen.xml、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt2 确认 versionCode 48 / versionName 2.4,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装,无数据迁移。
## 2026-11-30 · 分割线中列完整镜像,真正与时间上下对齐(v2.3)
- 起因:v2.2 修复无效——锚点 FrameLayout 与左右两栏同被 `center_vertical` 居中,但锚点列只有时间高(T),侧栏多出「10dp+15sp 小字」(C>T),高度不同的列各自居中后顶不对齐,锚点中心仍落在屏幕中心,与旧版位置完全相同。
- 方案:中列完整镜像左右两栏——`vertical LinearLayout` 内①1dp FrameLayout(130sp 粗体不可见锚点文字 + center 分割线)②与侧栏同规格(15sp、marginTop 10dp)的不可见小字占位。三列同高同顶,锚点中心严格等于时间中心。锚点文字加 `maxLines=1`,防止 1dp 宽父容器把 "00:00" 折行撑高。
- 纯静态 XML,锁屏/悬浮窗两条链路同时生效;字体缩放同步。
- 改动文件:layout-land/activity_lock_screen.xml、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt 确认 versionCode 47 / versionName 2.3,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装,无数据迁移。
## 2026-11-30 · 横屏分割线与时间上下精确对齐(v2.2)
- 起因:用户反馈分割线高度已与左右时间一致,但位置偏下、底部超出时间墨迹边线。
- 根因:分割线是横排 `center_vertical` LinearLayout 的直系子 View,居中基准是整个左右两栏(时间 + 10dp 间距 + 15sp 小字),下方多出的一截把线中心下拉约 15dp。
- 方案:镜像锚点——分割线外套 1dp 宽 FrameLayout,内放与左右时间同规格(130sp 粗体、includeFontPadding=false)的不可见占位文字,分割线在其中 center 对齐;线中心严格等于时间文字中心。纯静态 XML,不受锁屏/悬浮窗特殊窗口运行时布局失效问题影响,字体缩放变化也同步。悬浮窗复用同一布局,两条链路同时生效。
- 改动文件:layout-land/activity_lock_screen.xml、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt 确认 versionCode 46 / versionName 2.2,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装,无数据迁移。
## 2026-11-30 · 分割线降至与时间等高 + 改项目迁移关联任务 + 重要紧急排序(v2.1)
- 分割线:150dp 偏高,降到 92dp(≈130sp 粗体数字字面高度 0.71em×130),与左右时间视觉等高。
- 改项目重复 bug:编辑已有任务换项目时,只有当前行更新了 project_id,而周期系列的其他实例(origin_id=根id)和完成记录副本(origin_id=实例id)都还复制着旧项目,导致新旧项目各显示一份同名任务。现在 updateTask 检测到项目变化时,把根任务、系列实例、实例的完成记录副本一起迁移到新项目(带旧项目条件保证幂等);编辑完成记录副本本身则只移动该行、不牵连源任务。
- 普通任务排序:改为按重要度+紧急度总分降序(各 0低/1中/2高,总分 4→0 对应:最重要最紧急 → 最重要或最紧急 → 中重要中紧急 → 中重要或中紧急 → 低低),同分内再按有截止日优先/截止日升序/创建先后。置顶、逾期分组保持在前不变。
- 改动文件:layout-land/activity_lock_screen.xml、Store.kt、build.gradle.kts、build.sh、SettingsFragment.kt。
- 本地验证:构建通过,aapt 确认 versionCode 45 / versionName 2.1,签名 SHA-256 7bcbd511…cc8c83 不变。
- 升级说明:直接覆盖安装,无数据迁移。
## 2026-11-30 · 分割线恢复原始可见实现 + 逾期任务置顶后优先(v2.0) ## 2026-11-30 · 分割线恢复原始可见实现 + 逾期任务置顶后优先(v2.0)

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
package com.focusbox.app.model package com.focusbox.app.model
/** 项目(清单)。收件箱固定 id=1,不可删除。 */ /** 项目(清单)。id=0 表示未分类,不对应项目行;项目行均可编辑/归档/删除。 */
data class Project( data class Project(
val id: Long, val id: Long,
val name: String, val name: String,
@@ -62,6 +62,30 @@ data class Task(
/** 一条专注记录的起止时刻与实际秒数,用于在已完成任务上显示真实工作时段。 */ /** 一条专注记录的起止时刻与实际秒数,用于在已完成任务上显示真实工作时段。 */
data class SessionSpan(val startAt: Long, val endAt: Long, val seconds: Int = 0) data class SessionSpan(val startAt: Long, val endAt: Long, val seconds: Int = 0)
/**
* 项目卡展开后的一条任务行:任务本体 + 三项统计。
* 仅用于项目页展开列表,任务页的 Task 口径不变。
*/
data class ProjectTaskStat(
val task: Task,
/** 最近一次完成时刻(源任务 done_at 与该任务 sessions 最近 end_at 取大),0 表示未完成过 */
val lastDoneAt: Long,
/** 累计完成次数(done_pomodoros;勾选完成且无 session 时至少 1) */
val doneCount: Int,
/** 累计专注秒数(sessions 里该任务的 seconds 之和) */
val focusSeconds: Int,
)
/** 项目页一条完成记录:对应一条已完成的任务行(与任务页完成记录同源)。 */
data class ProjectCompletion(
val taskId: Long,
val taskTitle: String,
val note: String,
val startAt: Long,
val endAt: Long,
val seconds: Int,
)
/** 提前完成时交给 UI 落备注的实际专注信息 */ /** 提前完成时交给 UI 落备注的实际专注信息 */
data class FocusFinish( data class FocusFinish(
val taskId: Long, val taskId: Long,

View File

@@ -254,6 +254,15 @@ class MainActivity : AppCompatActivity() {
showTab(TAB_FOCUS) showTab(TAB_FOCUS)
} }
/**
* 按任务 id 开始计时,供项目页的完成记录行使用:
* 记录行本身是已完成的行,先经 [Store.startTargetFor] 换成系列里可计时的任务。
*/
fun startFocusFrom(taskId: Long) {
val target = Store.startTargetFor(taskId) ?: return
startFocusOn(target)
}
/** 设置改动后(清空数据、改主题)统一刷新其余页面 */ /** 设置改动后(清空数据、改主题)统一刷新其余页面 */
fun refreshAll() { fun refreshAll() {
for (f in fragments) { for (f in fragments) {

View File

@@ -26,6 +26,7 @@ import com.focusbox.app.model.Project
import com.focusbox.app.model.Task import com.focusbox.app.model.Task
import com.focusbox.app.service.TimerCore import com.focusbox.app.service.TimerCore
import com.focusbox.app.ui.SheetDialog import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.ui.tasks.TaskSheet
import com.focusbox.app.util.Dates import com.focusbox.app.util.Dates
import com.focusbox.app.util.Prefs import com.focusbox.app.util.Prefs
import com.focusbox.app.util.circleBg import com.focusbox.app.util.circleBg
@@ -404,6 +405,10 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
cachedProject = cachedTask?.let { Store.project(it.projectId) } cachedProject = cachedTask?.let { Store.project(it.projectId) }
} }
val task = cachedTask val task = cachedTask
// 专注进行中,任务已经绑进这一轮:右侧文案改成「正在专注」,整卡不可点。
// 否则中途换任务会把 elapsed 清零重建(setTask 会重设 totalMs),这一轮就白跑了。
val locked = TimerCore.running && TimerCore.mode == TimerCore.MODE_FOCUS && task != null
taskCard.isClickable = !locked
if (task == null) { if (task == null) {
taskDot.visible(false) taskDot.visible(false)
tvTask.text = getString(R.string.no_task) tvTask.text = getString(R.string.no_task)
@@ -417,7 +422,7 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
tvTask.text = task.title tvTask.text = task.title
val projectName = project?.name ?: getString(R.string.inbox) val projectName = project?.name ?: getString(R.string.inbox)
tvTaskMeta.text = getString(R.string.task_card_meta, projectName, task.focusMinutes, task.donePomodoros) tvTaskMeta.text = getString(R.string.task_card_meta, projectName, task.focusMinutes, task.donePomodoros)
tvTaskAction.text = getString(R.string.task_selected) tvTaskAction.text = getString(if (locked) R.string.task_focusing else R.string.task_selected)
} }
// ------------------------------------------------------------------ 手势 // ------------------------------------------------------------------ 手势
@@ -487,6 +492,33 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
// ------------------------------------------------------------------ 任务 // ------------------------------------------------------------------ 任务
/**
* 选任务弹层第二步底部的「立即创建」:拉起新建任务弹层。
*
* 保存成功后把新任务设为当前任务(圆环套用它设定的专注时长)并直接开始计时,
* 与「选中已有任务」走同一条路径;取消新建则什么都不变。
*/
private fun createTaskAndSelect() {
val ctx = context ?: return
val act = activity
val sheet = TaskSheet(ctx, null, 0L) { newId ->
if (newId > 0) {
Store.task(newId)?.let { t ->
TimerCore.setCountUp(false)
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
// 走的是同一条「选任务」路径,建完也直接开跑,保持口径一致
requestNotifPermissionIfNeeded()
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
Toast.makeText(ctx, R.string.task_created, Toast.LENGTH_SHORT).show()
}
cachedTaskId = Long.MIN_VALUE
(act as? com.focusbox.app.ui.MainActivity)?.refreshAll()
}
if (view != null) render()
}
sheet.show()
}
/** /**
* 选择任务:第一步选项目,第二步只列出该项目的待办。 * 选择任务:第一步选项目,第二步只列出该项目的待办。
* 用自绘底部弹层而不是系统 AlertDialog,便于圆角、分步标题与选中态。 * 用自绘底部弹层而不是系统 AlertDialog,便于圆角、分步标题与选中态。
@@ -543,7 +575,8 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
btnBack.visibility = View.VISIBLE btnBack.visibility = View.VISIBLE
btnClear.visibility = View.VISIBLE btnClear.visibility = View.VISIBLE
list.removeAllViews() list.removeAllViews()
val tasks = Store.tasks(projectId, includeDone = false) // 选任务只按项目列任务:不按完成、逾期过滤,也不显示完成记录
val tasks = Store.projectTasks(projectId)
if (tasks.isEmpty()) { if (tasks.isEmpty()) {
list.addView(TextView(ctx).apply { list.addView(TextView(ctx).apply {
text = getString(R.string.pick_task_empty) text = getString(R.string.pick_task_empty)
@@ -554,10 +587,8 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
}) })
} }
tasks.forEach { t -> tasks.forEach { t ->
val meta = buildString { // 行内只写任务时间(专注时长),不挂截止/随时、也不标完成或逾期
append(getString(R.string.minutes_value, t.focusMinutes)) val meta = "${t.focusMinutes}分钟"
if (t.due > 0) append(" · ${Dates.dueLabel(t.due)}截止")
}
addRow( addRow(
title = t.title, title = t.title,
meta = meta, meta = meta,
@@ -568,6 +599,10 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
TimerCore.setCountUp(false) TimerCore.setCountUp(false)
TimerCore.setTask(t.id, t.projectId, t.focusMinutes) TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
sheet.dismiss() sheet.dismiss()
// 选完即开跑,不用再点一次「开始专注」;
// 没跑过就 start,暂停过的(elapsed > 0)走 resume,才会补写暂停原因
requestNotifPermissionIfNeeded()
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
render() render()
} }
} }
@@ -586,7 +621,7 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
Store.projects().forEach { p -> Store.projects().forEach { p ->
addRow( addRow(
title = p.name, title = p.name,
meta = getString(R.string.pick_project_meta, p.openTasks), meta = getString(R.string.pick_project_meta, p.totalTasks),
color = p.color, color = p.color,
selected = p.id == currentPid, selected = p.id == currentPid,
alignLeft = true, // 项目列表不要左侧色点缩进,名称贴左对齐 alignLeft = true, // 项目列表不要左侧色点缩进,名称贴左对齐
@@ -597,10 +632,12 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
btnBack.setOnClickListener { showProjects() } btnBack.setOnClickListener { showProjects() }
btnClose.setOnClickListener { sheet.dismiss() } btnClose.setOnClickListener { sheet.dismiss() }
// 第二步底部:没有合适的任务就当场建一个,建完自动选中并回到专注页
btnClear.text = getString(R.string.create_now)
btnClear.setTextColor(col(R.color.brand))
btnClear.setOnClickListener { btnClear.setOnClickListener {
TimerCore.setTask(0, 0)
sheet.dismiss() sheet.dismiss()
render() createTaskAndSelect()
} }
sheet.setContentView(root) sheet.setContentView(root)
showProjects() showProjects()

View File

@@ -1,30 +1,61 @@
package com.focusbox.app.ui.projects package com.focusbox.app.ui.projects
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Paint
import android.text.Spannable
import android.text.SpannableString
import android.text.style.StrikethroughSpan
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.TextView import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.focusbox.app.R import com.focusbox.app.R
import com.focusbox.app.model.Project import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectCompletion
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.model.Task
import com.focusbox.app.util.Dates import com.focusbox.app.util.Dates
import com.focusbox.app.util.col import com.focusbox.app.util.col
import com.focusbox.app.util.roundBg import com.focusbox.app.util.roundBg
import com.focusbox.app.util.tint import com.focusbox.app.util.tint
import com.focusbox.app.util.visible
/**
* 项目列表:点击项目头就地展开该项目下创建的任务,不再跳转任务页。
* 任务不按完成/逾期过滤,全部列出;任务下方用「展开/收起完成记录」开关
* 控制该项目的历史完成记录,避免记录越积越长。
*/
class ProjectAdapter( class ProjectAdapter(
private val onClick: (Project) -> Unit, private val onToggleExpand: (Project) -> Unit,
private val onLongClick: (Project) -> Unit, private val onLongClick: (Project) -> Unit,
private val onMore: (Project) -> Unit, private val onMore: (Project) -> Unit,
private val onStart: (Task) -> Unit,
private val onEdit: (Task) -> Unit,
private val onToggleDone: () -> Unit,
) : RecyclerView.Adapter<ProjectAdapter.VH>() { ) : RecyclerView.Adapter<ProjectAdapter.VH>() {
private var items: List<Project> = emptyList() private var items: List<Project> = emptyList()
private var expandedId: Long = -1L
private var stats: Map<Long, List<ProjectTaskStat>> = emptyMap()
private var completions: Map<Long, List<ProjectCompletion>> = emptyMap()
private var showDone: Boolean = false
fun submit(list: List<Project>) { fun submit(
list: List<Project>,
expanded: Long,
taskStats: Map<Long, List<ProjectTaskStat>>,
completionRows: Map<Long, List<ProjectCompletion>>,
showDoneRows: Boolean,
) {
items = list items = list
expandedId = expanded
stats = taskStats
completions = completionRows
showDone = showDoneRows
notifyDataSetChanged() notifyDataSetChanged()
} }
@@ -41,16 +72,19 @@ class ProjectAdapter(
private val progress: ProgressBar = v.findViewById(R.id.progress) private val progress: ProgressBar = v.findViewById(R.id.progress)
private val colorBar: View = v.findViewById(R.id.colorBar) private val colorBar: View = v.findViewById(R.id.colorBar)
private val more: ImageView = v.findViewById(R.id.btnMore) private val more: ImageView = v.findViewById(R.id.btnMore)
private val header: View = v.findViewById(R.id.projectHeader)
private val taskList: LinearLayout = v.findViewById(R.id.taskList)
private val tvTaskEmpty: TextView = v.findViewById(R.id.tvTaskEmpty)
fun bind(p: Project) { fun bind(p: Project) {
val ctx = itemView.context val ctx = itemView.context
name.text = p.name name.text = p.name
colorBar.background = ctx.roundBg(p.color, 2f) colorBar.background = ctx.roundBg(p.color, 2f)
// 只看任务与时长,不再显示番茄数 // 项目页只统计项目下创建的任务:总数、已完成数、累计专注时长
val parts = ArrayList<String>(3) val parts = ArrayList<String>(3)
parts.add("${p.openTasks} 待办") parts.add(ctx.getString(R.string.project_tasks_total, p.totalTasks))
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成") if (p.doneTasks > 0) parts.add(ctx.getString(R.string.project_tasks_done, p.doneTasks))
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds)) if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
meta.text = parts.joinToString(" · ") meta.text = parts.joinToString(" · ")
@@ -61,11 +95,127 @@ class ProjectAdapter(
more.tint(ctx.col(R.color.text_tertiary)) more.tint(ctx.col(R.color.text_tertiary))
more.setOnClickListener { onMore(p) } more.setOnClickListener { onMore(p) }
itemView.setOnClickListener { onClick(p) } header.setOnClickListener { onToggleExpand(p) }
itemView.setOnLongClickListener { header.setOnLongClickListener {
onLongClick(p) onLongClick(p)
true true
} }
val expanded = expandedId == p.id
val rows = if (expanded) stats[p.id].orEmpty() else emptyList()
val records = if (expanded) completions[p.id].orEmpty() else emptyList()
taskList.visible(expanded && (rows.isNotEmpty() || records.isNotEmpty()))
tvTaskEmpty.visible(expanded && rows.isEmpty() && records.isEmpty())
if (!expanded) return
fun addTaskRow(row: ProjectTaskStat) {
val item = LayoutInflater.from(ctx)
.inflate(R.layout.item_project_task, taskList, false)
bindTaskRow(item, row, p)
taskList.addView(item)
}
taskList.removeAllViews()
// 项目下创建的任务全部列出:不按完成/逾期过滤,也不重复生成
rows.forEach { addTaskRow(it) }
// 任务下面单独一条开关:展开/隐藏该项目下的完成记录
if (records.isNotEmpty()) {
val toggle = LayoutInflater.from(ctx)
.inflate(R.layout.item_footer, taskList, false)
val tv = toggle.findViewById<TextView>(R.id.tvFooter)
tv.text = ctx.getString(
if (showDone) R.string.project_collapse_done else R.string.project_expand_done,
records.size,
)
tv.setTextColor(ctx.col(R.color.brand))
toggle.setOnClickListener { onToggleDone() }
taskList.addView(toggle)
if (showDone) records.forEach { addCompletionRow(it, p) }
}
}
private fun bindTaskRow(item: View, row: ProjectTaskStat, p: Project) {
val ctx = item.context
val task = row.task
val tvTitle: TextView = item.findViewById(R.id.tvTaskTitle)
val tvMeta: TextView = item.findViewById(R.id.tvTaskMeta)
val btnPlay: ImageView = item.findViewById(R.id.btnTaskPlay)
item.findViewById<View>(R.id.taskColorBar).background = ctx.roundBg(p.color, 2f)
// 顶部是「创建了就一直在」的任务清单:不划线、不变灰;
// 完成与否只体现在下面的完成记录里
tvTitle.text = task.title
tvTitle.setTextColor(ctx.col(R.color.text))
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
// 任务时间(专注时长)· 最近完成 · 累计次数与累计专注
val parts = ArrayList<String>(3)
parts.add("${task.focusMinutes}分钟")
if (row.lastDoneAt > 0) {
val whenText = "${Dates.md(row.lastDoneAt)}·${Dates.hm(row.lastDoneAt)}"
parts.add(ctx.getString(R.string.project_task_last_done, whenText))
}
val totals = StringBuilder()
if (row.doneCount > 0) {
totals.append(ctx.getString(R.string.project_task_done_count, row.doneCount))
}
if (row.focusSeconds > 0) {
// 累计专注只写「数字分钟」,不加说明文案,也不留空格
totals.append(row.focusSeconds / 60).append("分钟")
}
if (totals.isNotEmpty()) parts.add(totals.toString())
tvMeta.text = parts.joinToString(" · ")
// 开始键常驻:已完成的创建任务同样可以再开始一轮,
// 由调用方把「已完成的行」换成系列里当前可计时的任务
btnPlay.visible(true)
btnPlay.tint(ctx.col(R.color.brand))
btnPlay.setOnClickListener { onStart(task) }
// 与任务页一致:点行打开编辑/删除弹窗
item.setOnClickListener { onEdit(task) }
}
private fun addCompletionRow(record: ProjectCompletion, p: Project) {
val ctx = itemView.context
val item = LayoutInflater.from(ctx)
.inflate(R.layout.item_project_task, taskList, false)
item.findViewById<View>(R.id.taskColorBar).background = ctx.roundBg(p.color, 2f)
val tvTitle: TextView = item.findViewById(R.id.tvTaskTitle)
val tvMeta: TextView = item.findViewById(R.id.tvTaskMeta)
val btnPlay: ImageView = item.findViewById(R.id.btnTaskPlay)
// 完成记录行只做历史展示:开始键只出现在上面的创建任务行
btnPlay.visible(false)
// 完成记录与任务页底部一致:任务名划线,完成原因跟在后面但不划线
val noteText = record.note.replace('\n', ' ')
val titleText = if (noteText.isBlank()) {
record.taskTitle
} else {
"${record.taskTitle} · $noteText"
}
val line = SpannableString(titleText)
if (record.taskTitle.isNotEmpty()) {
line.setSpan(
StrikethroughSpan(), 0, record.taskTitle.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
)
}
tvTitle.text = line
tvTitle.setTextColor(ctx.col(R.color.text_secondary))
tvTitle.paintFlags = tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
// 与任务页完成记录同格式:日期 周几 起-止 · 专注X;没有真实时长就只写完成时刻
tvMeta.text = if (record.seconds > 0) {
"${Dates.dateWithWeek(record.startAt)} ${Dates.hms(record.startAt)}" +
"-${Dates.hms(record.endAt)} · 专注${Dates.duration(record.seconds)}"
} else {
"${Dates.dateWithWeek(record.endAt)} ${Dates.hms(record.endAt)}完成"
}
item.isClickable = false
item.setOnClickListener(null)
taskList.addView(item)
} }
} }
} }

View File

@@ -13,6 +13,7 @@ import androidx.appcompat.app.AlertDialog
import com.focusbox.app.R import com.focusbox.app.R
import com.focusbox.app.data.Store import com.focusbox.app.data.Store
import com.focusbox.app.model.Project import com.focusbox.app.model.Project
import com.focusbox.app.service.TimerCore
import com.focusbox.app.ui.SheetDialog import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.util.Palette import com.focusbox.app.util.Palette
import com.focusbox.app.util.circleBg import com.focusbox.app.util.circleBg
@@ -35,7 +36,11 @@ class ProjectSheet(
private var color: Int = existing?.color ?: Palette.colorAt(0) private var color: Int = existing?.color ?: Palette.colorAt(0)
init { init {
setContentView(root) // 项目编辑含多个输入框:必须走满屏容器 + 键盘顶起,否则输入法会盖住弹层
fitOnIme(root)
// 满屏容器后仍保留“点弹层外关闭”,点弹层内部空白不关闭
(root.parent as? View)?.setOnClickListener { dismiss() }
root.setOnClickListener { }
root.findViewById<TextView>(R.id.sheetTitle).setText( root.findViewById<TextView>(R.id.sheetTitle).setText(
if (existing == null) R.string.add_project else R.string.edit if (existing == null) R.string.add_project else R.string.edit
) )
@@ -57,6 +62,11 @@ class ProjectSheet(
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ -> .setPositiveButton(R.string.delete) { _, _ ->
Store.deleteProject(existing.id) Store.deleteProject(existing.id)
// 项目下的任务行已经删掉了:正在计时的如果正好是其中一条,
// 必须先把计时解绑,否则这一轮结束时会写出一条挂不到任务上的记录
if (TimerCore.taskId > 0 && Store.task(TimerCore.taskId) == null) {
TimerCore.setTask(0, 0)
}
onSaved() onSaved()
dismiss() dismiss()
} }
@@ -89,28 +99,37 @@ class ProjectSheet(
} }
} }
/**
* 20 色两行平铺(每行 10 个)。
*
* 从一行横向滑动改成两行:20 个色点若排成一行要滑很久才找得到,
* 两行 × 10 个刚好铺满一屏宽度(10 × 32dp = 320dp),窄屏仍可横向滑动兜底。
*/
private fun renderColors() { private fun renderColors() {
val ctx = context val ctx = context
colorRow.removeAllViews() colorRow.removeAllViews()
Palette.colors.forEach { c -> Palette.colors.toList().chunked(10).forEach { rowColors ->
val wrap = FrameLayout(ctx) val row = LinearLayout(ctx).apply { orientation = LinearLayout.HORIZONTAL }
val lp = LinearLayout.LayoutParams(dpi(40f), dpi(40f)) colorRow.addView(row)
lp.marginEnd = dpi(2f) rowColors.forEach { c ->
wrap.layoutParams = lp val wrap = FrameLayout(ctx)
wrap.background = if (c == color) ctx.roundBg(Color.TRANSPARENT, 100f, c, 2f) else null val lp = LinearLayout.LayoutParams(dpi(32f), dpi(32f))
wrap.layoutParams = lp
wrap.background = if (c == color) ctx.roundBg(Color.TRANSPARENT, 100f, c, 2f) else null
val dot = View(ctx) val dot = View(ctx)
val dlp = FrameLayout.LayoutParams(dpi(26f), dpi(26f)) val dlp = FrameLayout.LayoutParams(dpi(20f), dpi(20f))
dlp.gravity = Gravity.CENTER dlp.gravity = Gravity.CENTER
dot.layoutParams = dlp dot.layoutParams = dlp
dot.background = circleBg(c) dot.background = circleBg(c)
wrap.addView(dot) wrap.addView(dot)
wrap.setOnClickListener { wrap.setOnClickListener {
color = c color = c
renderColors() renderColors()
}
row.addView(wrap)
} }
colorRow.addView(wrap)
} }
} }
} }

View File

@@ -10,8 +10,12 @@ import androidx.recyclerview.widget.RecyclerView
import com.focusbox.app.R import com.focusbox.app.R
import com.focusbox.app.data.Store import com.focusbox.app.data.Store
import com.focusbox.app.model.Project import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectCompletion
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.service.TimerCore
import com.focusbox.app.ui.MainActivity import com.focusbox.app.ui.MainActivity
import com.focusbox.app.ui.SheetDialog import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.ui.tasks.TaskSheet
import com.focusbox.app.util.col import com.focusbox.app.util.col
import com.focusbox.app.util.visible import com.focusbox.app.util.visible
@@ -25,6 +29,13 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
private var showArchived = false private var showArchived = false
/** 当前展开的项目 id;-1 表示全部收起。只展开一个,避免列表过长 */
private var expandedProjectId = -1L
private var taskStats: Map<Long, List<ProjectTaskStat>> = emptyMap()
private var completions: Map<Long, List<ProjectCompletion>> = emptyMap()
/** 项目任务下方的完成记录默认折叠,避免历史记录越积越长 */
private var showDoneInProject = false
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
recycler = view.findViewById(R.id.recycler) recycler = view.findViewById(R.id.recycler)
@@ -33,9 +44,20 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
btnArchived = view.findViewById(R.id.btnArchived) btnArchived = view.findViewById(R.id.btnArchived)
adapter = ProjectAdapter( adapter = ProjectAdapter(
onClick = { p -> (activity as? MainActivity)?.openProjectTasks(p.id) }, onToggleExpand = { p ->
val opening = expandedProjectId != p.id
expandedProjectId = if (opening) p.id else -1L
if (opening) showDoneInProject = false
reload()
},
onLongClick = { p -> showActions(p) }, onLongClick = { p -> showActions(p) },
onMore = { p -> showActions(p) }, onMore = { p -> showActions(p) },
onStart = { t -> (activity as? MainActivity)?.startFocusFrom(t.id) },
onEdit = { t -> TaskSheet(requireContext(), t, 0L) { reload() }.show() },
onToggleDone = {
showDoneInProject = !showDoneInProject
reload()
},
) )
recycler.layoutManager = LinearLayoutManager(requireContext()) recycler.layoutManager = LinearLayoutManager(requireContext())
recycler.adapter = adapter recycler.adapter = adapter
@@ -68,10 +90,16 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
val archived = all.filter { it.archived } val archived = all.filter { it.archived }
val shown = if (showArchived) all else active val shown = if (showArchived) all else active
adapter.submit(shown) // 展开态只在可见项目上加载统计;项目被删/归档后自动收起,不留悬空 id
if (expandedProjectId != -1L && shown.none { it.id == expandedProjectId }) {
expandedProjectId = -1L
}
taskStats = shown.associate { it.id to Store.projectTaskRows(it.id) }
completions = shown.associate { it.id to Store.projectCompletions(it.id) }
adapter.submit(shown, expandedProjectId, taskStats, completions, showDoneInProject)
tvSummary.text = getString( tvSummary.text = getString(
R.string.project_summary, active.size, active.sumOf { it.openTasks } R.string.project_summary, active.size, active.sumOf { it.totalTasks }
) )
tvEmpty.visible(shown.isEmpty()) tvEmpty.visible(shown.isEmpty())
@@ -79,7 +107,7 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
btnArchived.visible(false) btnArchived.visible(false)
} else { } else {
btnArchived.visible(true) btnArchived.visible(true)
btnArchived.text = if (showArchived) "隐藏已归档" else "已归档 ${archived.size}" btnArchived.text = if (showArchived) "隐藏已归档" else "已归档${archived.size}"
} }
} }
@@ -148,6 +176,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
) { which -> ) { which ->
if (which == 1) { if (which == 1) {
Store.deleteProject(p.id) Store.deleteProject(p.id)
// 项目下的任务行已随之删除:正在计时的若属于它们,先解绑,
// 否则这一轮结束会写成一条挂不到任务的「未关联」记录
if (TimerCore.taskId > 0 && Store.task(TimerCore.taskId) == null) {
TimerCore.setTask(0, 0)
}
reload() reload()
} }
} }

View File

@@ -138,6 +138,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
section(R.string.section_data) section(R.string.section_data)
card( card(
// 清理旧版本删除任务后残留的孤儿记录,排在「清空所有数据」前面:
// 它只动查不到任务的记录,比全清安全一档
action(getString(R.string.purge_orphan), "", danger = true) { confirmPurgeOrphan() },
action(getString(R.string.clear_data), "", danger = true) { confirmClear() }, action(getString(R.string.clear_data), "", danger = true) { confirmClear() },
) )
@@ -481,6 +484,71 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
dialog.show() dialog.show()
} }
/**
* 清空未关联数据:弹窗结构与「清空所有数据」完全一致,只是正文会说清要删多少条。
*
* 删的是「找不到任务」的专注记录(旧版本删任务时把 task_id 清零留下的残骸、
* 以及没选任务直接开始的那几轮)。它们只能堆成饼图里的「未关联任务」,
* 占一块地方又查不到是谁的,所以单独给一个清理入口。
*/
private fun confirmPurgeOrphan() {
val ctx = requireContext()
val stat = Store.orphanSessions()
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val panel = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(20f), dpi(20f), dpi(20f), dpi(14f))
}
panel.addView(TextView(ctx).apply {
text = getString(R.string.purge_orphan)
textSize = 16f
typeface = Typeface.DEFAULT_BOLD
setTextColor(col(R.color.text))
})
panel.addView(TextView(ctx).apply {
text = if (stat.count > 0) {
getString(R.string.purge_confirm, stat.count, Dates.duration(stat.seconds))
} else {
getString(R.string.purge_none)
}
textSize = 14f
setTextColor(col(R.color.text_secondary))
setPadding(0, dpi(10f), 0, dpi(6f))
})
val btnRow = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.END
setPadding(0, dpi(12f), 0, 0)
}
fun btn(labelRes: Int, danger: Boolean, onClick: () -> Unit) = TextView(ctx).apply {
text = getString(labelRes)
textSize = 14f
typeface = Typeface.DEFAULT_BOLD
gravity = Gravity.CENTER
setTextColor(col(if (danger) R.color.danger else R.color.brand))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(22f), dpi(10f), dpi(22f), dpi(10f))
setOnClickListener { onClick() }
}
btnRow.addView(btn(R.string.cancel, false) { dialog.dismiss() })
btnRow.addView(btn(R.string.delete, true) {
dialog.dismiss()
if (stat.count > 0) Store.purgeOrphanSessions()
(activity as? MainActivity)?.refreshAll()
build()
}, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
marginStart = dpi(10f)
})
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
}
private fun confirmClear() { private fun confirmClear() {
val ctx = requireContext() val ctx = requireContext()
val dialog = android.app.Dialog(ctx) val dialog = android.app.Dialog(ctx)
@@ -539,6 +607,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
} }
companion object { companion object {
const val VERSION = "2.0" const val VERSION = "3.3"
} }
} }

View File

@@ -2,6 +2,7 @@ package com.focusbox.app.ui.stats
import android.content.Context import android.content.Context
import android.graphics.Typeface import android.graphics.Typeface
import android.graphics.drawable.GradientDrawable
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue import android.util.TypedValue
import android.view.Gravity import android.view.Gravity
@@ -15,6 +16,7 @@ import com.focusbox.app.util.Dates
import com.focusbox.app.util.col import com.focusbox.app.util.col
import com.focusbox.app.util.dpi import com.focusbox.app.util.dpi
import com.focusbox.app.widget.LabelDonutView import com.focusbox.app.widget.LabelDonutView
import kotlin.math.roundToInt
/** /**
* 「项目分布 / 任务分布」卡片:自带 日 / 周 / 月 / 年 四档与左右翻页。 * 「项目分布 / 任务分布」卡片:自带 日 / 周 / 月 / 年 四档与左右翻页。
@@ -42,6 +44,12 @@ class PeriodDistributionCard @JvmOverloads constructor(
private val btnNext = ImageView(context) private val btnNext = ImageView(context)
private val donut = LabelDonutView(context) private val donut = LabelDonutView(context)
/**
* 环下方明细列表:环只标占比最高的 6 条,剩下的全部在这里逐条列出。
* 不合并成「其他」——被合并掉的任务在页面上等于消失,用户根本不知道自己漏了什么。
*/
private val legend = LinearLayout(context)
/** 当前粒度,默认按天 */ /** 当前粒度,默认按天 */
var scale = Scale.DAY var scale = Scale.DAY
private set private set
@@ -145,6 +153,90 @@ class PeriodDistributionCard @JvmOverloads constructor(
addView(donut, LayoutParams(LayoutParams.MATCH_PARENT, context.dpi(222f)).apply { addView(donut, LayoutParams(LayoutParams.MATCH_PARENT, context.dpi(222f)).apply {
topMargin = context.dpi(2f) topMargin = context.dpi(2f)
}) })
legend.apply {
orientation = VERTICAL
visibility = GONE
}
addView(legend, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT).apply {
topMargin = context.dpi(6f)
})
}
// ------------------------------------------------------------------ 明细列表
/**
* 把环上没有牵线的切片按「圆点 + 名称 / 时长 · 占比」两列铺开(参考图版式)。
* 每格宽度均分,名称超长省略,保证列对齐不来回跳。
*/
private fun renderLegend(rest: List<LabelDonutView.Slice>, total: Int) {
legend.removeAllViews()
if (rest.isEmpty() || total <= 0) {
legend.visibility = GONE
return
}
legend.visibility = VISIBLE
rest.chunked(2).forEach { pair ->
val row = LinearLayout(context).apply { orientation = HORIZONTAL }
legend.addView(row, LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT))
pair.forEach { slice ->
row.addView(buildLegendCell(slice, total), LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
}
// 单数时补一个空位,最后一行不会因为权重拉伸变成通栏
if (pair.size == 1) {
row.addView(android.view.View(context), LayoutParams(0, 1, 1f))
}
}
}
private fun buildLegendCell(slice: LabelDonutView.Slice, total: Int): LinearLayout {
val cell = LinearLayout(context).apply {
orientation = HORIZONTAL
setPadding(0, context.dpi(7f), context.dpi(8f), context.dpi(7f))
}
val dot = android.view.View(context).apply {
background = GradientDrawable().apply {
shape = GradientDrawable.OVAL
setColor(slice.color)
}
}
// 8dp 圆点,下移 5dp 与名称首行的视觉中心对齐
cell.addView(dot, LayoutParams(context.dpi(8f), context.dpi(8f)).apply {
topMargin = context.dpi(5f)
})
val text = LinearLayout(context).apply {
orientation = VERTICAL
setPadding(context.dpi(8f), 0, 0, 0)
}
cell.addView(text, LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f))
text.addView(TextView(context).apply {
this.text = slice.name
setTextSize(TypedValue.COMPLEX_UNIT_SP, 13f)
setTextColor(context.col(R.color.title))
maxLines = 1
ellipsize = android.text.TextUtils.TruncateAt.END
includeFontPadding = false
})
val pct = slice.seconds * 100f / total
val pctText = if (pct < 1f) "<1%" else "${pct.roundToInt()}%"
text.addView(TextView(context).apply {
this.text = context.getString(
R.string.legend_meta,
Dates.duration(slice.seconds),
pctText,
)
setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f)
setTextColor(context.col(R.color.text_secondary))
maxLines = 1
includeFontPadding = false
})
return cell
} }
// ------------------------------------------------------------------ 交互 // ------------------------------------------------------------------ 交互
@@ -204,7 +296,9 @@ class PeriodDistributionCard @JvmOverloads constructor(
) )
} }
) )
donut.centerText = Dates.durationBrief(raw.sumOf { it.seconds }) val total = raw.sumOf { it.seconds }
donut.centerText = Dates.durationBrief(total)
renderLegend(donut.unlabeled, total)
tvPeriod.text = periodLabel(from, to) tvPeriod.text = periodLabel(from, to)
applySegments() applySegments()

View File

@@ -71,6 +71,25 @@ class TaskAdapter(
} }
} }
/**
* 标题与图标之间的间距:旧版用三个空格,视觉偏宽。
* 改用无字形占位,宽度精确等于三个空格的一半,避免随字体变化忽大忽小。
*/
private fun appendIconGap(title: SpannableStringBuilder) {
title.append(" ")
title.setSpan(IconGapSpan(), title.length - 1, title.length, 0)
}
/**
* 间距与图标必须各占一个字符。若把两个 ReplacementSpan 套在同一字符上,
* 后设置的图标会覆盖间距,视觉上就贴住了。
*/
private fun appendIconSpan(title: SpannableStringBuilder, span: Any) {
appendIconGap(title)
title.append(" ")
title.setSpan(span, title.length - 1, title.length, 0)
}
private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) { private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
private val tvTitle: TextView = v.findViewById(R.id.tvTitle) private val tvTitle: TextView = v.findViewById(R.id.tvTitle)
private val tvMeta: TextView = v.findViewById(R.id.tvMeta) private val tvMeta: TextView = v.findViewById(R.id.tvMeta)
@@ -85,23 +104,25 @@ class TaskAdapter(
val ctx = itemView.context val ctx = itemView.context
// 标题右侧的属性图标,未完成与已完成都显示: // 标题右侧的属性图标,未完成与已完成都显示:
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→ // 置顶圆圈箭头(「随时」未完成任务)→ 重要度圆圈数字 → 紧急度五角星。
// 紧急度五角星 → 随时上箭头。 // 置顶与重要度两个圆圈统一自绘:同一尺寸(0.85 倍字号)、同一描边(s/10),
// 各字形在字体里的字面尺寸不同:以圆圈数字 0.85 为基准, // 保证粗细与高度完全一致;五角星仍用字形,0.95 倍不作参照。
// 上箭头与圆圈同高;五角星 0.95 不作参照
val title = SpannableStringBuilder(task.title) val title = SpannableStringBuilder(task.title)
val iconSize = tvTitle.textSize * 0.85f
val (badge, badgeColor) = when (task.priority) { // 置顶图标前移到重要度圆圈之前(品牌蓝圆圈内向上箭头)
2 -> " ③" to R.color.urgent_high if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
1 -> " ②" to R.color.urgent_mid appendIconSpan(title, PinIconSpan(ctx.col(R.color.brand), iconSize))
else -> " ①" to R.color.urgent_low
} }
title.append(badge)
title.setSpan( // 重要度圆圈:3 高 / 2 中 / 1 普通,颜色与紧急度同色系
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)), val (digit, badgeColor) = when (task.priority) {
title.length - badge.length, title.length, 0 2 -> "3" to R.color.urgent_high
) 1 -> "2" to R.color.urgent_mid
title.setSpan(RelativeSizeSpan(0.85f), title.length - badge.length, title.length, 0) else -> "1" to R.color.urgent_low
}
// 与标题、与置顶圆圈各留半个旧间距,避免图标贴在一起又不显得散
appendIconSpan(title, PriorityBadgeSpan(ctx.col(badgeColor), iconSize, digit))
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰 // 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
val (stars, starColor) = when (task.urgency) { val (stars, starColor) = when (task.urgency) {
@@ -116,17 +137,6 @@ class TaskAdapter(
) )
title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0) title.setSpan(RelativeSizeSpan(0.95f), title.length - stars.length, title.length, 0)
// 「随时」任务:标题后带品牌蓝圆圈上箭头表示置顶,列表里排在未完成最前面。
// 图标与重要度圆圈数字同规格(0.85 倍字号,圆圈里画向上箭头),
// 圆圈与箭头同色(品牌蓝);前面的细空格(U+2009)保持与星标的间距一致。
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
title.append("\u2009 ")
title.setSpan(
PinIconSpan(ctx.col(R.color.brand), tvTitle.textSize * 0.85f),
title.length - 1, title.length, 0,
)
}
// 完成横线只画任务名本身(MidStrikeSpan 限定区间,且划线取文字墨迹 // 完成横线只画任务名本身(MidStrikeSpan 限定区间,且划线取文字墨迹
// 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字 // 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字
// 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。 // 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。
@@ -206,6 +216,22 @@ class TaskAdapter(
} }
} }
/**
* 图标间距占位:宽度等于旧版三个空格的一半,且不绘制任何字形。
* 用 ReplacementSpan 而不是固定 dp,间距会随字号等比缩放。
*/
private class IconGapSpan : android.text.style.ReplacementSpan() {
override fun getSize(
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
): Int = (paint.measureText(" ") / 2f).toInt().coerceAtLeast(1)
override fun draw(
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
) = Unit
}
/** /**
* 任务名删除线:系统 StrikethroughSpan 的划线位置按"字体半高"(baseline + ascent/2) * 任务名删除线:系统 StrikethroughSpan 的划线位置按"字体半高"(baseline + ascent/2)
* 计算,但数字/汉字的实际墨迹顶比字体 ascent 低不少,划线视觉上偏下。 * 计算,但数字/汉字的实际墨迹顶比字体 ascent 低不少,划线视觉上偏下。
@@ -236,6 +262,61 @@ private class MidStrikeSpan : android.text.style.ReplacementSpan() {
} }
} }
/** 置顶与重要度共用的圆环绘制:同尺寸、同描边(s/10),保证两个圆圈粗细一致。 */
private fun drawBadgeRing(
canvas: android.graphics.Canvas, cx: Float, cy: Float, size: Float, ringColor: Int,
) {
val ring = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG).apply {
this.color = ringColor
style = android.graphics.Paint.Style.STROKE
strokeWidth = size / 10f
strokeCap = android.graphics.Paint.Cap.ROUND
}
canvas.drawCircle(cx, cy, size / 2f - ring.strokeWidth / 2f, ring)
}
/**
* 重要度圆圈数字:自绘圆环 + 数字,与置顶圆圈共用 drawBadgeRing,
* 高度(0.85 倍字号)与描边(s/10)严格一致,不再依赖系统字形 ①②③ 的墨迹差异。
*/
private class PriorityBadgeSpan(
private val badgeColor: Int,
private val size: Float,
private val digit: String,
) : android.text.style.ReplacementSpan() {
override fun getSize(
paint: Paint, text: CharSequence, start: Int, end: Int, fm: Paint.FontMetricsInt?,
): Int {
val s = size.toInt()
if (fm != null) {
fm.ascent = -s
fm.descent = 0
fm.top = fm.ascent
fm.bottom = fm.descent
}
return s
}
override fun draw(
canvas: android.graphics.Canvas, text: CharSequence, start: Int, end: Int,
x: Float, top: Int, baseline: Int, bottom: Int, paint: Paint,
) {
val s = size
val cy = baseline - s * 0.45f
val cx = x + s / 2f
drawBadgeRing(canvas, cx, cy, s, badgeColor)
val num = Paint(Paint.ANTI_ALIAS_FLAG).apply {
this.color = badgeColor
textSize = s * 0.60f
typeface = Typeface.DEFAULT
textAlign = Paint.Align.CENTER
}
val fm = num.fontMetrics
canvas.drawText(digit, cx, cy - (fm.ascent + fm.descent) / 2f, num)
}
}
/** /**
* 置顶图标:圆圈内向上箭头。 * 置顶图标:圆圈内向上箭头。
* 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符, * 自绘而不是用字体字形——常用字体里没有"圆圈+箭头"的组合字符,
@@ -270,13 +351,8 @@ private class PinIconSpan(
// 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上 // 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上
val cx = x + s / 2f val cx = x + s / 2f
val cy = baseline - s * 0.45f val cy = baseline - s * 0.45f
// 圈线与重要度圆圈数字的描边粗细一致(约 1/10 图标高) // 与重要度圆圈共用同一绘制函数:同尺寸、同 1/10 描边,粗细与高度严格一致
val ring = Paint(Paint.ANTI_ALIAS_FLAG) drawBadgeRing(canvas, cx, cy, s, iconColor)
ring.color = iconColor
ring.style = Paint.Style.STROKE
ring.strokeWidth = s / 10f
ring.strokeCap = Paint.Cap.ROUND
canvas.drawCircle(cx, cy, s / 2f - ring.strokeWidth / 2f, ring)
// 箭头比圈线更细(约 1/15 图标高),整体落在圆内 // 箭头比圈线更细(约 1/15 图标高),整体落在圆内
val arrow = Paint(Paint.ANTI_ALIAS_FLAG) val arrow = Paint(Paint.ANTI_ALIAS_FLAG)

View File

@@ -32,7 +32,7 @@ class TaskSheet(
context: Context, context: Context,
private val existing: Task?, private val existing: Task?,
presetProjectId: Long, presetProjectId: Long,
private val onSaved: () -> Unit, private val onSaved: (Long) -> Unit,
) : SheetDialog(context) { ) : SheetDialog(context) {
private val root = LayoutInflater.from(context).inflate(R.layout.sheet_task, null) private val root = LayoutInflater.from(context).inflate(R.layout.sheet_task, null)
@@ -105,12 +105,13 @@ class TaskSheet(
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ -> .setPositiveButton(R.string.delete) { _, _ ->
existing?.let { existing?.let {
Store.deleteTask(it.id) // 删除会连同整个任务系列(重复实例 + 完成记录副本)及其专注记录一起删掉,
// 删除的正是当前选中任务时必须解除绑定: // 只要当前计时绑在这一系列的任意一行上就要解绑,
// 否则计时继续走,到点后完成记录会落成"未关联任务" // 否则到点后完成记录会挂到一个已经不存在的任务上
if (TimerCore.taskId == it.id) TimerCore.setTask(0, 0) val removed = Store.deleteTask(it.id)
if (TimerCore.taskId in removed) TimerCore.setTask(0, 0)
} }
onSaved() onSaved(0L)
dismiss() dismiss()
} }
.show() .show()
@@ -258,7 +259,8 @@ class TaskSheet(
periodic && due <= 0 -> Dates.todayStart() periodic && due <= 0 -> Dates.todayStart()
else -> due else -> due
} }
if (existing == null) { // 回传任务 id:专注页「没有任务 → 立即创建」需要拿新行 id 自动选中
val savedId = if (existing == null) {
Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every, urgency) Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every, urgency)
} else { } else {
Store.updateTask( Store.updateTask(
@@ -274,8 +276,9 @@ class TaskSheet(
repeatEvery = every, repeatEvery = every,
) )
) )
existing.id
} }
onSaved() onSaved(savedId)
dismiss() dismiss()
} }
} }

View File

@@ -28,8 +28,8 @@ import com.focusbox.app.util.visible
* *
* 项目 / 时间 / 重要度 / 紧急度 / 状态,每栏单选,行内放不下自动换行。 * 项目 / 时间 / 重要度 / 紧急度 / 状态,每栏单选,行内放不下自动换行。
* 筛选面板默认收起,只显示一行当前条件摘要;点摘要展开,选中任意胶囊后自动收起。 * 筛选面板默认收起,只显示一行当前条件摘要;点摘要展开,选中任意胶囊后自动收起。
* 默认「项目=全部 · 时间=全部 · 重要度=全部 · 紧急度=全部 · 状态=未完成」, * 默认「项目=全部 · 时间=全部 · 重要度=全部 · 紧急度=全部 · 状态=全部」,
* 与旧版「完成后从列表消失」的行为一致;想看历史切到「已完成」。 * 逾期任务与完成记录都在同一列表里;只想看待办可切到「未完成」。
*/ */
class TasksFragment : Fragment(R.layout.fragment_tasks) { class TasksFragment : Fragment(R.layout.fragment_tasks) {
@@ -83,7 +83,8 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
adapter = TaskAdapter( adapter = TaskAdapter(
onEdit = { openSheet(it) }, onEdit = { openSheet(it) },
onToggle = { task -> onToggle = { task ->
Store.setTaskDone(task.id, !task.done) // 手动勾选完成:备注写「手动完成」,这一次不算专注,不进累计与饼图
Store.setTaskDone(task.id, !task.done, markManual = true)
reload() reload()
}, },
onStart = { task -> (activity as? MainActivity)?.startFocusOn(task) }, onStart = { task -> (activity as? MainActivity)?.startFocusOn(task) },
@@ -282,7 +283,7 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
// 有任一条件偏离默认值时摘要高亮,提示当前列表被筛过 // 有任一条件偏离默认值时摘要高亮,提示当前列表被筛过
val filtered = filterProjectId > 0L || timeFilter != TIME_ALL || val filtered = filterProjectId > 0L || timeFilter != TIME_ALL ||
priorityFilter >= 0 || urgencyFilter >= 0 || statusFilter != 0 priorityFilter >= 0 || urgencyFilter >= 0 || statusFilter != -1
tvFilterSummary.setTextColor( tvFilterSummary.setTextColor(
ctx.col(if (filtered) R.color.brand else R.color.text_secondary) ctx.col(if (filtered) R.color.brand else R.color.text_secondary)
) )
@@ -382,7 +383,10 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
private fun toRow(task: Task, spans: Map<Long, SessionSpan>): TaskAdapter.Row.Item { private fun toRow(task: Task, spans: Map<Long, SessionSpan>): TaskAdapter.Row.Item {
val project = projects.firstOrNull { it.id == task.projectId } val project = projects.firstOrNull { it.id == task.projectId }
val overdue = task.due > 0 && task.due < Dates.todayStart() // 重复任务按周期滚动,本轮没做不算逾期(下一轮生成时会自动结束旧实例);
// 只有不重复的任务才标「已逾期」
val overdue = task.due > 0 && task.due < Dates.todayStart() &&
task.repeatType == com.focusbox.app.model.Repeat.NONE
return TaskAdapter.Row.Item( return TaskAdapter.Row.Item(
task = task, task = task,
projectName = project?.name ?: getString(R.string.inbox), projectName = project?.name ?: getString(R.string.inbox),
@@ -414,7 +418,7 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
} }
private fun openSheet(task: Task?) { private fun openSheet(task: Task?) {
// 新建任务时默认归到当前筛选的项目;全部/收件箱则不预选 // 新建任务时默认归到当前筛选的项目;全部/未分类则不预选
TaskSheet(requireContext(), task, filterProjectId.takeIf { it > 0 } ?: 0L) { reload() }.show() TaskSheet(requireContext(), task, filterProjectId.takeIf { it > 0 } ?: 0L) { reload() }.show()
} }
} }

View File

@@ -1,9 +1,19 @@
package com.focusbox.app.util package com.focusbox.app.util
/** 项目配色。八色一组,两两之间在色相上有足够间距,圆点上也能分辨。 */ /**
* 项目配色:20 色,按色相环顺序排列,冷暖交替铺开。
*
* 排布原则:
* 1. 前 8 个保持 v3.13 及以前的顺序不变 —— 老项目的颜色不能因为扩容而整体位移;
* 2. 新增 12 个按色相插空补齐(红橙 → 黄绿 → 青 → 蓝紫 → 紫红 → 酒红),
* 相邻两个至少差 15° 色相,圆点(20dp)和饼图上都能分清;
* 3. 统一压到中等明度(HSB 的 B ≈ 60–75%,S ≈ 40–65%),
* 深色主题下不刺眼、浅色主题下不吃掉白字,也不会盖过品牌色。
*/
object Palette { object Palette {
val colors = intArrayOf( val colors = intArrayOf(
// ---- 原有 8 色(顺序保持不变)
0xFFC75B45.toInt(), // 陶土红 0xFFC75B45.toInt(), // 陶土红
0xFFD98324.toInt(), // 琥珀 0xFFD98324.toInt(), // 琥珀
0xFFC9A227.toInt(), // 芥黄 0xFFC9A227.toInt(), // 芥黄
@@ -12,9 +22,22 @@ object Palette {
0xFF3B7DD8.toInt(), // 靛蓝 0xFF3B7DD8.toInt(), // 靛蓝
0xFF6C5CE7.toInt(), // 紫 0xFF6C5CE7.toInt(), // 紫
0xFFB7548E.toInt(), // 玫红 0xFFB7548E.toInt(), // 玫红
// ---- 新增 12 色:暖色 6 个 + 冷色 6 个
0xFFE0703C.toInt(), // 柚橙(暖)
0xFFA8B33A.toInt(), // 柠黄绿(暖偏中性)
0xFF6E8B3D.toInt(), // 橄榄(暖绿)
0xFFA34A52.toInt(), // 酒红(暖)
0xFFD96C93.toInt(), // 玫瑰粉(暖)
0xFFA9663A.toInt(), // 焦糖(暖)
0xFF2E7D57.toInt(), // 森林绿(冷)
0xFF45B08C.toInt(), // 薄荷(冷)
0xFF2E9AAE.toInt(), // 青蓝(冷)
0xFF4B9CD3.toInt(), // 天蓝(冷)
0xFF5B6BC0.toInt(), // 靛紫(冷)
0xFF9A7BD0.toInt(), // 丁香紫(冷)
) )
/** 收件箱用中性灰,避免和自建项目争注意力 */ /** 未分类用中性灰,避免和自建项目争注意力 */
const val INBOX = 0xFF7A756C.toInt() const val INBOX = 0xFF7A756C.toInt()
fun colorAt(index: Int): Int = colors[index.mod(colors.size)] fun colorAt(index: Int): Int = colors[index.mod(colors.size)]

View File

@@ -15,6 +15,14 @@ object Prefs {
fun init(context: Context) { fun init(context: Context) {
sp = context.getSharedPreferences("focusbox", Context.MODE_PRIVATE) sp = context.getSharedPreferences("focusbox", Context.MODE_PRIVATE)
// 一次性把旧的默认「未完成」改为「全部」:任务页要同时看到逾期与完成记录。
// 用户之后仍可手动切回「未完成」,迁移只执行一次。
if (!sp.getBoolean("ui_filter_status_all_migrated", false)) {
if (sp.getInt("ui_filter_status", 0) == 0) {
sp.edit().putInt("ui_filter_status", -1).apply()
}
sp.edit().putBoolean("ui_filter_status_all_migrated", true).apply()
}
} }
// ---- 时长 ---- // ---- 时长 ----
@@ -165,7 +173,7 @@ object Prefs {
set(v) = sp.edit().putInt("ui_filter_urgency", v).apply() set(v) = sp.edit().putInt("ui_filter_urgency", v).apply()
var uiFilterStatus: Int var uiFilterStatus: Int
get() = sp.getInt("ui_filter_status", 0) get() = sp.getInt("ui_filter_status", -1)
set(v) = sp.edit().putInt("ui_filter_status", v).apply() set(v) = sp.edit().putInt("ui_filter_status", v).apply()
var uiFilterExpanded: Boolean var uiFilterExpanded: Boolean

View File

@@ -15,6 +15,7 @@ import com.focusbox.app.util.col
import com.focusbox.app.util.dpf import com.focusbox.app.util.dpf
import com.focusbox.app.util.spf import com.focusbox.app.util.spf
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.roundToInt
import kotlin.math.sin import kotlin.math.sin
/** /**
@@ -43,9 +44,28 @@ class LabelDonutView @JvmOverloads constructor(
invalidate() invalidate()
} }
/** 最多画几条引线标注,多出来的合并成「其他」,避免标注挤成一团 */ /**
* 环上最多给几条切片牵引线标注(取占比最高的若干条)。
*
* 超出部分**不再合并成「其他」**:环本身照旧把每一块都按真实占比画出来,
* 只是没牵到线的切片记进 [unlabeled],由调用方在图表下方完整列出。
* 6 条(每侧 3 条)在 222dp 高度里间距仍舒展,再往上夹逼会把相邻标注压到一起。
*/
var maxLabels: Int = 6 var maxLabels: Int = 6
/** 扇区张角小于该值时不牵线:引线会叠在同一个点上,约 0.8% 以下的占比 */
private val minLabelSweep = 3f
/**
* 环上没能牵线的切片(占比排在 [maxLabels] 之外,或扇区太窄),按占比从高到低。
* 调用方必须把它们全部列在图表下方,否则这些任务/项目在视觉上就"消失"了。
*/
var unlabeled: List<Slice> = emptyList()
private set
/** 已经牵到线的切片,按同一套规则算出,供绘制使用 */
private var labeled: List<Slice> = emptyList()
private val strokeW = context.dpf(28f) private val strokeW = context.dpf(28f)
private val arcPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { private val arcPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
@@ -83,9 +103,29 @@ class LabelDonutView @JvmOverloads constructor(
fun setSlices(list: List<Slice>) { fun setSlices(list: List<Slice>) {
slices = list slices = list
plan(list)
invalidate() invalidate()
} }
/**
* 标注计划:按占比排序,前 [maxLabels] 名里扇区够宽的才牵线,
* 其余(含前 N 名但太窄的)全部落到 [unlabeled]。
*/
private fun plan(list: List<Slice>) {
val total = list.sumOf { it.seconds }
val sorted = list.sortedByDescending { it.seconds }
val head = if (total <= 0) emptyList() else sorted.take(maxLabels).filter {
it.seconds.toFloat() / total * 360f >= minLabelSweep
}
labeled = head
// 用「逐个摘除」而不是 toSet 差集:同名同色同时长的两条切片也能各算一次
val left = head.toMutableList()
unlabeled = sorted.filter { s ->
val i = left.indexOf(s)
if (i >= 0) { left.removeAt(i); false } else true
}
}
private data class Tag( private data class Tag(
val slice: Slice, val slice: Slice,
val midDeg: Float, val midDeg: Float,
@@ -110,21 +150,25 @@ class LabelDonutView @JvmOverloads constructor(
return return
} }
val shown = collapse(slices)
val box = RectF(cx - r, cy - r, cx + r, cy + r) val box = RectF(cx - r, cy - r, cx + r, cy + r)
val gapDeg = if (shown.size > 1) 2.2f else 0f // 不再合并「其他」后切片可能有几十条,固定 2.2° 的缝隙累计起来会吃掉小半个环
// (40 条就是 88°),因此按条数摊薄,总缝隙不超过约 14°
val gapDeg = if (slices.size > 1) minOf(2.2f, 14f / slices.size) else 0f
// ---- 弧与百分比 // ---- 弧与百分比:每一块都按真实占比画,绝不合并
var start = -90f var start = -90f
val tags = ArrayList<Tag>(shown.size) val tags = ArrayList<Tag>(labeled.size)
shown.forEach { s -> val pending = labeled.toMutableList()
slices.forEach { s ->
val sweep = s.seconds.toFloat() / total * 360f val sweep = s.seconds.toFloat() / total * 360f
val midDeg = start + sweep / 2f val midDeg = start + sweep / 2f
arcPaint.color = s.color arcPaint.color = s.color
canvas.drawArc(box, start + gapDeg / 2f, (sweep - gapDeg).coerceAtLeast(0.5f), false, arcPaint) canvas.drawArc(box, start + gapDeg / 2f, (sweep - gapDeg).coerceAtLeast(0.2f), false, arcPaint)
val arcLen = sweep / 360f * (2 * Math.PI.toFloat() * r) val arcLen = sweep / 360f * (2 * Math.PI.toFloat() * r)
val pct = "${(s.seconds * 100f / total).toInt().coerceAtLeast(1)}%" // 与下方明细用同一套舍入(四舍五入),否则 7.6% 环上写 7、列表写 8,
// 看起来就像「排第 7 的都牵了线,前 6 反而没牵」
val pct = "${(s.seconds * 100.0 / total).roundToInt().coerceAtLeast(1)}%"
// 环加粗后百分比必须完整落在色带里:按实测字宽缩字号,两侧各留 5dp 边距 // 环加粗后百分比必须完整落在色带里:按实测字宽缩字号,两侧各留 5dp 边距
var pctSize = 11f var pctSize = 11f
pctPaint.textSize = context.spf(pctSize) pctPaint.textSize = context.spf(pctSize)
@@ -141,14 +185,16 @@ class LabelDonutView @JvmOverloads constructor(
canvas.drawText(pct, px, py - (fm.ascent + fm.descent) / 2f, pctPaint) canvas.drawText(pct, px, py - (fm.ascent + fm.descent) / 2f, pctPaint)
} }
// 太薄的扇区不牵线,否则几条线会叠在同一个点上 // 只有进了标注计划的切片才牵线;pending 逐个摘除,重复切片也各算一次
if (sweep >= 5f) { if (sweep >= minLabelSweep && pending.remove(s)) {
val cosA = cos(radians(midDeg)) val cosA = cos(radians(midDeg))
val sinA = sin(radians(midDeg)) val sinA = sin(radians(midDeg))
tags.add( tags.add(
Tag( Tag(
slice = s, slice = s,
midDeg = midDeg, midDeg = midDeg,
// 只看扇区中线在左半还是右半:标注就该贴在自己那块色旁边。
// v3.14 试过强行左右均分,被分到对面的扇区引线必然横穿圆环,已撤回。
side = if (cosA >= 0.0) 1 else -1, side = if (cosA >= 0.0) 1 else -1,
anchorY = cy + ((r + strokeW) * sinA).toFloat(), anchorY = cy + ((r + strokeW) * sinA).toFloat(),
) )
@@ -164,17 +210,6 @@ class LabelDonutView @JvmOverloads constructor(
private fun radians(deg: Float): Double = Math.toRadians(deg.toDouble()) private fun radians(deg: Float): Double = Math.toRadians(deg.toDouble())
private fun collapse(list: List<Slice>): List<Slice> {
if (list.size <= maxLabels) return list
val head = list.take(maxLabels - 1)
val rest = list.drop(maxLabels - 1)
return head + Slice(
name = context.getString(R.string.slice_other),
seconds = rest.sumOf { it.seconds },
color = context.col(R.color.text_tertiary),
)
}
/** /**
* 环中心只画一行:累计时间(或空态提示)。 * 环中心只画一行:累计时间(或空态提示)。
* 之前按 cy + 2dp 硬偏移定位,字面重心偏下;改为按字体度量 * 之前按 cy + 2dp 硬偏移定位,字面重心偏下;改为按字体度量
@@ -245,7 +280,8 @@ class LabelDonutView @JvmOverloads constructor(
linePaint.color = color linePaint.color = color
linePaint.alpha = 200 linePaint.alpha = 200
// 从环外缘斜出到折点,再水平指向外侧圆点 // 标注永远在扇区自己那一侧,从环外缘斜出到折点,再水平指向外侧圆点,
// 引线不会跨过圆环(v3.14 的三段式是为强制左右均分服务的,已随均分一起撤回)。
canvas.drawLine(startX, startY, kneeX, tag.y, linePaint) canvas.drawLine(startX, startY, kneeX, tag.y, linePaint)
canvas.drawLine(kneeX, tag.y, dotX, tag.y, linePaint) canvas.drawLine(kneeX, tag.y, dotX, tag.y, linePaint)

View File

@@ -8,6 +8,14 @@
固定 dp 高度,无任何运行时改动(此前的 View.post / fontMetrics / 固定 dp 高度,无任何运行时改动(此前的 View.post / fontMetrics /
match_parent 结构化三版方案在锁屏/悬浮窗链路上全部失效)。 match_parent 结构化三版方案在锁屏/悬浮窗链路上全部失效)。
高度 150dp ≈ 130sp 时间文字的墨迹高度(1.17 × 130sp),仅分割两块大时间。 高度 150dp ≈ 130sp 时间文字的墨迹高度(1.17 × 130sp),仅分割两块大时间。
v2.2/v2.3 位置对齐:分割线作为横排直系子 View 时,center_vertical 相对「整个
左右两栏(时间+10dp间距+15sp小字)」居中,下方多出的一截把线的中心往下拉。
v2.2 只在分割线外套锚点 FrameLayout,但锚点列比侧栏矮(没有补小字占位),
三列各自居中后锚点中心仍落在屏幕中心,位置不变、修复无效。
v2.3 改为中列完整镜像左右两栏(时间锚点 + 同规格小字占位),三列同高同顶,
锚点中心严格等于时间文字中心;纯静态 XML,不受锁屏/悬浮窗特殊窗口运行时
调整失效问题影响,字体缩放变化也同步。
--> -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lockRoot" android:id="@+id/lockRoot"
@@ -48,12 +56,7 @@
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<!-- 中:细分隔线(仅分割两块大时间,150dp≈130sp 文字墨迹高度) --> <!-- 中列分割线已按用户要求移除(v2.9):左右两栏各占一半宽度,文字各自居中 -->
<View
android:id="@+id/lockDivider"
android:layout_width="1dp"
android:layout_height="150dp"
android:background="#26FFFFFF" />
<!-- 右:时钟(大)+ 日期星期在时钟下面 --> <!-- 右:时钟(大)+ 日期星期在时钟下面 -->
<LinearLayout <LinearLayout

View File

@@ -2,8 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical"
android:gravity="center_vertical"
android:background="@drawable/bg_card" android:background="@drawable/bg_card"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
@@ -13,6 +12,15 @@
android:paddingTop="14dp" android:paddingTop="14dp"
android:paddingBottom="14dp"> android:paddingBottom="14dp">
<!-- 项目头:点击整行展开/收起任务列表 -->
<LinearLayout
android:id="@+id/projectHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground">
<View <View
android:id="@+id/colorBar" android:id="@+id/colorBar"
android:layout_width="4dp" android:layout_width="4dp"
@@ -63,4 +71,25 @@
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_more" android:src="@drawable/ic_more"
android:contentDescription="@string/edit" /> android:contentDescription="@string/edit" />
</LinearLayout>
<!-- 展开区:该项目下添加过的任务(含已完成),默认收起 -->
<LinearLayout
android:id="@+id/taskList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" />
<TextView
android:id="@+id/tvTaskEmpty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="18dp"
android:paddingEnd="12dp"
android:paddingBottom="12dp"
android:text="@string/project_no_tasks"
android:textColor="@color/text_tertiary"
android:textSize="12sp"
android:visibility="gone" />
</LinearLayout> </LinearLayout>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 项目卡展开后的任务行:结构与任务列表一致,但不显示分类(项目名)。
顶部任务行 meta =「专注时长 · 最近完成 · 累计次数+累计专注」,不划线;
完成记录行同一布局,任务名划线、meta 为「日期 周几 起-止 · 专注X」。
两种行右侧都常驻开始键(btnTaskPlay),点击即开始该任务。 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:paddingStart="18dp"
android:paddingEnd="10dp"
android:paddingTop="9dp"
android:paddingBottom="9dp">
<View
android:id="@+id/taskColorBar"
android:layout_width="3dp"
android:layout_height="30dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="11dp"
android:orientation="vertical">
<TextView
android:id="@+id/tvTaskTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textColor="@color/text"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="@+id/tvTaskMeta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:maxLines="2"
android:ellipsize="end"
style="@style/T.Caption" />
</LinearLayout>
<ImageView
android:id="@+id/btnTaskPlay"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginStart="6dp"
android:padding="9dp"
android:background="@drawable/bg_play_circle"
android:scaleType="fitCenter"
android:src="@drawable/ic_play"
android:contentDescription="@string/start" />
</LinearLayout>

View File

@@ -102,7 +102,7 @@
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
android:background="@drawable/bg_btn_ghost" android:background="@drawable/bg_btn_ghost"
android:gravity="center" android:gravity="center"
android:text="@string/clear_task" android:text="@string/create_now"
android:textSize="14sp" android:textSize="14sp"
android:textColor="@color/text_secondary" android:textColor="@color/text_secondary"
android:visibility="gone" /> android:visibility="gone" />

View File

@@ -91,7 +91,7 @@
android:text="@string/project_color" android:text="@string/project_color"
style="@style/T.Section" /> style="@style/T.Section" />
<!-- 八色圆点横向可滑,末位颜色不再被弹层右边缘裁掉 --> <!-- 20 色圆点排成两行(每行 10 个),屏幕再窄也是在容器内横向滑动,不会被弹层右边缘裁掉 -->
<HorizontalScrollView <HorizontalScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -104,7 +104,7 @@
android:id="@+id/colorRow" android:id="@+id/colorRow"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical"
android:paddingTop="4dp" android:paddingTop="4dp"
android:paddingBottom="4dp" /> android:paddingBottom="4dp" />
</HorizontalScrollView> </HorizontalScrollView>

View File

@@ -14,6 +14,8 @@
<string name="mode_long_break">长休息</string> <string name="mode_long_break">长休息</string>
<string name="start">开始专注</string> <string name="start">开始专注</string>
<string name="create_now">立即创建</string>
<string name="task_created">任务已创建,已选为当前任务</string>
<string name="start_break">开始休息</string> <string name="start_break">开始休息</string>
<string name="start_timing">开始计时</string> <string name="start_timing">开始计时</string>
<string name="pause">暂停</string> <string name="pause">暂停</string>
@@ -49,14 +51,16 @@
<string name="no_task">未选择任务 · 直接开始也可以</string> <string name="no_task">未选择任务 · 直接开始也可以</string>
<string name="pick_task">选择任务</string> <string name="pick_task">选择任务</string>
<string name="task_selected">已选任务</string> <string name="task_selected">已选任务</string>
<!-- 计时进行中,任务已锁定:右侧不再显示「已选任务」 -->
<string name="task_focusing">正在专注</string>
<string name="pick_project">选择项目</string> <string name="pick_project">选择项目</string>
<string name="pick_back">返回上一步</string> <string name="pick_back">返回上一步</string>
<string name="clear_task">不选择任务,直接开始</string> <string name="clear_task">立即创建</string>
<string name="pick_step">第 %1$d 步 / 共 2 步</string> <string name="pick_step">第 %1$d 步 / 共 2 步</string>
<string name="pick_project_hint">先选项目,再从这个项目里挑一件要做的事</string> <string name="pick_project_hint">先选项目,再从这个项目里挑一件要做的事</string>
<string name="pick_task_hint">选中的任务会自动套用它设定的专注时长</string> <string name="pick_task_hint">选中的任务会自动套用它设定的专注时长</string>
<string name="pick_project_meta">%1$d 项待办</string> <string name="pick_project_meta">%1$d 项任务</string>
<string name="pick_task_empty">这个项目还没有待办任务,点返回换个项目</string> <string name="pick_task_empty">这个项目还没有任务,点返回换个项目</string>
<string name="no_task_to_pick">还没有待办任务,先去「任务」新建一个</string> <string name="no_task_to_pick">还没有待办任务,先去「任务」新建一个</string>
<string name="rounds_today">今天第 %1$d 个番茄</string> <string name="rounds_today">今天第 %1$d 个番茄</string>
@@ -122,14 +126,21 @@
<string name="archive">归档</string> <string name="archive">归档</string>
<string name="unarchive">取消归档</string> <string name="unarchive">取消归档</string>
<string name="archived">已归档</string> <string name="archived">已归档</string>
<string name="delete_task_confirm">删除这个任务?专注记录会保留。</string> <string name="delete_task_confirm">删除这个任务?该任务的专注记录与统计会一并删除,不可恢复。</string>
<string name="delete_project_confirm">删除项目「%1$s」?项目下的任务会移到收件箱。</string> <string name="delete_project_confirm">删除项目「%1$s」?项目下的任务、这些任务的专注记录与统计会一并删除,不可恢复。</string>
<string name="projects_title">项目</string> <string name="projects_title">项目</string>
<string name="project_summary">%1$d 个项目 · %2$d 个待办</string> <string name="project_no_tasks">还没有添加任务</string>
<string name="project_tasks_total">%1$d个任务</string>
<string name="project_tasks_done">%1$d已完成</string>
<string name="project_task_last_done">最近%1$s完成</string>
<string name="project_task_done_count">累计%1$d次</string>
<string name="project_expand_done">展开完成记录(%1$d)</string>
<string name="project_collapse_done">收起完成记录(%1$d)</string>
<string name="project_summary">%1$d个项目 · %2$d个任务</string>
<string name="add_project">新建项目</string> <string name="add_project">新建项目</string>
<string name="project_name_hint">项目名称</string> <string name="project_name_hint">项目名称</string>
<string name="inbox">收件箱</string> <string name="inbox">未分类</string>
<string name="project_color">颜色</string> <string name="project_color">颜色</string>
<string name="show_archived">显示已归档</string> <string name="show_archived">显示已归档</string>
<string name="empty_projects">还没有项目\n按用途分组,统计里就能看到时间花在哪</string> <string name="empty_projects">还没有项目\n按用途分组,统计里就能看到时间花在哪</string>
@@ -160,9 +171,11 @@
<string name="period_month">%1$d年%2$d月</string> <string name="period_month">%1$d年%2$d月</string>
<string name="period_year">%1$d年</string> <string name="period_year">%1$d年</string>
<string name="slice_other">其他</string> <string name="slice_other">其他</string>
<!-- 环图下方明细行:「时长 · 占比」 -->
<string name="legend_meta">%1$s · %2$s</string>
<string name="no_record">暂无记录</string> <string name="no_record">暂无记录</string>
<string name="summary_title">累计</string> <string name="summary_title">累计</string>
<string name="streak_days">连续打卡</string> <string name="streak_days">连续专注</string>
<string name="streak_value">%1$d天</string> <string name="streak_value">%1$d天</string>
<string name="total_focus">总专注</string> <string name="total_focus">总专注</string>
<string name="total_pomo">总番茄</string> <string name="total_pomo">总番茄</string>
@@ -205,6 +218,9 @@
<string name="theme_light">浅色</string> <string name="theme_light">浅色</string>
<string name="theme_dark">深色</string> <string name="theme_dark">深色</string>
<string name="clear_data">清空所有数据</string> <string name="clear_data">清空所有数据</string>
<string name="purge_orphan">清空未关联数据</string>
<string name="purge_confirm">将删除 %1$d 条没有关联任务的专注记录(合计 %2$s)。\n这些记录在统计里只记作「未关联任务」,删掉后饼图对应分块会消失,此操作不可恢复。</string>
<string name="purge_none">当前没有未关联任务的专注记录,无需清理。</string>
<string name="clear_data_hint">项目、任务、专注记录全部删除,不可恢复</string> <string name="clear_data_hint">项目、任务、专注记录全部删除,不可恢复</string>
<string name="clear_confirm">确定清空全部数据?此操作不可恢复。</string> <string name="clear_confirm">确定清空全部数据?此操作不可恢复。</string>
<string name="about_version">V%1$s</string> <string name="about_version">V%1$s</string>
@@ -236,5 +252,5 @@
<string name="task_card_meta">%1$s · %2$d 分钟 · 已完成 %3$d 次</string> <string name="task_card_meta">%1$s · %2$d 分钟 · 已完成 %3$d 次</string>
<string name="stat_today_minutes">%1$d分钟</string> <string name="stat_today_minutes">%1$d分钟</string>
<!-- %1$d 连续天数 / %2$d 每日目标分钟 --> <!-- %1$d 连续天数 / %2$d 每日目标分钟 -->
<string name="stat_streak">连续打卡%1$d天 · 目标%2$d分钟</string> <string name="stat_streak">连续专注%1$d天 · 目标%2$d分钟</string>
</resources> </resources>