首页任务选择改为两步式圆角弹层;新增按钮深色高对比;统计目标文案与热力图自适应

This commit is contained in:
XIGE
2026-11-28 07:29:37 +08:00
parent d57de2d3f5
commit ec21b3cc0a
14 changed files with 330 additions and 40 deletions

View File

@@ -1,5 +1,9 @@
# 变更记录
## 2026-11-28 · 首页任务选择改为两步式圆角弹层;新增按钮深色高对比;统计目标文案与热力图自适应
- 同步源码更新 13 个文件(新增/修改 13,删除 0)。
## 2026-11-28 · v0.4.0:统计页按参考图重做分布卡片(日/周/月/年 + 引线标注环图)
- **删除统计页右上角的区间筛选栏**(今日/本周/本月/全部)。趋势图随之固定为「最近 7 天」,不再受全局区间牵制。

View File

@@ -14,7 +14,6 @@ import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.focusbox.app.R
@@ -22,6 +21,7 @@ import com.focusbox.app.data.Store
import com.focusbox.app.model.Project
import com.focusbox.app.model.Task
import com.focusbox.app.service.TimerCore
import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.util.Dates
import com.focusbox.app.util.Prefs
import com.focusbox.app.util.circleBg
@@ -405,35 +405,117 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
// ------------------------------------------------------------------ 任务
/**
* 选择任务:第一步选项目,第二步只列出该项目的待办。
* 用自绘底部弹层而不是系统 AlertDialog,便于圆角、分步标题与选中态。
*/
private fun pickTask() {
val tasks = Store.tasks(includeDone = false)
if (tasks.isEmpty()) {
AlertDialog.Builder(requireContext())
.setMessage(R.string.no_task_to_pick)
.setPositiveButton(R.string.save, null)
.show()
return
val ctx = requireContext()
val sheet = SheetDialog(ctx)
val root = layoutInflater.inflate(R.layout.sheet_pick_task, null)
val tvTitle = root.findViewById<TextView>(R.id.pickTitle)
val tvStep = root.findViewById<TextView>(R.id.pickStep)
val tvHint = root.findViewById<TextView>(R.id.pickHint)
val btnBack = root.findViewById<ImageView>(R.id.pickBack)
val btnClose = root.findViewById<ImageView>(R.id.pickClose)
val btnClear = root.findViewById<TextView>(R.id.pickClear)
val list = root.findViewById<LinearLayout>(R.id.pickList)
val scroll = root.findViewById<android.widget.ScrollView>(R.id.pickScroll)
fun addRow(
title: String,
meta: String,
color: Int?,
selected: Boolean,
onClick: () -> Unit,
) {
val row = layoutInflater.inflate(R.layout.item_pick_row, list, false)
row.findViewById<View>(R.id.rowDot).apply {
visible(color != null)
if (color != null) background = ctx.circleBg(color)
}
row.findViewById<TextView>(R.id.rowTitle).text = title
row.findViewById<TextView>(R.id.rowMeta).text = meta
row.findViewById<ImageView>(R.id.rowMark).visible(selected)
row.setOnClickListener { onClick() }
val lp = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
)
lp.bottomMargin = dpi(8f)
row.layoutParams = lp
list.addView(row)
}
val names = tasks.map { t ->
val p = Store.project(t.projectId)
(p?.name?.let { "$it · " } ?: "") + t.title
} + getString(R.string.no_task)
val current = tasks.indexOfFirst { it.id == TimerCore.taskId }
AlertDialog.Builder(requireContext())
.setTitle(R.string.pick_task)
.setSingleChoiceItems(names.toTypedArray(), current) { d, which ->
if (which == tasks.size) {
TimerCore.setTask(0, 0)
} else {
val t = tasks[which]
// 局部函数必须先声明后引用:showTasks 在前,showProjects 的点击回调才能调用它
fun showTasks(projectId: Long) {
val project = Store.project(projectId)
tvTitle.text = project?.name ?: getString(R.string.inbox)
tvStep.text = getString(R.string.pick_step, 2)
tvHint.text = getString(R.string.pick_task_hint)
btnBack.visibility = View.VISIBLE
btnClear.visibility = View.VISIBLE
list.removeAllViews()
val tasks = Store.tasks(projectId, includeDone = false)
if (tasks.isEmpty()) {
list.addView(TextView(ctx).apply {
text = getString(R.string.pick_task_empty)
gravity = android.view.Gravity.CENTER
setPadding(dpi(12f), dpi(28f), dpi(12f), dpi(28f))
textSize = 13f
setTextColor(col(R.color.text_tertiary))
})
}
tasks.forEach { t ->
val meta = buildString {
append(getString(R.string.minutes_value, t.focusMinutes))
if (t.due > 0) append(" · ${Dates.dueLabel(t.due)}截止")
}
addRow(
title = t.title,
meta = meta,
color = project?.color,
selected = t.id == TimerCore.taskId,
) {
// 选中任务后回到倒计时,并把圆环切到该任务设定的时长
TimerCore.setCountUp(false)
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
sheet.dismiss()
render()
}
d.dismiss()
render()
}
.show()
scroll.scrollTo(0, 0)
}
fun showProjects() {
tvTitle.text = getString(R.string.pick_project)
tvStep.text = getString(R.string.pick_step, 1)
tvHint.text = getString(R.string.pick_project_hint)
btnBack.visibility = View.INVISIBLE
btnClear.visibility = View.GONE
list.removeAllViews()
val currentPid = if (TimerCore.taskId > 0) TimerCore.projectId else -1L
Store.projects().forEach { p ->
addRow(
title = p.name,
meta = getString(R.string.pick_project_meta, p.openTasks),
color = p.color,
selected = p.id == currentPid,
) { showTasks(p.id) }
}
scroll.scrollTo(0, 0)
}
btnBack.setOnClickListener { showProjects() }
btnClose.setOnClickListener { sheet.dismiss() }
btnClear.setOnClickListener {
TimerCore.setTask(0, 0)
sheet.dismiss()
render()
}
sheet.setContentView(root)
showProjects()
sheet.show()
}
private fun applyKeepScreen(on: Boolean) {

View File

@@ -102,7 +102,7 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
todayRing.progress = stat.goalProgress
todayRing.ringColor = col(if (stat.goalProgress >= 1f) R.color.rest else R.color.brand)
tvGoalPct.text = "${(stat.goalProgress * 100).toInt()}%"
tvGoalHint.text = "目标 ${goal}m"
tvGoalHint.text = getString(R.string.goal_short, goal)
tvTodayMinutes.text = "${stat.minutes} 分钟"
tvTodayPomo.text = "${stat.pomodoros}"
tvTodayDone.text = "${stat.doneTasks}"

View File

@@ -109,7 +109,7 @@ class HeatmapView @JvmOverloads constructor(
private val cellPaint = Paint(Paint.ANTI_ALIAS_FLAG)
private val textPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
textSize = context.spf(9f)
textSize = context.spf(10f)
color = context.col(R.color.text_tertiary)
textAlign = Paint.Align.RIGHT
}
@@ -145,18 +145,19 @@ class HeatmapView @JvmOverloads constructor(
override fun onDraw(canvas: Canvas) {
if (days.isEmpty()) return
val labelW = context.dpf(16f)
val labelW = context.dpf(18f)
val gap = context.dpf(3f)
val top = context.dpf(2f)
val firstMs = Dates.dayStartOfKey(days.first().key)
val startCol = weekdayIndex(firstMs) // 第一列从周一算起,前面留空
val totalCells = startCol + days.size
val cols = (totalCells + 6) / 7
val cellW = (width - labelW - gap * (cols - 1)) / cols
// 高度也要参与取小:宽屏时按宽度算出的格子会把第 7 行挤出可视区
val cellH = (height - top - gap * 6) / 7f
val cell = minOf(cellW.toFloat(), cellH, context.dpf(15f))
val radius = cell * 0.28f
// 格边长同时受宽和高约束,取消过去的 15dp 硬上限:
// 同一屏宽下尽量把格子铺到右侧,不在末尾留大片空白。
val cellH = (height - gap * 6f - context.dpf(8f)) / 7f
val cell = minOf(cellW.toFloat(), cellH).coerceAtLeast(context.dpf(6f))
val top = ((height - (cell * 7f + gap * 6f)) / 2f).coerceAtLeast(context.dpf(2f))
val radius = cell * 0.24f
val rect = RectF()
days.forEachIndexed { i, d ->
@@ -170,11 +171,11 @@ class HeatmapView @JvmOverloads constructor(
canvas.drawRoundRect(rect, radius, radius, cellPaint)
}
// 只在周一/三/五标字,避免七行小字糊在一起
val labels = mapOf(0 to "一", 2 to "三", 4 to "五")
labels.forEach { (row, s) ->
val y = top + row * (cell + gap) + cell * 0.78f
canvas.drawText(s, labelW - context.dpf(4f), y, textPaint)
// 只标一/三/五/日四行,既不漏掉周末,也不会七行小字糊在一起
val baseline = cell / 2f + context.spf(10f) * 0.35f
for (row in listOf(0, 2, 4, 6)) {
val y = top + row * (cell + gap) + baseline
canvas.drawText(Dates.weekdayShort(row), labelW - context.dpf(3f), y, textPaint)
}
}
}

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/ripple_surface">
<item>
<shape android:shape="oval">
<solid android:color="@color/icon_add_bg" />
<stroke android:width="1dp" android:color="@color/icon_add_stroke" />
</shape>
</item>
</ripple>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/ripple_surface">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/surface_alt" />
<corners android:radius="12dp" />
<stroke android:width="1dp" android:color="@color/card_stroke" />
</shape>
</item>
</ripple>

View File

@@ -52,9 +52,10 @@
android:id="@+id/btnAdd"
android:layout_width="42dp"
android:layout_height="42dp"
android:background="@drawable/bg_icon_btn"
android:background="@drawable/bg_add_btn"
android:padding="10dp"
android:src="@drawable/ic_plus"
android:tint="@color/icon_add_fg"
android:contentDescription="@string/add_project" />
</LinearLayout>

View File

@@ -237,14 +237,14 @@
<com.focusbox.app.widget.HeatmapView
android:id="@+id/heatmap"
android:layout_width="match_parent"
android:layout_height="112dp"
android:layout_height="168dp"
android:layout_marginTop="8dp" />
<LinearLayout
android:id="@+id/heatLegend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:orientation="horizontal"
android:gravity="center_vertical" />

View File

@@ -38,9 +38,10 @@
android:id="@+id/btnAdd"
android:layout_width="42dp"
android:layout_height="42dp"
android:background="@drawable/bg_icon_btn"
android:background="@drawable/bg_add_btn"
android:padding="10dp"
android:src="@drawable/ic_plus"
android:tint="@color/icon_add_fg"
android:contentDescription="@string/add_task" />
</LinearLayout>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<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:minHeight="58dp"
android:background="@drawable/bg_pick_row"
android:paddingStart="14dp"
android:paddingEnd="14dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<View
android:id="@+id/rowDot"
android:layout_width="10dp"
android:layout_height="10dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/rowTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
style="@style/T.Body" />
<TextView
android:id="@+id/rowMeta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:singleLine="true"
android:ellipsize="end"
style="@style/T.Caption" />
</LinearLayout>
<ImageView
android:id="@+id/rowMark"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="8dp"
android:src="@drawable/ic_check"
android:tint="@color/brand"
android:visibility="gone"
android:contentDescription="@string/done" />
</LinearLayout>

View File

@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/bg_sheet">
<!-- 拖拽把手:提示这是可下滑关闭的底部弹层 -->
<View
android:layout_width="36dp"
android:layout_height="4dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="@color/divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingTop="14dp"
android:paddingBottom="22dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/pickBack"
android:layout_width="34dp"
android:layout_height="34dp"
android:background="@drawable/bg_icon_btn"
android:padding="8dp"
android:src="@drawable/ic_back"
android:tint="@color/text_secondary"
android:contentDescription="@string/pick_back" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:orientation="vertical">
<TextView
android:id="@+id/pickTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pick_project"
style="@style/T.Title" />
<TextView
android:id="@+id/pickStep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
style="@style/T.Caption" />
</LinearLayout>
<ImageView
android:id="@+id/pickClose"
android:layout_width="34dp"
android:layout_height="34dp"
android:background="@drawable/bg_icon_btn"
android:padding="8dp"
android:src="@drawable/ic_close"
android:tint="@color/text_secondary"
android:contentDescription="@string/cancel" />
</LinearLayout>
<TextView
android:id="@+id/pickHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
style="@style/T.Meta" />
<ScrollView
android:id="@+id/pickScroll"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="10dp"
android:clipToPadding="false"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:scrollbars="none">
<LinearLayout
android:id="@+id/pickList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
<TextView
android:id="@+id/pickClear"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="6dp"
android:background="@drawable/bg_btn_ghost"
android:gravity="center"
android:text="@string/clear_task"
android:textSize="14sp"
android:textColor="@color/text_secondary"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

View File

@@ -29,6 +29,11 @@
<color name="segment_track">#262A2E</color>
<color name="segment_on">#33383E</color>
<!-- 深色下用明显更亮的描边与加号,保证一眼能找到 -->
<color name="icon_add_bg">#3C2A25</color>
<color name="icon_add_stroke">#8A5140</color>
<color name="icon_add_fg">#FFB49A</color>
<color name="ripple_surface">#1FFFFFFF</color>
<color name="ripple_brand">#33FFFFFF</color>

View File

@@ -34,6 +34,11 @@
<color name="segment_track">#EBE5DA</color>
<color name="segment_on">#FFFFFF</color>
<!-- 新增按钮:独立配色,避免深色下 + 号与底色糊成一片 -->
<color name="icon_add_bg">#F6DED6</color>
<color name="icon_add_stroke">#E3B2A1</color>
<color name="icon_add_fg">#9E3F29</color>
<color name="ripple_surface">#14000000</color>
<color name="ripple_brand">#33FFFFFF</color>

View File

@@ -31,6 +31,14 @@
<string name="current_task">当前任务</string>
<string name="no_task">未选择任务 · 直接开始也可以</string>
<string name="pick_task">选择任务</string>
<string name="pick_project">选择项目</string>
<string name="pick_back">返回上一步</string>
<string name="clear_task">不选择任务,直接开始</string>
<string name="pick_step">第 %1$d 步 / 共 2 步</string>
<string name="pick_project_hint">先选项目,再从这个项目里挑一件要做的事</string>
<string name="pick_task_hint">选中的任务会自动套用它设定的专注时长</string>
<string name="pick_project_meta">%1$d 项待办</string>
<string name="pick_task_empty">这个项目还没有待办任务,点返回换个项目</string>
<string name="no_task_to_pick">还没有待办任务,先去「任务」新建一个</string>
<string name="rounds_today">今天第 %1$d 个番茄</string>
@@ -101,6 +109,7 @@
<string name="pomodoro_count">番茄数</string>
<string name="completed_tasks">完成任务</string>
<string name="goal_progress">今日目标 %1$d%%</string>
<string name="goal_short">%1$dM</string>
<string name="trend_title">专注趋势</string>
<string name="heatmap_title">打卡热力图</string>
<string name="distribution_title">项目分布</string>