feat: add long-term projects with AI creation
- Add project model, schema v4, sync triggers, and server support\n- Add project panel, deadline countdown, manual create/edit/complete/delete\n- Parse AI project operations and show them in the proposal diff\n- Sync projects to Android and display them read-only\n- Rebuild AppImage and update validation docs and screenshots
This commit is contained in:
@@ -26,6 +26,7 @@ import com.misaki.schedule.background.BackgroundScheduler
|
||||
import com.misaki.schedule.background.NotificationHelper
|
||||
import com.misaki.schedule.data.TimeUtils
|
||||
import com.misaki.schedule.sync.SyncManager
|
||||
import com.misaki.schedule.ui.ProjectAdapter
|
||||
import com.misaki.schedule.ui.ScheduleAdapter
|
||||
import com.misaki.schedule.ui.ScheduleDialog
|
||||
import com.misaki.schedule.ui.SettingsDialog
|
||||
@@ -39,7 +40,10 @@ class MainActivity : AppCompatActivity() {
|
||||
private lateinit var prefs: Prefs
|
||||
private lateinit var syncManager: SyncManager
|
||||
private lateinit var adapter: ScheduleAdapter
|
||||
private lateinit var projectAdapter: ProjectAdapter
|
||||
private lateinit var list: RecyclerView
|
||||
private lateinit var projectList: RecyclerView
|
||||
private lateinit var projectHeader: TextView
|
||||
private lateinit var emptyText: TextView
|
||||
private lateinit var dateText: TextView
|
||||
private lateinit var syncStatus: TextView
|
||||
@@ -69,6 +73,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
list = findViewById(R.id.scheduleList)
|
||||
projectList = findViewById(R.id.projectList)
|
||||
projectHeader = findViewById(R.id.projectHeader)
|
||||
emptyText = findViewById(R.id.emptyText)
|
||||
dateText = findViewById(R.id.dateText)
|
||||
syncStatus = findViewById(R.id.syncStatus)
|
||||
@@ -84,6 +90,9 @@ class MainActivity : AppCompatActivity() {
|
||||
)
|
||||
list.layoutManager = LinearLayoutManager(this)
|
||||
list.adapter = adapter
|
||||
projectAdapter = ProjectAdapter()
|
||||
projectList.layoutManager = LinearLayoutManager(this)
|
||||
projectList.adapter = projectAdapter
|
||||
|
||||
findViewById<FloatingActionButton>(R.id.addButton).setOnClickListener {
|
||||
val start = TimeUtils.defaultStart(selectedDate)
|
||||
@@ -168,6 +177,10 @@ class MainActivity : AppCompatActivity() {
|
||||
val items = repository.itemsForDate(selectedDate)
|
||||
adapter.submit(items)
|
||||
emptyText.visibility = if (items.isEmpty()) View.VISIBLE else View.GONE
|
||||
val projects = repository.projects()
|
||||
projectAdapter.submit(projects)
|
||||
projectHeader.visibility = if (projects.isEmpty()) View.GONE else View.VISIBLE
|
||||
projectList.visibility = if (projects.isEmpty()) View.GONE else View.VISIBLE
|
||||
}
|
||||
|
||||
private fun showScheduleDialog(item: ScheduleItem?, fallbackStart: java.time.LocalDateTime? = null) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
|
||||
class ScheduleDb(context: Context) : SQLiteOpenHelper(context, "schedule.db", null, 2) {
|
||||
class ScheduleDb(context: Context) : SQLiteOpenHelper(context, "schedule.db", null, 3) {
|
||||
override fun onConfigure(db: SQLiteDatabase) {
|
||||
super.onConfigure(db)
|
||||
db.setForeignKeyConstraintsEnabled(true)
|
||||
@@ -66,6 +66,7 @@ class ScheduleDb(context: Context) : SQLiteOpenHelper(context, "schedule.db", nu
|
||||
db.execSQL(
|
||||
"CREATE TABLE reminder_sent(key TEXT PRIMARY KEY, block_id TEXT NOT NULL, sent_at TEXT NOT NULL)"
|
||||
)
|
||||
createProjectTable(db)
|
||||
db.execSQL("CREATE INDEX idx_timeblock_start ON timeblock(start_at)")
|
||||
db.execSQL("CREATE INDEX idx_timeblock_task ON timeblock(task_id)")
|
||||
db.execSQL("CREATE INDEX idx_outbox_entity ON outbox(entity_type, entity_id)")
|
||||
@@ -77,5 +78,30 @@ class ScheduleDb(context: Context) : SQLiteOpenHelper(context, "schedule.db", nu
|
||||
"CREATE TABLE IF NOT EXISTS reminder_sent(key TEXT PRIMARY KEY, block_id TEXT NOT NULL, sent_at TEXT NOT NULL)"
|
||||
)
|
||||
}
|
||||
if (oldVersion < 3) {
|
||||
createProjectTable(db)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createProjectTable(db: SQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS project(
|
||||
id TEXT PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT,
|
||||
source TEXT,
|
||||
source_ref TEXT,
|
||||
deadline TEXT,
|
||||
priority INTEGER DEFAULT 1,
|
||||
status TEXT DEFAULT 'active',
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL,
|
||||
version INTEGER DEFAULT 0,
|
||||
device_id TEXT NOT NULL
|
||||
)
|
||||
""".trimIndent()
|
||||
)
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS idx_project_deadline ON project(status, deadline)")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,21 @@ data class TimeBlock(
|
||||
val deviceId: String,
|
||||
)
|
||||
|
||||
data class Project(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val description: String?,
|
||||
val source: String,
|
||||
val sourceRef: String?,
|
||||
val deadline: String?,
|
||||
val priority: Int,
|
||||
val status: String,
|
||||
val createdAt: String,
|
||||
val updatedAt: String,
|
||||
val version: Int,
|
||||
val deviceId: String,
|
||||
)
|
||||
|
||||
data class ScheduleItem(val task: Task, val block: TimeBlock) {
|
||||
fun isActive(): Boolean = block.status == "scheduled" || block.status == "in_progress"
|
||||
fun isDone(): Boolean = block.status == "done"
|
||||
|
||||
@@ -46,6 +46,40 @@ class ScheduleRepository(context: Context) {
|
||||
return result
|
||||
}
|
||||
|
||||
fun projects(): 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 = 'active'
|
||||
ORDER BY CASE WHEN deadline IS NULL THEN 1 ELSE 0 END, deadline ASC, priority 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) ?: "active",
|
||||
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()
|
||||
@@ -280,6 +314,7 @@ class ScheduleRepository(context: Context) {
|
||||
when (entityType) {
|
||||
"task" -> database.delete("task", "id = ?", arrayOf(entityId))
|
||||
"timeblock" -> database.delete("timeblock", "id = ?", arrayOf(entityId))
|
||||
"project" -> database.delete("project", "id = ?", arrayOf(entityId))
|
||||
}
|
||||
applied++
|
||||
} else if (op == "upsert") {
|
||||
@@ -301,6 +336,13 @@ class ScheduleRepository(context: Context) {
|
||||
applied++
|
||||
}
|
||||
}
|
||||
"project" -> {
|
||||
payload.put("updated_at", remoteUpdated)
|
||||
payload.put("version", change.optInt("version", 0))
|
||||
payload.put("device_id", change.optString("device_id"))
|
||||
database.insertWithOnConflict("project", null, projectValues(payload), SQLiteDatabase.CONFLICT_REPLACE)
|
||||
applied++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -370,6 +412,7 @@ class ScheduleRepository(context: Context) {
|
||||
val table = when (entityType) {
|
||||
"task" -> "task"
|
||||
"timeblock" -> "timeblock"
|
||||
"project" -> "project"
|
||||
else -> return null
|
||||
}
|
||||
database.rawQuery("SELECT updated_at FROM $table WHERE id = ?", arrayOf(entityId)).use { cursor ->
|
||||
@@ -457,6 +500,21 @@ class ScheduleRepository(context: Context) {
|
||||
put("device_id", block.deviceId)
|
||||
}
|
||||
|
||||
private fun projectValues(payload: JSONObject): ContentValues = ContentValues().apply {
|
||||
put("id", payload.optString("id"))
|
||||
put("title", payload.optString("title", "未命名项目"))
|
||||
put("description", payload.stringOrNull("description"))
|
||||
put("source", payload.optString("source", "android"))
|
||||
put("source_ref", payload.stringOrNull("source_ref"))
|
||||
put("deadline", payload.stringOrNull("deadline"))
|
||||
put("priority", payload.optInt("priority", 1))
|
||||
put("status", payload.optString("status", "active"))
|
||||
put("created_at", payload.optString("created_at", TimeUtils.nowIso()))
|
||||
put("updated_at", payload.optString("updated_at", TimeUtils.nowIso()))
|
||||
put("version", payload.optInt("version", 0))
|
||||
put("device_id", payload.optString("device_id"))
|
||||
}
|
||||
|
||||
private fun blockValues(payload: JSONObject): ContentValues = ContentValues().apply {
|
||||
put("id", payload.optString("id"))
|
||||
put("task_id", payload.optString("task_id"))
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.misaki.schedule.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.misaki.schedule.R
|
||||
import com.misaki.schedule.data.Project
|
||||
import java.time.LocalDate
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
class ProjectAdapter : RecyclerView.Adapter<ProjectAdapter.ViewHolder>() {
|
||||
private var items: List<Project> = emptyList()
|
||||
|
||||
fun submit(projects: List<Project>) {
|
||||
items = projects
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_project, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
class ViewHolder(itemView: android.view.View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val title: TextView = itemView.findViewById(R.id.projectTitle)
|
||||
private val deadline: TextView = itemView.findViewById(R.id.projectDeadline)
|
||||
|
||||
fun bind(project: Project) {
|
||||
title.text = project.title
|
||||
deadline.text = deadlineLabel(project)
|
||||
}
|
||||
|
||||
private fun deadlineLabel(project: Project): String {
|
||||
val date = runCatching { LocalDate.parse(project.deadline) }.getOrNull()
|
||||
?: return "无截止日期"
|
||||
val days = ChronoUnit.DAYS.between(LocalDate.now(), date).toInt()
|
||||
return when {
|
||||
days < 0 -> "截止 ${date} · 已逾期 ${-days} 天"
|
||||
days == 0 -> "截止 今天"
|
||||
else -> "截止 ${date} · 剩余 ${days} 天"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,25 @@
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/projectHeader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingTop="4dp"
|
||||
android:text="@string/long_term_projects"
|
||||
android:textStyle="bold"
|
||||
android:textSize="13sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/projectList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="120dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="4dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="14dp"
|
||||
android:layout_marginVertical="4dp"
|
||||
app:cardCornerRadius="10dp"
|
||||
app:cardElevation="0dp"
|
||||
app:strokeWidth="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/projectTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="2"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/projectDeadline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="3dp"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
@@ -6,6 +6,7 @@
|
||||
<string name="previous_day">前一天</string>
|
||||
<string name="next_day">后一天</string>
|
||||
<string name="add_schedule">新建日程</string>
|
||||
<string name="long_term_projects">长期项目</string>
|
||||
<string name="empty_schedule">今天还没有安排</string>
|
||||
<string name="sync_local">本地</string>
|
||||
<string name="sync_not_configured">未配置同步服务</string>
|
||||
|
||||
Reference in New Issue
Block a user