Files
FocusBox/src/main/java/com/focusbox/app/ui/projects/ProjectAdapter.kt
XIGE d52deeff5e 导入 v0.1.0 / v0.2.0 源码:五模块首版、交互重构、重复任务、任务分布
- 源码镜像 src/main(81 个文件):首页双模式、任务、项目、统计、设置
- 补齐 README / LICENSE / CHANGELOG / CONTRIBUTING / .gitignore
- 不含构建配置、签名材料、编译产物与备份数据
2026-11-28 00:25:22 +08:00

72 lines
2.6 KiB
Kotlin

package com.focusbox.app.ui.projects
import android.content.res.ColorStateList
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
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.util.Dates
import com.focusbox.app.util.col
import com.focusbox.app.util.roundBg
import com.focusbox.app.util.tint
class ProjectAdapter(
private val onClick: (Project) -> Unit,
private val onLongClick: (Project) -> Unit,
private val onMore: (Project) -> Unit,
) : RecyclerView.Adapter<ProjectAdapter.VH>() {
private var items: List<Project> = emptyList()
fun submit(list: List<Project>) {
items = list
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH =
VH(LayoutInflater.from(parent.context).inflate(R.layout.item_project, parent, false))
override fun getItemCount(): Int = items.size
override fun onBindViewHolder(holder: VH, position: Int) = holder.bind(items[position])
inner class VH(v: View) : RecyclerView.ViewHolder(v) {
private val name: TextView = v.findViewById(R.id.tvName)
private val meta: TextView = v.findViewById(R.id.tvMeta)
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)
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} 已完成")
if (p.focusSeconds >= 60) parts.add(Dates.duration(p.focusSeconds))
meta.text = parts.joinToString(" · ")
progress.progress = (p.progress * 100).toInt()
progress.progressTintList = ColorStateList.valueOf(p.color)
progress.progressBackgroundTintList = ColorStateList.valueOf(ctx.col(R.color.ring_track))
more.tint(ctx.col(R.color.text_tertiary))
more.setOnClickListener { onMore(p) }
itemView.setOnClickListener { onClick(p) }
itemView.setOnLongClickListener {
onLongClick(p)
true
}
}
}
}