v3.17 类型分布、完成任务口径、重复任务删除修复
- 专注页选任务不再自动开跑,底部文案改为「请选择任务后开始专注」 - 项目新增 type 字段(DB v10),设置页可配置类型,统计页新增类型分布卡 - 今日完成任务只统计真实专注(sessions.completed=1 且 seconds>0) - 重复任务删除不再复活:只从真根滚动、完成副本不写悬空 origin、 新增 pruneDanglingInstances 清理断链残渣、滚动前校验根存在
This commit is contained in:
@@ -498,8 +498,8 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
||||
* [projectId] 是刚才在第二步看到的那个项目 —— 用户都已经点进这个项目的任务列表了,
|
||||
* 新建的任务必然属于它,所以弹层里直接预选好项目,不用再选一次。
|
||||
*
|
||||
* 保存成功后把新任务设为当前任务(圆环套用它设定的专注时长)并直接开始计时,
|
||||
* 与「选中已有任务」走同一条路径;取消新建则什么都不变。
|
||||
* 保存成功后把新任务设为当前任务(圆环套用它设定的专注时长),
|
||||
* 与「选中已有任务」一样停在这一页等用户点开始,方便先调时长。
|
||||
*/
|
||||
private fun createTaskAndSelect(projectId: Long) {
|
||||
val ctx = context ?: return
|
||||
@@ -509,9 +509,6 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
||||
Store.task(newId)?.let { t ->
|
||||
TimerCore.setCountUp(false)
|
||||
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
|
||||
// 走的是同一条「选任务」路径,建完也直接开跑,保持口径一致
|
||||
requestNotifPermissionIfNeeded()
|
||||
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
|
||||
Toast.makeText(ctx, R.string.task_created, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
cachedTaskId = Long.MIN_VALUE
|
||||
@@ -602,14 +599,12 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
||||
color = project?.color,
|
||||
selected = t.id == TimerCore.taskId,
|
||||
) {
|
||||
// 选中任务后回到倒计时,并把圆环切到该任务设定的时长
|
||||
// 选中任务后回到倒计时,并把圆环切到该任务设定的时长。
|
||||
// 这里**不自动开始**:选完任务常常还要上下拖动圆环调整本轮时长,
|
||||
// 一旦自动跑起来,纵向拖动就被 handleDialTouch 判为忽略(running 时才不让调)。
|
||||
TimerCore.setCountUp(false)
|
||||
TimerCore.setTask(t.id, t.projectId, t.focusMinutes)
|
||||
sheet.dismiss()
|
||||
// 选完即开跑,不用再点一次「开始专注」;
|
||||
// 没跑过就 start,暂停过的(elapsed > 0)走 resume,才会补写暂停原因
|
||||
requestNotifPermissionIfNeeded()
|
||||
if (TimerCore.elapsedNow() > 0) TimerCore.resume() else TimerCore.start()
|
||||
render()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ import com.focusbox.app.model.Project
|
||||
import com.focusbox.app.service.TimerCore
|
||||
import com.focusbox.app.ui.SheetDialog
|
||||
import com.focusbox.app.util.Palette
|
||||
import com.focusbox.app.util.Prefs
|
||||
import com.focusbox.app.util.circleBg
|
||||
import com.focusbox.app.util.dpi
|
||||
import com.focusbox.app.util.makeChip
|
||||
import com.focusbox.app.util.roundBg
|
||||
import com.focusbox.app.util.visible
|
||||
|
||||
@@ -32,9 +34,16 @@ class ProjectSheet(
|
||||
private val etSortIndex: EditText = root.findViewById(R.id.etSortIndex)
|
||||
private val swPinned: androidx.appcompat.widget.SwitchCompat = root.findViewById(R.id.swPinned)
|
||||
private val colorRow: LinearLayout = root.findViewById(R.id.colorRow)
|
||||
private val typeRow: com.focusbox.app.util.FlowLayout = root.findViewById(R.id.typeRow)
|
||||
|
||||
private var color: Int = existing?.color ?: Palette.colorAt(0)
|
||||
|
||||
/**
|
||||
* 当前选中的类型。空串表示「不设置」——老项目全部是空串,
|
||||
* 打开编辑时默认就停在「不设置」,不会因为用户只想改个名字被强行归类。
|
||||
*/
|
||||
private var type: String = existing?.type.orEmpty()
|
||||
|
||||
init {
|
||||
// 项目编辑含多个输入框:必须走满屏容器 + 键盘顶起,否则输入法会盖住弹层
|
||||
fitOnIme(root)
|
||||
@@ -50,6 +59,7 @@ class ProjectSheet(
|
||||
etSortIndex.setText(existing.sortIndex.toString())
|
||||
}
|
||||
swPinned.isChecked = (existing?.pinnedAt ?: 0L) > 0L
|
||||
renderTypes()
|
||||
renderColors()
|
||||
|
||||
val btnDelete = root.findViewById<TextView>(R.id.btnDelete)
|
||||
@@ -83,7 +93,7 @@ class ProjectSheet(
|
||||
val pinned = swPinned.isChecked
|
||||
if (existing == null) {
|
||||
// 新建置顶:置顶时间取当下,排进置顶组
|
||||
Store.addProject(name, color, sortIndex, pinned)
|
||||
Store.addProject(name, color, sortIndex, pinned, type)
|
||||
} else {
|
||||
// 已置顶且保持置顶 → 保留原置顶时间(重复保存不刷新排序);
|
||||
// 新勾置顶 → 以保存这一刻为置顶时间;取消置顶 → Store 里归 0
|
||||
@@ -92,13 +102,47 @@ class ProjectSheet(
|
||||
existing.pinnedAt > 0L -> existing.pinnedAt
|
||||
else -> System.currentTimeMillis()
|
||||
}
|
||||
Store.updateProject(existing.id, name, color, existing.archived, sortIndex, pinned, pinnedAt)
|
||||
Store.updateProject(
|
||||
existing.id, name, color, existing.archived, sortIndex, pinned, pinnedAt, type,
|
||||
)
|
||||
}
|
||||
onSaved()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型胶囊:设置页里的类型列表 + 一个「不设置」。
|
||||
*
|
||||
* 老项目不带类型,编辑时必须能保持空值;如果只给列表不给「不设置」,
|
||||
* 用户点开编辑就等于被迫归类,改回去还得再找一圈。
|
||||
* 已选但后来在设置里被删掉的类型照样显示出来(selected 为真),
|
||||
* 否则用户看不到自己原来选的是什么,一保存就被清空。
|
||||
*/
|
||||
private fun renderTypes() {
|
||||
val ctx = context
|
||||
typeRow.removeAllViews()
|
||||
val options = ArrayList<String>(Prefs.projectTypes)
|
||||
if (type.isNotBlank() && !options.contains(type)) options.add(0, type)
|
||||
|
||||
val none = ctx.makeChip(ctx.getString(R.string.project_type_none), type.isBlank())
|
||||
none.setOnClickListener {
|
||||
type = ""
|
||||
renderTypes()
|
||||
}
|
||||
typeRow.addView(none)
|
||||
|
||||
options.forEach { name ->
|
||||
val chip = ctx.makeChip(name, name == type)
|
||||
chip.setOnClickListener {
|
||||
// 再点一次已选中的类型 = 取消归类
|
||||
type = if (type == name) "" else name
|
||||
renderTypes()
|
||||
}
|
||||
typeRow.addView(chip)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 20 色两行平铺(每行 10 个)。
|
||||
*
|
||||
|
||||
@@ -156,10 +156,10 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
when {
|
||||
which == 0 -> ProjectSheet(requireContext(), p) { reload() }.show()
|
||||
which == 1 && !isInbox -> {
|
||||
// 归档/取消归档只切 archived,序号与置顶状态原样保留
|
||||
// 归档/取消归档只切 archived,序号、置顶状态与类型原样保留
|
||||
Store.updateProject(
|
||||
p.id, p.name, p.color, !p.archived,
|
||||
p.sortIndex, p.pinnedAt > 0, p.pinnedAt,
|
||||
p.sortIndex, p.pinnedAt > 0, p.pinnedAt, p.type,
|
||||
)
|
||||
reload()
|
||||
}
|
||||
|
||||
@@ -127,6 +127,15 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
},
|
||||
)
|
||||
|
||||
section(R.string.section_types)
|
||||
card(
|
||||
// 类型只是给项目打的标签:值列表可改,改完项目弹层与统计页的类型分布立刻跟着变
|
||||
action(
|
||||
getString(R.string.type_settings),
|
||||
Prefs.projectTypes.joinToString("、"),
|
||||
) { inputProjectTypes() },
|
||||
)
|
||||
|
||||
section(R.string.section_appearance)
|
||||
card(
|
||||
action(
|
||||
@@ -285,6 +294,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
textSize = 13f
|
||||
setTextColor(col(R.color.text_secondary))
|
||||
setPadding(0, 0, dpi(6f), 0)
|
||||
// 值可能是「工作、学习、娱乐、提升」这种长串,单行省略,别把右边箭头挤出去
|
||||
maxLines = 1
|
||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
})
|
||||
}
|
||||
if (showArrow) {
|
||||
@@ -421,6 +433,98 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}, 100L)
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目类型列表:一行英文逗号分隔的文本。
|
||||
*
|
||||
* 用纯文本而不是逐条增删的列表,是因为这个字段就是"几个词",
|
||||
* 一次粘贴「工作,学习,娱乐,提升」比点四次添加更快;
|
||||
* 解析时统一 trim / 去空项 / 去重,所以中文逗号、多余空格不会存进去
|
||||
* (中文逗号会被当成普通字符,所以在说明里明确写了要用英文逗号)。
|
||||
*/
|
||||
private fun inputProjectTypes() {
|
||||
val ctx = requireContext()
|
||||
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.type_settings)
|
||||
textSize = 16f
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
setTextColor(col(R.color.text))
|
||||
})
|
||||
panel.addView(TextView(ctx).apply {
|
||||
text = getString(R.string.type_settings_hint)
|
||||
textSize = 12f
|
||||
setTextColor(col(R.color.text_tertiary))
|
||||
setPadding(0, dpi(6f), 0, 0)
|
||||
})
|
||||
val et = android.widget.EditText(ctx).apply {
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT
|
||||
setText(Prefs.projectTypes.joinToString(","))
|
||||
textSize = 15f
|
||||
setTextColor(col(R.color.text))
|
||||
setSingleLine(true)
|
||||
background = ctx.roundBg(ctx.col(R.color.surface_alt), 12f)
|
||||
setPadding(dpi(14f), dpi(12f), dpi(14f), dpi(12f))
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
).apply { topMargin = dpi(12f) }
|
||||
}
|
||||
panel.addView(et)
|
||||
et.requestFocus()
|
||||
et.setSelection(et.text.length)
|
||||
|
||||
val btnRow = LinearLayout(ctx).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.END
|
||||
setPadding(0, dpi(12f), 0, 0)
|
||||
}
|
||||
fun btn(labelRes: Int, onClick: () -> Unit) = TextView(ctx).apply {
|
||||
text = getString(labelRes)
|
||||
textSize = 14f
|
||||
typeface = Typeface.DEFAULT_BOLD
|
||||
gravity = Gravity.CENTER
|
||||
setTextColor(col(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) { dialog.dismiss() })
|
||||
btnRow.addView(btn(R.string.save) {
|
||||
val parsed = et.text.toString()
|
||||
.split(',')
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.distinct()
|
||||
if (parsed.isEmpty()) {
|
||||
// 全空等于把"类型"变成死字段,直接拦住
|
||||
et.error = getString(R.string.type_settings_empty)
|
||||
} else {
|
||||
Prefs.projectTypes = parsed
|
||||
dialog.dismiss()
|
||||
build()
|
||||
}
|
||||
}, LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
).apply { marginStart = dpi(10f) })
|
||||
panel.addView(btnRow)
|
||||
|
||||
dialog.setContentView(panel)
|
||||
dialog.show()
|
||||
et.postDelayed({
|
||||
val imm = ctx.getSystemService(android.content.Context.INPUT_METHOD_SERVICE)
|
||||
as? android.view.inputmethod.InputMethodManager
|
||||
imm?.showSoftInput(et, android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT)
|
||||
}, 100L)
|
||||
}
|
||||
|
||||
/** 悬浮窗权限:标准 Android 特殊权限,有公开检测 API 和授权页,一键直达本应用 */
|
||||
private fun openOverlayPerm() {
|
||||
val ctx = requireContext()
|
||||
@@ -612,6 +716,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "3.16"
|
||||
const val VERSION = "3.17"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.data.Store
|
||||
import com.focusbox.app.util.Dates
|
||||
import com.focusbox.app.util.Prefs
|
||||
import com.focusbox.app.util.col
|
||||
import com.focusbox.app.util.dpi
|
||||
import com.focusbox.app.widget.LabelDonutView
|
||||
@@ -37,6 +38,9 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
YEAR(R.string.scale_year),
|
||||
}
|
||||
|
||||
/** 数据源:按项目 / 按任务 / 按项目类型。三张卡结构完全一致,只有取数不同 */
|
||||
enum class Mode { PROJECT, TASK, TYPE }
|
||||
|
||||
private val tvTitle = TextView(context)
|
||||
private val segItems = ArrayList<TextView>(4)
|
||||
private val tvPeriod = TextView(context)
|
||||
@@ -57,8 +61,8 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
/** 锚点:落在目标周期内的任意时刻,实际区间由它推导 */
|
||||
private var anchor = Dates.todayStart()
|
||||
|
||||
/** true = 按任务汇总,false = 按项目汇总 */
|
||||
var byTask = false
|
||||
/** 取数口径:项目 / 任务 / 类型 */
|
||||
var mode = Mode.PROJECT
|
||||
set(value) {
|
||||
field = value
|
||||
refresh()
|
||||
@@ -286,7 +290,12 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
val from = start()
|
||||
val to = end(from)
|
||||
|
||||
val raw = if (byTask) Store.taskSlices(from, to) else Store.distribution(from, to)
|
||||
val raw = when (mode) {
|
||||
Mode.TASK -> Store.taskSlices(from, to)
|
||||
// 类型归属链路与项目一致,只是把项目换成项目的类型字段
|
||||
Mode.TYPE -> Store.typeSlices(from, to, Prefs.projectTypes)
|
||||
Mode.PROJECT -> Store.distribution(from, to)
|
||||
}
|
||||
donut.setSlices(
|
||||
raw.map {
|
||||
LabelDonutView.Slice(
|
||||
|
||||
@@ -41,6 +41,7 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
private lateinit var heatmap: HeatmapView
|
||||
private lateinit var tvHeatHint: TextView
|
||||
private lateinit var heatLegend: LinearLayout
|
||||
private lateinit var cardType: PeriodDistributionCard
|
||||
private lateinit var cardProject: PeriodDistributionCard
|
||||
private lateinit var cardTask: PeriodDistributionCard
|
||||
private lateinit var summaryGrid: LinearLayout
|
||||
@@ -62,14 +63,18 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
heatmap = view.findViewById(R.id.heatmap)
|
||||
tvHeatHint = view.findViewById(R.id.tvHeatHint)
|
||||
heatLegend = view.findViewById(R.id.heatLegend)
|
||||
cardType = view.findViewById(R.id.cardType)
|
||||
cardProject = view.findViewById(R.id.cardProject)
|
||||
cardTask = view.findViewById(R.id.cardTask)
|
||||
summaryGrid = view.findViewById(R.id.summaryGrid)
|
||||
|
||||
// 类型分布排在项目分布上方:先看"时间花在哪类事情上",再看具体项目
|
||||
cardType.cardTitle = getString(R.string.type_distribution_title)
|
||||
cardType.mode = PeriodDistributionCard.Mode.TYPE
|
||||
cardProject.cardTitle = getString(R.string.distribution_title)
|
||||
cardProject.byTask = false
|
||||
cardProject.mode = PeriodDistributionCard.Mode.PROJECT
|
||||
cardTask.cardTitle = getString(R.string.task_distribution_title)
|
||||
cardTask.byTask = true
|
||||
cardTask.mode = PeriodDistributionCard.Mode.TASK
|
||||
|
||||
buildHeatLegend()
|
||||
reload()
|
||||
@@ -90,7 +95,8 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
renderToday()
|
||||
renderTrend()
|
||||
renderHeatmap()
|
||||
// 两张分布卡各自持有区间状态,回到页面只要重新取数
|
||||
// 三张分布卡各自持有区间状态,回到页面只要重新取数
|
||||
cardType.refresh()
|
||||
cardProject.refresh()
|
||||
cardTask.refresh()
|
||||
renderSummary()
|
||||
|
||||
Reference in New Issue
Block a user