ExpertSearchAdapter.kt 27.1 KB
Newer Older
1 2 3 4
package com.yidianling.consultant.adapter

import android.annotation.SuppressLint
import android.content.Context
5 6 7
import android.graphics.Typeface
import android.text.SpannableStringBuilder
import android.text.Spanned
8
import android.text.TextUtils
9
import android.text.style.StyleSpan
10 11 12 13
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
14 15 16
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
17 18 19
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydl_image.config.SimpleImageOpConfiger
konghaorui committed
20
import com.ydl.ydl_image.module.GlideApp
21
import com.ydl.ydlcommon.base.config.HttpConfig
upwork.021 committed
22
import com.ydl.ydlcommon.utils.LogUtil
23 24 25 26 27 28
import com.ydl.ydlcommon.utils.URLUtils
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.yidianling.consultant.IExpertSearchView
import com.yidianling.consultant.R
import com.yidianling.consultant.constants.ConsultBIConstants
29
import com.yidianling.consultant.listener.OnExpertClickListener
upwork.021 committed
30
import com.yidianling.consultant.model.bean.ExpertServiceItem
31
import com.yidianling.consultant.modular.utils.TempH5RouteUtils
32
import com.yidianling.consultant.router.ConsultantIn
33
import kotlinx.android.synthetic.main.consultant_activity_hot_search.*
34
import kotlinx.android.synthetic.main.consultant_expert_search_feedbackrate.view.*
35
import kotlinx.android.synthetic.main.consultant_expert_search_header_view.view.*
36 37 38 39 40
import kotlinx.android.synthetic.main.consultant_expert_search_item_view.view.*
import kotlinx.android.synthetic.main.consultant_expert_search_products_item.view.*
import kotlinx.android.synthetic.main.consultant_item_empty.view.*
import kotlinx.android.synthetic.main.consultant_item_footer.view.*
import kotlinx.android.synthetic.main.consultant_item_tag.view.*
41
import kotlinx.android.synthetic.main.consultant_layout_search_content.*
YKai committed
42
import java.math.BigDecimal
43 44 45 46

/**
 * 专家服务列表适配器
 */
