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)
|
}
|
}
|
|
|
}
|