6 Commits
v2.7 ... v3.0

10 changed files with 266 additions and 53 deletions

View File

@@ -1,5 +1,28 @@
# 变更记录 # 变更记录
## 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) ## 2026-11-30 · 删除 CountdownFit,竖屏恢复 v2.3 行为(v2.7)
- 起因:用户报告竖屏专注时间变小(回归)。v2.6 的 CountdownFit 等宽缩号在锁屏页与悬浮窗两条链路都接入,竖屏被波及——该工具只要倒计时文字比时钟宽几像素(鸿蒙字体数字非严格等宽时必然发生)就缩小倒计时,前提错误。 - 起因:用户报告竖屏专注时间变小(回归)。v2.6 的 CountdownFit 等宽缩号在锁屏页与悬浮窗两条链路都接入,竖屏被波及——该工具只要倒计时文字比时钟宽几像素(鸿蒙字体数字非严格等宽时必然发生)就缩小倒计时,前提错误。

View File

@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper
import com.focusbox.app.model.DayPoint import com.focusbox.app.model.DayPoint
import com.focusbox.app.model.Project import com.focusbox.app.model.Project
import com.focusbox.app.model.ProjectSlice import com.focusbox.app.model.ProjectSlice
import com.focusbox.app.model.ProjectTaskStat
import com.focusbox.app.model.Repeat import com.focusbox.app.model.Repeat
import com.focusbox.app.model.SessionSpan import com.focusbox.app.model.SessionSpan
import com.focusbox.app.model.Task import com.focusbox.app.model.Task
@@ -267,6 +268,56 @@ object Store {
return list 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? { fun task(id: Long): Task? {
db.rawQuery("SELECT $taskColumns FROM tasks WHERE _id = ?", arrayOf(id.toString())).use { c -> db.rawQuery("SELECT $taskColumns FROM tasks WHERE _id = ?", arrayOf(id.toString())).use { c ->
return if (c.moveToFirst()) cursorToTask(c) else null 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) 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 落备注的实际专注信息 */ /** 提前完成时交给 UI 落备注的实际专注信息 */
data class FocusFinish( data class FocusFinish(
val taskId: Long, val taskId: Long,

View File

@@ -1,30 +1,44 @@
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.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.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,
) : 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()
fun submit(list: List<Project>) { fun submit(list: List<Project>, expanded: Long, taskStats: Map<Long, List<ProjectTaskStat>>) {
items = list items = list
expandedId = expanded
stats = taskStats
notifyDataSetChanged() notifyDataSetChanged()
} }
@@ -41,13 +55,16 @@ 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("${p.openTasks} 待办")
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成") if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成")
@@ -61,11 +78,58 @@ 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()
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.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.ProjectTaskStat
import com.focusbox.app.model.Task
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.util.col import com.focusbox.app.util.col
@@ -25,6 +27,10 @@ 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()
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 +39,13 @@ 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 ->
expandedProjectId = if (expandedProjectId == p.id) -1L else p.id
reload()
},
onLongClick = { p -> showActions(p) }, onLongClick = { p -> showActions(p) },
onMore = { p -> showActions(p) }, onMore = { p -> showActions(p) },
onStart = { t -> (activity as? MainActivity)?.startFocusOn(t) },
) )
recycler.layoutManager = LinearLayoutManager(requireContext()) recycler.layoutManager = LinearLayoutManager(requireContext())
recycler.adapter = adapter recycler.adapter = adapter
@@ -68,7 +78,12 @@ 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) }
adapter.submit(shown, expandedProjectId, taskStats)
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.openTasks }

View File

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

View File

@@ -56,49 +56,7 @@
android:textSize="15sp" /> android:textSize="15sp" />
</LinearLayout> </LinearLayout>
<!-- 中:细分隔线(92dp≈130sp 粗体数字的字面高度 0.71em×130,与时间视觉等高) <!-- 中列分割线已按用户要求移除(v2.9):左右两栏各占一半宽度,文字各自居中 -->
v2.3 中列完整镜像左右两栏:上方 1dp FrameLayout 内放与时间同规格的 130sp
不可见锚点文字(maxLines=1,防止 1dp 宽度触发折行撑高),分割线在其中
center;下方补一段与侧栏小字同规格(15sp、marginTop 10dp)的不可见占位,
使中列总高与左右两栏一致。三列同高且都被 center_vertical 居中 → 同顶,
锚点中心严格等于时间文字中心。(v2.2 只放了锚点没补占位,中列比侧栏矮
一截,居中后中心仍落在屏幕中心,与旧版位置相同,故无效) -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="1dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:maxLines="1"
android:visibility="invisible"
android:text="00:00"
android:textSize="130sp"
android:textStyle="bold" />
<View
android:id="@+id/lockDivider"
android:layout_width="1dp"
android:layout_height="92dp"
android:layout_gravity="center"
android:background="#26FFFFFF" />
</FrameLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:maxLines="1"
android:visibility="invisible"
android:text="0"
android:textSize="15sp" />
</LinearLayout>
<!-- 右:时钟(大)+ 日期星期在时钟下面 --> <!-- 右:时钟(大)+ 日期星期在时钟下面 -->
<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"
@@ -64,3 +72,24 @@
android:src="@drawable/ic_more" android:src="@drawable/ic_more"
android:contentDescription="@string/edit" /> android:contentDescription="@string/edit" />
</LinearLayout> </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="delete_project_confirm">删除项目「%1$s」?项目下的任务会移到收件箱。</string>
<string name="projects_title">项目</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="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>