ExpertSearchFragment.kt 58.1 KB
Newer Older
洪国微 committed
1 2 3 4 5 6 7 8
package com.yidianling.consultant

import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.content.Context
import android.graphics.Typeface
upwork.021 committed
9
import android.os.Handler
洪国微 committed
10
import android.text.TextUtils
konghaorui committed
11
import android.view.View
洪国微 committed
12 13 14 15
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
upwork.021 committed
16
import androidx.core.content.ContextCompat
YKai committed
17
import androidx.fragment.app.FragmentActivity
upwork.021 committed
18 19 20
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
konghaorui committed
21
import com.alibaba.android.arouter.facade.annotation.Route
洪国微 committed
22
import com.alibaba.android.arouter.launcher.ARouter
YKai committed
23
import com.google.android.material.appbar.AppBarLayout
洪国微 committed
24 25 26 27 28 29
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydl_image.config.SimpleImageOpConfiger
import com.ydl.ydl_image.listener.YDLImageRecyclerOnScrollListener
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.ydl.ydlcommon.base.BaseMvpFragment
30
import com.ydl.ydlcommon.base.config.ChannelConfig
洪国微 committed
31
import com.ydl.ydlcommon.base.config.HttpConfig
严久程 committed
32
import com.ydl.ydlcommon.data.PlatformDataManager
洪国微 committed
33 34
import com.ydl.ydlcommon.ui.LogoLoadingView
import com.ydl.ydlcommon.utils.BuryPointUtils
洪国微 committed
35
import com.ydl.ydlcommon.utils.DisplayUtils
洪国微 committed
36 37 38 39 40 41 42 43 44 45
import com.ydl.ydlcommon.utils.StatusBarUtils
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.ydl.ydlcommon.view.listener.EndlessRecyclerViewScrollListener
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.RxImageTool
import com.yidianling.common.tools.ToastUtil
import com.yidianling.consultant.adapter.ExpertSearchAdapter
import com.yidianling.consultant.constants.ConsultBIConstants
import com.yidianling.consultant.listener.OnCategoriesSelectedListener
46
import com.yidianling.consultant.listener.OnExpertClickListener
洪国微 committed
47 48 49 50 51 52 53 54 55
import com.yidianling.consultant.listener.OnFilterConfirmListener
import com.yidianling.consultant.listener.OnSortItemSelectedListener
import com.yidianling.consultant.model.bean.*
import com.yidianling.consultant.modular.singlton.ConsultAssistantDialogUtils
import com.yidianling.consultant.router.ConsultantIn
import com.yidianling.consultant.ui.view.AreaPopupWindow
import com.yidianling.consultant.ui.view.CategoryPopupWindow
import com.yidianling.consultant.ui.view.FilterPopupWindow
import com.yidianling.consultant.ui.view.SortPopupWindow
徐健 committed
56
import com.yidianling.consultant.ui.view.topView.RecommendListView
upwork.021 committed
57 58
import com.yidianling.home.api.event.HomeModuleTabEvent
import de.greenrobot.event.EventBus
洪国微 committed
59 60 61 62 63 64
import kotlinx.android.synthetic.main.consultant_activity_expert_search_list.*
import kotlinx.android.synthetic.main.consultant_item_filter_online.view.*
import kotlinx.android.synthetic.main.consultant_layout_search_content.*
import kotlinx.android.synthetic.main.consultant_layout_search_toolbar.*
import org.json.JSONObject
import java.util.concurrent.Executors
YKai committed
65

konghaorui committed
66
@Route(path = "/consultant/consultant")
67 68
class ExpertSearchFragment : BaseMvpFragment<IExpertSearchView, ExpertSearchPresenter>(),
    View.OnClickListener, IExpertSearchView,
69
    OnCategoriesSelectedListener, OnSortItemSelectedListener, OnFilterConfirmListener,
70
    SwipeRefreshLayout.OnRefreshListener {
71 72
    private lateinit var mContext: Context
    private lateinit var mActivity: FragmentActivity
73 74 75
    var startTime = 0L
    var endTime = 0L
    private var mIdssign1: String = "" // 列表埋点咨询师列表id拼接参数
76

洪国微 committed
77 78 79 80 81
    override fun layoutResId(): Int {
        return R.layout.consultant_activity_expert_search_list
    }

    override fun initDataAndEvent() {
upwork.021 committed
82
        EventBus.getDefault().register(this)
YKai committed
83 84 85
        mContext = requireContext()
        mActivity = requireActivity()
        val statusBarHeight = StatusBarUtils.getStatusBarHeight(mContext)
86
        rootView.setPadding(0, statusBarHeight, 0, 0)
洪国微 committed
87
        btn_back.visibility = View.GONE
88
        title_layout.setPadding(DisplayUtils.dp2px(context, 15), 0, 0, 0)
洪国微 committed
89 90
        initViews()
        initData()
徐健 committed
91

严久程 committed
92
        val ffrom = PlatformDataManager.getRam().getChannelName()
93
        if (!TextUtils.isEmpty(ffrom) &&
94
            (ffrom.endsWith(ChannelConfig.Xinliceshiyiyu.name))
95
        ) {
96
            //抑郁焦虑测试
严久程 committed
97 98 99 100
            rl_hot_fix_for_huawei.visibility = View.GONE
        } else {
            rl_hot_fix_for_huawei.visibility = View.VISIBLE
        }
101

洪国微 committed
102 103 104 105 106 107 108
    }

    override fun initDataAndEventLazy() {

    }

    override fun showImage(url: String?, imgView: ImageView) {
109 110 111
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView)
        }
洪国微 committed
112 113 114
    }

    override fun showImage(url: String?, imgView: ImageView, ops: SimpleImageOpConfiger) {
115 116 117
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView, ops)
        }
洪国微 committed
118 119
    }

120 121 122 123 124 125 126
    override fun showImage(
        url: String?,
        imgView: ImageView,
        width: Int,
        heigh: Int,
        ops: SimpleImageOpConfiger
    ) {
127 128 129
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView, width, heigh, ops)
        }
