lmw
2023-06-13 4b7d8d9a038f6522df46d0f14fa07eb940a1b34d
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
package com.kuanzhai.driver.ui.driver_server.adapter
 
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.clickDelay
import cn.sinata.xldutils.utils.gone
import com.kuanzhai.driver.R
import com.kuanzhai.driver.base.BaseRvAdapter
import com.kuanzhai.driver.base.BaseViewHolder
import com.kuanzhai.driver.bean.CarCommendListData
import com.kuanzhai.driver.utils.DateUtil
import com.kuanzhai.driver.utils.glide.GlideUtil
import kotlinx.android.synthetic.main.item_car_commend.view.*
 
class CarCommendAdapter:BaseRvAdapter<CarCommendListData>() {
    override fun getLayoutResId(viewType: Int): Int {
        return R.layout.item_car_commend
    }
 
    override fun onBindItem(holder: BaseViewHolder?, view: View?, item: CarCommendListData?) {
        holder?.itemView?.apply {
            var adapter = CarCommendRepairAdapter()
            recycler_view_repair.layoutManager = LinearLayoutManager(context)
            recycler_view_repair.adapter = adapter
            adapter.maxLength =  if (item!!.showDetail || (!item!!.replyCommentList.isNullOrEmpty() && item!!.replyCommentList.size <= 3)) -1 else 3
            adapter.data.addAll(item!!.replyCommentList)
            adapter.notifyDataSetChanged()
            GlideUtil.loady(context,item!!.userAvatar,iv_head)
            tv_name.text = item.userName
            var isOpenComment = item.content.length > 65
//            tv_content_commend.text = if (isOpenComment) item.content.substring(0,64)+"..." else item.content
            tv_content_commend.text = item.content
 
            tv_all_content.visibility = if (isOpenComment) View.VISIBLE else View.GONE
            tv_all_content.clickDelay {
                tv_content_commend.maxLines = 1000
                tv_content_commend.text = item.content
                tv_all_content.gone()
            }
            var timeLong = DateUtil.dateToStamp(DateUtil.TYPE0,item.getCreateTime1())
            tv_time.text = DateUtil.getTime(DateUtil.TYPE3,timeLong,true)
            tv_repair.visibility = if (!item!!.replyCommentList.isNullOrEmpty() && item!!.replyCommentList.size > 3 && !item.showDetail && adapter.maxLength == 3) View.VISIBLE else View.GONE
            tv_repair.text = "展开"+(item!!.replyCommentList.size - 3)+"条回复"
            tv_repair.clickDelay {
                tv_repair.gone()
                item.showDetail = true
                notifyDataSetChanged()
                adapter.data.clear()
                adapter.data.addAll(item!!.replyCommentList)
                adapter.maxLength = -1
                adapter.notifyDataSetChanged()
            }
 
            tv_comment.clickDelay {
                commentMain?.comment(item,holder.adapterPosition)
            }
 
            adapter.replyComment = object : CarCommendRepairAdapter.ReplyComment{
                override fun commentReply(itemReply: CarCommendListData) {
                    commentMain?.commentReply(item,itemReply,holder.adapterPosition)
                }
 
            }
        }
    }
 
    var commentMain:CommentMain? = null
 
    interface CommentMain{
        fun comment(item: CarCommendListData,poisition:Int)
        fun commentReply(mainItem:CarCommendListData,replyItem:CarCommendListData,poisition:Int)
    }
}