feat: add completed task and project summary

- Add completed timeblock queries and completed project aggregation\n- Add desktop completed summary dialog with range filters, stats, and streak\n- Add medal entry point in the today panel\n- Add Android completed summary menu with local statistics\n- Rebuild AppImage and update validation docs/screenshots
This commit is contained in:
Misaki
2026-11-10 16:45:54 +08:00
parent 35cabb37b2
commit bfab0579a7
33 changed files with 860 additions and 17 deletions
@@ -6,6 +6,7 @@ import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.ScrollView
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
@@ -114,6 +115,10 @@ class MainActivity : AppCompatActivity() {
val toolbar = findViewById<MaterialToolbar>(R.id.toolbar)
toolbar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.action_completed -> {
showCompletedSummary()
true
}
R.id.action_sync -> {
syncManager.reload()
true
@@ -172,6 +177,47 @@ class MainActivity : AppCompatActivity() {
super.onDestroy()
}
private fun showCompletedSummary() {
val items = repository.completedItems()
val projects = repository.completedProjects()
val focusedMinutes = items.sumOf {
val start = TimeUtils.parse(it.block.startAt)
val end = TimeUtils.parse(it.block.endAt)
if (start != null && end != null) {
maxOf(0, java.time.Duration.between(start, end).toMinutes().toInt())
} else 0
}
val summaryText = buildString {
append("短期任务 ${items.size} · 长期项目 ${projects.size}\n")
append("累计专注 ${focusedMinutes / 60} 小时 ${focusedMinutes % 60} 分钟\n\n")
if (items.isNotEmpty()) {
append("短期任务\n")
items.take(50).forEach {
append("· ${it.task.title} ${TimeUtils.formatDate(it.block.doneAt ?: it.block.endAt)}\n")
}
append("\n")
}
if (projects.isNotEmpty()) {
append("长期项目\n")
projects.forEach { append("· ${it.title} ${TimeUtils.formatDate(it.updatedAt)}\n") }
}
if (items.isEmpty() && projects.isEmpty()) {
append("还没有已完成记录。")
}
}
val content = TextView(this).apply {
text = summaryText
textSize = 14f
setPadding(48, 24, 48, 24)
}
val scroll = ScrollView(this).apply { addView(content) }
MaterialAlertDialogBuilder(this)
.setTitle(R.string.completed_summary)
.setView(scroll)
.setPositiveButton(android.R.string.ok, null)
.show()
}
private fun refresh() {
dateText.text = selectedDate.format(dateFormatter)
val items = repository.itemsForDate(selectedDate)
@@ -80,6 +80,58 @@ class ScheduleRepository(context: Context) {
return result
}
fun completedItems(): List<ScheduleItem> {
val result = mutableListOf<ScheduleItem>()
db.rawQuery(
"""
SELECT t.id, t.title, t.description, t.source, t.source_ref, t.estimated_min,
t.energy_req, t.deadline, t.priority, t.status, t.created_at, t.updated_at,
t.version, t.device_id,
b.id, b.task_id, b.start_at, b.end_at, b.granularity, b.splittable,
b.breakable, b.status, b.done_at, b.created_at, b.updated_at, b.version, b.device_id
FROM timeblock b JOIN task t ON t.id = b.task_id
WHERE b.status = 'done'
ORDER BY COALESCE(b.done_at, b.end_at) DESC
LIMIT 200
""".trimIndent(),
emptyArray()
).use { cursor ->
while (cursor.moveToNext()) result.add(readItem(cursor))
}
return result
}
fun completedProjects(): List<Project> {
val result = mutableListOf<Project>()
db.rawQuery(
"""
SELECT id, title, description, source, source_ref, deadline, priority, status,
created_at, updated_at, version, device_id
FROM project WHERE status = 'done'
ORDER BY updated_at DESC
""".trimIndent(),
emptyArray()
).use { cursor ->
while (cursor.moveToNext()) {
result.add(Project(
id = cursor.getString(0),
title = cursor.getString(1),
description = cursor.stringOrNull(2),
source = cursor.getString(3) ?: "android",
sourceRef = cursor.stringOrNull(4),
deadline = cursor.stringOrNull(5),
priority = cursor.getInt(6),
status = cursor.getString(7) ?: "done",
createdAt = cursor.getString(8),
updatedAt = cursor.getString(9),
version = cursor.getInt(10),
deviceId = cursor.getString(11),
))
}
}
return result
}
fun create(title: String, start: LocalDateTime, end: LocalDateTime, deviceId: String): String {
val now = TimeUtils.nowIso()
val taskId = UUID.randomUUID().toString()
@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_completed"
android:title="@string/completed_summary"
android:showAsAction="never" />
<item
android:id="@+id/action_sync"
android:title="@string/sync_now"
@@ -7,6 +7,7 @@
<string name="next_day">后一天</string>
<string name="add_schedule">新建日程</string>
<string name="long_term_projects">长期项目</string>
<string name="completed_summary">已完成汇总</string>
<string name="empty_schedule">今天还没有安排</string>
<string name="sync_local">本地</string>
<string name="sync_not_configured">未配置同步服务</string>