v3.22 按复查报告修 P1-1/P2-1..P2-4/P2-8/P3 全部

This commit is contained in:
XIGE
2026-12-02 20:05:33 +08:00
parent 9584603d8b
commit 4788c2353f
16 changed files with 399 additions and 86 deletions

View File

@@ -8,7 +8,6 @@ import android.view.WindowManager
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.focusbox.app.R
import com.focusbox.app.data.Store
import com.focusbox.app.model.Repeat
@@ -105,23 +104,7 @@ class TaskSheet(
val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
btnDelete.visible(existing != null)
btnDelete.setOnClickListener {
AlertDialog.Builder(context)
.setMessage(R.string.delete_task_confirm)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.delete) { _, _ ->
existing?.let {
// 删除会连同整个任务系列(重复实例 + 完成记录副本)及其专注记录一起删掉,
// 只要当前计时绑在这一系列的任意一行上就要解绑,
// 否则到点后完成记录会挂到一个已经不存在的任务上
val removed = Store.deleteTask(it.id)
if (TimerCore.taskId in removed) TimerCore.setTask(0, 0)
}
onSaved(0L)
dismiss()
}
.show()
}
btnDelete.setOnClickListener { confirmDelete() }
root.findViewById<View>(R.id.btnSave).setOnClickListener { save() }
@@ -132,6 +115,48 @@ class TaskSheet(
updateDue()
}
/**
* 删除确认走自绘圆角弹层,与项目页的确认、本页其余弹层是同一套外观。
* 之前这里单独用系统 AlertDialog:圆角、字号、按钮排布都是系统样式,
* 夹在一堆自绘弹层里很扎眼。
*/
private fun confirmDelete() {
val task = existing ?: return
val ctx = context
val sheet = SheetDialog(ctx)
val panel = LayoutInflater.from(ctx).inflate(R.layout.sheet_project_actions, null)
panel.findViewById<TextView>(R.id.actionsTitle).text = ctx.getString(R.string.delete)
panel.findViewById<TextView>(R.id.actionsMessage).apply {
text = ctx.getString(R.string.delete_task_confirm)
visibility = View.VISIBLE
}
val list = panel.findViewById<LinearLayout>(R.id.actionsList)
listOf(ctx.getString(R.string.cancel) to false, ctx.getString(R.string.delete) to true)
.forEachIndexed { index, (label, destructive) ->
val row = LayoutInflater.from(ctx).inflate(R.layout.item_action_row, list, false)
val tv = row.findViewById<TextView>(R.id.actionLabel)
tv.text = label
if (destructive) tv.setTextColor(ctx.col(R.color.danger))
row.setOnClickListener {
sheet.dismiss()
if (index == 1) deleteTask(task)
}
list.addView(row)
}
sheet.setContentView(panel)
sheet.show()
}
private fun deleteTask(task: Task) {
// 删除会连同整个任务系列(重复实例 + 完成记录副本)及其专注记录一起删掉,
// 只要当前计时绑在这一系列的任意一行上就要解绑,
// 否则到点后完成记录会挂到一个已经不存在的任务上
val removed = Store.deleteTask(task.id)
if (TimerCore.taskId in removed) TimerCore.setTask(0, 0)
onSaved(0L)
dismiss()
}
private fun renderProjects() {
val ctx = context
projectRow.removeAllViews()

View File

@@ -72,6 +72,9 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
private var projects: List<Project> = emptyList()
/** 上一次重建筛选面板时的条件指纹:没变就不重建,见 [renderFilters] */
private var filterSignature: String? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
recycler = view.findViewById(R.id.recycler)
@@ -172,12 +175,12 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
tvEmpty.visible(rows.isEmpty())
recycler.visible(rows.isNotEmpty())
// 当前筛选条件落盘,重建后恢复
Prefs.uiFilterProject = filterProjectId
Prefs.uiFilterTime = timeFilter
Prefs.uiFilterPriority = priorityFilter
Prefs.uiFilterUrgency = urgencyFilter
Prefs.uiFilterStatus = statusFilter
// 当前筛选条件落盘,重建后恢复。
// 只在真的变了才写:reload 会被滚动、切页、onResume 频繁触发,
// 逐项赋值等于每次刷新都往 SharedPreferences 写五遍
if (Prefs.uiFilterDirty(filterProjectId, timeFilter, priorityFilter, urgencyFilter, statusFilter)) {
Prefs.saveUiFilter(filterProjectId, timeFilter, priorityFilter, urgencyFilter, statusFilter)
}
}
// ------------------------------------------------------------ 联动筛选
@@ -387,7 +390,25 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
)
}
/**
* 筛选面板:项目集合或选中态没变时直接复用现有视图。
*
* 原来每次 reload 都 removeAllViews 重建全部胶囊,而 reload 会被滚动跨天、
* 切页、onResume、保存任务反复触发;项目一多,重建就是可见的卡顿。
*/
private fun renderFilters() {
val signature = buildString(96) {
append(filterProjectId).append('|')
append(timeFilter).append('|').append(priorityFilter).append('|')
append(urgencyFilter).append('|').append(statusFilter)
projects.forEach {
append('|').append(it.id).append(':').append(it.name)
append(':').append(if (it.archived) 1 else 0).append(':').append(it.color)
}
}
if (signature == filterSignature && filterPanel.childCount > 0) return
filterSignature = signature
filterPanel.removeAllViews()
val ctx = requireContext()