18034727885
2026-04-27 3a4c1bbb2cf4fb1cdda8a5061b0674f30e7456b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.example.smart.ui.plan.adapter
 
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.graphics.drawable.DrawableCompat
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.example.basecore.util.SchemeUtils
import com.example.basecore.util.showOnlyToast
import com.example.smart.R
import com.example.smart.enumlist.CheckTaskState
import com.example.smart.ui.plan.data.CheckTaskBean
import com.example.smart.util.projectScheme
 
 
class PlanDetailsAdapter(private val mContext: Context, val data: ArrayList<CheckTaskBean>,
                         private val planId: String) :
    Adapter<PlanDetailsAdapter.PageViewHolder>() {
 
 
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PageViewHolder {
        return PageViewHolder(
            LayoutInflater.from(mContext).inflate(R.layout.item_plan_detail_page, parent, false)
        )
    }
 
    override fun getItemCount() = data.size
    override fun onBindViewHolder(holder: PageViewHolder, position: Int) {
 
        val itemInfo = data[position]
        holder.titleTv.text = itemInfo.project.name
        holder.introTv.text = itemInfo.location
        holder.statusTv.text = itemInfo.state.desc
 
        holder.statusTv.setTextColor(mContext.resources.getColor(R.color.white))
        // 为statusTv增加圆角背景
        holder.statusTv.setBackgroundResource(R.drawable.bg_item)
 
        // 为statusTv增加padding
        holder.statusTv.setPadding(20, 5, 20, 5)
 
        // 设置背景颜色
        val drawable = holder.statusTv.background
        val wrappedDrawable = DrawableCompat.wrap(drawable)
        DrawableCompat.setTint(wrappedDrawable, itemInfo.state.color)
        holder.statusTv.background = wrappedDrawable
 
        val scheme = projectScheme + "?task_id=" + itemInfo.id + "&plan_id=" + planId + "&project_id=" + itemInfo.project.id
        val bundle = Bundle()
        holder.itemView.setOnClickListener {
            if (itemInfo.state.name == CheckTaskState.Init.name) {
                mContext.showOnlyToast("该任务未开始")
            } else{
                SchemeUtils.openSchemeWithParam(mContext, scheme, bundle)
            }
        }
    }
 
    fun notifyData(dataList: List<CheckTaskBean>) {
        data.clear()
        data.addAll(dataList)
        notifyDataSetChanged()
    }
 
    fun clearData() {
        data.clear()
        notifyDataSetChanged()
    }
 
 
    inner class PageViewHolder(itemView: View) : ViewHolder(itemView) {
 
        val titleTv: TextView
        val introTv: TextView
        val statusTv: TextView
 
        init {
            titleTv = itemView.findViewById(R.id.title_tv)
            introTv = itemView.findViewById(R.id.intro_tv)
            statusTv = itemView.findViewById(R.id.status_tv)
        }
    }
 
 
}