项目列表点击就地展开任务与统计,任务页零改动(v3.0)

This commit is contained in:
XIGE
2026-12-01 11:24:03 +08:00
parent eb3d961b0a
commit 9c8e2eb534
9 changed files with 255 additions and 10 deletions

View File

@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper
import com.focusbox.app.model.DayPoint
import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectSlice
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.model.Repeat
import com.focusbox.app.model.SessionSpan
import com.focusbox.app.model.Task
@@ -267,6 +268,56 @@ object Store {
return list
}
/**
* 项目卡展开用:该项目下"添加过的任务 + 统计"。
*
* 与任务页的唯一差别在筛选口径:
* - 排除每次专注生成的完成记录副本(done=1 且 repeat_type=0 且 origin_id>0),
* 它们是历史流水而非用户添加的任务,否则同一个任务会重复出现 N 行;
* - 保留已完成的任务本体(用户要求"只要不删除就一直保留在这里"),
* 任务页默认把这类行隐藏,这里不隐藏。
*
* 完成次数直接取 tasks.done_pomodoros(每次完成的 session 都 +1),
* 最近完成时刻取 sessions 里该任务最近一次完成,与次数口径一致。
* 排序沿用任务页:未完成在前 → 置顶 → 逾期 → 重要+紧急 → 截止日。
*/
fun projectTaskRows(projectId: Long): List<ProjectTaskStat> {
val todayStart = Dates.todayStart()
val sql = """
SELECT $taskColumns,
COALESCE((
SELECT MAX(s.end_at) FROM sessions s
WHERE s.task_id = t._id AND s.completed = 1
), 0) AS last_done,
COALESCE((
SELECT SUM(s.seconds) FROM sessions s WHERE s.task_id = t._id
), 0) AS focus_sec
FROM tasks t
WHERE t.project_id = ?
AND NOT (t.done = 1 AND t.repeat_type = ${Repeat.NONE} AND t.origin_id > 0)
ORDER BY t.done ASC,
CASE WHEN t.done = 1 THEN t.done_at ELSE 0 END DESC,
CASE WHEN t.done = 0 AND t.repeat_type = ${Repeat.ANYTIME} THEN 0 ELSE 1 END ASC,
CASE WHEN t.done = 0 AND t.due > 0 AND t.due < $todayStart THEN 0 ELSE 1 END ASC,
CASE WHEN t.done = 0 THEN t.priority + t.urgency ELSE 0 END DESC,
CASE WHEN t.due = 0 THEN 1 ELSE 0 END ASC, t.due ASC, t._id DESC
""".trimIndent()
val list = ArrayList<ProjectTaskStat>()
db.rawQuery(sql, arrayOf(projectId.toString())).use { c ->
while (c.moveToNext()) {
list.add(
ProjectTaskStat(
task = cursorToTask(c),
lastDoneAt = c.getLong(17),
doneCount = c.getInt(6),
focusSeconds = c.getInt(18),
)
)
}
}
return list
}
fun task(id: Long): Task? {
db.rawQuery("SELECT $taskColumns FROM tasks WHERE _id = ?", arrayOf(id.toString())).use { c ->
return if (c.moveToFirst()) cursorToTask(c) else null