首页任务选择改为两步式圆角弹层;新增按钮深色高对比;统计目标文案与热力图自适应
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user