洪国微 committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
    }

    companion object {
        const val EXTRA_CATEGORY = "category"
        const val EXTRA_CATEGORY_NAME = "category_name"
        const val EXTRA_SHOW_TYPE = "showType"
        const val EXTRA_FROM_PAGE = "fromPage"
        const val HOT_SEARCH_DOCTOR_NAME = "hot_search_doctor_name"
        private const val EXTRA_IS_SHOW_HOT = "isInitShowHot"
        private const val EXTRA_SEARCH_WORD = "searchWord"
        private const val EXTRA_IS_FROM_SPLASH = "isFromSplash"
        private const val FILTER_STATUS_NORMAL = 0 //默认筛选状态
        private const val FILTER_STATUS_FILTERED = 1 //非默认筛选状态
        private const val FILTER_STATUS_OPEN = 2 //筛选窗打开状态
        const val FROM_HOME_SREARCH = 0
        const val FROM_FIND_EXPERT = 1
        const val FROM_ONLINE_EXPERT = 2
        const val PAGE_SIZE = 15
148 149
        //列表点击回来不刷新列表
        var needRefresh = true;
洪国微 committed
150 151 152 153
    }

    private val allFilter = AllFilter() //当前筛选
    private val tempFilter = AllFilter() //临时筛选,未确认状态
upwork.021 committed
154
    private val doctorList = ArrayList<ExpertServiceItem>()
洪国微 committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    private var hasMore = true
    private var initShowType: Int = 0
    private lateinit var doctorAdapter: ExpertSearchAdapter
    private lateinit var onScrollListener: EndlessRecyclerViewScrollListener
    private var headData: HeadData? = null //筛选数据
    private val props1 = JSONObject() //筛选标题埋点参数
    private var isRecommend = false //埋点数据
    private var isDoSearch: Boolean = false //埋点判断是否通过搜索进入埋点的
    private var hasSelectedArea = false  //是否选择过地区
    private var hasSelectedSort = false  //是否选择过排序


    override fun createPresenter(): ExpertSearchPresenter = ExpertSearchPresenter()

    private fun initViews() {
konghaorui committed
170
        srlContainer.isEnabled = true
洪国微 committed
171 172 173 174 175 176 177
        tvSubject.setOnClickListener(this)
        tvArea.setOnClickListener(this)
        tvSort.setOnClickListener(this)
        tvFilter.setOnClickListener(this)
        btn_call.setOnClickListener(this)
        tv_guide.setOnClickListener(this)
        rl_search.setOnClickListener(this)
178 179 180 181 182 183
        srlContainer.setColorSchemeColors(
            ContextCompat.getColor(
                mActivity,
                R.color.platform_main_theme
            )
        )
184 185
        srlContainer.setProgressViewOffset(false, 0, 200)
        srlContainer.setOnRefreshListener(this)
洪国微 committed
186 187
        initNetLossView()

188 189
        recommendListView.addViewPagerScrollStateListener(object :
            RecommendListView.ViewPagerScrollStateCallback {
徐健 committed
190 191 192 193 194 195
            override fun viewPagerScroll(isScrolling: Boolean) {
                //如果viewpager正在滚动,则禁止下拉刷新
                srlContainer.isEnabled = !isScrolling
            }
        })

YKai committed
196
        appbar_layout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, i ->
徐健 committed
197
            srlContainer.isEnabled = i >= 0
YKai committed
198
        })
徐健 committed
199

200 201 202 203 204 205
        doctorAdapter = ExpertSearchAdapter(mContext, this, doctorList,object  :OnExpertClickListener{
            override fun onExpertClick() {
                needRefresh = false
            }

        })
洪国微 committed
206 207

        rvExperts.adapter = doctorAdapter
YKai committed
208 209 210 211 212
        val layoutManager = LinearLayoutManager(
            context,
            LinearLayoutManager.VERTICAL,
            false
        )
洪国微 committed
213 214 215 216
        rvExperts.layoutManager = layoutManager
        onScrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
            private var isBtnShow: Boolean = false
            private var sIsScrolling = false
YKai committed
217
            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
洪国微 committed
218 219 220 221
                super.onScrollStateChanged(recyclerView, newState)
                hideSoftInput()
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
                    sIsScrolling = true
222 223
                    //滚动
                    hideConsultAssistantDialog()
洪国微 committed
224 225

                } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
226 227
                    //没有滚动
                    showConsultAssistantDialog()
upwork.021 committed
228
                    sIsScrolling = false
洪国微 committed
229 230 231 232
                }
            }

            override fun onScrollTop() {
upwork.021 committed
233 234 235 236
                val alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
                val animator =
237 238
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
239 240 241 242 243 244 245 246 247 248 249 250 251
                animator.addListener(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        image_scroll_top.visibility = View.GONE
                        isBtnShow = false
                    }
                })
                animator.start()
            }

            override fun onScrollDown() {
                if (isBtnShow) {
                    return
                }
upwork.021 committed
252 253 254 255
                val alpha = PropertyValuesHolder.ofFloat("alpha", 0f, 1f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 0f, 1f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 0f, 1f)
                val animator =
256 257
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
258 259 260 261 262 263 264 265 266 267 268 269 270
                animator.addListener(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        image_scroll_top.visibility = View.VISIBLE
                        isBtnShow = true
                    }
                })
                animator.start()
            }

            override fun onScrollUp() {
                if (!isBtnShow) {
                    return
                }
upwork.021 committed
271 272 273 274
                val alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
                val animator =
275 276
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
277 278 279 280 281 282 283 284 285 286 287
                animator.addListener(object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        image_scroll_top.visibility = View.GONE
                        isBtnShow = false
                    }
                })
                animator.start()
            }

            override fun onLoadMore(page: Int, totalItemsCount: Int, view: RecyclerView?) {
                if (hasMore) {
upwork.021 committed
288
                    getPresenter().fetchListData(allFilter, getPresenter().mExtras)
洪国微 committed
289 290 291 292 293 294
                }
            }
        }
        rvExperts.addOnScrollListener(onScrollListener)
        rvExperts.addOnScrollListener(YDLImageRecyclerOnScrollListener(activity))
        image_scroll_top.setOnClickListener(this)
徐健 committed
295
    }
洪国微 committed
296

徐健 committed
297 298
    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
严久程 committed
299
        if (isVisibleToUser && isResumed) {
300
            startTime = System.currentTimeMillis()
301 302 303
            showConsultAssistantDialog()
        } else {
            hideConsultAssistantDialog()
304 305 306 307 308 309
            if (startTime != 0L) {
                endTime = System.currentTimeMillis()
                ActionCountUtils.count(
                    ConsultBIConstants.ConsultEvent.YDL_USER_CONSULT_PAGE_STAY_VISIT,
                    (endTime - startTime).toString()
                )
霍志良 committed
310
            }
311
        }
徐健 committed
312 313 314 315 316 317
        if (isVisibleToUser && isResumed) {
            onResume()
        }
    }

    private fun showConsultAssistantDialog() {
YKai committed
318
        ConsultAssistantDialogUtils.INSTANCE.fitRequest(mActivity, "doctor_list")
洪国微 committed
319 320
    }

