v3.18 按审查报告修缺陷:口径统一、生命周期补漏、读数与百分比修正
- 项目时长/次数改为按任务当前项目统计,与统计页分布一致 - 进度条不再把重复任务跑一轮算成完成 - 清空数据补清 t_task/t_project 等并解绑内存任务 - 进程被杀补记同时写完成记录;结束本轮清空暂存备注 - 通知「结束」先前台化再 stopSelf - 正计时锁屏读数按需刷新;悬浮窗 addView 失败先 removeView - 百分比统一 <1%、分布卡加大下界、清空后刷新专注页 - 删除死代码与 41 个未引用字符串,计时状态一次落盘
This commit is contained in:
@@ -270,6 +270,9 @@ class MainActivity : AppCompatActivity() {
|
||||
is TasksFragment -> f.reload()
|
||||
is ProjectsFragment -> f.reload()
|
||||
is StatsFragment -> f.reload()
|
||||
// 专注页缓存着任务名与项目色,清空/批量改动后必须重读,
|
||||
// 否则切过去还挂着已经被删掉的任务(要等进程重启才消失)
|
||||
is FocusFragment -> f.reloadTask()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +198,12 @@ class FocusFragment : Fragment(R.layout.fragment_focus) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 数据被清空或批量改动后由 Activity 调用:丢掉任务缓存并按当前状态重画 */
|
||||
fun reloadTask() {
|
||||
cachedTaskId = Long.MIN_VALUE
|
||||
if (view != null) render()
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 绘制
|
||||
|
||||
private fun buildPageDots() {
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.focusbox.app.ui.projects
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Typeface
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.StrikethroughSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -82,16 +85,31 @@ class ProjectAdapter(
|
||||
colorBar.background = ctx.roundBg(p.color, 2f)
|
||||
|
||||
// 项目页统计口径(全周期累计,不是今日,也没有时间上限):
|
||||
// 类型 = 项目新增的类型标签(工作/学习/娱乐/提升或自定义),排在任务数前面,
|
||||
// 用项目色加粗,与左侧色条呼应;未设置类型时不占位;
|
||||
// 任务数 = 项目下创建的任务本体(不含重复实例/完成记录副本);
|
||||
// 已完成 = 真实跑完的专注次数(sessions.completed = 1 的条数),
|
||||
// 重复任务每完成一轮就 +1,和「累计时长」同源;
|
||||
// 手动勾选完成、周期滚动时的自动完成都没有专注记录,不计入;
|
||||
// 时长 = 该项目全部专注记录秒数之和。
|
||||
val parts = ArrayList<String>(3)
|
||||
val parts = ArrayList<String>(4)
|
||||
val typeText = p.type.trim()
|
||||
if (typeText.isNotEmpty()) parts.add(typeText)
|
||||
parts.add(ctx.getString(R.string.project_tasks_total, p.totalTasks))
|
||||
if (p.pomodoros > 0) parts.add(ctx.getString(R.string.project_tasks_done, p.pomodoros))
|
||||
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
|
||||
meta.text = parts.joinToString(" · ")
|
||||
val metaLine = SpannableString(parts.joinToString(" · "))
|
||||
if (typeText.isNotEmpty()) {
|
||||
metaLine.setSpan(
|
||||
ForegroundColorSpan(p.color), 0, typeText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
)
|
||||
metaLine.setSpan(
|
||||
StyleSpan(Typeface.BOLD), 0, typeText.length,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
)
|
||||
}
|
||||
meta.text = metaLine
|
||||
|
||||
progress.progress = (p.progress * 100).toInt()
|
||||
progress.progressTintList = ColorStateList.valueOf(p.color)
|
||||
@@ -156,7 +174,7 @@ class ProjectAdapter(
|
||||
|
||||
// 任务时间(专注时长)· 最近完成 · 累计次数与累计专注
|
||||
val parts = ArrayList<String>(3)
|
||||
parts.add("${task.focusMinutes}分钟")
|
||||
parts.add(ctx.getString(R.string.minutes_value, task.focusMinutes))
|
||||
if (row.lastDoneAt > 0) {
|
||||
val whenText = "${Dates.md(row.lastDoneAt)}·${Dates.hm(row.lastDoneAt)}"
|
||||
parts.add(ctx.getString(R.string.project_task_last_done, whenText))
|
||||
@@ -167,7 +185,7 @@ class ProjectAdapter(
|
||||
}
|
||||
if (row.focusSeconds > 0) {
|
||||
// 累计专注只写「数字分钟」,不加说明文案,也不留空格
|
||||
totals.append(row.focusSeconds / 60).append("分钟")
|
||||
totals.append(ctx.getString(R.string.minutes_value, row.focusSeconds / 60))
|
||||
}
|
||||
if (totals.isNotEmpty()) parts.add(totals.toString())
|
||||
tvMeta.text = parts.joinToString(" · ")
|
||||
@@ -213,10 +231,17 @@ class ProjectAdapter(
|
||||
|
||||
// 与任务页完成记录同格式:日期 周几 起-止 · 专注X;没有真实时长就只写完成时刻
|
||||
tvMeta.text = if (record.seconds > 0) {
|
||||
"${Dates.dateWithWeek(record.startAt)} ${Dates.hms(record.startAt)}" +
|
||||
"-${Dates.hms(record.endAt)} · 专注${Dates.duration(record.seconds)}"
|
||||
ctx.getString(
|
||||
R.string.done_meta,
|
||||
"${Dates.dateWithWeek(record.startAt)} ${Dates.hms(record.startAt)}" +
|
||||
"-${Dates.hms(record.endAt)}",
|
||||
Dates.duration(record.seconds),
|
||||
)
|
||||
} else {
|
||||
"${Dates.dateWithWeek(record.endAt)} ${Dates.hms(record.endAt)}完成"
|
||||
ctx.getString(
|
||||
R.string.done_at_only,
|
||||
"${Dates.dateWithWeek(record.endAt)} ${Dates.hms(record.endAt)}",
|
||||
)
|
||||
}
|
||||
item.isClickable = false
|
||||
item.setOnClickListener(null)
|
||||
|
||||
@@ -94,8 +94,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
if (expandedProjectId != -1L && shown.none { it.id == expandedProjectId }) {
|
||||
expandedProjectId = -1L
|
||||
}
|
||||
taskStats = shown.associate { it.id to Store.projectTaskRows(it.id) }
|
||||
completions = shown.associate { it.id to Store.projectCompletions(it.id) }
|
||||
// 只给展开的那一个项目取统计:两条都是递归 CTE,对全部项目逐个跑一遍
|
||||
// 是纯浪费(未展开的项目根本不会渲染这些行)
|
||||
val expanded = expandedProjectId
|
||||
taskStats = if (expanded == -1L) emptyMap() else mapOf(expanded to Store.projectTaskRows(expanded))
|
||||
completions = if (expanded == -1L) emptyMap() else mapOf(expanded to Store.projectCompletions(expanded))
|
||||
adapter.submit(shown, expandedProjectId, taskStats, completions, showDoneInProject)
|
||||
|
||||
tvSummary.text = getString(
|
||||
@@ -107,7 +110,11 @@ class ProjectsFragment : Fragment(R.layout.fragment_projects) {
|
||||
btnArchived.visible(false)
|
||||
} else {
|
||||
btnArchived.visible(true)
|
||||
btnArchived.text = if (showArchived) "隐藏已归档" else "已归档${archived.size}"
|
||||
btnArchived.text = if (showArchived) {
|
||||
getString(R.string.hide_archived)
|
||||
} else {
|
||||
getString(R.string.archived_count, archived.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -282,21 +282,39 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
minimumHeight = dpi(54f)
|
||||
if (onClick != null) setOnClickListener { onClick() }
|
||||
}
|
||||
// 标题固定单行、按内容取宽。原来的写法是标题吃 weight = 1,
|
||||
// 值一长(「工作、学习、娱乐、提升」)就把标题挤到只剩几十像素,
|
||||
//「类型设置」被迫折成两行,右边再跟一个被省略号截断的值,很难看。
|
||||
row.addView(TextView(ctx).apply {
|
||||
text = title
|
||||
textSize = 15f
|
||||
setTextColor(col(if (danger) R.color.danger else R.color.text))
|
||||
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)
|
||||
isSingleLine = true
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
)
|
||||
})
|
||||
if (value.isNotEmpty()) {
|
||||
row.addView(TextView(ctx).apply {
|
||||
text = value
|
||||
textSize = 13f
|
||||
gravity = Gravity.END or Gravity.CENTER_VERTICAL
|
||||
setTextColor(col(R.color.text_secondary))
|
||||
setPadding(0, 0, dpi(6f), 0)
|
||||
// 值可能是「工作、学习、娱乐、提升」这种长串,单行省略,别把右边箭头挤出去
|
||||
setPadding(dpi(12f), 0, dpi(6f), 0)
|
||||
// 值只吃剩余宽度:单行、末尾省略;完整内容点整行在弹窗里看
|
||||
maxLines = 1
|
||||
ellipsize = android.text.TextUtils.TruncateAt.END
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
0,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
1f,
|
||||
)
|
||||
})
|
||||
} else {
|
||||
// 没有值的行补一个弹性占位,否则箭头会紧贴标题
|
||||
row.addView(View(ctx).apply {
|
||||
layoutParams = LinearLayout.LayoutParams(0, 1, 1f)
|
||||
})
|
||||
}
|
||||
if (showArrow) {
|
||||
@@ -702,6 +720,9 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
TimerCore.reset()
|
||||
Store.clearAll()
|
||||
Prefs.clearTimer()
|
||||
// 内存里的绑定也要解掉:只清磁盘的话,下一次开始专注仍带着旧 taskId 落库,
|
||||
// 会立刻写出一条指向已删除任务行的「未关联记录」
|
||||
TimerCore.setTask(0, 0)
|
||||
Prefs.timerRound = 0
|
||||
TimerCore.resetRound()
|
||||
(activity as? MainActivity)?.refreshAll()
|
||||
@@ -716,6 +737,6 @@ class SettingsFragment : Fragment(R.layout.fragment_settings) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val VERSION = "3.17"
|
||||
const val VERSION = "3.18"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ 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.util.percentText
|
||||
import com.focusbox.app.widget.LabelDonutView
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* 「项目分布 / 任务分布」卡片:自带 日 / 周 / 月 / 年 四档与左右翻页。
|
||||
@@ -226,13 +226,11 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
includeFontPadding = false
|
||||
})
|
||||
|
||||
val pct = slice.seconds * 100f / total
|
||||
val pctText = if (pct < 1f) "<1%" else "${pct.roundToInt()}%"
|
||||
text.addView(TextView(context).apply {
|
||||
this.text = context.getString(
|
||||
R.string.legend_meta,
|
||||
Dates.duration(slice.seconds),
|
||||
pctText,
|
||||
percentText(slice.seconds, total),
|
||||
)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, 11f)
|
||||
setTextColor(context.col(R.color.text_secondary))
|
||||
@@ -255,6 +253,7 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
|
||||
private fun shift(delta: Int) {
|
||||
if (delta > 0 && !canNext()) return
|
||||
if (delta < 0 && !canPrev()) return
|
||||
val s = start()
|
||||
anchor = when (scale) {
|
||||
Scale.DAY -> Dates.addDays(s, delta)
|
||||
@@ -284,6 +283,16 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
/** 未来没有记录,往后翻到当前周期为止 */
|
||||
private fun canNext(): Boolean = start() < periodStart(Dates.todayStart())
|
||||
|
||||
/**
|
||||
* 最早一条记录所在的周期:再往前必然是空图。
|
||||
* 原来左箭头没有下界,按「日」一路连点能翻到 1970 年。
|
||||
*/
|
||||
private fun canPrev(): Boolean {
|
||||
val earliest = Store.earliestSessionAt()
|
||||
if (earliest <= 0L) return false
|
||||
return start() > periodStart(earliest)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 渲染
|
||||
|
||||
fun refresh() {
|
||||
@@ -312,6 +321,7 @@ class PeriodDistributionCard @JvmOverloads constructor(
|
||||
tvPeriod.text = periodLabel(from, to)
|
||||
applySegments()
|
||||
btnNext.alpha = if (canNext()) 1f else 0.2f
|
||||
btnPrev.alpha = if (canPrev()) 1f else 0.2f
|
||||
}
|
||||
|
||||
private fun periodLabel(from: Long, to: Long): String = when (scale) {
|
||||
|
||||
@@ -126,7 +126,7 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
tvTrendTotal.text = if (totalMinutes <= 0) {
|
||||
getString(R.string.no_data)
|
||||
} else {
|
||||
"共${Dates.duration(totalMinutes * 60)}"
|
||||
getString(R.string.trend_total, Dates.duration(totalMinutes * 60))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
val series = Store.dailySeries(Dates.addDays(Dates.todayStart(), -83), 84)
|
||||
heatmap.setData(series)
|
||||
val activeDays = series.count { it.minutes > 0 }
|
||||
tvHeatHint.text = "近12周 · ${activeDays}天有记录"
|
||||
tvHeatHint.text = getString(R.string.heat_hint, activeDays)
|
||||
}
|
||||
|
||||
private fun buildHeatLegend() {
|
||||
val ctx = requireContext()
|
||||
heatLegend.removeAllViews()
|
||||
heatLegend.addView(label("少"))
|
||||
heatLegend.addView(label(getString(R.string.heat_less)))
|
||||
for (i in 0..4) {
|
||||
val box = View(ctx)
|
||||
val lp = LinearLayout.LayoutParams(dpi(11f), dpi(11f))
|
||||
@@ -150,7 +150,7 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
|
||||
box.background = ctx.roundBg(ctx.col(heatColorRes(i)), 3f)
|
||||
heatLegend.addView(box)
|
||||
}
|
||||
heatLegend.addView(label("多"))
|
||||
heatLegend.addView(label(getString(R.string.heat_more)))
|
||||
}
|
||||
|
||||
private fun heatColorRes(index: Int): Int = when (index) {
|
||||
|
||||
@@ -121,6 +121,11 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
||||
fun reload() {
|
||||
if (view == null) return
|
||||
projects = Store.projects()
|
||||
// 项目被删掉后,上次选的筛选 id 会一直留在 Prefs 里:列表恒为空,
|
||||
// 摘要又因为找不到项目名回落成「全部」,看起来像"什么都没筛却什么都没有"
|
||||
if (filterProjectId > 0 && projects.none { it.id == filterProjectId }) {
|
||||
filterProjectId = 0L
|
||||
}
|
||||
renderFilters()
|
||||
renderFilterSummary()
|
||||
|
||||
@@ -402,17 +407,24 @@ class TasksFragment : Fragment(R.layout.fragment_tasks) {
|
||||
if (task.logSeconds > 0 && task.originId > 0 && task.doneAt > task.createdAt) {
|
||||
val range = "${Dates.dateWithWeek(task.createdAt)} " +
|
||||
"${Dates.hms(task.createdAt)}-${Dates.hms(task.doneAt)}"
|
||||
return "$range · 专注${Dates.duration(task.logSeconds)}"
|
||||
return getString(R.string.done_meta, range, Dates.duration(task.logSeconds))
|
||||
}
|
||||
val span = spans[task.id]
|
||||
if (span != null) {
|
||||
val range = "${Dates.dateWithWeek(span.startAt)} " +
|
||||
"${Dates.hms(span.startAt)}-${Dates.hms(span.endAt)}"
|
||||
// 记录里存的是实际专注秒数(不含暂停),不能拿起止时间差冒充
|
||||
return if (span.seconds > 0) "$range · 专注${Dates.duration(span.seconds)}" else range
|
||||
return if (span.seconds > 0) {
|
||||
getString(R.string.done_meta, range, Dates.duration(span.seconds))
|
||||
} else {
|
||||
range
|
||||
}
|
||||
}
|
||||
if (task.doneAt > 0) {
|
||||
return "${Dates.dateWithWeek(task.doneAt)} ${Dates.hms(task.doneAt)}"
|
||||
return getString(
|
||||
R.string.done_at_only,
|
||||
"${Dates.dateWithWeek(task.doneAt)} ${Dates.hms(task.doneAt)}",
|
||||
)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user