47 48 49
class ExpertSearchAdapter(
    private val context: Context,
    private val expertSearchView: IExpertSearchView,
50 51
    private val listData: ArrayList<ExpertServiceItem>,
    private val onExpertClick: OnExpertClickListener? = null
52
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
53 54

    companion object {
55
        const val HEADER_VIEW = 3
56 57 58 59 60
        const val NORMAL_VIEW = 0
        const val FOOT_VIEW = 1
        const val EMPTY_VIEW = 2
    }

61 62 63 64 65 66 67 68 69 70
    interface OnClickLister {
        fun onClick(searchWords:String)
    }

    private lateinit var mOnClickLister: OnClickLister

    fun setOnClickLister(lister: OnClickLister) {
        mOnClickLister = lister
    }

71
    //记录当前选择主题的id
72
    var cateId: String? = null
73 74 75

    var hasMore = true

76
    var pageIndex: Int = 0
77 78 79
    var clickCount=0                    // 搜索结果提示标签点击次数

    var mIsRecommendWords = false       // 是否是推荐词
80

81
    fun setEntrance(pageIndex: Int) {
82
        this.pageIndex = pageIndex
83 84
    }

85 86 87 88
    fun setIsRecommendWords(isRecommend:Boolean){
        mIsRecommendWords = isRecommend
    }

89
    @SuppressLint("SetTextI18n")
YKai committed
90
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
91 92 93 94 95
        if (holder is HeaderViewHolder) {           //  搜索结果提示头部
            if (listData.size>0){
                if (listData[0].is_head_view){
                    if (clickCount==0){
                        holder.clSearchWords.visibility = View.VISIBLE
upwork.021 committed
96
                        var text = "根据匹配,为您推荐“${listData[0].related_word}”的搜索结果"
97 98
                        holder.tvSearchRelatedWord.text = setTextBold(text,listData[0].related_word)
                        holder.tvSearchWord.text = listData[0].search_content
99 100 101 102 103 104
                        // 埋点
                        if (mIsRecommendWords){
                            ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_map_word_visit",listData[0].search_content,listData[0].related_word,"app")
                        }else{
                            ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_correction_word_visit",listData[0].search_content,listData[0].related_word,"app")
                        }
105 106 107 108 109 110 111 112
                        holder.tvSearchWord.setOnClickListener {
                            mOnClickLister.onClick(holder.tvSearchWord.text.toString())
                            ++clickCount
                            if (clickCount==1){
                                text = "以下是“${listData[0].search_content}”的搜索结果"
                                holder.tvSearchRelatedWord.text = setTextBold(text,listData[0].search_content)
                                holder.tvSearchTips.text = "你要找的是不是"
                                holder.tvSearchWord.text = listData[0].related_word
113 114 115 116 117 118
                                // 埋点
                                if (mIsRecommendWords){
                                    ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_map_inputword_click",listData[0].related_word,listData[0].search_content,"app")
                                }else{
                                    ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_correction_inputword_click",listData[0].related_word,listData[0].search_content,"app")
                                }
119
                            }else if (clickCount==2){    // 第二次点击搜索标签隐藏搜索匹配结果提示
120 121 122 123 124 125
                                    // 埋点
                                    if (mIsRecommendWords){
                                        ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_map_recommendword_click",listData[0].search_content,listData[0].related_word,"app")
                                    }else{
                                        ActionCountUtils.baiDuCountSign3(ConsultBIConstants.PART_ID_YDL_USER_MAIN_PAGE,"ydl_user_correction_recommendword_click",listData[0].search_content,listData[0].related_word,"app")
                                    }
126
                                listData.removeAt(0)
127
                                clickCount = 0  // 点击两次后重置为0
128 129 130 131 132 133
                            }
                        }
                    }
                }
            }
        } else if (holder is NormalViewHolder) {
134 135 136
            val itemBean = listData[position]
            //头像
            val headConfig = SimpleImageOpConfiger()
137 138
            headConfig.loadingPic = R.drawable.consultant_avatar_def_circle
            headConfig.errorPic = R.drawable.consultant_avatar_def_circle
139 140 141 142 143 144 145
            expertSearchView.showImage(
                itemBean.head,
                holder.imgHead,
                holder.imgHead.width,
                holder.imgHead.height,
                headConfig
            )
146
            //姓名
upwork.021 committed
147
            holder.tvName.text = itemBean.doctor_name
148 149

            //服务中
150
            if (itemBean.open_chat_agency == 2 && itemBean.service_status == 2) {
151 152 153
                holder.imgHead_online_server.visibility = View.VISIBLE
                holder.chat_people_in_question.visibility = View.GONE
                holder.imgHead_online.visibility = View.GONE
154
            } else {
155
                //不是服务中且问询人数大于0
156
                when {
upwork.021 committed
157
                    itemBean.chat_num > 5 -> {
158 159 160
                        holder.chat_people_in_question.visibility = View.VISIBLE
                        holder.chat_people_in_question.text = "多人在问询"
                    }
upwork.021 committed
161
                    itemBean.chat_num > 0 -> {
162
                        holder.chat_people_in_question.visibility = View.VISIBLE
upwork.021 committed
163
                        holder.chat_people_in_question.text = "${itemBean.chat_num}人在问询"
164 165 166 167
                    }
                    else -> {
                        holder.chat_people_in_question.visibility = View.GONE
                    }
168 169 170
                }
                //可预约
                holder.imgHead_online_server.visibility = View.GONE
171
                if (itemBean.is_free_today== 1) {
172
                    holder.imgHead_online.visibility = View.VISIBLE
173
                } else {
174 175 176 177 178 179
                    holder.imgHead_online.visibility = View.GONE
                }
            }


            //省市
180 181
            if (!TextUtils.isEmpty(itemBean.display_region)) {
                holder.tvCity.text = itemBean.display_region
182
            } else {
183 184
                holder.tvCity.text = ""
            }
185 186

            //公益图标,不与其他图标冲突
187
            if (1 == itemBean.has_servicefree_experience) {
upwork.021 committed
188
                if (null != itemBean.icons && !TextUtils.isEmpty(itemBean.icons.service_free_icon)) {
189
                    expertSearchView.showImage(
upwork.021 committed
190
                        itemBean.icons.service_free_icon,
191 192 193
                        holder.imgServiceFree
                    )
                } else {
194
                    val sp = SimpleImageOpConfiger()
195 196
                    sp.loadingPic = R.drawable.consultant_service_free
                    sp.errorPic = R.drawable.consultant_service_free
197
                    expertSearchView.showImage("", holder.imgServiceFree, sp)
198 199
                }
                holder.imgServiceFree.visibility = View.VISIBLE
200
            } else {
201 202
                holder.imgServiceFree.visibility = View.GONE
            }
203 204
            // 展示了抗疫,就不展示其他标签
            if (itemBean.fightEpidemicIconShow) {
upwork.021 committed
205 206
                itemBean.icons?.fight_epidemic_icon?.let {
                    GlideApp.with(context).load(itemBean.icons?.fight_epidemic_icon)
207 208
                        .into(holder.imgFightEpidemicIcon)
                    holder.imgFightEpidemicIcon.visibility = View.VISIBLE
209
                }
严久程 committed
210

211
                if (itemBean.joinActivity == true) {
严久程 committed
212 213 214 215 216 217 218
                    //活动图标
                    if (!TextUtils.isEmpty(itemBean.activityImg)) {
                        holder.imgActivity.visibility = View.VISIBLE
                        GlideApp.with(context).load(itemBean.activityImg).into(holder.imgActivity)
                    } else {
                        holder.imgActivity.visibility = View.GONE
                    }
219
                } else {
严久程 committed
220
                    holder.imgActivity.visibility = View.GONE
严久程 committed
221 222
                }

223 224
                //影藏其余所有标签(除公益)
                holder.imgAbilityLevel.visibility = View.GONE
225
                holder.imgNewEnter.visibility = View.GONE
226
            } else {
227
                holder.imgFightEpidemicIcon.visibility = View.GONE
228
                //能力等级标签
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
                when (itemBean.abilityLevel) {
                    1 -> {
                        //实习
                        holder.imgAbilityLevel.background =
                            context.resources.getDrawable(R.drawable.consultant_expert_search_shixi)
                        holder.imgAbilityLevel.visibility = View.VISIBLE
                    }
                    2 -> {
                        //新手
                        holder.imgAbilityLevel.background =
                            context.resources.getDrawable(R.drawable.consultant_expert_search_xinshou)
                        holder.imgAbilityLevel.visibility = View.VISIBLE
                    }
                    else -> {
                        holder.imgAbilityLevel.visibility = View.GONE
                    }
245 246 247 248 249 250 251 252 253
                }
                //活动图标
                if (!TextUtils.isEmpty(itemBean.activityImg)) {
                    holder.imgActivity.visibility = View.VISIBLE
                    GlideApp.with(context).load(itemBean.activityImg).into(holder.imgActivity)
                } else {
                    holder.imgActivity.visibility = View.GONE
                }
                //新驻图标
254
                if (itemBean.is_new_enter != null && itemBean.is_new_enter!!) {
upwork.021 committed
255
                    if (null != itemBean.icons && !TextUtils.isEmpty(itemBean.icons.new_enter_icon)) {
256
                        expertSearchView.showImage(
upwork.021 committed
257
                            itemBean.icons.new_enter_icon,
258 259 260 261 262 263 264 265 266 267 268 269
                            holder.imgNewEnter
                        )
                    } else {
                        val sp = SimpleImageOpConfiger()
                        sp.loadingPic = R.drawable.consultant_new_enter
                        sp.errorPic = R.drawable.consultant_new_enter
                        expertSearchView.showImage("", holder.imgNewEnter, sp)
                    }
                    holder.imgNewEnter.visibility = View.VISIBLE
                } else {
                    holder.imgNewEnter.visibility = View.GONE
                }
270 271
            }
            holder.ll_feedbackRate.removeAllViews()
272 273 274 275 276 277
            for (num in 1..5) {
                val view = LayoutInflater.from(context).inflate(
                    R.layout.consultant_expert_search_feedbackrate,
                    holder.ll_feedbackRate,
                    false
                )
upwork.021 committed
278
                if (itemBean.evaluation_average_score >= num) {
279 280
                    (view.imgRate as ImageView).background =
                        context.resources.getDrawable(R.drawable.consultant_expert_search_full_star)
upwork.021 committed
281
                } else if (itemBean.evaluation_average_score < num && itemBean.evaluation_average_score > num - 1) {
282 283 284 285 286
                    (view.imgRate as ImageView).background =
                        context.resources.getDrawable(R.drawable.consultant_expert_search_half_star)
                } else {
                    (view.imgRate as ImageView).background =
                        context.resources.getDrawable(R.drawable.consultant_expert_search_nothing_star)
287 288 289 290 291
                }
                holder.ll_feedbackRate.addView(view)
            }
            //XXX人点评
            val numSb = StringBuffer()
292
            holder.tv_zixunOrderNum.text =
upwork.021 committed
293
                numSb.append(itemBean.evaluate_num).append("").toString()
294
            //咨询师简介
upwork.021 committed
295
            holder.tvTeamCertifications.text = itemBean.title
296 297
            //咨询师标签
            holder.ll_tags.removeAllViews()
298
            itemBean.feature_tags?.let {
299 300 301 302
                if (it.isNotEmpty()) {
                    for (tag in itemBean.feature_tags) {
                        val view = LayoutInflater.from(context)
                            .inflate(R.layout.consultant_item_tag, holder.ll_tags, false)
303
                        tag.tag_name.let { name ->
304 305 306
                            if (name.length > 4) {
                                view.tvTag.text = "${name.substring(0, 4)}…"
                            } else {
307 308 309
                                view.tvTag.text = name
                            }
                        }
310
                        if (tag.is_highlight) {
upwork.021 committed
311
                            view.tvTag.setBackgroundResource(R.drawable.consultant_bg_radius_line_eb892c)
312 313 314 315 316 317 318
                            view.tvTag.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.color_EB892C
                                )
                            )
                        } else {
upwork.021 committed
319
                            view.tvTag.setBackgroundResource(R.drawable.consultant_bg_radius_line_gray_1)
320 321 322 323 324 325
                            view.tvTag.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.platform_color_666666
                                )
                            )
upwork.021 committed
326 327
                        }
                        holder.ll_tags.addView(view)
konghaorui committed
328
                    }
