项目列表点击就地展开任务与统计,任务页零改动(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

@@ -1,5 +1,18 @@
# 变更记录
## 2026-12-01 · 项目列表点击就地展开任务与统计,任务页零改动(v3.0)
- 同步源码更新 8 个文件(新增/修改 8,删除 0)。
## 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 打包字体在鸿蒙锁屏/悬浮窗上渲染异常(时间乱铺),按用户要求回退并移除分割线。

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

View File

@@ -62,6 +62,20 @@ data class Task(
/** 一条专注记录的起止时刻与实际秒数,用于在已完成任务上显示真实工作时段。 */
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,
/** 累计完成次数(sessions 里 completed=1 的条数) */
val doneCount: Int,
/** 累计专注秒数(sessions 里该任务的 seconds 之和) */
val focusSeconds: Int,
)
/** 提前完成时交给 UI 落备注的实际专注信息 */
data class FocusFinish(
val taskId: Long,

View File

@@ -1,30 +1,44 @@
package com.focusbox.app.ui.projects
import android.content.res.ColorStateList
import android.graphics.Paint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.focusbox.app.R
import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.model.Task
import com.focusbox.app.util.Dates
import com.focusbox.app.util.col
import com.focusbox.app.util.roundBg
import com.focusbox.app.util.tint
import com.focusbox.app.util.visible
/**
* 项目列表:点击项目头就地展开该项目下的任务,不再跳转任务页。
* 展开区只展示统计,交互只有右侧「开始」——编辑/勾选仍走原任务页,任务页逻辑不动。
*/
class ProjectAdapter(
private val onClick: (Project) -> Unit,
private val onToggleExpand: (Project) -> Unit,
private val onLongClick: (Project) -> Unit,
private val onMore: (Project) -> Unit,
private val onStart: (Task) -> Unit,
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
private var items: List<Project> = emptyList()
private var expandedId: Long = -1L
private var stats: Map<Long, List<ProjectTaskStat>> = emptyMap()
fun submit(list: List<Project>) {
fun submit(list: List<Project>, expanded: Long, taskStats: Map<Long, List<ProjectTaskStat>>) {
items = list
expandedId = expanded
stats = taskStats
notifyDataSetChanged()
}
@@ -41,13 +55,16 @@ class ProjectAdapter(
private val progress: ProgressBar = v.findViewById(R.id.progress)
private val colorBar: View = v.findViewById(R.id.colorBar)
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) {
val ctx = itemView.context
name.text = p.name
colorBar.background = ctx.roundBg(p.color, 2f)
// 只看任务与时长,不再显示番茄数
// 只看任务与时长,不再显示番茄数(与改动前一致)
val parts = ArrayList<String>(3)
parts.add("${p.openTasks} 待办")
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成")
@@ -61,11 +78,58 @@ class ProjectAdapter(
more.tint(ctx.col(R.color.text_tertiary))
more.setOnClickListener { onMore(p) }
itemView.setOnClickListener { onClick(p) }
itemView.setOnLongClickListener {
header.setOnClickListener { onToggleExpand(p) }
header.setOnLongClickListener {
onLongClick(p)
true
}
val expanded = expandedId == p.id
val rows = if (expanded) stats[p.id].orEmpty() else emptyList()
taskList.visible(expanded && rows.isNotEmpty())
tvTaskEmpty.visible(expanded && rows.isEmpty())
if (!expanded) return
taskList.removeAllViews()
rows.forEach { row ->
val item = LayoutInflater.from(ctx)
.inflate(R.layout.item_project_task, taskList, false)
bindTaskRow(item, row, p)
taskList.addView(item)
}
}
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(if (task.done) R.color.text_tertiary else R.color.text))
tvTitle.paintFlags = if (task.done) {
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
} else {
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
}
// 三项统计:单轮时长 · 最近完成时间 · 累计完成次数;不显示分类(项目名)
val parts = ArrayList<String>(3)
parts.add(ctx.getString(R.string.minutes_value, 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))
}
if (row.doneCount > 0) {
parts.add(ctx.getString(R.string.project_task_done_count, row.doneCount))
}
tvMeta.text = parts.joinToString(" · ")
btnPlay.visible(!task.done)
btnPlay.tint(ctx.col(R.color.brand))
btnPlay.setOnClickListener { onStart(task) }
}
}
}

View File

@@ -10,6 +10,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.focusbox.app.R
import com.focusbox.app.data.Store
import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.model.Task
import com.focusbox.app.ui.MainActivity
import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.util.col
@@ -25,6 +27,10 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
private var showArchived = false
/** 当前展开的项目 id;-1 表示全部收起。只展开一个,避免列表过长 */
private var expandedProjectId = -1L
private var taskStats: Map<Long, List<ProjectTaskStat>> = emptyMap()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
recycler = view.findViewById(R.id.recycler)
@@ -33,9 +39,13 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
btnArchived = view.findViewById(R.id.btnArchived)
adapter = ProjectAdapter(
onClick = { p -> (activity as? MainActivity)?.openProjectTasks(p.id) },
onToggleExpand = { p ->
expandedProjectId = if (expandedProjectId == p.id) -1L else p.id
reload()
},
onLongClick = { p -> showActions(p) },
onMore = { p -> showActions(p) },
onStart = { t -> (activity as? MainActivity)?.startFocusOn(t) },
)
recycler.layoutManager = LinearLayoutManager(requireContext())
recycler.adapter = adapter
@@ -68,7 +78,12 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
val archived = all.filter { it.archived }
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) }
adapter.submit(shown, expandedProjectId, taskStats)
tvSummary.text = getString(
R.string.project_summary, active.size, active.sumOf { it.openTasks }

View File

@@ -539,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
}
companion object {
const val VERSION = "2.9"
const val VERSION = "3.0"
}
}

View File

@@ -2,8 +2,7 @@
<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:orientation="vertical"
android:background="@drawable/bg_card"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
@@ -13,6 +12,15 @@
android:paddingTop="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
android:id="@+id/colorBar"
android:layout_width="4dp"
@@ -64,3 +72,24 @@
android:src="@drawable/ic_more"
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>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 项目卡展开后的任务行:结构与任务列表一致,但不显示分类(项目名),
meta 改为「单轮时长 · 最近完成时间 · 累计完成次数」,右侧保留开始按钮。 -->
<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

@@ -126,6 +126,9 @@
<string name="delete_project_confirm">删除项目「%1$s」?项目下的任务会移到收件箱。</string>
<string name="projects_title">项目</string>
<string name="project_no_tasks">还没有添加任务</string>
<string name="project_task_last_done">最近 %1$s 完成</string>
<string name="project_task_done_count">累计 %1$d 次</string>
<string name="project_summary">%1$d 个项目 · %2$d 个待办</string>
<string name="add_project">新建项目</string>
<string name="project_name_hint">项目名称</string>