筛选面板卡片底、栏名固定宽与胶囊对齐;去收件箱;状态全部提前
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user