徐健 committed
321 322 323 324
    private fun hideConsultAssistantDialog() {
        ConsultAssistantDialogUtils.INSTANCE.hide()
    }

洪国微 committed
325
    private fun initNetLossView() {
326
        v_loading.setListener(object : LogoLoadingView.LogoLoadingListener {
洪国微 committed
327
            override fun onDataResetClick() {
328 329 330 331
                rvExperts.visibility = View.GONE
                v_loading.visibility = View.VISIBLE
                ll_network_error.visibility = View.GONE
                v_loading.setViewType(LogoLoadingView.TYPE_LOADING, null)
洪国微 committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
                refresh(false)
            }

            override fun onBackClick() {
//                finish()
            }
        })
    }

    override fun localData() {

    }

    private fun initData() {
        allFilter.showType.key = initShowType
upwork.021 committed
347

348
        getPresenter().fetchListHead()
349
        recommendListView.requestData("")
洪国微 committed
350

351 352
        v_loading.visibility = View.VISIBLE
        v_loading.setViewType(LogoLoadingView.TYPE_LOADING, null)
洪国微 committed
353

严久程 committed
354
        doctorAdapter.setEntrance(0)
洪国微 committed
355 356 357
    }

    /**
upwork.021 committed
358
     *  获取所有的筛选选项数据
洪国微 committed
359 360 361 362
     */
    override fun onHeadFetched(headData: HeadData?) {
        //头部数据获取到后初始化筛选数据
        this.headData = headData
upwork.021 committed
363 364 365 366 367 368 369
        headData?.let { it ->
//            allFilter.reorder = it.reorder[0]
            allFilter.showType = it.filters.showType[initShowType]
            if (it.highlighter.size > 0) {
                //设置热门搜索
                initHotViews(lin_filter2, it.highlighter)
            }
370 371 372 373
            it.cates[0].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
374 375
                allFilter.childList.add(childrenBean)
            }
376 377 378 379
            it.cates[1].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
380 381
                allFilter.stressList.add(childrenBean)
            }
382 383 384 385
            it.cates[2].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
386 387
                allFilter.loveEmotionList.add(childrenBean)
            }
388 389 390 391
            it.cates[3].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
392 393
                allFilter.marriedFamilyList.add(childrenBean)
            }
394 395 396 397
            it.cates[4].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
398 399
                allFilter.personalGrowthList.add(childrenBean)
            }
400 401 402 403
            it.cates[5].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
404 405
                allFilter.interpersonalRelationshipList.add(childrenBean)
            }
406 407 408 409
            it.cates[6].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
410 411
                allFilter.careerDevelopmentList.add(childrenBean)
            }