329 330 331 332
                }
            }
            //帮助人数
            val orderUser = StringBuffer()
upwork.021 committed
333
            holder.tvOrderNum.text = orderUser.append(itemBean.help_num).append("").toString()
konghaorui committed
334
            //私聊文案
upwork.021 committed
335
            if (TextUtils.isEmpty(itemBean.chat_btn_text)) {
konghaorui committed
336
                holder.tvChat.text = "私聊"
337 338 339
                holder.tvChat.setTextColor(
                    ContextCompat.getColor(
                        context,
konghaorui committed
340
                        R.color.platform_but_text_color
341 342
                    )
                )
343 344 345 346 347 348
                holder.tvChat.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.platform_but_text_color
                    )
                )
349 350 351
                holder.tvChat.background =
                    ContextCompat.getDrawable(context, R.drawable.consultant_expert_search_chat)
            } else {
upwork.021 committed
352
                holder.tvChat.text = itemBean.chat_btn_text
353 354 355 356 357 358 359 360 361 362
                holder.tvChat.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.platform_color_999999
                    )
                )
                holder.tvChat.background = ContextCompat.getDrawable(
                    context,
                    R.drawable.consultant_expert_search_chat_rest
                )
konghaorui committed
363
            }
364
            //服务时长
365
            val durationStringBuffer = StringBuffer()
