项目列表点击就地展开任务与统计,任务页零改动(v3.0)
This commit is contained in:
@@ -1,30 +1,44 @@
|
||||
package com.focusbox.app.ui.projects
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Paint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.focusbox.app.R
|
||||
import com.focusbox.app.model.Project
|
||||
import com.focusbox.app.model.ProjectTaskStat
|
||||
import com.focusbox.app.model.Task
|
||||
import com.focusbox.app.util.Dates
|
||||
import com.focusbox.app.util.col
|
||||
import com.focusbox.app.util.roundBg
|
||||
import com.focusbox.app.util.tint
|
||||
import com.focusbox.app.util.visible
|
||||
|
||||
/**
|
||||
* 项目列表:点击项目头就地展开该项目下的任务,不再跳转任务页。
|
||||
* 展开区只展示统计,交互只有右侧「开始」——编辑/勾选仍走原任务页,任务页逻辑不动。
|
||||
*/
|
||||
class ProjectAdapter(
|
||||
private val onClick: (Project) -> Unit,
|
||||
private val onToggleExpand: (Project) -> Unit,
|
||||
private val onLongClick: (Project) -> Unit,
|
||||
private val onMore: (Project) -> Unit,
|
||||
private val onStart: (Task) -> Unit,
|
||||
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
|
||||
|
||||
private var items: List<Project> = emptyList()
|
||||
private var expandedId: Long = -1L
|
||||
private var stats: Map<Long, List<ProjectTaskStat>> = emptyMap()
|
||||
|
||||
fun submit(list: List<Project>) {
|
||||
fun submit(list: List<Project>, expanded: Long, taskStats: Map<Long, List<ProjectTaskStat>>) {
|
||||
items = list
|
||||
expandedId = expanded
|
||||
stats = taskStats
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
@@ -41,13 +55,16 @@ class ProjectAdapter(
|
||||
private val progress: ProgressBar = v.findViewById(R.id.progress)
|
||||
private val colorBar: View = v.findViewById(R.id.colorBar)
|
||||
private val more: ImageView = v.findViewById(R.id.btnMore)
|
||||
private val header: View = v.findViewById(R.id.projectHeader)
|
||||
private val taskList: LinearLayout = v.findViewById(R.id.taskList)
|
||||
private val tvTaskEmpty: TextView = v.findViewById(R.id.tvTaskEmpty)
|
||||
|
||||
fun bind(p: Project) {
|
||||
val ctx = itemView.context
|
||||
name.text = p.name
|
||||
colorBar.background = ctx.roundBg(p.color, 2f)
|
||||
|
||||
// 只看任务与时长,不再显示番茄数
|
||||
// 只看任务与时长,不再显示番茄数(与改动前一致)
|
||||
val parts = ArrayList<String>(3)
|
||||
parts.add("${p.openTasks} 待办")
|
||||
if (p.doneTasks > 0) parts.add("${p.doneTasks} 已完成")
|
||||
@@ -61,11 +78,58 @@ class ProjectAdapter(
|
||||
more.tint(ctx.col(R.color.text_tertiary))
|
||||
more.setOnClickListener { onMore(p) }
|
||||
|
||||
itemView.setOnClickListener { onClick(p) }
|
||||
itemView.setOnLongClickListener {
|
||||
header.setOnClickListener { onToggleExpand(p) }
|
||||
header.setOnLongClickListener {
|
||||
onLongClick(p)
|
||||
true
|
||||
}
|
||||
|
||||
val expanded = expandedId == p.id
|
||||
val rows = if (expanded) stats[p.id].orEmpty() else emptyList()
|
||||
taskList.visible(expanded && rows.isNotEmpty())
|
||||
tvTaskEmpty.visible(expanded && rows.isEmpty())
|
||||
if (!expanded) return
|
||||
|
||||
taskList.removeAllViews()
|
||||
rows.forEach { row ->
|
||||
val item = LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.item_project_task, taskList, false)
|
||||
bindTaskRow(item, row, p)
|
||||
taskList.addView(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindTaskRow(item: View, row: ProjectTaskStat, p: Project) {
|
||||
val ctx = item.context
|
||||
val task = row.task
|
||||
val tvTitle: TextView = item.findViewById(R.id.tvTaskTitle)
|
||||
val tvMeta: TextView = item.findViewById(R.id.tvTaskMeta)
|
||||
val btnPlay: ImageView = item.findViewById(R.id.btnTaskPlay)
|
||||
item.findViewById<View>(R.id.taskColorBar).background = ctx.roundBg(p.color, 2f)
|
||||
|
||||
tvTitle.text = task.title
|
||||
tvTitle.setTextColor(ctx.col(if (task.done) R.color.text_tertiary else R.color.text))
|
||||
tvTitle.paintFlags = if (task.done) {
|
||||
tvTitle.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG
|
||||
} else {
|
||||
tvTitle.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
|
||||
}
|
||||
|
||||
// 三项统计:单轮时长 · 最近完成时间 · 累计完成次数;不显示分类(项目名)
|
||||
val parts = ArrayList<String>(3)
|
||||
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))
|
||||
}
|
||||
if (row.doneCount > 0) {
|
||||
parts.add(ctx.getString(R.string.project_task_done_count, row.doneCount))
|
||||
}
|
||||
tvMeta.text = parts.joinToString(" · ")
|
||||
|
||||
btnPlay.visible(!task.done)
|
||||
btnPlay.tint(ctx.col(R.color.brand))
|
||||
btnPlay.setOnClickListener { onStart(task) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user