412 413 414 415
            it.cates[7].children?.forEachIndexed { index, children ->
                val type = if (children.cate_name.length > 4) 2 else 1
                val childrenBean =
                    ChildrenBean(children.cate_name, children.cate_id, index <= 12, type)
upwork.021 committed
416
                allFilter.mentalHealthList.add(childrenBean)
洪国微 committed
417 418 419 420 421 422 423 424 425 426 427
            }
        }
    }

    /**
     * 热门
     */
    private fun initHotViews(view: LinearLayout, hotData: List<HighlighterItem>) {
        if (view.childCount > 0) {
            return
        }
upwork.021 committed
428
        for (hot in hotData) {
洪国微 committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
            val tv = View.inflate(context, R.layout.consultant_item_filter_online, null) as TextView
            val textView = tv.tvFree
            val params = LinearLayout.LayoutParams(0, RxImageTool.dp2px(22f))
            params.weight = 1f
            params.setMargins(0, 0, RxImageTool.dp2px(10f), 0)
            textView.layoutParams = params

            textView.text = hot.value
            textView.setOnClickListener {
                if (textView.isSelected) {
                    dealHotSelect(hot, false)
                    textView!!.isSelected = false
                    textView.paint.isFakeBoldText = false
                } else {
                    dealHotSelect(hot, true)
                    textView.isSelected = true
                    textView.paint.isFakeBoldText = true
upwork.021 committed
446
                    // 埋点
447 448 449 450 451 452 453
                    ActionCountUtils.baiDuCountSign3(
                        ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
                        ConsultBIConstants.ConsultEvent.POSITION_CHOICE_FILTER_CLICK,
                        hot.value!!,
                        "app",
                        ""
                    )
洪国微 committed
454 455 456
                }
                filterLabelSet()
                //开始筛选数据
upwork.021 committed
457
                refresh()
洪国微 committed
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
            }
            view.addView(textView)
        }
    }


    /**
     * 处理热门搜索的选中逻辑
     * * 1:主题
     * 2:省
     * 3:排序
     * 4:咨询方式
     * 5:年龄选择
     * 6:其他选择
     * 7:资质选择
     * 8.市
     *
     * @param isAdd 是否是添加
     */
    private fun dealHotSelect(hotData: HighlighterItem, isAdd: Boolean) {
        when (hotData.type) {
            "1" -> {
upwork.021 committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
//                if (headData?.cates!!.size > 0) {
//                    for (bean in headData?.cates!!) {
//                        if (TextUtils.equals(hotData.id, bean.cateId.toString())) {
//                            if (isAdd) {
//                                if (allFilter.categories.size == 1 && allFilter.categories[0].cateId == "0") {
//                                    allFilter.categories.clear()
//                                }
//                                updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
//                            } else {
//                                allFilter.categories.remove(bean)
//                                if (allFilter.categories.size == 0) {
//                                    updateFilterTextViewStatus(tvSubject, FILTER_STATUS_NORMAL)
//                                }
//                            }
//                        }
//                    }
//                    if (allFilter.categories.size == 1 && "全部" != allFilter.categories[0].cateName) {
//                        //显示选中标题
//                        tvSubject.text = allFilter.categories[0].cateName
//                    } else {
//                        //显示主标题
//                        tvSubject.text = "主题"
//                    }
//                }
                updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
洪国微 committed
505 506 507
            }
            "2" -> {//省
                if (headData?.region!!.size > 0) {
508
                    val bean = RegionItem()
洪国微 committed
509 510 511 512 513
                    if (isAdd) {
                        //热门中如果选择过地区、要把其他已选中的置位未选中
                        if (hasSelectedArea) {
                            for ((index, bean) in headData!!.highlighter.withIndex()) {
                                if (bean.type == "2" || bean.type == "8") {
514
                                    val textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
515 516 517 518 519
                                    textview.isSelected = false
                                    textview.paint.isFakeBoldText = false
                                }
                            }
                        }
520
                        bean.code = hotData.id
洪国微 committed
521 522
                        bean.value = hotData.value
                        for (headBean in headData!!.region) {
523
                            if (TextUtils.equals(headBean.code, bean.code)) {
洪国微 committed
524 525 526 527 528 529
                                bean.sub = headBean.sub
                                break
                            }
                        }
                        allFilter.region = bean
                        if (allFilter.region.value?.length ?: 0 > 4) {
530
                            tvArea.text = allFilter.region.value?.substring(0, 3) + "..."
洪国微 committed
531
                        } else {
532
                            tvArea.text = allFilter.region.value
洪国微 committed
533 534 535 536 537 538
                        }
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)

                        hasSelectedArea = true
                    } else {
                        allFilter.region = RegionItem()
539
                        tvArea.text = "地区"
洪国微 committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)

                        hasSelectedArea = false
                    }
                    allFilter.sub = SubItem("不限", null)
                }
            }
            "3" -> {
                //排序
                if (headData?.reorder!!.size > 0) {
                    for (bean in headData?.reorder!!) {
                        if (TextUtils.equals(hotData.id, bean.key.toString())) {
                            if (isAdd) {
                                if (hasSelectedSort) {
                                    for ((index, bean) in headData!!.highlighter.withIndex()) {
                                        if (bean.type == "3") {
556
                                            var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
                                            textview.isSelected = false
                                            textview.paint.isFakeBoldText = false
                                        }
                                    }
                                }
                                allFilter.reorder = bean
                                updateFilterTextViewStatus(tvSort, FILTER_STATUS_FILTERED)

                                hasSelectedSort = true
                            } else {
                                allFilter.reorder = headData?.reorder?.get(0) ?: ReorderItem()
                                updateFilterTextViewStatus(tvSort, FILTER_STATUS_NORMAL)

                                hasSelectedSort = false
                            }
                        }
                    }
                    when {
575 576 577 578
                        allFilter.reorder.value.equals("综合排序") -> tvSort.text = "排序"
                        allFilter.reorder.value?.length ?: 0 > 4 -> tvSort.text =
                            allFilter.reorder.value?.substring(0, 3) + "..."
                        else -> tvSort.text = allFilter.reorder.value
洪国微 committed
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
                    }
                }
            }
            "4" -> {
                //咨询方式
                if (headData?.filters?.enquiry!!.isNotEmpty()) {
                    for (bean in headData?.filters?.enquiry!!) {
                        if (TextUtils.equals(hotData.id, bean.key.toString())) {
                            if (isAdd) {
                                allFilter.enquiries.add(bean)
                            } else {
                                allFilter.enquiries.remove(bean)
                            }
                        }
                    }
                }
595
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size + allFilter.specialityCrowd.size > 0) {
洪国微 committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "5" -> {
                //年龄选择
                if (headData?.filters?.age!!.isNotEmpty()) {
                    for (bean in headData?.filters?.age!!) {
                        if (TextUtils.equals(hotData.id, bean.key.toString())) {
                            if (isAdd) {
                                allFilter.ages.add(bean)
                            } else {
                                allFilter.ages.remove(bean)
                            }
                        }
                    }
                }
615
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size + allFilter.specialityCrowd.size > 0) {
洪国微 committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "6" -> {
                //其他选择
                if (headData?.filters?.other!!.isNotEmpty()) {
                    for (bean in headData?.filters?.other!!) {
                        if (TextUtils.equals(hotData.id, bean.key.toString())) {
                            if (isAdd) {
                                allFilter.others.add(bean)
                            } else {
                                allFilter.others.remove(bean)
                            }
                        }
                    }
                }
635
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size + allFilter.specialityCrowd.size > 0) {
洪国微 committed
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "7" -> {
                //资质选择
                if (headData?.filters?.title!!.isNotEmpty()) {
                    for (bean in headData?.filters?.title!!) {
                        if (TextUtils.equals(hotData.id, bean.key.toString())) {
                            if (isAdd) {
                                allFilter.title.add(bean)
                            } else {
                                allFilter.title.remove(bean)
                            }
                        }
                    }
                }
655
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size + allFilter.specialityCrowd.size > 0) {
洪国微 committed
656 657 658 659 660 661 662 663 664
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "8" -> {
                //市
                if (headData?.region!!.size > 0) {
665
                    val bean = SubItem()
洪国微 committed
666 667 668 669 670
                    if (isAdd) {
                        //热门中如果选择过地区、要把其他已选中的置位未选中
                        if (hasSelectedArea) {
                            for ((index, bean) in headData!!.highlighter.withIndex()) {
                                if (bean.type == "2" || bean.type == "8") {
671
                                    val textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
672 673 674 675 676 677
                                    textview.isSelected = false
                                    textview.paint.isFakeBoldText = false
                                }
                            }
                        }

678
                        bean.code = hotData.id
洪国微 committed
679 680
                        bean.value = hotData.value
                        for (headBean in headData!!.region) {
681
                            if (TextUtils.equals(
682 683
                                    headBean.code!!.substring(0, 2),
                                    bean.code!!.substring(0, 2)
684 685
                                )
                            ) {
洪国微 committed
686 687 688 689 690 691
                                allFilter.region = headBean
                                break
                            }
                        }
                        allFilter.sub = bean
                        if (allFilter.sub.value?.length ?: 0 > 4) {
692
                            tvArea.text = allFilter.sub.value?.substring(0, 3) + "..."
洪国微 committed
693
                        } else {
694
                            tvArea.text = allFilter.sub.value
洪国微 committed
695 696 697 698 699 700 701 702
                        }
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)

                        hasSelectedArea = true
                    } else {
                        allFilter.region = RegionItem()
                        allFilter.sub = SubItem("不限", null)

703
                        tvArea.text = "地区"
洪国微 committed
704 705 706 707 708 709 710 711 712 713 714
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)

                        hasSelectedArea = false
                    }
                }
            }
        }
    }


    //用于侧滑筛选过来更新快捷筛选选中状态
upwork.021 committed
715
    private fun updateOtherViews(otherData: List<OtherItem>) {
洪国微 committed
716 717 718
        if (lin_filter2.childCount > 0) {
            //清空选中
            for (i in 0.until(lin_filter2.childCount)) {
719
                val textView = lin_filter2.getChildAt(i) as TextView
洪国微 committed
720 721 722 723
                textView.isSelected = false
                textView.paint.isFakeBoldText = false
            }
            //重置选中状态
upwork.021 committed
724
            for (other in otherData) {
洪国微 committed
725
                for (i in 0 until lin_filter2.childCount) {
726
                    val textView = lin_filter2.getChildAt(i) as TextView
洪国微 committed
727 728 729 730 731 732 733 734 735
                    if (textView.text == other.value) {
                        textView.isSelected = true
                        textView.paint.isFakeBoldText = true
                    }
                }
            }
        }
    }