366 367
            holder.tvSaleDurationForMonth.text =
                durationStringBuffer.append(itemBean.sum_service_time.toInt()).append("").toString()
368
            //价格
upwork.021 committed
369 370
            val price = BigDecimal(itemBean.min_price)
//             去掉末尾无用的.00
YKai committed
371
            holder.tvPrice.text = price.stripTrailingZeros().toPlainString()
372 373
            //套餐
            holder.ll_products.removeAllViews()
upwork.021 committed
374 375
            if (null != itemBean.doctor_products && itemBean.doctor_products.isNotEmpty()) {
                for (item in itemBean.doctor_products) {
376 377 378 379 380
                    val view = LayoutInflater.from(context).inflate(
                        R.layout.consultant_expert_search_products_item,
                        holder.ll_tags,
                        false
                    )
upwork.021 committed
381 382
                    when (item.product_type) {
                        "1" -> {
upwork.021 committed
383 384 385 386
                            view.tvTitle.text = "单次"
                            view.tvTitle.setTextColor(context.resources.getColor(R.color.platform_color_1DA1F2))
                            view.tvTitle.background =
                                context.resources.getDrawable(R.drawable.consultant_expert_search_single)
upwork.021 committed
387
                            view.tvContent.text = item.product_name
upwork.021 committed
388 389
                            holder.ll_products.addView(view)
                        }
upwork.021 committed
390
                        "2" -> {
upwork.021 committed
391 392 393 394
                            view.tvTitle.text = "套餐"
                            view.tvTitle.setTextColor(context.resources.getColor(R.color.consultant_color_FF9500))
                            view.tvTitle.background =
                                context.resources.getDrawable(R.drawable.consultant_expert_search_menu)
upwork.021 committed
395
                            view.tvContent.text = item.product_name
upwork.021 committed
396 397 398
                            holder.ll_products.addView(view)
                        }
                        else -> {
399

upwork.021 committed
400
                        }
401 402 403 404 405 406 407
                    }
                }
            }
        } else if (holder is FooterViewHolder) {
            if (hasMore) {
                holder.itemView.visibility = View.VISIBLE
                holder.pbLoading.visibility = View.VISIBLE
408
                holder.tvHint.text = context.getString(R.string.consultant_loading)
409
            } else {
410
                holder.pbLoading.visibility = View.GONE
konghaorui committed
411
                holder.tvHint.text = context.getString(R.string.platform_no_more)
412 413 414 415
            }
        }
    }

