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