已完成与时长统一累计口径、20色重排高反差、任务时长可输入、文案去空格

This commit is contained in:
XIGE
2026-12-02 00:11:46 +08:00
parent d8033ef71d
commit 87c95b4b89
7 changed files with 130 additions and 31 deletions

View File

@@ -81,10 +81,15 @@ class ProjectAdapter(
name.text = p.name
colorBar.background = ctx.roundBg(p.color, 2f)
// 项目页只统计项目下创建的任务:总数、已完成数、累计专注时长
// 项目页统计口径(全周期累计,不是今日,也没有时间上限):
// 任务数 = 项目下创建的任务本体(不含重复实例/完成记录副本);
// 已完成 = 真实跑完的专注次数(sessions.completed = 1 的条数),
// 重复任务每完成一轮就 +1,和「累计时长」同源;
// 手动勾选完成、周期滚动时的自动完成都没有专注记录,不计入;
// 时长 = 该项目全部专注记录秒数之和。
val parts = ArrayList<String>(3)
parts.add(ctx.getString(R.string.project_tasks_total, p.totalTasks))
if (p.doneTasks > 0) parts.add(ctx.getString(R.string.project_tasks_done, p.doneTasks))
if (p.pomodoros > 0) parts.add(ctx.getString(R.string.project_tasks_done, p.pomodoros))
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
meta.text = parts.joinToString(" · ")

View File

@@ -612,6 +612,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
}
companion object {
const val VERSION = "3.4"
const val VERSION = "3.5"
}
}

View File

@@ -18,7 +18,9 @@ import com.focusbox.app.ui.SheetDialog
import com.focusbox.app.util.Dates
import com.focusbox.app.util.Prefs
import com.focusbox.app.util.col
import com.focusbox.app.util.dpi
import com.focusbox.app.util.makeChip
import com.focusbox.app.util.roundBg
import com.focusbox.app.util.visible
import java.util.Calendar
@@ -72,6 +74,8 @@ class TaskSheet(
etTitle.setText(existing?.title ?: "")
etNote.setText(existing?.note ?: "")
renderFocus()
// 点数字直接输入时长,微调按钮保留做快速微调
tvFocus.setOnClickListener { inputFocus() }
root.findViewById<View>(R.id.btnFocusMinus).setOnClickListener {
focusMin = (focusMin - 5).coerceAtLeast(TimerCore.MIN_MINUTES)
@@ -173,6 +177,88 @@ class TaskSheet(
tvFocus.text = context.getString(R.string.minutes_value, focusMin)
}
/**
* 专注时长支持直接输入(与设置页「每日目标」同一套交互)。
*
* 微调按钮一次只有 5 分钟,25 → 90 要点十几次;
* 输入后统一夹紧到 [TimerCore.MIN_MINUTES, TimerCore.MAX_MINUTES]。
*/
private fun inputFocus() {
val ctx = context
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val panel = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(20f), dpi(20f), dpi(20f), dpi(14f))
}
panel.addView(TextView(ctx).apply {
text = ctx.getString(R.string.focus_duration)
textSize = 16f
typeface = android.graphics.Typeface.DEFAULT_BOLD
setTextColor(ctx.col(R.color.text))
})
val et = EditText(ctx).apply {
inputType = android.text.InputType.TYPE_CLASS_NUMBER
setText(focusMin.toString())
setSelection(text.length)
textSize = 15f
setTextColor(ctx.col(R.color.text))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(14f), dpi(12f), dpi(14f), dpi(12f))
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
).apply { topMargin = dpi(14f) }
}
panel.addView(et)
val btnRow = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = android.view.Gravity.END
setPadding(0, dpi(12f), 0, 0)
}
fun btn(labelRes: Int, onClick: () -> Unit) = TextView(ctx).apply {
text = ctx.getString(labelRes)
textSize = 14f
typeface = android.graphics.Typeface.DEFAULT_BOLD
gravity = android.view.Gravity.CENTER
setTextColor(ctx.col(R.color.brand))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(22f), dpi(10f), dpi(22f), dpi(10f))
setOnClickListener { onClick() }
}
btnRow.addView(btn(R.string.cancel) { dialog.dismiss() })
btnRow.addView(
btn(R.string.save) {
val input = et.text.toString().trim().toIntOrNull()
if (input == null) {
et.error = " "
} else {
focusMin = input.coerceIn(TimerCore.MIN_MINUTES, TimerCore.MAX_MINUTES)
renderFocus()
dialog.dismiss()
}
},
LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
).apply { marginStart = dpi(10f) },
)
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
et.post {
et.requestFocus()
runCatching {
(ctx.getSystemService(Context.INPUT_METHOD_SERVICE) as? android.view.inputmethod.InputMethodManager)
?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
}
}
}
/** 重复单位五选一;只有真正的周期重复(天/周/月)才露出间隔步进器 */
private fun renderRepeat() {
val ctx = context