416
    override fun getItemCount(): Int =
417
//        if (listData.size < ExpertSearchActivity.PAGE_SIZE && hasMore) {
418 419 420 421 422
        if (listData.size==1) {
            listData.size
        } else {
            listData.size + 1
        }
423

YKai committed
424
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
425
        when (viewType) {
426 427 428 429
            HEADER_VIEW -> {
                val view = LayoutInflater.from(context).inflate(R.layout.consultant_expert_search_header_view, parent, false)
                HeaderViewHolder(view)
            }
430 431 432 433 434 435
            NORMAL_VIEW -> {
                val view = LayoutInflater.from(context)
                    .inflate(R.layout.consultant_expert_search_item_view, parent, false)
                NormalViewHolder(view)
            }
            FOOT_VIEW -> {
436 437
                val view = LayoutInflater.from(context)
                    .inflate(R.layout.consultant_item_footer, parent, false)
438 439 440 441 442 443
                FooterViewHolder(view)
            }
            else -> {
                val view = LayoutInflater.from(context)
                    .inflate(R.layout.consultant_item_empty, parent, false)
                EmptyViewHolder(view)
444
            }
445
        }
446

447 448
    override fun getItemViewType(position: Int): Int =
        when {
449
            position==0&&listData.size>0&&listData[0].is_head_view ->{
450 451
                HEADER_VIEW
            }
452
            position < listData.size -> {
453 454 455 456 457 458 459
                NORMAL_VIEW
            }
            !hasMore && listData.size == 0 -> {
                EMPTY_VIEW
            }
            else -> FOOT_VIEW
        }
460 461 462 463

    inner class NormalViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        //头像
        val imgHead = itemView.imgHead!!
严久程 committed
464
        val cv_head_view = itemView.cv_head_view!!
465

466 467
        //专家姓名
        val tvName = itemView.tvName!!
468

konghaorui committed
469 470
        //活动图标
        val imgActivity = itemView.img_activity!!
471

472 473
        //优质图标
        val imgAbilityLevel = itemView.imgAbilityLevel!!
474

475 476
        //公益图标
        val imgServiceFree = itemView.imgServiceFree!!
477

478 479
        //新驻图标
        val imgNewEnter = itemView.imgNewEnter!!
480

严久程 committed
481 482
        //荣誉标签
        val ll_honor_layout = itemView.ll_honor_layout!!
483

484 485
        //好评率
        val ll_feedbackRate = itemView.ll_feedbackRate!!
486

487 488
        //xxx人点评
        val tv_zixunOrderNum = itemView.tv_zixunOrderNum!!
489

490 491
        //咨询师简介
        val tvTeamCertifications = itemView.tvTeamCertifications!!
492

493 494
        //咨询师标签
        val ll_tags = itemView.ll_tags!!
495

496 497
        //帮助人数
        val tvOrderNum = itemView.tvOrderNum!!
498

499 500
        //帮助人数文案
        val tvOrderNumContent = itemView.tvOrderNumContent
501

502
        //服务时长
503
        val tvSaleDurationForMonth = itemView.tvSaleDurationForMonth!!
504

505 506
        //月售时长文案
        val tvSaleDurationForMonthContent = itemView.tvSaleDurationForMonthContent
507

508 509
        //价格
        val tvPrice = itemView.tvPrice!!
严久程 committed
510 511
        val tvPriceContent = itemView.tvPriceContent!!
        val tv_money_symbol = itemView.tv_money_symbol!!
512

513 514
        //服务套餐
        val ll_products = itemView.ll_products!!
515

516 517
        //私聊按钮
        val tvChat = itemView.tvChat!!
518

