项目色板20色、删除级联清理、未关联数据清理、饼图左右各三、手动完成标记(v3.14)

This commit is contained in:
XIGE
2026-12-01 20:40:39 +08:00
parent 1df122af48
commit 853186015d
11 changed files with 281 additions and 50 deletions

View File

@@ -138,6 +138,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
section(R.string.section_data)
card(
// 清理旧版本删除任务后残留的孤儿记录,排在「清空所有数据」前面:
// 它只动查不到任务的记录,比全清安全一档
action(getString(R.string.purge_orphan), "", danger = true) { confirmPurgeOrphan() },
action(getString(R.string.clear_data), "", danger = true) { confirmClear() },
)
@@ -481,6 +484,71 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
dialog.show()
}
/**
* 清空未关联数据:弹窗结构与「清空所有数据」完全一致,只是正文会说清要删多少条。
*
* 删的是「找不到任务」的专注记录(旧版本删任务时把 task_id 清零留下的残骸、
* 以及没选任务直接开始的那几轮)。它们只能堆成饼图里的「未关联任务」,
* 占一块地方又查不到是谁的,所以单独给一个清理入口。
*/
private fun confirmPurgeOrphan() {
val ctx = requireContext()
val stat = Store.orphanSessions()
val dialog = android.app.Dialog(ctx)
dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
val panel = LinearLayout(ctx).apply {
orientation = LinearLayout.VERTICAL
background = ctx.roundBg(ctx.col(R.color.surface), 16f, ctx.col(R.color.card_stroke), 1f)
setPadding(dpi(20f), dpi(20f), dpi(20f), dpi(14f))
}
panel.addView(TextView(ctx).apply {
text = getString(R.string.purge_orphan)
textSize = 16f
typeface = Typeface.DEFAULT_BOLD
setTextColor(col(R.color.text))
})
panel.addView(TextView(ctx).apply {
text = if (stat.count > 0) {
getString(R.string.purge_confirm, stat.count, Dates.duration(stat.seconds))
} else {
getString(R.string.purge_none)
}
textSize = 14f
setTextColor(col(R.color.text_secondary))
setPadding(0, dpi(10f), 0, dpi(6f))
})
val btnRow = LinearLayout(ctx).apply {
orientation = LinearLayout.HORIZONTAL
gravity = Gravity.END
setPadding(0, dpi(12f), 0, 0)
}
fun btn(labelRes: Int, danger: Boolean, onClick: () -> Unit) = TextView(ctx).apply {
text = getString(labelRes)
textSize = 14f
typeface = Typeface.DEFAULT_BOLD
gravity = Gravity.CENTER
setTextColor(col(if (danger) R.color.danger else R.color.brand))
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
setPadding(dpi(22f), dpi(10f), dpi(22f), dpi(10f))
setOnClickListener { onClick() }
}
btnRow.addView(btn(R.string.cancel, false) { dialog.dismiss() })
btnRow.addView(btn(R.string.delete, true) {
dialog.dismiss()
if (stat.count > 0) Store.purgeOrphanSessions()
(activity as? MainActivity)?.refreshAll()
build()
}, LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT).apply {
marginStart = dpi(10f)
})
panel.addView(btnRow)
dialog.setContentView(panel)
dialog.show()
}
private fun confirmClear() {
val ctx = requireContext()
val dialog = android.app.Dialog(ctx)
@@ -539,6 +607,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
}
companion object {
const val VERSION = "3.13"
const val VERSION = "3.14"
}
}