任务完成后从列表消失;重要度改名并新增紧急度五角星;通知按钮间距与默认专注页

This commit is contained in:
XIGE
2026-11-28 17:11:28 +08:00
parent 6d13a5bf3c
commit 6b68d56467
13 changed files with 176 additions and 58 deletions

View File

@@ -27,7 +27,7 @@ object Store {
const val INBOX_ID = 1L
private const val DB_NAME = "focusbox.db"
private const val DB_VERSION = 5
private const val DB_VERSION = 6
private lateinit var helper: Helper
@@ -70,7 +70,8 @@ object Store {
repeat_type INTEGER NOT NULL DEFAULT 0,
repeat_every INTEGER NOT NULL DEFAULT 1,
origin_id INTEGER NOT NULL DEFAULT 0,
log_seconds INTEGER NOT NULL DEFAULT 0
log_seconds INTEGER NOT NULL DEFAULT 0,
urgency INTEGER NOT NULL DEFAULT 1
)
""".trimIndent()
)
@@ -117,10 +118,14 @@ object Store {
"WHERE note LIKE '%【%' OR note LIKE '%】%'"
)
}
// v4 → v5:每次专注单独成一条完成记录,存本轮秒数以显示真实起止
// v4 → v5:每次专注单独成条完成记录,存本轮秒数以显示真实起止
if (oldVersion < 5) {
db.execSQL("ALTER TABLE tasks ADD COLUMN log_seconds INTEGER NOT NULL DEFAULT 0")
}
// v5 → v6:紧急度(0 不急 / 1 中 / 2 紧急),旧任务统一归为中
if (oldVersion < 6) {
db.execSQL("ALTER TABLE tasks ADD COLUMN urgency INTEGER NOT NULL DEFAULT 1")
}
}
}
@@ -206,11 +211,12 @@ object Store {
repeatEvery = c.getInt(13),
originId = c.getLong(14),
logSeconds = c.getInt(15),
urgency = c.getInt(16),
)
private val taskColumns =
"_id, title, note, project_id, priority, focus_min, done_pomodoros, due, done, done_at, " +
"created_at, sort, repeat_type, repeat_every, origin_id, log_seconds"
"created_at, sort, repeat_type, repeat_every, origin_id, log_seconds, urgency"
fun tasks(projectId: Long = 0L, includeDone: Boolean = true): List<Task> {
val where = StringBuilder("1 = 1")
@@ -246,12 +252,14 @@ object Store {
due: Long,
repeatType: Int,
repeatEvery: Int,
urgency: Int = 1,
): Long {
val cv = ContentValues().apply {
put("title", title)
put("note", note)
put("project_id", projectId)
put("priority", priority)
put("urgency", urgency.coerceIn(0, 2))
put("focus_min", focusMinutes)
put("est_pomodoros", (focusMinutes / 25).coerceAtLeast(1))
put("done_pomodoros", 0)
@@ -272,6 +280,7 @@ object Store {
put("note", task.note)
put("project_id", task.projectId)
put("priority", task.priority)
put("urgency", task.urgency.coerceIn(0, 2))
put("focus_min", task.focusMinutes)
put("est_pomodoros", (task.focusMinutes / 25).coerceAtLeast(1))
put("due", task.due)
@@ -321,6 +330,7 @@ object Store {
put("note", note)
put("project_id", source?.projectId ?: INBOX_ID)
put("priority", source?.priority ?: 1)
put("urgency", source?.urgency?.coerceIn(0, 2) ?: 1)
put("focus_min", source?.focusMinutes ?: 25)
put("est_pomodoros", 1)
put("done_pomodoros", 1)
@@ -348,6 +358,7 @@ object Store {
due = due,
repeatType = source.repeatType,
repeatEvery = source.repeatEvery,
urgency = source.urgency,
)
if (id > 0) {
db.update(

View File

@@ -40,6 +40,8 @@ data class Task(
val repeatType: Int, // Repeat.NONE / DAY / WEEK / MONTH
val repeatEvery: Int, // 每 N 天 / 周 / 月
val originId: Long = 0L, // 重复系列的根任务 id;0 表示自己就是根
/** 紧急度:0 不急 / 1 中 / 2 紧急;列表标题后按档位显示彩色五角星 */
val urgency: Int = 1,
/** 仅在完成记录上有效:这一轮的专注秒数,配合 createdAt/doneAt 显示真实起止 */
val logSeconds: Int = 0,
) {

View File

@@ -194,6 +194,13 @@ object TimerCore {
if (countUp && accumMs < 0) accumMs = 0
// 进程被杀重启(或手机重启)后闹钟已丢失,计时还在走就要重新排到点闹钟
if (running && !countUp) scheduleDeadlineAlarm()
// 打开 APP 默认显示专注页:空闲状态下不保留上次停在休息页的位置
if (!running && mode != MODE_FOCUS) {
mode = MODE_FOCUS
totalMs = durationFor(MODE_FOCUS)
remainingMs = totalMs
save()
}
}
fun durationFor(m: Int): Long = when {
@@ -490,6 +497,9 @@ object TimerCore {
seconds = seconds,
)
}
// 完成按钮 = 这次任务做完了:源任务从列表消失,历史在「已完成」视图看;
// 重复任务不用管,跨零点后 rollRepeatingTasks 会按周期生成新实例
Store.setTaskDone(taskId, true)
}
clearRoundNotes()
running = false

View File

@@ -112,6 +112,10 @@ class MainActivity : AppCompatActivity() {
// 进程常驻时跨天不会重走 App.onCreate,回到前台再滚一次重复任务。
// 放在 super 之前:片段 onResume 里的 reload 读到的就是推进后的日期。
runCatching { Store.rollRepeatingTasks() }
// 打开/回到前台默认停在专注页;休息正在计时时不打断
if (!TimerCore.running && TimerCore.mode != TimerCore.MODE_FOCUS) {
runCatching { TimerCore.setMode(TimerCore.MODE_FOCUS) }
}
super.onResume()
rollHandler.removeCallbacks(rollRunner)
rollHandler.postDelayed(rollRunner, 60_000L)

View File

@@ -67,6 +67,7 @@ class TaskAdapter(
private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
private val tvTitle: TextView = v.findViewById(R.id.tvTitle)
private val tvStars: TextView = v.findViewById(R.id.tvStars)
private val tvMeta: TextView = v.findViewById(R.id.tvMeta)
private val tvNote: TextView = v.findViewById(R.id.tvNote)
private val checkCircle: View = v.findViewById(R.id.checkCircle)
@@ -87,6 +88,20 @@ class TaskAdapter(
tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text))
tvTitle.typeface = if (task.priority >= 2 && !task.done) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
// 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰;完成任务不再显示
if (!task.done) {
val (stars, color) = when (task.urgency) {
2 -> "★★★" to R.color.urgent_high
1 -> "★★" to R.color.urgent_mid
else -> "★" to R.color.urgent_low
}
tvStars.text = stars
tvStars.setTextColor(ctx.col(color))
tvStars.visible(true)
} else {
tvStars.visible(false)
}
if (task.done) {
checkCircle.background = ctx.circleBg(ctx.col(R.color.brand))
checkMark.visible(true)

View File

@@ -41,6 +41,7 @@ class TaskSheet(
private val etNote: EditText = root.findViewById(R.id.etNote)
private val projectRow: LinearLayout = root.findViewById(R.id.projectRow)
private val priorityRow: LinearLayout = root.findViewById(R.id.priorityRow)
private val urgencyRow: LinearLayout = root.findViewById(R.id.urgencyRow)
private val repeatRow: LinearLayout = root.findViewById(R.id.repeatRow)
private val repeatEveryRow: View = root.findViewById(R.id.repeatEveryRow)
private val tvFocus: TextView = root.findViewById(R.id.tvFocus)
@@ -51,6 +52,8 @@ class TaskSheet(
private var projectId: Long = existing?.projectId
?: if (presetProjectId > 0) presetProjectId else Store.INBOX_ID
private var priority: Int = existing?.priority ?: 1
// 紧急度:0 不急 / 1 中 / 2 紧急,旧数据默认归为中
private var urgency: Int = (existing?.urgency ?: 1).coerceIn(0, 2)
// 旧数据的时长可能超出新范围(早先是"番茄数×25"),这里统一夹紧
private var focusMin: Int = (existing?.focusMinutes ?: Prefs.focusMinutes)
.coerceIn(TimerCore.MIN_MINUTES, TimerCore.MAX_MINUTES)
@@ -112,6 +115,7 @@ class TaskSheet(
renderProjects()
renderPriority()
renderUrgency()
renderRepeat()
updateDue()
}
@@ -143,6 +147,21 @@ class TaskSheet(
}
}
/** 紧急度三选一:列表标题后按档位显示三颗红 / 两颗绿 / 一颗灰五角星 */
private fun renderUrgency() {
val ctx = context
urgencyRow.removeAllViews()
val labels = listOf(R.string.p_low, R.string.p_mid, R.string.p_high)
labels.forEachIndexed { index, res ->
val chip = ctx.makeChip(ctx.getString(res), index == urgency)
chip.setOnClickListener {
urgency = index
renderUrgency()
}
urgencyRow.addView(chip)
}
}
private fun renderFocus() {
tvFocus.text = context.getString(R.string.minutes_value, focusMin)
}
@@ -214,7 +233,7 @@ class TaskSheet(
// 重复任务必须有日期作为节奏起点,否则既进不了「今日」,也无法按间隔滚动
val effectiveDue = if (repeatType != Repeat.NONE && due <= 0) Dates.todayStart() else due
if (existing == null) {
Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every)
Store.addTask(title, note, projectId, priority, focusMin, effectiveDue, repeatType, every, urgency)
} else {
Store.updateTask(
existing.copy(
@@ -222,6 +241,7 @@ class TaskSheet(
note = note,
projectId = projectId,
priority = priority,
urgency = urgency,
focusMinutes = focusMin,
due = effectiveDue,
repeatType = repeatType,

View File

@@ -119,19 +119,12 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
ViewFilter.TODAY -> {
val from = Dates.todayStart()
val to = Dates.addDays(from, 1)
// 今日 = 截止日正好是今天、且还没完成的任务
// + 今天勾选完成的任务
// 逾期(截止日在今天之前)不进来:那是「全部」里带"已逾期"标记的事,
// 混进今日会把列表撑成一大串旧账,也让人分不清今天到底要做什么。
// 今日 = 截止日正好是今天、还没完成的任务。
// 完成的任务直接从列表消失(历史统一去「已完成」视图看),
// 重复任务由跨零点的 rollRepeatingTasks 按周期生成新实例。
val dueToday = pending.filter { it.due >= from && it.due < to }
val doneToday = done.filter { it.doneAt >= from && it.doneAt < to }
dueToday.forEach { rows.add(toRow(it, spans)) }
doneToday.forEach { rows.add(toRow(it, spans)) }
tvCount.text = if (doneToday.isEmpty()) {
getString(R.string.task_count_today, dueToday.size)
} else {
getString(R.string.task_count_today_mixed, dueToday.size, doneToday.size)
}
tvCount.text = getString(R.string.task_count_today, dueToday.size)
tvEmpty.setText(R.string.empty_today)
}