2026-11-28 00:25:22 +08:00
|
|
|
|
package com.focusbox.app.ui.tasks
|
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
2026-11-28 18:17:27 +08:00
|
|
|
|
import android.view.Gravity
|
2026-11-28 00:25:22 +08:00
|
|
|
|
import android.view.View
|
2026-11-28 18:58:52 +08:00
|
|
|
|
import android.widget.ImageView
|
2026-11-28 00:25:22 +08:00
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
|
|
import android.widget.TextView
|
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
|
|
|
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.SessionSpan
|
|
|
|
|
|
import com.focusbox.app.model.Task
|
|
|
|
|
|
import com.focusbox.app.ui.MainActivity
|
|
|
|
|
|
import com.focusbox.app.util.Dates
|
2026-11-28 18:17:27 +08:00
|
|
|
|
import com.focusbox.app.util.FlowLayout
|
2026-11-28 21:21:36 +08:00
|
|
|
|
import com.focusbox.app.util.Prefs
|
2026-11-28 18:17:27 +08:00
|
|
|
|
import com.focusbox.app.util.col
|
|
|
|
|
|
import com.focusbox.app.util.dpi
|
2026-11-28 00:25:22 +08:00
|
|
|
|
import com.focusbox.app.util.makeChip
|
|
|
|
|
|
import com.focusbox.app.util.visible
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-11-28 18:17:27 +08:00
|
|
|
|
* 任务页:五栏联动筛选,从上到下依次叠加(AND)。
|
2026-11-28 00:25:22 +08:00
|
|
|
|
*
|
2026-11-28 18:17:27 +08:00
|
|
|
|
* 项目 / 时间 / 重要度 / 紧急度 / 状态,每栏单选,行内放不下自动换行。
|
2026-11-28 18:58:52 +08:00
|
|
|
|
* 筛选面板默认收起,只显示一行当前条件摘要;点摘要展开,选中任意胶囊后自动收起。
|
2026-12-01 14:51:04 +08:00
|
|
|
|
* 默认「项目=全部 · 时间=全部 · 重要度=全部 · 紧急度=全部 · 状态=全部」,
|
|
|
|
|
|
* 逾期任务与完成记录都在同一列表里;只想看待办可切到「未完成」。
|
2026-11-28 00:25:22 +08:00
|
|
|
|
*/
|
|
|
|
|
|
class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
|
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
private companion object {
|
|
|
|
|
|
// 时间栏:0 全部 / 1 今日 / 2 明天 / 3 本周 / 4 本月 / 5 随时
|
2026-11-28 18:34:45 +08:00
|
|
|
|
// 今日/明天/本周/本月都要求设了截止日(区间起点均大于 0,无截止日的任务天然不命中),
|
|
|
|
|
|
// 没有设置时间的任务统一归到「随时」(due = 0)
|
2026-11-28 18:17:27 +08:00
|
|
|
|
const val TIME_ALL = 0
|
|
|
|
|
|
const val TIME_TODAY = 1
|
|
|
|
|
|
const val TIME_TOMORROW = 2
|
|
|
|
|
|
const val TIME_WEEK = 3
|
|
|
|
|
|
const val TIME_MONTH = 4
|
|
|
|
|
|
const val TIME_ANYTIME = 5
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
|
private lateinit var recycler: RecyclerView
|
|
|
|
|
|
private lateinit var tvCount: TextView
|
|
|
|
|
|
private lateinit var tvEmpty: TextView
|
2026-11-28 18:17:27 +08:00
|
|
|
|
private lateinit var filterPanel: LinearLayout
|
2026-11-28 18:58:52 +08:00
|
|
|
|
private lateinit var tvFilterSummary: TextView
|
|
|
|
|
|
private lateinit var btnFilterToggle: ImageView
|
2026-11-28 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
|
private lateinit var adapter: TaskAdapter
|
|
|
|
|
|
|
2026-11-28 21:21:36 +08:00
|
|
|
|
// 筛选条件落在 Prefs:主题切换重建 / 冷启动后保留上次的选择
|
|
|
|
|
|
private var filterProjectId = Prefs.uiFilterProject
|
|
|
|
|
|
private var timeFilter = Prefs.uiFilterTime
|
|
|
|
|
|
private var priorityFilter = Prefs.uiFilterPriority
|
|
|
|
|
|
private var urgencyFilter = Prefs.uiFilterUrgency
|
|
|
|
|
|
private var statusFilter = Prefs.uiFilterStatus
|
2026-11-28 18:17:27 +08:00
|
|
|
|
|
2026-11-28 21:21:36 +08:00
|
|
|
|
/** 筛选面板展开态:默认收起,只留一行摘要;同样持久化 */
|
|
|
|
|
|
private var filterExpanded = Prefs.uiFilterExpanded
|
2026-11-28 18:58:52 +08:00
|
|
|
|
|
2026-11-28 00:25:22 +08:00
|
|
|
|
private var projects: List<Project> = emptyList()
|
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
|
recycler = view.findViewById(R.id.recycler)
|
|
|
|
|
|
tvCount = view.findViewById(R.id.tvCount)
|
|
|
|
|
|
tvEmpty = view.findViewById(R.id.tvEmpty)
|
2026-11-28 18:17:27 +08:00
|
|
|
|
filterPanel = view.findViewById(R.id.filterPanel)
|
2026-11-28 18:58:52 +08:00
|
|
|
|
tvFilterSummary = view.findViewById(R.id.tvFilterSummary)
|
|
|
|
|
|
btnFilterToggle = view.findViewById(R.id.btnFilterToggle)
|
|
|
|
|
|
|
|
|
|
|
|
// 摘要行即开关:点击展开 / 收起五栏筛选
|
2026-11-28 21:21:36 +08:00
|
|
|
|
filterPanel.visible(filterExpanded)
|
|
|
|
|
|
btnFilterToggle.rotation = if (filterExpanded) 270f else 90f // 展开朝上 / 收起朝下
|
2026-11-28 18:58:52 +08:00
|
|
|
|
view.findViewById<View>(R.id.filterHeader).setOnClickListener { toggleFilterPanel() }
|
2026-11-28 00:25:22 +08:00
|
|
|
|
|
|
|
|
|
|
adapter = TaskAdapter(
|
|
|
|
|
|
onEdit = { openSheet(it) },
|
|
|
|
|
|
onToggle = { task ->
|
2026-12-01 20:40:39 +08:00
|
|
|
|
// 手动勾选完成:备注写「手动完成」,这一次不算专注,不进累计与饼图
|
|
|
|
|
|
Store.setTaskDone(task.id, !task.done, markManual = true)
|
2026-11-28 00:25:22 +08:00
|
|
|
|
reload()
|
|
|
|
|
|
},
|
|
|
|
|
|
onStart = { task -> (activity as? MainActivity)?.startFocusOn(task) },
|
2026-11-28 18:17:27 +08:00
|
|
|
|
onFooterClick = {},
|
2026-11-28 00:25:22 +08:00
|
|
|
|
)
|
|
|
|
|
|
recycler.layoutManager = LinearLayoutManager(requireContext())
|
|
|
|
|
|
recycler.adapter = adapter
|
|
|
|
|
|
recycler.itemAnimator = null
|
|
|
|
|
|
|
|
|
|
|
|
view.findViewById<View>(R.id.btnAdd).setOnClickListener {
|
2026-11-28 18:17:27 +08:00
|
|
|
|
TaskSheet(requireContext(), null, filterProjectId.takeIf { it > 0 } ?: 0L) {
|
|
|
|
|
|
reload()
|
|
|
|
|
|
}.show()
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onResume() {
|
|
|
|
|
|
super.onResume()
|
|
|
|
|
|
if (view != null) reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onHiddenChanged(hidden: Boolean) {
|
|
|
|
|
|
super.onHiddenChanged(hidden)
|
|
|
|
|
|
if (!hidden && view != null) reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
/** 从项目页点进来:只看这个项目的任务 */
|
2026-11-28 00:25:22 +08:00
|
|
|
|
fun applyProjectFilter(projectId: Long) {
|
|
|
|
|
|
filterProjectId = projectId
|
|
|
|
|
|
if (view != null) reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun reload() {
|
|
|
|
|
|
if (view == null) return
|
|
|
|
|
|
projects = Store.projects()
|
2026-11-28 18:17:27 +08:00
|
|
|
|
renderFilters()
|
2026-11-28 18:58:52 +08:00
|
|
|
|
renderFilterSummary()
|
2026-11-28 18:17:27 +08:00
|
|
|
|
|
|
|
|
|
|
val all = Store.tasks(includeDone = true)
|
|
|
|
|
|
val spans = if (all.any { it.done }) Store.lastSessions() else emptyMap()
|
2026-11-29 09:25:24 +08:00
|
|
|
|
// 提前完成的任务:源任务行(无备注)隐藏,只显示带备注的独立完成记录
|
|
|
|
|
|
val finishedIds = Store.completedSourceIds()
|
2026-11-28 18:17:27 +08:00
|
|
|
|
|
2026-11-29 09:25:24 +08:00
|
|
|
|
val matched = all.filter { matches(it) && !(it.done && it.id in finishedIds) }
|
2026-11-28 18:17:27 +08:00
|
|
|
|
val rows = ArrayList<TaskAdapter.Row>(matched.size)
|
|
|
|
|
|
matched.forEach { rows.add(toRow(it, spans)) }
|
|
|
|
|
|
|
|
|
|
|
|
val pendingCount = matched.count { !it.done }
|
|
|
|
|
|
val doneCount = matched.count { it.done }
|
|
|
|
|
|
tvCount.text = when (statusFilter) {
|
|
|
|
|
|
1 -> getString(R.string.task_count_done, doneCount)
|
|
|
|
|
|
-1 -> getString(R.string.task_count_all, matched.size)
|
|
|
|
|
|
else -> getString(R.string.task_count, pendingCount)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 21:21:36 +08:00
|
|
|
|
adapter.submitList(rows)
|
2026-11-28 18:17:27 +08:00
|
|
|
|
tvEmpty.visible(rows.isEmpty())
|
|
|
|
|
|
recycler.visible(rows.isNotEmpty())
|
2026-11-28 21:21:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 当前筛选条件落盘,重建后恢复
|
|
|
|
|
|
Prefs.uiFilterProject = filterProjectId
|
|
|
|
|
|
Prefs.uiFilterTime = timeFilter
|
|
|
|
|
|
Prefs.uiFilterPriority = priorityFilter
|
|
|
|
|
|
Prefs.uiFilterUrgency = urgencyFilter
|
|
|
|
|
|
Prefs.uiFilterStatus = statusFilter
|
2026-11-28 18:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------ 联动筛选
|
|
|
|
|
|
|
|
|
|
|
|
private fun matches(t: Task): Boolean {
|
2026-11-28 18:34:45 +08:00
|
|
|
|
// 项目:0 = 全部,>0 = 指定项目
|
|
|
|
|
|
if (filterProjectId > 0 && t.projectId != filterProjectId) return false
|
2026-11-28 18:17:27 +08:00
|
|
|
|
if (!matchTime(t)) return false
|
|
|
|
|
|
if (priorityFilter >= 0 && t.priority != priorityFilter) return false
|
|
|
|
|
|
if (urgencyFilter >= 0 && t.urgency != urgencyFilter) return false
|
|
|
|
|
|
when (statusFilter) {
|
|
|
|
|
|
0 -> if (t.done) return false
|
|
|
|
|
|
1 -> if (!t.done) return false
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 截止日落在所选区间内;随时 = 没有设置截止日 */
|
|
|
|
|
|
private fun matchTime(t: Task): Boolean {
|
|
|
|
|
|
val today = Dates.todayStart()
|
|
|
|
|
|
val due = t.due
|
|
|
|
|
|
return when (timeFilter) {
|
|
|
|
|
|
TIME_TODAY -> due >= today && due < Dates.addDays(today, 1)
|
|
|
|
|
|
TIME_TOMORROW -> due >= Dates.addDays(today, 1) && due < Dates.addDays(today, 2)
|
|
|
|
|
|
TIME_WEEK -> due >= Dates.weekStart() && due < Dates.addDays(Dates.weekStart(), 7)
|
|
|
|
|
|
TIME_MONTH -> due >= Dates.monthStart() && due < Dates.addMonths(Dates.monthStart(), 1)
|
|
|
|
|
|
TIME_ANYTIME -> due <= 0L
|
|
|
|
|
|
else -> true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------ 筛选面板
|
|
|
|
|
|
|
2026-11-28 18:34:45 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 一行筛选:左侧固定宽度栏名 + 右侧流式胶囊。
|
|
|
|
|
|
* 栏名与胶囊同一行垂直居中,所有行的栏名左对齐成一条竖线,视觉上成组。
|
|
|
|
|
|
*/
|
|
|
|
|
|
private fun filterRow(label: String): LinearLayout {
|
2026-11-28 18:17:27 +08:00
|
|
|
|
val ctx = requireContext()
|
2026-11-28 18:34:45 +08:00
|
|
|
|
val row = LinearLayout(ctx).apply {
|
|
|
|
|
|
orientation = LinearLayout.HORIZONTAL
|
2026-11-28 18:17:27 +08:00
|
|
|
|
gravity = Gravity.CENTER_VERTICAL
|
|
|
|
|
|
}
|
2026-11-28 18:34:45 +08:00
|
|
|
|
row.addView(TextView(ctx).apply {
|
|
|
|
|
|
text = label
|
|
|
|
|
|
textSize = 12f
|
|
|
|
|
|
includeFontPadding = false
|
|
|
|
|
|
setTextColor(ctx.col(R.color.text_secondary))
|
|
|
|
|
|
minWidth = ctx.dpi(52f)
|
|
|
|
|
|
}, LinearLayout.LayoutParams(
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
|
|
|
))
|
|
|
|
|
|
val flow = FlowLayout(ctx)
|
|
|
|
|
|
row.addView(flow, LinearLayout.LayoutParams(
|
|
|
|
|
|
0,
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
|
|
|
1f,
|
|
|
|
|
|
))
|
2026-11-28 18:17:27 +08:00
|
|
|
|
return row
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:34:45 +08:00
|
|
|
|
/** 取行里的流式容器加胶囊 */
|
|
|
|
|
|
private fun chipsOf(row: LinearLayout): FlowLayout = row.getChildAt(1) as FlowLayout
|
|
|
|
|
|
|
|
|
|
|
|
private fun chip(row: LinearLayout, text: String, selected: Boolean, dotColor: Int? = null, onClick: () -> Unit) {
|
2026-11-28 18:17:27 +08:00
|
|
|
|
val chip = requireContext().makeChip(text, selected, dotColor)
|
2026-11-28 18:58:52 +08:00
|
|
|
|
// 选中任意胶囊后自动收起面板:改条件 → 刷新列表 → 收起
|
|
|
|
|
|
chip.setOnClickListener {
|
|
|
|
|
|
onClick()
|
|
|
|
|
|
collapseFilterPanel()
|
|
|
|
|
|
}
|
2026-11-28 18:34:45 +08:00
|
|
|
|
chipsOf(row).addView(chip)
|
2026-11-28 18:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:58:52 +08:00
|
|
|
|
// ------------------------------------------------------------ 展开 / 收起
|
|
|
|
|
|
|
|
|
|
|
|
private fun toggleFilterPanel() {
|
|
|
|
|
|
if (filterExpanded) collapseFilterPanel() else expandFilterPanel()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun expandFilterPanel() {
|
|
|
|
|
|
filterExpanded = true
|
2026-11-28 21:21:36 +08:00
|
|
|
|
Prefs.uiFilterExpanded = true
|
2026-11-28 18:58:52 +08:00
|
|
|
|
filterPanel.visible(true)
|
|
|
|
|
|
btnFilterToggle.animate().rotation(270f).setDuration(150L).start() // 展开时朝上
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun collapseFilterPanel() {
|
|
|
|
|
|
if (!filterExpanded) return
|
|
|
|
|
|
filterExpanded = false
|
2026-11-28 21:21:36 +08:00
|
|
|
|
Prefs.uiFilterExpanded = false
|
2026-11-28 18:58:52 +08:00
|
|
|
|
filterPanel.visible(false)
|
|
|
|
|
|
btnFilterToggle.animate().rotation(90f).setDuration(150L).start() // 收起时朝下
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 收起态摘要:当前五个条件用「·」串起来,如「全部 · 今日 · 全部 · 全部 · 未完成」 */
|
|
|
|
|
|
private fun renderFilterSummary() {
|
|
|
|
|
|
val ctx = requireContext()
|
|
|
|
|
|
val project = when {
|
|
|
|
|
|
filterProjectId == 0L -> getString(R.string.filter_all)
|
|
|
|
|
|
else -> projects.firstOrNull { it.id == filterProjectId }?.name ?: getString(R.string.filter_all)
|
|
|
|
|
|
}
|
|
|
|
|
|
val time = when (timeFilter) {
|
|
|
|
|
|
TIME_TODAY -> getString(R.string.filter_today)
|
|
|
|
|
|
TIME_TOMORROW -> getString(R.string.time_tomorrow)
|
|
|
|
|
|
TIME_WEEK -> getString(R.string.time_this_week)
|
|
|
|
|
|
TIME_MONTH -> getString(R.string.time_this_month)
|
|
|
|
|
|
TIME_ANYTIME -> getString(R.string.time_anytime)
|
|
|
|
|
|
else -> getString(R.string.filter_all)
|
|
|
|
|
|
}
|
|
|
|
|
|
val priority = when (priorityFilter) {
|
|
|
|
|
|
2 -> getString(R.string.p_high)
|
|
|
|
|
|
1 -> getString(R.string.p_mid)
|
|
|
|
|
|
0 -> getString(R.string.p_low)
|
|
|
|
|
|
else -> getString(R.string.filter_all)
|
|
|
|
|
|
}
|
|
|
|
|
|
val urgency = when (urgencyFilter) {
|
|
|
|
|
|
2 -> getString(R.string.urgency_high)
|
|
|
|
|
|
1 -> getString(R.string.urgency_mid)
|
|
|
|
|
|
0 -> getString(R.string.urgency_low)
|
|
|
|
|
|
else -> getString(R.string.filter_all)
|
|
|
|
|
|
}
|
|
|
|
|
|
val status = when (statusFilter) {
|
|
|
|
|
|
-1 -> getString(R.string.filter_all)
|
|
|
|
|
|
1 -> getString(R.string.filter_done)
|
|
|
|
|
|
else -> getString(R.string.status_pending)
|
|
|
|
|
|
}
|
|
|
|
|
|
tvFilterSummary.text = listOf(project, time, priority, urgency, status).joinToString(" · ")
|
|
|
|
|
|
|
|
|
|
|
|
// 有任一条件偏离默认值时摘要高亮,提示当前列表被筛过
|
|
|
|
|
|
val filtered = filterProjectId > 0L || timeFilter != TIME_ALL ||
|
2026-12-01 14:51:04 +08:00
|
|
|
|
priorityFilter >= 0 || urgencyFilter >= 0 || statusFilter != -1
|
2026-11-28 18:58:52 +08:00
|
|
|
|
tvFilterSummary.setTextColor(
|
|
|
|
|
|
ctx.col(if (filtered) R.color.brand else R.color.text_secondary)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
private fun renderFilters() {
|
|
|
|
|
|
filterPanel.removeAllViews()
|
|
|
|
|
|
val ctx = requireContext()
|
|
|
|
|
|
|
2026-11-28 18:34:45 +08:00
|
|
|
|
fun addRow(row: LinearLayout) {
|
2026-11-28 18:17:27 +08:00
|
|
|
|
filterPanel.addView(row, LinearLayout.LayoutParams(
|
|
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
2026-11-28 18:34:45 +08:00
|
|
|
|
).apply { topMargin = ctx.dpi(6f) })
|
2026-11-28 18:17:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 第一栏:项目
|
|
|
|
|
|
run {
|
|
|
|
|
|
val row = filterRow(getString(R.string.filter_project))
|
|
|
|
|
|
chip(row, getString(R.string.filter_all), filterProjectId == 0L) {
|
|
|
|
|
|
filterProjectId = 0L; reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
projects.forEach { p ->
|
|
|
|
|
|
if (p.archived) return@forEach
|
|
|
|
|
|
chip(row, p.name, filterProjectId == p.id, p.color) {
|
|
|
|
|
|
filterProjectId = p.id; reload()
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-11-28 18:17:27 +08:00
|
|
|
|
addRow(row)
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
// 第二栏:时间
|
|
|
|
|
|
run {
|
|
|
|
|
|
val row = filterRow(getString(R.string.filter_time))
|
|
|
|
|
|
listOf(
|
|
|
|
|
|
TIME_ALL to R.string.filter_all,
|
|
|
|
|
|
TIME_TODAY to R.string.filter_today,
|
|
|
|
|
|
TIME_TOMORROW to R.string.time_tomorrow,
|
|
|
|
|
|
TIME_WEEK to R.string.time_this_week,
|
|
|
|
|
|
TIME_MONTH to R.string.time_this_month,
|
|
|
|
|
|
TIME_ANYTIME to R.string.time_anytime,
|
|
|
|
|
|
).forEach { (value, res) ->
|
|
|
|
|
|
chip(row, getString(res), timeFilter == value) {
|
|
|
|
|
|
timeFilter = value; reload()
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
2026-11-28 18:17:27 +08:00
|
|
|
|
addRow(row)
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
// 第三栏:重要度(高/中/低,对应 priority 2/1/0)
|
|
|
|
|
|
run {
|
|
|
|
|
|
val row = filterRow(getString(R.string.filter_importance))
|
|
|
|
|
|
chip(row, getString(R.string.filter_all), priorityFilter == -1) {
|
|
|
|
|
|
priorityFilter = -1; reload()
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
2026-11-28 18:17:27 +08:00
|
|
|
|
listOf(2 to R.string.p_high, 1 to R.string.p_mid, 0 to R.string.p_low)
|
|
|
|
|
|
.forEach { (value, res) ->
|
|
|
|
|
|
chip(row, getString(res), priorityFilter == value) {
|
|
|
|
|
|
priorityFilter = value; reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
addRow(row)
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
// 第四栏:紧急度(紧急/中/不急,对应 urgency 2/1/0)
|
|
|
|
|
|
run {
|
|
|
|
|
|
val row = filterRow(getString(R.string.filter_urgency))
|
|
|
|
|
|
chip(row, getString(R.string.filter_all), urgencyFilter == -1) {
|
|
|
|
|
|
urgencyFilter = -1; reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
listOf(2 to R.string.urgency_high, 1 to R.string.urgency_mid, 0 to R.string.urgency_low)
|
|
|
|
|
|
.forEach { (value, res) ->
|
|
|
|
|
|
chip(row, getString(res), urgencyFilter == value) {
|
|
|
|
|
|
urgencyFilter = value; reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
addRow(row)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:34:45 +08:00
|
|
|
|
// 第五栏:状态(全部在前)
|
2026-11-28 18:17:27 +08:00
|
|
|
|
run {
|
|
|
|
|
|
val row = filterRow(getString(R.string.filter_status))
|
|
|
|
|
|
listOf(
|
2026-11-28 18:34:45 +08:00
|
|
|
|
-1 to R.string.filter_all,
|
2026-11-28 18:17:27 +08:00
|
|
|
|
0 to R.string.status_pending,
|
|
|
|
|
|
1 to R.string.filter_done,
|
|
|
|
|
|
).forEach { (value, res) ->
|
|
|
|
|
|
chip(row, getString(res), statusFilter == value) {
|
|
|
|
|
|
statusFilter = value; reload()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
addRow(row)
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-28 18:17:27 +08:00
|
|
|
|
// ------------------------------------------------------------ 列表渲染
|
|
|
|
|
|
|
2026-11-28 00:25:22 +08:00
|
|
|
|
private fun toRow(task: Task, spans: Map<Long, SessionSpan>): TaskAdapter.Row.Item {
|
|
|
|
|
|
val project = projects.firstOrNull { it.id == task.projectId }
|
2026-12-01 16:28:21 +08:00
|
|
|
|
// 重复任务按周期滚动,本轮没做不算逾期(下一轮生成时会自动结束旧实例);
|
|
|
|
|
|
// 只有不重复的任务才标「已逾期」
|
|
|
|
|
|
val overdue = task.due > 0 && task.due < Dates.todayStart() &&
|
|
|
|
|
|
task.repeatType == com.focusbox.app.model.Repeat.NONE
|
2026-11-28 00:25:22 +08:00
|
|
|
|
return TaskAdapter.Row.Item(
|
|
|
|
|
|
task = task,
|
|
|
|
|
|
projectName = project?.name ?: getString(R.string.inbox),
|
|
|
|
|
|
projectColor = project?.color ?: 0xFF7A756C.toInt(),
|
|
|
|
|
|
overdue = overdue,
|
|
|
|
|
|
doneRange = if (task.done) doneRange(task, spans) else null,
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 11月27日 周五 09:12:03-09:37:03 */
|
|
|
|
|
|
private fun doneRange(task: Task, spans: Map<Long, SessionSpan>): String? {
|
2026-11-28 14:00:53 +08:00
|
|
|
|
// 每次专注单独成一条完成记录:起止与秒数存在这条记录上,不再靠 session 回查
|
|
|
|
|
|
if (task.logSeconds > 0 && task.originId > 0 && task.doneAt > task.createdAt) {
|
|
|
|
|
|
val range = "${Dates.dateWithWeek(task.createdAt)} " +
|
|
|
|
|
|
"${Dates.hms(task.createdAt)}-${Dates.hms(task.doneAt)}"
|
|
|
|
|
|
return "$range · 专注${Dates.duration(task.logSeconds)}"
|
|
|
|
|
|
}
|
2026-11-28 00:25:22 +08:00
|
|
|
|
val span = spans[task.id]
|
|
|
|
|
|
if (span != null) {
|
2026-11-28 10:39:57 +08:00
|
|
|
|
val range = "${Dates.dateWithWeek(span.startAt)} " +
|
2026-11-28 00:25:22 +08:00
|
|
|
|
"${Dates.hms(span.startAt)}-${Dates.hms(span.endAt)}"
|
2026-11-28 10:39:57 +08:00
|
|
|
|
// 记录里存的是实际专注秒数(不含暂停),不能拿起止时间差冒充
|
|
|
|
|
|
return if (span.seconds > 0) "$range · 专注${Dates.duration(span.seconds)}" else range
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (task.doneAt > 0) {
|
|
|
|
|
|
return "${Dates.dateWithWeek(task.doneAt)} ${Dates.hms(task.doneAt)}"
|
|
|
|
|
|
}
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun openSheet(task: Task?) {
|
2026-12-01 13:42:12 +08:00
|
|
|
|
// 新建任务时默认归到当前筛选的项目;全部/未分类则不预选
|
2026-11-28 18:17:27 +08:00
|
|
|
|
TaskSheet(requireContext(), task, filterProjectId.takeIf { it > 0 } ?: 0L) { reload() }.show()
|
2026-11-28 00:25:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|