upwork.021 committed
736 737 738
    /**
     * 获取专家列表数据
     */
739 740 741 742 743
    override fun onDoctorListFetched(
        data: MutableList<ExpertServiceItem>,
        extras: Extras?,
        curPage: Int
    ) {
洪国微 committed
744
        if (rvExperts.adapter != doctorAdapter) {
745
            rvExperts.adapter = doctorAdapter
洪国微 committed
746 747 748
        }
        LogUtil.d("data size " + data.size)

749
        // 如果是第一页
750 751
        if (curPage == 1) {
            if (data.size >= 10) {
752 753
                hasMore = true
                doctorAdapter.hasMore = true
754
            } else {
755 756 757
                hasMore = false
                doctorAdapter.hasMore = false
            }
upwork.021 committed
758
            doctorList.clear()
洪国微 committed
759
        }
upwork.021 committed
760

761
        if (data.size == 0) {     // data的长度为0的时候为最后一页
洪国微 committed
762 763
            hasMore = false
            doctorAdapter.hasMore = false
764
        } else {
765
            doctorList.addAll(data)
洪国微 committed
766 767 768 769 770
        }
        doctorAdapter.notifyDataSetChanged()
        isDoSearch = false
        isRecommend = false

771

772 773
        v_loading.visibility = View.GONE
        ll_network_error.visibility = View.GONE
洪国微 committed
774

775
        rvExperts.visibility = View.VISIBLE
洪国微 committed
776
        srlContainer.isRefreshing = false
upwork.021 committed
777 778

        // 埋点
779 780 781 782 783 784 785 786
        mIdssign1 = data.joinToString(",") { it.id }
        ActionCountUtils.baiDuCountSign3(
            ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
            ConsultBIConstants.POSITION_CONSULT_COUNSELOR_LIST_PAGE_VISIT,
            mIdssign1,
            sign2,
            "app"
        )
洪国微 committed
787 788 789 790 791 792
    }

    override fun fetchListFailed(msg: String?) {
        isDoSearch = false
        isRecommend = false

upwork.021 committed
793
        if (getPresenter().mExtras == null) {
794 795 796 797 798
            v_loading.setViewType(
                LogoLoadingView.TYPE_NET_LOSS,
                getString(R.string.consultant_reload_hint)
            )
            v_loading.visibility = View.VISIBLE
洪国微 committed
799

800
            ll_network_error.visibility = View.GONE
洪国微 committed
801 802 803
        } else {
            ToastHelper.show("网络不给力")
        }
804
        srlContainer.isRefreshing = false
洪国微 committed
805 806 807 808 809 810
    }

    override fun fetchListEmpty(msg: String?) {
        isDoSearch = false
        isRecommend = false

811 812 813 814
        tv_reload.visibility = View.GONE
        tv_reload_hint.text = msg
        ll_network_error.visibility = View.VISIBLE
        iv_exception.setImageResource(R.drawable.platform_ico_img_zixun_empty)
洪国微 committed
815

816 817
        rvExperts.visibility = View.GONE
        srlContainer.isRefreshing = false
洪国微 committed
818 819 820 821 822 823 824 825
    }

    override fun fetchFailed(msg: String?) {
        isDoSearch = false
        isRecommend = false
        if (msg != null) {
            ToastUtil.toastShort(msg)
        }
826 827 828 829 830
        v_loading.setViewType(
            LogoLoadingView.TYPE_NET_LOSS,
            getString(R.string.consultant_reload_hint)
        )
        v_loading.visibility = View.VISIBLE
洪国微 committed
831

832
        ll_network_error.visibility = View.GONE
洪国微 committed
833

834 835
        rvExperts.visibility = View.GONE
        appbar_layout.setExpanded(false)
洪国微 committed
836 837 838
    }

    override fun showRefreshLayout() {
839
        srlContainer.isRefreshing = true
洪国微 committed
840 841 842 843 844 845 846 847 848 849 850
    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.image_scroll_top -> {
                scrollToTop()
            }
            R.id.tvSubject -> {
                props1.put("filtrate_first", "主题")
                hideSoftInput()
851 852
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
853
                    showSubjectPopupWindow()
upwork.021 committed
854
                }, 300)
洪国微 committed
855 856 857 858 859

            }
            R.id.tvArea -> {
                props1.put("filtrate_first", "地区")
                hideSoftInput()
860 861
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
862
                    showAreaPopupWindow()
upwork.021 committed
863
                }, 300)
洪国微 committed
864 865 866 867 868

            }
            R.id.tvSort -> {
                props1.put("filtrate_first", "排序")
                hideSoftInput()
869 870
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
871
                    showSortPopupWindow()
upwork.021 committed
872
                }, 300)
洪国微 committed
873 874 875 876 877

            }
            R.id.tvFilter -> {
                props1.put("filtrate_first", "筛选")
                hideSoftInput()
878 879
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
880
                    showFilterPopupWindow()
upwork.021 committed
881
                }, 300)
洪国微 committed
882 883 884 885 886

            }
            R.id.tv_guide -> {
                ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_CONSULT_GUIDE_CLICK)

887
                val h5param = H5Params(HttpConfig.H5_URL + "help/consultation/", "咨询指南")
洪国微 committed
888 889 890 891 892 893
                h5param.isShowMenu = true
                NewH5Activity.start(context, h5param)
            }
            R.id.btn_call -> {
                ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_ONLINE_CUSTOMER_CLICK)

YKai committed
894
                ConsultantIn.startP2PXiaoYi(mContext)
