项目统计补累计专注分钟、展开行点开编辑删除、置顶前移并统一圆圈规格、已完成任务折叠(v3.1)
This commit is contained in:
@@ -22,23 +22,33 @@ import com.focusbox.app.util.visible
|
||||
|
||||
/**
|
||||
* 项目列表:点击项目头就地展开该项目下的任务,不再跳转任务页。
|
||||
* 展开区只展示统计,交互只有右侧「开始」——编辑/勾选仍走原任务页,任务页逻辑不动。
|
||||
* 展开行显示统计、右侧保留开始按钮;点击行复用任务页同款编辑/删除弹窗。
|
||||
* 已完成任务默认折叠,用「展开/收起完成记录」开关控制,避免历史越积越长。
|
||||
*/
|
||||
class ProjectAdapter(
|
||||
private val onToggleExpand: (Project) -> Unit,
|
||||
private val onLongClick: (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>() {
|
||||
|
||||
private var items: List<Project> = emptyList()
|
||||
private var expandedId: Long = -1L
|
||||
private var stats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||
private var showDone: Boolean = false
|
||||
|
||||
fun submit(list: List<Project>, expanded: Long, taskStats: Map<Long, List<ProjectTaskStat>>) {
|
||||
fun submit(
|
||||
list: List<Project>,
|
||||
expanded: Long,
|
||||
taskStats: Map<Long, List<ProjectTaskStat>>,
|
||||
showDoneRows: Boolean,
|
||||
) {
|
||||
items = list
|
||||
expandedId = expanded
|
||||
stats = taskStats
|
||||
showDone = showDoneRows
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
@@ -86,17 +96,36 @@ class ProjectAdapter(
|
||||
|
||||
val expanded = expandedId == p.id
|
||||
val rows = if (expanded) stats[p.id].orEmpty() else emptyList()
|
||||
val openRows = rows.filter { !it.task.done }
|
||||
val doneRows = rows.filter { it.task.done }
|
||||
taskList.visible(expanded && rows.isNotEmpty())
|
||||
tvTaskEmpty.visible(expanded && rows.isEmpty())
|
||||
if (!expanded) return
|
||||
|
||||
taskList.removeAllViews()
|
||||
rows.forEach { row ->
|
||||
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()
|
||||
openRows.forEach { addTaskRow(it) }
|
||||
|
||||
// 已完成任务默认折叠:开关行永远紧贴在已完成记录之前
|
||||
if (doneRows.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,
|
||||
doneRows.size,
|
||||
)
|
||||
tv.setTextColor(ctx.col(R.color.brand))
|
||||
toggle.setOnClickListener { onToggleDone() }
|
||||
taskList.addView(toggle)
|
||||
if (showDone) doneRows.forEach { addTaskRow(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindTaskRow(item: View, row: ProjectTaskStat, p: Project) {
|
||||
@@ -115,21 +144,30 @@ class ProjectAdapter(
|
||||
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))
|
||||
}
|
||||
val totals = StringBuilder()
|
||||
if (row.doneCount > 0) {
|
||||
parts.add(ctx.getString(R.string.project_task_done_count, row.doneCount))
|
||||
totals.append(ctx.getString(R.string.project_task_done_count, row.doneCount))
|
||||
}
|
||||
if (row.focusSeconds > 0) {
|
||||
// 累计专注只写「数字 分钟」,不加任何说明文案;紧跟在累计次数后一个空格
|
||||
if (totals.isNotEmpty()) totals.append(' ')
|
||||
totals.append(row.focusSeconds / 60).append(" 分钟")
|
||||
}
|
||||
if (totals.isNotEmpty()) parts.add(totals.toString())
|
||||
tvMeta.text = parts.joinToString(" · ")
|
||||
|
||||
btnPlay.visible(!task.done)
|
||||
btnPlay.tint(ctx.col(R.color.brand))
|
||||
btnPlay.setOnClickListener { onStart(task) }
|
||||
// 与任务页一致:点行打开编辑/删除弹窗
|
||||
item.setOnClickListener { onEdit(task) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.ui.tasks.TaskSheet
|
||||
import com.focusbox.app.util.col
|
||||
import com.focusbox.app.util.visible
|
||||
|
||||
@@ -30,6 +31,8 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
/** 当前展开的项目 id;-1 表示全部收起。只展开一个,避免列表过长 */
|
||||
private var expandedProjectId = -1L
|
||||
private var taskStats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||
/** 展开区内已完成记录默认折叠,避免历史记录越积越长 */
|
||||
private var showDoneInProject = false
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -46,6 +49,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
onLongClick = { p -> showActions(p) },
|
||||
onMore = { p -> showActions(p) },
|
||||
onStart = { t -> (activity as? MainActivity)?.startFocusOn(t) },
|
||||
onEdit = { t -> TaskSheet(requireContext(), t, 0L) { reload() }.show() },
|
||||
onToggleDone = {
|
||||
showDoneInProject = !showDoneInProject
|
||||
reload()
|
||||
},
|
||||
)
|
||||
recycler.layoutManager = LinearLayoutManager(requireContext())
|
||||
recycler.adapter = adapter
|
||||
@@ -83,7 +91,7 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
expandedProjectId = -1L
|
||||
}
|
||||
taskStats = shown.associate { it.id to Store.projectTaskRows(it.id) }
|
||||
adapter.submit(shown, expandedProjectId, taskStats)
|
||||
adapter.submit(shown, expandedProjectId, taskStats, showDoneInProject)
|
||||
|
||||
tvSummary.text = getString(
|
||||
R.string.project_summary, active.size, active.sumOf { it.openTasks }
|
||||
|
||||
@@ -539,6 +539,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "3.0"
|
||||
const val VERSION = "3.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,23 +85,32 @@ class TaskAdapter(
|
||||
val ctx = itemView.context
|
||||
|
||||
// 标题右侧的属性图标,未完成与已完成都显示:
|
||||
// 重要度圆圈数字(③ 高 / ② 中 / ① 普通,颜色与紧急度同色系)→
|
||||
// 紧急度五角星 → 随时上箭头。
|
||||
// 各字形在字体里的字面尺寸不同:以圆圈数字 0.85 为基准,
|
||||
// 上箭头与圆圈同高;五角星 0.95 不作参照
|
||||
// 置顶圆圈箭头(「随时」未完成任务)→ 重要度圆圈数字 → 紧急度五角星。
|
||||
// 置顶与重要度两个圆圈统一自绘:同一尺寸(0.85 倍字号)、同一描边(s/10),
|
||||
// 保证粗细与高度完全一致;五角星仍用字形,0.95 倍不作参照。
|
||||
val title = SpannableStringBuilder(task.title)
|
||||
val iconSize = tvTitle.textSize * 0.85f
|
||||
|
||||
val (badge, badgeColor) = when (task.priority) {
|
||||
2 -> " ③" to R.color.urgent_high
|
||||
1 -> " ②" to R.color.urgent_mid
|
||||
else -> " ①" to R.color.urgent_low
|
||||
// 置顶图标前移到重要度圆圈之前(品牌蓝圆圈内向上箭头)
|
||||
if (task.repeatType == com.focusbox.app.model.Repeat.ANYTIME && !task.done) {
|
||||
title.append("\u2009")
|
||||
title.setSpan(
|
||||
PinIconSpan(ctx.col(R.color.brand), iconSize),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
}
|
||||
title.append(badge)
|
||||
|
||||
// 重要度圆圈:3 高 / 2 中 / 1 普通,颜色与紧急度同色系
|
||||
val (digit, badgeColor) = when (task.priority) {
|
||||
2 -> "3" to R.color.urgent_high
|
||||
1 -> "2" to R.color.urgent_mid
|
||||
else -> "1" to R.color.urgent_low
|
||||
}
|
||||
title.append(" ")
|
||||
title.setSpan(
|
||||
android.text.style.ForegroundColorSpan(ctx.col(badgeColor)),
|
||||
title.length - badge.length, title.length, 0
|
||||
PriorityBadgeSpan(ctx.col(badgeColor), iconSize, digit),
|
||||
title.length - 1, title.length, 0,
|
||||
)
|
||||
title.setSpan(RelativeSizeSpan(0.85f), title.length - badge.length, title.length, 0)
|
||||
|
||||
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰
|
||||
val (stars, starColor) = when (task.urgency) {
|
||||
@@ -116,17 +125,6 @@ class TaskAdapter(
|
||||
)
|
||||
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 限定区间,且划线取文字墨迹
|
||||
// 的垂直中点——系统 StrikethroughSpan 用整字面半高定位,数字/汉字
|
||||
// 会让线显得偏下)。重要度/紧急度/置顶图标不跟着划线。
|
||||
@@ -236,6 +234,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 +323,8 @@ private class PinIconSpan(
|
||||
// 圆心取基线上方 0.45 个图标高,比之前 0.50 略下移,底部不再"悬空"显偏上
|
||||
val cx = x + s / 2f
|
||||
val cy = baseline - s * 0.45f
|
||||
// 圈线与重要度圆圈数字的描边粗细一致(约 1/10 图标高)
|
||||
val ring = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
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/10 描边,粗细与高度严格一致
|
||||
drawBadgeRing(canvas, cx, cy, s, iconColor)
|
||||
|
||||
// 箭头比圈线更细(约 1/15 图标高),整体落在圆内
|
||||
val arrow = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
|
||||
@@ -129,6 +129,8 @@
|
||||
<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_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="project_name_hint">项目名称</string>
|
||||
|
||||
Reference in New Issue
Block a user