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

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

@@ -1,5 +1,9 @@
# 变更记录 # 变更记录
## 2026-11-28 · 任务完成后从列表消失;重要度改名并新增紧急度五角星;通知按钮间距与默认专注页
- 同步源码更新 12 个文件(新增/修改 12,删除 0)。
## 2026-11-28 · v0.5.6:到点闹钟兜底、饼图空格与备注文案 ## 2026-11-28 · v0.5.6:到点闹钟兜底、饼图空格与备注文案
- **通知/锁屏负数计时修复**:EMUI 息屏冻结进程导致到点结算停摆,通知 Chronometer 倒数穿零变负。新增 `DeadlineReceiver` + 精确闹钟(`setExactAndAllowWhileIdle`,权限被拒退化窗口闹钟),到点强制唤醒补结算;TimerCore 全部起止路径统一调度/取消闹钟,进程恢复与手机重启后也会重排。到点后正常弹出「本轮完成」提醒并撤掉常驻通知。 - **通知/锁屏负数计时修复**:EMUI 息屏冻结进程导致到点结算停摆,通知 Chronometer 倒数穿零变负。新增 `DeadlineReceiver` + 精确闹钟(`setExactAndAllowWhileIdle`,权限被拒退化窗口闹钟),到点强制唤醒补结算;TimerCore 全部起止路径统一调度/取消闹钟,进程恢复与手机重启后也会重排。到点后正常弹出「本轮完成」提醒并撤掉常驻通知。

View File

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

View File

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

View File

@@ -194,6 +194,13 @@ object TimerCore {
if (countUp && accumMs < 0) accumMs = 0 if (countUp && accumMs < 0) accumMs = 0
// 进程被杀重启(或手机重启)后闹钟已丢失,计时还在走就要重新排到点闹钟 // 进程被杀重启(或手机重启)后闹钟已丢失,计时还在走就要重新排到点闹钟
if (running && !countUp) scheduleDeadlineAlarm() 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 { fun durationFor(m: Int): Long = when {
@@ -490,6 +497,9 @@ object TimerCore {
seconds = seconds, seconds = seconds,
) )
} }
// 完成按钮 = 这次任务做完了:源任务从列表消失,历史在「已完成」视图看;
// 重复任务不用管,跨零点后 rollRepeatingTasks 会按周期生成新实例
Store.setTaskDone(taskId, true)
} }
clearRoundNotes() clearRoundNotes()
running = false running = false

View File

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

View File

