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

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

@@ -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}"