519 520
        //个人铭言整个布局
        val group_desc = itemView.group_desc!!
521

522 523
        //个人铭言
        val tvDesc = itemView.tvDesc!!
524

525 526
        //省市
        val tvCity = itemView.tvCity!!
527

528 529
        //今日是否可约
        val imgHead_online = itemView.imgHead_online!!
530

531 532
        //服务中(咨询中或者聆听中)
        val imgHead_online_server = itemView.imgHead_online_server!!
533

534 535
        //多少人在问询
        val chat_people_in_question = itemView.people_in_question!!
536

537 538
        // 抗疫先锋图标
        val imgFightEpidemicIcon = itemView.img_fightEpidemicIcon
539 540 541 542 543 544

        init {
            itemView.setOnClickListener {
                //跳转专家主页
                if (adapterPosition != RecyclerView.NO_POSITION) {
                    val itemBean = listData[adapterPosition]
upwork.021 committed
545
                    var linkUrl = itemBean.link_url
546

547 548
                    if (!TextUtils.isEmpty(cateId)) {
                        linkUrl = URLUtils.appendParmas(linkUrl, "cateId", cateId)
549
                    }
550
                    onExpertClick?.onExpertClick()
551
                    TempH5RouteUtils.tempH5Route(linkUrl)
upwork.021 committed
552 553

                    // 埋点
554 555 556 557 558 559 560
                    ActionCountUtils.baiDuCountSign3(
                        ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
                        ConsultBIConstants.ConsultEvent.POSITION_CONSULT_COUNSELOR_CARD_CLICK,
                        itemBean.id ?: "",
                        "app",
                        ""
                    )
561 562 563 564 565 566
                }
            }

            itemView.tvChat.setOnClickListener {
                if (adapterPosition != RecyclerView.NO_POSITION) {
                    val doctor = listData[adapterPosition]
567 568 569
                    if (pageIndex == 0) {
                        ActionCountUtils.count(
                            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_CHAT_CLICK,
upwork.021 committed
570
                            doctor.id ?: ""
571 572 573 574
                        )
                    } else {
                        ActionCountUtils.count(
                            ConsultBIConstants.ConsultSearchListEvent.APP_CONSULT_SEARCH_LIST_CHAT_CLICK,
upwork.021 committed
575
                            doctor.id ?: ""
576 577
                        )
                    }
578
                    onExpertClick?.onExpertClick()
严久程 committed
579
                    //判断是否已登录
580
                    if (!ConsultantIn.getUserImpl().loginByOneKeyLogin(context, true)) {
严久程 committed
581 582 583
                        return@setOnClickListener
                    }

584 585 586 587

                    if (!TextUtils.isEmpty(doctor.uid)) {
                        //跳转私聊
                        ConsultantIn.startP2PSession(context as AppCompatActivity, doctor.uid!!)
588
                        ActionCountUtils.count(ConsultBIConstants.UserMainEvent.YDL_PRIVATE_CHAT_CLICK)
589 590 591 592 593 594 595 596
                    } else {
                        ToastHelper.show("请联系客服,专家参数错误!")
                    }
                }
            }
        }
    }

597 598 599 600 601 602 603
    inner class HeaderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val clSearchWords = itemView.cl_search_words
        val tvSearchRelatedWord = itemView.tv_search_related_word
        val tvSearchTips = itemView.tv_search_tips
        val tvSearchWord = itemView.tv_search_word
    }

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
    inner class FooterViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val pbLoading = itemView.pbLoading!!
        val tvHint = itemView.tvHint!!
    }

    inner class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val btnSearchByCat = itemView.btnSearchByCat!!

        init {
            btnSearchByCat.setOnClickListener {
                val h5Params = H5Params(HttpConfig.H5_URL + "experts/cates", null)
                NewH5Activity.start(context, h5Params)
            }
        }
    }
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636

    private fun setTextBold(text: String, content: String): SpannableStringBuilder {
        return if (text.contains(content)) {
            val s1 = text.split(content)[0]
            val s2 = text.split(content)[1]
            val spannableBuilder1 = SpannableStringBuilder(s1)
            val spannableBuilder2 = SpannableStringBuilder(content)
            spannableBuilder2.setSpan(
                StyleSpan(Typeface.BOLD),
                0,
                content.length,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )
            spannableBuilder1.append(spannableBuilder2).append(SpannableStringBuilder(s2))
        } else {
            SpannableStringBuilder(text)
        }
    }
637
}