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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.kuanzhai.driver.ui.driver_server.fragment
 
import androidx.recyclerview.widget.LinearLayoutManager
import cn.sinata.xldutils.utils.clickDelay
import com.bumptech.glide.Glide
import com.kuanzhai.driver.R
import com.kuanzhai.driver.base.MyBaseFragment
import com.kuanzhai.driver.bean.*
import com.kuanzhai.driver.netUtls.Api
import com.kuanzhai.driver.netUtls.callNet
import com.kuanzhai.driver.netUtls.getMapByAny
import com.kuanzhai.driver.ui.driver_server.adapter.CarCommendAdapter
import com.kuanzhai.driver.ui.driver_server.adapter.ShowCommendDialog
import com.kuanzhai.driver.utils.Cache.CacheKey
import com.kuanzhai.driver.utils.glide.GlideUtil
import kotlinx.android.synthetic.main.fragment_car_detail_commend.*
 
class CarDetailCommendFragment : MyBaseFragment() {
    var orderId = ""
 
    var type = 1 //1=租车,2=卖车,3=招聘)
 
    val commendAdapter by lazy {
        CarCommendAdapter()
    }
 
 
    override fun layoutId(): Int {
        return R.layout.fragment_car_detail_commend
    }
 
    override fun initView() {
        recycler_view_commend.layoutManager = LinearLayoutManager(requireContext())
        recycler_view_commend.adapter = commendAdapter
        GlideUtil.loady(requireContext(),CacheKey.getUserInfo().avatar,iv_head_mine)
        refresh()
 
        ll_bottom_commend.clickDelay {
            var commendDialog = ShowCommendDialog()
            commendDialog.replyName = ""
            commendDialog.show(childFragmentManager, "id")
            commendDialog.comment = object : ShowCommendDialog.Comment {
                override fun comment(content: String) {
                    callComment(content, "") {
                        commendAdapter.data.add(0, it)
                        commendAdapter.notifyDataSetChanged()
                    }
                }
            }
        }
 
        smart_refresh_layout.setOnRefreshListener {
            refresh()
        }
 
        smart_refresh_layout.setOnLoadMoreListener {
            loadMore()
        }
 
        commendAdapter.commentMain = object : CarCommendAdapter.CommentMain {
 
 
            override fun comment(item: CarCommendListData, poisition: Int) {
                //一级评论
                var commendDialog = ShowCommendDialog()
                commendDialog.replyName = item.userName
                commendDialog.show(childFragmentManager, "id")
                commendDialog.comment = object : ShowCommendDialog.Comment {
                    override fun comment(content: String) {
                        callComment(content, item.id.toString()) {
                            commendAdapter.data[poisition].showDetail = true
                            commendAdapter.data[poisition].replyCommentList.add(it)
                            commendAdapter.notifyItemChanged(poisition)
                        }
                    }
                }
            }
 
            override fun commentReply(
                mainItem: CarCommendListData,
                replyItem: CarCommendListData, poisition: Int
            ) {
                //二级评论
                //一级评论
                var commendDialog = ShowCommendDialog()
                commendDialog.replyName = replyItem.userName
                commendDialog.show(childFragmentManager, "id")
                commendDialog.comment = object : ShowCommendDialog.Comment {
                    override fun comment(content: String) {
                        callComment(content, replyItem.id.toString()) {
                            commendAdapter.data[poisition].showDetail = true
                            commendAdapter.data[poisition].replyCommentList.add(it)
                            commendAdapter.notifyItemChanged(poisition)
                        }
                    }
                }
            }
 
        }
    }
 
    private fun callComment(
        content: String,
        commentId: String,
        function: (CarCommendListData) -> Unit
    ) {
        var map = getMapByAny()
        map["userId"] = CacheKey.getUserId()
        map["type"] = type
        map["orderId"] = orderId
        map["content"] = content
        if (commentId.isNotEmpty()) {
            map["commentId"] = commentId
 
        }
        callNet(Api.insertComment, map) {
                var bean = gson.fromJson<CarCommend>(it, CarCommend::class.java)
                function(bean.data)
        }
 
    }
 
    fun refresh() {
        pageNumber = 1
        callAllCommend() {
            commendAdapter.data.clear()
            commendAdapter.data.addAll(it)
            commendAdapter.notifyDataSetChanged()
            smart_refresh_layout.finishRefresh()
            smart_refresh_layout.finishLoadMore()
        }
    }
 
    fun loadMore() {
        pageNumber++
        callAllCommend() {
            commendAdapter.data.addAll(it)
            commendAdapter.notifyDataSetChanged()
            smart_refresh_layout.finishRefresh()
            smart_refresh_layout.finishLoadMore()
        }
    }
 
 
    private fun callAllCommend(function: (List<CarCommendListData>) -> Unit) {
        var map = getMapByAny()
        map["orderId"] = orderId
        map["pageNum"] = pageNumber
        map["size"] = 10
        map["type"] = type
        callNet(Api.getCommentList, map) {
            var bean = gson.fromJson<CarCommendList>(it, CarCommendList::class.java)
            function(bean.data)
        }
 
    }
}