筛选面板卡片底、栏名固定宽与胶囊对齐;去收件箱;状态全部提前

This commit is contained in:
XIGE
2026-11-28 18:34:45 +08:00
parent f291721e3a
commit dca24a154b
3 changed files with 49 additions and 41 deletions

View File

@@ -1,5 +1,9 @@
# 变更记录
## 2026-11-28 · 筛选面板卡片底、栏名固定宽与胶囊对齐;去收件箱;状态全部提前
- 同步源码更新 2 个文件(新增/修改 2,删除 0)。
## 2026-11-28 · v0.5.9:任务页五栏联动筛选
- **筛选重做**:原「视图+项目」两条横滑胶囊改为五栏联动筛选,从上到下 AND 叠加:

View File

@@ -3,7 +3,6 @@ package com.focusbox.app.ui.tasks
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.fragment.app.Fragment
@@ -32,10 +31,9 @@ import com.focusbox.app.util.visible
class TasksFragment : Fragment(R.layout.fragment_tasks) {
private companion object {
/** 收件箱:没有归属项目的任务(project_id = 0) */
const val PROJECT_INBOX = -1L
// 时间栏:0 全部 / 1 今日 / 2 明天 / 3 本周 / 4 本月 / 5 随时
// 今日/明天/本周/本月都要求设了截止日(区间起点均大于 0,无截止日的任务天然不命中),
// 没有设置时间的任务统一归到「随时」(due = 0)
const val TIME_ALL = 0
const val TIME_TODAY = 1
const val TIME_TOMORROW = 2
@@ -131,11 +129,8 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
// ------------------------------------------------------------ 联动筛选
private fun matches(t: Task): Boolean {
// 项目
when {
filterProjectId == PROJECT_INBOX -> if (t.projectId != 0L) return false
filterProjectId > 0 -> if (t.projectId != filterProjectId) return false
}
// 项目:0 = 全部,>0 = 指定项目
if (filterProjectId > 0 && t.projectId != filterProjectId) return false
if (!matchTime(t)) return false
if (priorityFilter >= 0 && t.priority != priorityFilter) return false
if (urgencyFilter >= 0 && t.urgency != urgencyFilter) return false
@@ -162,40 +157,53 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
// ------------------------------------------------------------ 筛选面板
/** 一行筛选:左侧灰色栏名 + 右侧流式胶囊(放不下自动换行) */
private fun filterRow(label: String): FlowLayout {
/**
* 一行筛选:左侧固定宽度栏名 + 右侧流式胶囊。
* 栏名与胶囊同一行垂直居中,所有行的栏名左对齐成一条竖线,视觉上成组。
*/
private fun filterRow(label: String): LinearLayout {
val ctx = requireContext()
val row = FlowLayout(ctx)
val label2 = TextView(ctx).apply {
text = label
textSize = 11f
val row = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.CENTER_VERTICAL
includeFontPadding = false
setTextColor(ctx.col(R.color.text_tertiary))
setPadding(0, 0, ctx.dpi(4f), 0)
}
row.addView(label2, ViewGroup.MarginLayoutParams(
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
).apply { rightMargin = ctx.dpi(2f) })
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,
))
return row
}
private fun chip(row: FlowLayout, text: String, selected: Boolean, dotColor: Int? = null, onClick: () -> Unit) {
/** 取行里的流式容器加胶囊 */
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) {
val chip = requireContext().makeChip(text, selected, dotColor)
chip.setOnClickListener { onClick() }
row.addView(chip)
chipsOf(row).addView(chip)
}
private fun renderFilters() {
filterPanel.removeAllViews()
val ctx = requireContext()
fun addRow(row: FlowLayout) {
fun addRow(row: LinearLayout) {
filterPanel.addView(row, LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
).apply { topMargin = ctx.dpi(5f) })
).apply { topMargin = ctx.dpi(6f) })
}
// 第一栏:项目
@@ -204,9 +212,6 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
chip(row, getString(R.string.filter_all), filterProjectId == 0L) {
filterProjectId = 0L; reload()
}
chip(row, getString(R.string.inbox), filterProjectId == PROJECT_INBOX) {
filterProjectId = PROJECT_INBOX; reload()
}
projects.forEach { p ->
if (p.archived) return@forEach
chip(row, p.name, filterProjectId == p.id, p.color) {
@@ -264,13 +269,13 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
addRow(row)
}
// 第五栏:状态
// 第五栏:状态(全部在前)
run {
val row = filterRow(getString(R.string.filter_status))
listOf(
-1 to R.string.filter_all,
0 to R.string.status_pending,
1 to R.string.filter_done,
-1 to R.string.filter_all,
).forEach { (value, res) ->
chip(row, getString(res), statusFilter == value) {
statusFilter = value; reload()

View File

@@ -45,21 +45,20 @@
android:contentDescription="@string/add_task" />
</LinearLayout>
<!-- 五栏联动筛选:项目 / 时间 / 重要度 / 紧急度 / 状态,行内放不下自动换行 -->
<!-- 五栏联动筛选:项目 / 时间 / 重要度 / 紧急度 / 状态;整体圆角卡片底 -->
<LinearLayout
android:id="@+id/filterPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="2dp"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingTop="4dp"
android:paddingBottom="10dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider" />
android:background="@drawable/bg_card"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingTop="10dp"
android:paddingBottom="8dp" />
<FrameLayout
android:layout_width="match_parent"