@@ -67,6 +67,7 @@ class TaskAdapter(
private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) { private inner class TaskViewHolder(v: View) : RecyclerView.ViewHolder(v) {
private val tvTitle: TextView = v.findViewById(R.id.tvTitle) 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 tvMeta: TextView = v.findViewById(R.id.tvMeta)
private val tvNote: TextView = v.findViewById(R.id.tvNote) private val tvNote: TextView = v.findViewById(R.id.tvNote)
private val checkCircle: View = v.findViewById(R.id.checkCircle) 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.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 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) { if (task.done) {
checkCircle.background = ctx.circleBg(ctx.col(R.color.brand)) checkCircle.background = ctx.circleBg(ctx.col(R.color.brand))
checkMark.visible(true) checkMark.visible(true)

View File

@@ -41,6 +41,7 @@ class TaskSheet(
private val etNote: EditText = root.findViewById(R.id.etNote) private val etNote: EditText = root.findViewById(R.id.etNote)
private val projectRow: LinearLayout = root.findViewById(R.id.projectRow) private val projectRow: LinearLayout = root.findViewById(R.id.projectRow)
private val priorityRow: LinearLayout = root.findViewById(R.id.priorityRow) 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 repeatRow: LinearLayout = root.findViewById(R.id.repeatRow)
private val repeatEveryRow: View = root.findViewById(R.id.repeatEveryRow) private val repeatEveryRow: View = root.findViewById(R.id.repeatEveryRow)
private val tvFocus: TextView = root.findViewById(R.id.tvFocus) private val tvFocus: TextView = root.findViewById(R.id.tvFocus)
@@ -51,6 +52,8 @@ class TaskSheet(
private var projectId: Long = existing?.projectId private var projectId: Long = existing?.projectId
?: if (presetProjectId > 0) presetProjectId else Store.INBOX_ID ?: if (presetProjectId > 0) presetProjectId else Store.INBOX_ID
private var priority: Int = existing?.priority ?: 1 private var priority: Int = existing?.priority ?: 1
// 紧急度:0 不急 / 1 中 / 2 紧急,旧数据默认归为中
private var urgency: Int = (existing?.urgency ?: 1).coerceIn(0, 2)
// 旧数据的时长可能超出新范围(早先是"番茄数×25"),这里统一夹紧 // 旧数据的时长可能超出新范围(早先是"番茄数×25"),这里统一夹紧
private var focusMin: Int = (existing?.focusMinutes ?: Prefs.focusMinutes) private var focusMin: Int = (existing?.focusMinutes ?: Prefs.focusMinutes)
.coerceIn(TimerCore.MIN_MINUTES, TimerCore.MAX_MINUTES) .coerceIn(TimerCore.MIN_MINUTES, TimerCore.MAX_MINUTES)
@@ -112,6 +115,7 @@ class TaskSheet(
renderProjects() renderProjects()
renderPriority() renderPriority()
renderUrgency()
renderRepeat() renderRepeat()
updateDue() 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() { private fun renderFocus() {
tvFocus.text = context.getString(R.string.minutes_value, focusMin) 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 val effectiveDue = if (repeatType != Repeat.NONE && due <= 0) Dates.todayStart() else due
if (existing == null) { 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 { } else {
Store.updateTask( Store.updateTask(
existing.copy( existing.copy(
@@ -222,6 +241,7 @@ class TaskSheet(
note = note, note = note,
projectId = projectId, projectId = projectId,
priority = priority, priority = priority,
urgency = urgency,
focusMinutes = focusMin, focusMinutes = focusMin,
due = effectiveDue, due = effectiveDue,
repeatType = repeatType, repeatType = repeatType,

View File

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

View File

@@ -37,15 +37,33 @@
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <LinearLayout
android:id="@+id/tvTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="15sp" android:textSize="15sp"
android:textColor="@color/text" android:textColor="@color/text"
android:maxLines="2" android:maxLines="2"
android:ellipsize="end" /> android:ellipsize="end" />
<TextView
android:id="@+id/tvStars"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:textSize="11sp"
android:includeFontPadding="false"
android:letterSpacing="0.08"
android:visibility="gone" />
</LinearLayout>
<TextView <TextView
android:id="@+id/tvMeta" android:id="@+id/tvMeta"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -64,6 +64,7 @@
android:id="@+id/notifStop" android:id="@+id/notifStop"
android:layout_width="44dp" android:layout_width="44dp"
android:layout_height="44dp" android:layout_height="44dp"
android:layout_marginStart="8dp"
android:padding="10dp" android:padding="10dp"
android:background="@drawable/bg_notif_action" android:background="@drawable/bg_notif_action"
android:scaleType="fitCenter" android:scaleType="fitCenter"

View File

@@ -96,6 +96,33 @@
android:orientation="horizontal" /> android:orientation="horizontal" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/urgency"
style="@style/T.Section" />
<LinearLayout
android:id="@+id/urgencyRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal" />
</LinearLayout>
</LinearLayout>
<!-- 专注时长在左,截止日期在右:设置一组日期时顺带确认时长 -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:orientation="horizontal">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -145,12 +172,17 @@
android:textColor="@color/text" /> android:textColor="@color/text" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="16dp"
android:orientation="vertical">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:text="@string/due_date" android:text="@string/due_date"
style="@style/T.Section" /> style="@style/T.Section" />
@@ -184,6 +216,8 @@
android:contentDescription="@string/clear_due" android:contentDescription="@string/clear_due"
android:visibility="gone" /> android:visibility="gone" />
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -14,6 +14,11 @@
<color name="rest_deep">#2F6455</color> <color name="rest_deep">#2F6455</color>
<color name="danger">#C0392B</color> <color name="danger">#C0392B</color>
<!-- 紧急度五角星:紧急三颗红 / 中两颗绿 / 不急一颗灰 -->
<color name="urgent_high">#E5484D</color>
<color name="urgent_mid">#2FA96C</color>
<color name="urgent_low">#9E9E9E</color>
<color name="success">#2E7D51</color> <color name="success">#2E7D51</color>
<color name="bg">#F5F8FC</color> <color name="bg">#F5F8FC</color>

View File

@@ -78,7 +78,8 @@
<string name="empty_done">还没有已完成的任务</string> <string name="empty_done">还没有已完成的任务</string>
<string name="task_title_hint">要做什么?</string> <string name="task_title_hint">要做什么?</string>
<string name="task_note_hint">备注(可选)</string> <string name="task_note_hint">备注(可选)</string>
<string name="priority">优先级</string> <string name="priority">重要度</string>
<string name="urgency">紧急度</string>
<string name="p_low">低</string> <string name="p_low">低</string>
<string name="p_mid">中</string> <string name="p_mid">中</string>
<string name="p_high">高</string> <string name="p_high">高</string>