洪国微 committed
895 896 897
            }
            R.id.rl_search -> {
                ARouter.getInstance()
898 899 900
                    .build("/consult/hot_search")
                    .withString(HOT_SEARCH_DOCTOR_NAME, tv_search_content.text.toString())
                    .navigation()
洪国微 committed
901 902 903 904 905 906
            }
        }
    }

    private fun scrollToTop() {
        if ((rvExperts.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 10) {
907 908
            rvExperts.scrollToPosition(10)
            rvExperts.smoothScrollToPosition(0)
洪国微 committed
909
        } else {
910
            rvExperts.smoothScrollToPosition(0)
洪国微 committed
911 912 913 914 915 916 917 918 919 920 921 922 923 924
        }
    }

    //显示筛选弹窗
    private fun showFilterPopupWindow() {
        tempFilter.categories.clear()
        tempFilter.categories.addAll(allFilter.categories)
        tempFilter.reorder = allFilter.reorder
        tempFilter.region = allFilter.region
        tempFilter.sub = allFilter.sub

        tempFilter.showType = allFilter.showType
        tempFilter.ages.clear()
        tempFilter.ages.addAll(allFilter.ages)
925 926 927
        //学历
        tempFilter.doctorEdu.clear()
        tempFilter.doctorEdu.addAll(allFilter.doctorEdu)
洪国微 committed
928 929
        tempFilter.enquiries.clear()
        tempFilter.enquiries.addAll(allFilter.enquiries)
930 931 932
        // 擅长人群添加数据
        tempFilter.specialityCrowd.clear()
        tempFilter.specialityCrowd.addAll(allFilter.specialityCrowd)
洪国微 committed
933 934 935 936 937 938
        tempFilter.others.clear()
        tempFilter.others.addAll(allFilter.others)
        tempFilter.priceRanges = allFilter.priceRanges
        tempFilter.priceRangesView = allFilter.priceRangesView

        if (headData?.filters != null) {
YKai committed
939
            val filterPopupWindow = FilterPopupWindow(mContext, headData?.filters!!, tempFilter)
洪国微 committed
940
            filterPopupWindow.setOnDismissListener {
941
                viewDim.visibility = View.INVISIBLE
942
                viewDim_filter.visibility = View.GONE
943
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size + allFilter.specialityCrowd.size > 0 || !TextUtils.isEmpty(
944 945
                        allFilter.priceRanges?.min_price
                    ) || !TextUtils.isEmpty(allFilter.priceRanges?.max_price)
946
                ) {
洪国微 committed
947 948 949 950
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
徐健 committed
951
                showConsultAssistantDialog()
洪国微 committed
952 953
            }
            filterPopupWindow.isClippingEnabled = false
954
            filterPopupWindow.showAsDropDown(viewSep2)
徐健 committed
955
            hideConsultAssistantDialog()
洪国微 committed
956 957
            filterPopupWindow.onFilterConfirmListener = this
            updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
958
            viewDim.visibility = View.VISIBLE
洪国微 committed
959 960 961 962 963 964 965 966 967
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //筛选确认回调
    override fun onFilterConfirmed() {
        updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
upwork.021 committed
968

969 970
        props1.put(
            "filtrate_second",
971 972 973 974 975
            tempFilter.showType.value + ","
                    + tempFilter.enquiries.map { it.value }.joinToString(",") + ","
                    + tempFilter.ages.map { it.value }.joinToString(",") + ","
                    + tempFilter.doctorEdu.map { it.value }.joinToString(",") + ","
                    + tempFilter.others.map { it.value }.joinToString(",")
976
        )
洪国微 committed
977 978
        BuryPointUtils.buryPoint("Filtrate", props1)

upwork.021 committed
979
        // 埋点
980 981 982 983 984 985 986 987 988
        if (tempFilter.specialityCrowd.size > 0) {
            val sign1 = tempFilter.specialityCrowd.joinToString(",") { it.value!! }
            ActionCountUtils.baiDuCountSign3(
                ConsultBIConstants.PART_ID_CONSULT_FILTER_PAGE,
                ConsultBIConstants.ConsultEvent.POSITION_GOODAT_CROWD_CLICK,
                sign1,
                "app",
                ""
            )
upwork.021 committed
989 990
        }

洪国微 committed
991 992 993 994 995 996

        allFilter.showType = tempFilter.showType
        allFilter.enquiries.clear()
        allFilter.enquiries.addAll(tempFilter.enquiries)
        allFilter.ages.clear()
        allFilter.ages.addAll(tempFilter.ages)
997 998
        allFilter.doctorEdu.clear()
        allFilter.doctorEdu.addAll(tempFilter.doctorEdu)
999 1000 1001 1002
        // 擅长人群
        allFilter.specialityCrowd.clear()
        allFilter.specialityCrowd.addAll(tempFilter.specialityCrowd)
        // 其它
洪国微 committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014
        allFilter.others.clear()
        allFilter.others.addAll(tempFilter.others)
        allFilter.title.clear()
        allFilter.title.addAll(tempFilter.title)
        allFilter.priceRanges = tempFilter.priceRanges
        allFilter.priceRangesView = tempFilter.priceRangesView

        //判断主题选中,判断热门筛选中是否也有该主题
        Executors.newCachedThreadPool().execute {
            if (headData!!.highlighter.size > 0) {
                for (index in 0.until(headData!!.highlighter.size)) {
                    if (headData!!.highlighter[index].type == "4") {
YKai committed
1015
                        val textview = lin_filter2.getChildAt(index) as TextView
YKai committed
1016
                        mActivity.runOnUiThread {
洪国微 committed
1017 1018 1019 1020
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.enquiries) {
1021 1022 1023 1024 1025
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
YKai committed
1026
                                mActivity.runOnUiThread {
洪国微 committed
1027 1028 1029 1030 1031 1032 1033 1034
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "5") {
YKai committed
1035
                        val textview = lin_filter2.getChildAt(index) as TextView
YKai committed
1036
                        mActivity.runOnUiThread {
洪国微 committed
1037 1038 1039 1040
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.ages) {
1041 1042 1043 1044 1045
                            if (TextUtils.equals(
                                    bean.value.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
YKai committed
1046
                                mActivity.runOnUiThread {
洪国微 committed
1047 1048 1049 1050 1051 1052 1053 1054
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "6") {
YKai committed
1055
                        val textview = lin_filter2.getChildAt(index) as TextView
YKai committed
1056
                        mActivity.runOnUiThread {
洪国微 committed
1057 1058 1059 1060
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.others) {
1061 1062 1063 1064 1065
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
YKai committed
1066
                                mActivity.runOnUiThread {
洪国微 committed
1067 1068 1069 1070 1071 1072 1073 1074 1075
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }

                    if (headData!!.highlighter[index].type == "7") {
YKai committed
1076
                        val textview = lin_filter2.getChildAt(index) as TextView
YKai committed
1077
                        mActivity.runOnUiThread {
洪国微 committed
1078 1079 1080 1081
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.title) {
1082 1083 1084 1085 1086
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
YKai committed
1087
                                mActivity.runOnUiThread {
洪国微 committed
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                }
            }
        }

        filterLabelSet()
        //刷新快捷按钮选中状态
        updateOtherViews(allFilter.others)
        refresh()
    }

    //筛选标题显示处理
    private fun filterLabelSet() {
1107
        if ((allFilter.others.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.enquiries.size + allFilter.title.size + allFilter.specialityCrowd.size) == 1) {
洪国微 committed
1108
            var text: String? = ""
YKai committed
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121
            when {
                allFilter.others.size == 1 -> {
                    text = allFilter.others[0].value
                }
                allFilter.ages.size == 1 -> {
                    text = allFilter.ages[0].value
                }
                allFilter.enquiries.size == 1 -> {
                    text = allFilter.enquiries[0].value
                }
                allFilter.title.size == 1 -> {
                    text = allFilter.title[0].value
                }
1122
                allFilter.specialityCrowd.size == 1 -> {
YKai committed
1123 1124
                    text = allFilter.specialityCrowd[0].value
                }
1125
                allFilter.doctorEdu.size == 1 -> {
1126 1127
                    text = allFilter.doctorEdu[0].value
                }
YKai committed
1128 1129 1130
                else -> {
                    text = "筛选"
                }
洪国微 committed
1131 1132
            }
            if (text?.length ?: 0 > 4) {
1133
                tvFilter.text = text?.substring(0, 3) + "..."
洪国微 committed
1134
            } else {
1135
                tvFilter.text = text
洪国微 committed
1136 1137
            }
        } else {
1138
            tvFilter.text = "筛选"
洪国微 committed
1139 1140 1141 1142 1143 1144 1145 1146 1147
        }
    }


    private var sortPopup: SortPopupWindow? = null

    //显示排序弹窗
    private fun showSortPopupWindow() {
        if (headData?.reorder != null) {
YKai committed
1148
            sortPopup = SortPopupWindow(mActivity, headData?.reorder!!, allFilter.reorder, this)
洪国微 committed
1149
            sortPopup!!.setOnDismissListener {
1150
                viewDim.visibility = View.INVISIBLE
洪国微 committed
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
                if (allFilter.reorder != headData!!.reorder[0]) {
                    updateFilterTextViewStatus(tvSort, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvSort, FILTER_STATUS_NORMAL)
                }
            }
            if (sortPopup!!.selectedSort != allFilter.reorder) {
                sortPopup!!.selectedSort = allFilter.reorder
                sortPopup!!.notifyDataSetChanged()
            }
            sortPopup!!.showAsDropDown(viewSep2)
            updateFilterTextViewStatus(tvSort, FILTER_STATUS_OPEN)
1163
            viewDim.visibility = View.VISIBLE
洪国微 committed
1164 1165 1166 1167 1168 1169 1170 1171
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //排序选择回调
    override fun onSortItemSelected(sortItem: ReorderItem) {
1172 1173 1174 1175
        ActionCountUtils.count(
            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_SORT_CLICK, sortItem.value
                ?: ""
        )
洪国微 committed
1176

upwork.021 committed
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
        when {
            sortItem.value.equals("综合排序") -> {
                tvSort.text = "排序"
            }
            sortItem.value?.length ?: 0 > 4 -> {
                tvSort.text = sortItem.value?.substring(0, 3) + "..."
            }
            else -> {
                tvSort.text = sortItem.value
            }
洪国微 committed
1187 1188 1189 1190 1191 1192
        }

        //判断排序选中,判断热门筛选中是否也有该排序
        if (headData!!.highlighter.size > 0) {
            for (index in 0.until(headData!!.highlighter.size)) {
                if (headData!!.highlighter[index].type == "3") {
upwork.021 committed
1193
                    val textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
                    if (TextUtils.equals(sortItem.value, headData!!.highlighter[index].value)) {
                        textview.isSelected = true
                        textview.paint.isFakeBoldText = true

                        hasSelectedSort = true
                    } else {
                        textview.isSelected = false
                        textview.paint.isFakeBoldText = false
                    }
                }
            }
        }

        updateFilterTextViewStatus(tvSort, FILTER_STATUS_OPEN)
        LogUtil.d("sortItem key: " + sortItem.key + " sortItem value: " + sortItem.value)
        props1.put("filtrate_second", sortItem.value)
        BuryPointUtils.buryPoint("Filtrate", props1)
        allFilter.reorder = sortItem
        sortPopup?.dismiss()
        refresh()
    }

    //显示地区弹窗
    private fun showAreaPopupWindow() {
        if (headData?.region != null) {
1219 1220 1221 1222 1223 1224
            val regionPopupWindow = AreaPopupWindow(
                mActivity,
                headData?.region ?: ArrayList(),
                allFilter.region,
                allFilter.sub
            )
洪国微 committed
1225
            regionPopupWindow.showAsDropDown(viewSep2)
1226
            viewDim.visibility = View.VISIBLE
洪国微 committed
1227 1228
            updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
            regionPopupWindow.setOnDismissListener {
1229
                viewDim.visibility = View.INVISIBLE
洪国微 committed
1230 1231 1232 1233 1234 1235
                if (tvArea.text != "地区") {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)
                }
            }
1236 1237 1238 1239 1240 1241
            regionPopupWindow.onRegionSelectedListener =
                object : AreaPopupWindow.OnRegionSelectedListener {
                    override fun onRegionSelected(region: RegionItem, sub: SubItem) {
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
                        allFilter.region = region
                        allFilter.sub = sub
1242
                        if (TextUtils.isEmpty(region.code) && TextUtils.isEmpty(sub.code)) {
1243
                            tvArea.text = "地区"
1244
                        } else if (!TextUtils.isEmpty(region.code) && !TextUtils.isEmpty(sub.code)) {
1245 1246 1247 1248 1249
                            if (region.value?.length ?: 0 > 4) {
                                tvArea.text = region.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = region.value
                            }
洪国微 committed
1250
                        } else {
1251 1252 1253 1254 1255
                            if (sub.value?.length ?: 0 > 4) {
                                tvArea.text = sub.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = sub.value
                            }
洪国微 committed
1256
                        }
1257 1258 1259 1260 1261 1262 1263
                        ActionCountUtils.count(
                            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_AREA_CLICK,
                            region.value + "|" + sub.value
                        )

                        //更新热门搜索显示状态
                        if (headData!!.highlighter.size > 0) {
1264
                            for ((index, hot) in headData!!.highlighter.withIndex()) {
1265
                                if (hot.type == "2" || hot.type == "8") {
1266
                                    val textview = lin_filter2.getChildAt(index) as TextView
1267
                                    //有选择城市
1268 1269
                                    if (!TextUtils.isEmpty(sub.code)) {
                                        if (TextUtils.equals(sub.code, hot.id)) {
1270 1271 1272 1273 1274 1275 1276
                                            textview.isSelected = true
                                            textview.paint.isFakeBoldText = true
                                            hasSelectedArea = true
                                        } else {
                                            textview.isSelected = false
                                            textview.paint.isFakeBoldText = false
                                        }
洪国微 committed
1277
                                    } else {
1278
                                        if (TextUtils.equals(region.code, hot.id)) {
1279 1280 1281 1282 1283 1284 1285
                                            textview.isSelected = true
                                            textview.paint.isFakeBoldText = true
                                            hasSelectedArea = true
                                        } else {
                                            textview.isSelected = false
                                            textview.paint.isFakeBoldText = false
                                        }
洪国微 committed
1286 1287 1288 1289
                                    }
                                }
                            }
                        }
1290 1291
                        regionPopupWindow.dismiss()
                        refresh()
洪国微 committed
1292 1293 1294 1295 1296 1297 1298 1299
                    }
                }
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

1300
    private var mHandler: Handler? = null
洪国微 committed
1301

upwork.021 committed
1302 1303 1304
    /**
     *   显示八大类弹窗
     */
洪国微 committed
1305
    private fun showSubjectPopupWindow() {
1306 1307 1308 1309
        val categoryPopup = CategoryPopupWindow(mActivity, allFilter)
        mHandler = Handler()
        mHandler!!.post {
            categoryPopup.updateData()
洪国微 committed
1310
        }
1311 1312 1313 1314 1315 1316 1317 1318 1319
        categoryPopup.setOnDismissListener {
            viewDim.visibility = View.INVISIBLE
            showConsultAssistantDialog()
        }
        hideConsultAssistantDialog()
        categoryPopup.onSubjectsSelectedListener = this
        categoryPopup.showAsDropDown(viewSep2)
        updateFilterTextViewStatus(tvSubject, FILTER_STATUS_OPEN)
        viewDim.visibility = View.VISIBLE
洪国微 committed
1320 1321 1322 1323 1324 1325
    }

    /**
     * 主题选择确认回调
     *
     */
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
    override fun onCategoriesSelected(signLit: ArrayList<String>) {
        if (signLit.isNotEmpty()) {
            val sign1 = signLit.joinToString(",") { it }
            ActionCountUtils.baiDuCountSign3(
                ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
                ConsultBIConstants.ConsultEvent.POSITION_TWO_CATEGORY_CLICK,
                sign1,
                "app",
                ""
            )
upwork.021 committed
1336
        }
upwork.021 committed
1337

1338
        if (allFilter.categoryId2List.size > 0 || allFilter.categoryId3List.size > 0) {
upwork.021 committed
1339
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
1340
        } else {
upwork.021 committed
1341
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_NORMAL)
洪国微 committed
1342
        }
upwork.021 committed
1343
        refresh()
洪国微 committed
1344 1345
    }

1346 1347
    override fun onRefresh() {
        refresh(false)
1348
        recommendListView.requestData("")
1349 1350
    }

upwork.021 committed
1351 1352 1353 1354
    /**
     * EventBus从首页某个位置点击事件传递
     * sign 仅用于埋点事件统计
     */
1355
    private var sign2 = ""
upwork.021 committed
1356
    fun onEvent(event: HomeModuleTabEvent) {
1357 1358
        if (!TextUtils.isEmpty(event.sign)) {
            sign2 = event.sign
upwork.021 committed
1359
            // 埋点
1360 1361 1362 1363 1364 1365 1366 1367
            if (!TextUtils.isEmpty(mIdssign1)) {
                ActionCountUtils.baiDuCountSign3(
                    ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
                    ConsultBIConstants.POSITION_CONSULT_COUNSELOR_LIST_PAGE_VISIT,
                    mIdssign1,
                    sign2,
                    "app"
                )
upwork.021 committed
1368
            }
1369
        }
upwork.021 committed
1370 1371
    }

洪国微 committed
1372 1373
    //刷新列表
    private fun refresh(isShowRefresh: Boolean? = true) {
1374 1375
        srlContainer.isRefreshing = isShowRefresh!!
        val key = tv_search_content.text.toString()
洪国微 committed
1376 1377 1378 1379 1380 1381
        if (!TextUtils.isEmpty(key.trim())) {
            allFilter.searchWord = key.trim()
        } else {
            allFilter.searchWord = null
        }
        onScrollListener.resetState()
upwork.021 committed
1382 1383
        getPresenter().mExtras = null
        getPresenter().fetchListData(allFilter, getPresenter().mExtras)
1384
        rvExperts.scrollToPosition(0)
洪国微 committed
1385 1386 1387 1388 1389 1390 1391
    }

    //设置筛选点击按钮状态
    private fun updateFilterTextViewStatus(tv: TextView, status: Int) {
        when (status) {
            FILTER_STATUS_NORMAL -> {
                tv.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
YKai committed
1392
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.platform_colorTextDefault))
1393 1394 1395 1396 1397 1398
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
洪国微 committed
1399 1400 1401
            }
            FILTER_STATUS_FILTERED -> {
                tv.typeface = Typeface.DEFAULT_BOLD
YKai committed
1402
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.platform_main_theme))
1403 1404 1405 1406 1407 1408
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
洪国微 committed
1409 1410 1411
            }
            FILTER_STATUS_OPEN -> {
                tv.typeface = Typeface.DEFAULT_BOLD
YKai committed
1412
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.platform_colorTextDefault))
1413 1414 1415 1416 1417 1418
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_arrow_drop_down_en,
                    0
                )
洪国微 committed
1419 1420 1421 1422 1423
            }
        }
    }

    private fun hideSoftInput() {
YKai committed
1424
        val view = mActivity.currentFocus
洪国微 committed
1425
        if (view != null) {
YKai committed
1426
            val imm = mActivity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
洪国微 committed
1427 1428 1429 1430 1431 1432
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }

    override fun onResume() {
        super.onResume()
1433 1434 1435 1436 1437 1438
        if (needRefresh){
            refresh(false)
        }else{
            //
            needRefresh = true
        }
霍志良 committed
1439
        ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_PAGE_VISIT)
1440
        ActionCountUtils.count("daoyi_advertisement_page|daoyi_advertisement_visit", "6")
1441
    }
霍志良 committed
1442

洪国微 committed
1443 1444
    override fun onDestroy() {
        super.onDestroy()
upwork.021 committed
1445
        EventBus.getDefault().unregister(this)
1446
        mHandler = null
洪国微 committed
1447 1448 1449
        ConsultAssistantDialogUtils.INSTANCE.resetStatus()
    }
}