v0.3.0:今日筛选含逾期与今日完成、统计今日区间、重复任务自动滚动、通知自定义布局

This commit is contained in:
XIGE
2026-11-28 01:07:24 +08:00
parent 7c8dc3d0de
commit 3e237fafdb
11 changed files with 301 additions and 56 deletions

View File

@@ -28,8 +28,9 @@ import java.util.Calendar
/**
* 统计页。
*
* 三层信息:今天(我要不要现在开始)→ 本周趋势(这周还行不行)→ 累计与项目分布
* (时间到底花在哪)。三个区间的切换只影响趋势与分布,不改变"今日"卡片。
* 三层信息:今天(我要不要现在开始)→ 区间趋势(这周/这月还行不行)→ 累计与分布
* (时间到底花在哪)。四个区间(今日 / 本周 / 本月 / 全部)切换只影响趋势与两处分布,
* 不改变最上方的"今日"卡片——它永远是今天。
*/
class StatsFragment : Fragment(R.layout.fragment_stats) {
@@ -50,10 +51,12 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
private lateinit var donutTask: DonutView
private lateinit var taskLegend: LinearLayout
private lateinit var summaryGrid: LinearLayout
private lateinit var segToday: TextView
private lateinit var segWeek: TextView
private lateinit var segMonth: TextView
private lateinit var segAll: TextView
/** 0 今日 / 1 本周 / 2 本月 / 3 全部 */
private var range = 0
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -75,13 +78,15 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
donutTask = view.findViewById(R.id.donutTask)
taskLegend = view.findViewById(R.id.taskLegend)
summaryGrid = view.findViewById(R.id.summaryGrid)
segToday = view.findViewById(R.id.segToday)
segWeek = view.findViewById(R.id.segWeek)
segMonth = view.findViewById(R.id.segMonth)
segAll = view.findViewById(R.id.segAll)
segWeek.setOnClickListener { switchRange(0) }
segMonth.setOnClickListener { switchRange(1) }
segAll.setOnClickListener { switchRange(2) }
segToday.setOnClickListener { switchRange(0) }
segWeek.setOnClickListener { switchRange(1) }
segMonth.setOnClickListener { switchRange(2) }
segAll.setOnClickListener { switchRange(3) }
buildHeatLegend()
reload()
@@ -118,7 +123,7 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
val ctx = requireContext()
val onText = ctx.col(R.color.title)
val offText = ctx.col(R.color.text_secondary)
listOf(segWeek, segMonth, segAll).forEachIndexed { i, tv ->
listOf(segToday, segWeek, segMonth, segAll).forEachIndexed { i, tv ->
val selected = i == range
tv.background = if (selected) {
ContextCompat.getDrawable(ctx, R.drawable.bg_segment_on)
@@ -143,20 +148,35 @@ class StatsFragment : Fragment(R.layout.fragment_stats) {
}
private fun rangeStart(): Long = when (range) {
0 -> Dates.weekStart()
1 -> Store.monthStart()
0 -> Dates.todayStart()
1 -> Dates.weekStart()
2 -> Store.monthStart()
else -> 0L
}
private fun renderTrend() {
barChart.labelStep = 0
if (range == 0) {
// 今日:按小时看节奏,24 根柱子,标签每 6 小时一次
val series = Store.hourlySeries(Dates.todayStart())
barChart.labelStep = 6
barChart.setData(series)
val totalMinutes = series.sumOf { it.minutes }
tvTrendTotal.text = if (totalMinutes <= 0) {
getString(R.string.no_data)
} else {
"共 ${Dates.duration(totalMinutes * 60)}"
}
return
}
val from: Long
val days: Int
when (range) {
0 -> {
1 -> {
from = Dates.weekStart()
days = (((Dates.todayStart() - from) / 86_400_000L).toInt() + 1).coerceIn(1, 7)
}
1 -> {
2 -> {
from = Store.monthStart()
val c = Calendar.getInstance()
days = c.get(Calendar.DAY_OF_MONTH).coerceIn(1, 31)