ExpertSearchFragment.kt 60.5 KB
Newer Older
洪国微 committed
1 2 3 4 5 6 7 8 9 10
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
import android.os.Build
import android.support.v4.content.ContextCompat
11
import android.support.v4.widget.SwipeRefreshLayout
洪国微 committed
12 13 14
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
konghaorui committed
15 16
import android.view.Gravity
import android.view.View
洪国微 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.alibaba.android.arouter.launcher.ARouter
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
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.ui.LogoLoadingView
import com.ydl.ydlcommon.utils.BuryPointUtils
洪国微 committed
31
import com.ydl.ydlcommon.utils.DisplayUtils
洪国微 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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.RxDeviceTool
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
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
52
import com.yidianling.consultant.ui.view.topView.RecommendListView
洪国微 committed
53 54 55 56 57 58 59
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

60 61 62
class ExpertSearchFragment : BaseMvpFragment<IExpertSearchView, ExpertSearchPresenter>(),
    View.OnClickListener, IExpertSearchView,
    OnCategoriesSelectedListener, OnSortItemSelectedListener, OnFilterConfirmListener,
63 64 65
    SwipeRefreshLayout.OnRefreshListener {


洪国微 committed
66 67 68 69 70 71
    override fun layoutResId(): Int {
        return R.layout.consultant_activity_expert_search_list
    }

    override fun initDataAndEvent() {
        var statusBarHeight = StatusBarUtils.getStatusBarHeight(context);
72
        rootView.setPadding(0, statusBarHeight, 0, 0)
洪国微 committed
73
        btn_back.visibility = View.GONE
74
        title_layout.setPadding(DisplayUtils.dp2px(context, 15), 0, 0, 0)
洪国微 committed
75 76 77 78 79 80 81 82 83
        initViews()
        initData()
    }

    override fun initDataAndEventLazy() {

    }

    override fun showImage(url: String?, imgView: ImageView) {
84 85 86
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView)
        }
洪国微 committed
87 88 89
    }

    override fun showImage(url: String?, imgView: ImageView, ops: SimpleImageOpConfiger) {
90 91 92
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView, ops)
        }
洪国微 committed
93 94
    }

95 96 97 98 99 100 101
    override fun showImage(
        url: String?,
        imgView: ImageView,
        width: Int,
        heigh: Int,
        ops: SimpleImageOpConfiger
    ) {
102 103 104
        if (isAdded) {
            YDLImageCacheManager.showImage(activity, url, imgView, width, heigh, ops)
        }
洪国微 committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    }
//
//    override fun getStatusViewOptions(): StatusBarOptions {
//        return StatusBarOptions(true,true)
//    }

    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
    }

    private val allFilter = AllFilter() //当前筛选
    private val tempFilter = AllFilter() //临时筛选,未确认状态
    private var curPage = 1
    private val doctorList = ArrayList<DoctorServiceItem>()
    private val serviceList = ArrayList<DoctorServiceItem>()
    private var hasMore = true
    private var initCategory: Int = 0
    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 fromPageType: Int = 0 //从哪个页面跳转过来的
142
    private val fromPages = arrayOf("首页", "搜索页面", "在线专家")
洪国微 committed
143 144 145 146 147 148 149 150 151 152 153
    private var isRecommend = false //埋点数据
    private var keyWord: String? = null //埋点数据
    private var isDoSearch: Boolean = false //埋点判断是否通过搜索进入埋点的
    private val bannerList = ArrayList<String>()
    private var hasSelectedArea = false  //是否选择过地区
    private var hasSelectedSort = false  //是否选择过排序


    override fun createPresenter(): ExpertSearchPresenter = ExpertSearchPresenter()

    private fun initViews() {
konghaorui committed
154
        srlContainer.isEnabled = true
洪国微 committed
155 156 157 158 159 160 161
        tvSubject.setOnClickListener(this)
        tvArea.setOnClickListener(this)
        tvSort.setOnClickListener(this)
        tvFilter.setOnClickListener(this)
        btn_call.setOnClickListener(this)
        tv_guide.setOnClickListener(this)
        rl_search.setOnClickListener(this)
162 163 164 165 166 167
        srlContainer.setColorSchemeColors(
            ContextCompat.getColor(
                activity,
                R.color.consultant_main_theme
            )
        )
168 169
        srlContainer.setProgressViewOffset(false, 0, 200)
        srlContainer.setOnRefreshListener(this)
洪国微 committed
170 171
        initNetLossView()

172 173
        recommendListView.addViewPagerScrollStateListener(object :
            RecommendListView.ViewPagerScrollStateCallback {
徐健 committed
174 175 176 177 178 179
            override fun viewPagerScroll(isScrolling: Boolean) {
                //如果viewpager正在滚动,则禁止下拉刷新
                srlContainer.isEnabled = !isScrolling
            }
        })

徐健 committed
180 181 182 183
        appbar_layout.addOnOffsetChangedListener { appbarLayout, i ->
            srlContainer.isEnabled = i >= 0
        }

洪国微 committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208

//        etSearch.setOnEditorActionListener { _, actionId, _ ->
//            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//                doSearch()
//            }
//            true
//        }
//        etSearch.setOnClickListener { appbar_layout.setExpanded(false) }
//        etSearch.setOnFocusChangeListener { view, b -> if (b) appbar_layout.setExpanded(false) }
//        btn_back.setOnClickListener {
//            onBackPressed()
//        }
        doctorAdapter = ExpertSearchAdapter(context, this, doctorList)

        rvExperts.adapter = doctorAdapter
        val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
        rvExperts.layoutManager = layoutManager
        onScrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
            private var isBtnShow: Boolean = false
            private var sIsScrolling = false
            override fun onScrollStateChanged(recyclerView: RecyclerView?, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)
                hideSoftInput()
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
                    sIsScrolling = true
209 210
                    //滚动
                    hideConsultAssistantDialog()
洪国微 committed
211 212

                } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
213 214
                    //没有滚动
                    showConsultAssistantDialog()
洪国微 committed
215 216 217 218 219 220 221 222 223 224 225
                    if (sIsScrolling) {

                    }
                    sIsScrolling = false;
                }
            }

            override fun onScrollTop() {
                var alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                var scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                var scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
226 227 228
                var animator =
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
                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
                }
                var alpha = PropertyValuesHolder.ofFloat("alpha", 0f, 1f)
                var scaleX = PropertyValuesHolder.ofFloat("scaleX", 0f, 1f)
                var scaleY = PropertyValuesHolder.ofFloat("scaleY", 0f, 1f)
245 246 247
                var animator =
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
                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
                }
                var alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                var scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                var scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
264 265 266
                var animator =
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
洪国微 committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
                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) {
                    curPage++
                    getPresenter().fetchListData(allFilter, curPage)
                }
            }
        }
//        rvExperts.addItemDecoration(ExpertItemDecoration(this))
        rvExperts.addOnScrollListener(onScrollListener)
        rvExperts.addOnScrollListener(YDLImageRecyclerOnScrollListener(activity))
//        etSearch.addTextChangedListener(object : TextWatcher {
//            override fun afterTextChanged(s: Editable?) {}
//
//            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
//
//            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
//
//            }
//
//        })
        image_scroll_top.setOnClickListener(this)
//        initStatus()
徐健 committed
298
    }
洪国微 committed
299

徐健 committed
300 301
    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
302
        if (isVisibleToUser && isResumed) {
徐健 committed
303
            showConsultAssistantDialog()
304
        } else {
徐健 committed
305 306 307 308 309
            hideConsultAssistantDialog()
        }
        if (isVisibleToUser && isResumed) {
            onResume()
        }
徐健 committed
310

徐健 committed
311 312 313
    }

    private fun showConsultAssistantDialog() {
洪国微 committed
314 315 316
        ConsultAssistantDialogUtils.INSTANCE.fitRequest(activity, "doctor_list")
    }

徐健 committed
317 318 319 320
    private fun hideConsultAssistantDialog() {
        ConsultAssistantDialogUtils.INSTANCE.hide()
    }

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

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

    override fun localData() {
    }

    override fun updateCache(showType: Int, searchBean: ExpertSearchBean) {
    }

    private fun initData() {
        allFilter.showType.key = initShowType
        val cat = CateItem()
        cat.cateId = initCategory
        allFilter.categories.clear()
        allFilter.categories.add(cat)
        getPresenter().fetchListHead()
        //加载本地缓存数据
        getPresenter().localData(initShowType)
konghaorui committed
352
        //refresh(false)
洪国微 committed
353

354 355
        v_loading.visibility = View.VISIBLE
        v_loading.setViewType(LogoLoadingView.TYPE_LOADING, null)
洪国微 committed
356 357

        if (fromPageType != -1) {
358
            doctorAdapter.setEntrance(fromPages[fromPageType], 0)
洪国微 committed
359 360 361 362 363 364 365 366 367 368 369
        }
    }

    /**
     * 初始化状态栏位置
     */
    private fun initStatus() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4以下不支持状态栏变色
            StatusBarUtils.setTransparentForImageView(activity, null)
            val statusBarHeight = StatusBarUtils.getStatusBarHeight(context)

370
            val lp1 = title_layout.layoutParams as LinearLayout.LayoutParams
洪国微 committed
371
            lp1.height = (RxImageTool.dp2px(48f) + statusBarHeight)
372
            title_layout.setPadding(0, statusBarHeight, 0, 0)
洪国微 committed
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
        }
    }

    //筛选数据获取后回调
    override fun onHeadFetched(headData: HeadData?) {
        //头部数据获取到后初始化筛选数据
        this.headData = headData
        if (initCategory != 0) {
            if (headData?.cates != null) {
                for (cate in headData.cates) {
                    if (cate.cateId == initCategory) {
                        allFilter.categories.clear()
                        allFilter.categories.add(cate)
                        if (allFilter.categories.size == 1 && !"全部".equals(allFilter.categories[0].cateName)) {
                            //显示选中标题
388
                            tvSubject.text = allFilter.categories[0].cateName
洪国微 committed
389 390
                        } else {
                            //显示主标题
391
                            tvSubject.text = "主题"
洪国微 committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
                        }
                        updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
                        break
                    }
                }
            }
            initCategory = 0
        } else {
            allFilter.categories.clear()
            allFilter.categories.add(headData?.cates?.get(0) ?: CateItem())
        }
        allFilter.reorder = headData?.reorder?.get(0) ?: ReorderItem()
        allFilter.showType = headData?.filters?.showType?.get(initShowType) ?: ShowTypeItem()
        if (headData?.highlighter?.size ?: 0 > 0) {
            //设置热门搜索
            initHotViews(lin_filter2, headData!!.highlighter)
        }
    }

    /**
     * 热门
     */
    private fun initHotViews(view: LinearLayout, hotData: List<HighlighterItem>) {
        if (view.childCount > 0) {
            return
        }
        val popWidth = RxDeviceTool.getScreenWidth(context)
        val mWidth = (popWidth - RxImageTool.dp2px(10f)) / hotData.size
        for ((index, hot) in hotData!!.withIndex()) {
            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
                }
                filterLabelSet()
                //开始筛选数据
                refresh()
            }
            view.addView(textView)
        }
    }


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

                        hasSelectedArea = true
                    } else {
                        allFilter.region = RegionItem()
524
                        tvArea.text = "地区"
洪国微 committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
                        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") {
541
                                            var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
                                            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 {
560 561 562 563
                        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
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
                    }
                }
            }
            "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)
                            }
                        }
                    }
                }
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size > 0) {
                    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)
                            }
                        }
                    }
                }
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size > 0) {
                    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)
                            }
                        }
                    }
                }
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size > 0) {
                    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)
                            }
                        }
                    }
                }
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size > 0) {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "8" -> {
                //市
                if (headData?.region!!.size > 0) {
                    var bean = SubItem()
                    if (isAdd) {
                        //热门中如果选择过地区、要把其他已选中的置位未选中
                        if (hasSelectedArea) {
                            for ((index, bean) in headData!!.highlighter.withIndex()) {
                                if (bean.type == "2" || bean.type == "8") {
656
                                    var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
657 658 659 660 661 662 663 664 665
                                    textview.isSelected = false
                                    textview.paint.isFakeBoldText = false
                                }
                            }
                        }

                        bean.key = hotData.id
                        bean.value = hotData.value
                        for (headBean in headData!!.region) {
666 667 668 669 670
                            if (TextUtils.equals(
                                    headBean.key!!.substring(0, 2),
                                    bean.key!!.substring(0, 2)
                                )
                            ) {
洪国微 committed
671 672 673 674 675 676
                                allFilter.region = headBean
                                break
                            }
                        }
                        allFilter.sub = bean
                        if (allFilter.sub.value?.length ?: 0 > 4) {
677
                            tvArea.text = allFilter.sub.value?.substring(0, 3) + "..."
洪国微 committed
678
                        } else {
679
                            tvArea.text = allFilter.sub.value
洪国微 committed
680 681 682 683 684 685 686 687
                        }
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)

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

688
                        tvArea.text = "地区"
洪国微 committed
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)

                        hasSelectedArea = false
                    }
                }
            }
        }
    }


    //用于侧滑筛选过来更新快捷筛选选中状态
    private fun updateOtherViews(otherdata: List<OtherItem>) {
        if (lin_filter2.childCount > 0) {
            //清空选中
            for (i in 0.until(lin_filter2.childCount)) {
704
                val textView = lin_filter2.getChildAt(i) as TextView
洪国微 committed
705 706 707 708 709 710
                textView.isSelected = false
                textView.paint.isFakeBoldText = false
            }
            //重置选中状态
            for ((index, other) in otherdata.withIndex()) {
                for (i in 0 until lin_filter2.childCount) {
711
                    val textView = lin_filter2.getChildAt(i) as TextView
洪国微 committed
712 713 714 715 716 717 718 719 720 721
                    if (textView.text == other.value) {
                        textView.isSelected = true
                        textView.paint.isFakeBoldText = true
                    }
                }
            }
        }
    }

    //服务列表数据获取到后的回调
722 723 724 725 726
    override fun onServiceListFetched(
        data: MutableList<DoctorServiceItem>,
        page: Int,
        totalPage: Int
    ) {
洪国微 committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
        LogUtil.d("onServiceListFetched")
//        if (rvExperts.adapter != serviceAdapter) {
//            rvExperts.adapter = serviceAdapter
//        }

        if (page == 1) {
            if (fromPageType != -1 && isDoSearch) {
                LogUtil.d("keyword: " + keyWord + " isRecommend: " + isRecommend + " hasResult: " + (data.size > 0 && data != null ?: false) + " location: " + fromPages[fromPageType])
            }
            serviceList.clear()
            hasMore = true
//            serviceAdapter.hasMore = true
        }
        if (fromPageType == -1) {
            bury(keyWord ?: "", data.size > 0, isRecommend, "首页分类")
        } else {
            bury(keyWord ?: "", data.size > 0, isRecommend, fromPages[fromPageType])
        }

        if (page >= totalPage) {
            hasMore = false
//            serviceAdapter.hasMore = false
        }
        serviceList.addAll(data)
//        serviceAdapter.notifyDataSetChanged()
        isRecommend = false
        isDoSearch = false

755 756
        v_loading.visibility = View.GONE
        ll_network_error.visibility = View.GONE
洪国微 committed
757

758 759
        rvExperts.visibility = View.VISIBLE
        srlContainer.isRefreshing = false
洪国微 committed
760 761 762
    }

    //专家列表数据获取到后的回调
763 764 765 766 767
    override fun onDoctorListFetched(
        data: MutableList<DoctorServiceItem>,
        page: Int,
        totalPage: Int
    ) {
洪国微 committed
768 769
        LogUtil.d("onDoctorListFetched")
        if (rvExperts.adapter != doctorAdapter) {
770
            rvExperts.adapter = doctorAdapter
洪国微 committed
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
        }
        LogUtil.d("data size " + data.size)

        if (page == 1) {
            if (fromPageType != -1 && isDoSearch) {
                LogUtil.d("keyword: " + keyWord + " isRecommend: " + isRecommend + " hasResult: " + (data.size > 0 && data != null ?: false) + " location: " + fromPages[fromPageType])
            }
            doctorList.clear()
            doctorAdapter.hasMore = true
            hasMore = true
        }
        if (fromPageType == -1) {
            bury(keyWord ?: "", data != null && data.size > 0, isRecommend, "首页分类")
        } else {
            bury(keyWord ?: "", data != null && data.size > 0, isRecommend, fromPages[fromPageType])
        }
        if (page >= totalPage) {
            hasMore = false
            doctorAdapter.hasMore = false
        }

        doctorList.addAll(data)
        doctorAdapter.notifyDataSetChanged()
        isDoSearch = false
        isRecommend = false

797 798
        v_loading.visibility = View.GONE
        ll_network_error.visibility = View.GONE
洪国微 committed
799

800
        rvExperts.visibility = View.VISIBLE
洪国微 committed
801 802 803 804 805 806 807 808
        srlContainer.isRefreshing = false
    }

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

        if (curPage == 1) {
809 810 811 812 813
            v_loading.setViewType(
                LogoLoadingView.TYPE_NET_LOSS,
                getString(R.string.consultant_reload_hint)
            )
            v_loading.visibility = View.VISIBLE
洪国微 committed
814

815
            ll_network_error.visibility = View.GONE
洪国微 committed
816 817 818
        } else {
            ToastHelper.show("网络不给力")
        }
819
        srlContainer.isRefreshing = false
洪国微 committed
820 821 822 823 824 825
    }

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

826 827 828 829
        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
830

831 832
        rvExperts.visibility = View.GONE
        srlContainer.isRefreshing = false
洪国微 committed
833 834 835 836 837 838 839 840
    }

    override fun fetchFailed(msg: String?) {
        isDoSearch = false
        isRecommend = false
        if (msg != null) {
            ToastUtil.toastShort(msg)
        }
841 842 843 844 845
        v_loading.setViewType(
            LogoLoadingView.TYPE_NET_LOSS,
            getString(R.string.consultant_reload_hint)
        )
        v_loading.visibility = View.VISIBLE
洪国微 committed
846

847
        ll_network_error.visibility = View.GONE
洪国微 committed
848

849 850
        rvExperts.visibility = View.GONE
        appbar_layout.setExpanded(false)
洪国微 committed
851 852 853
    }

    override fun showRefreshLayout() {
854
        srlContainer.isRefreshing = true
洪国微 committed
855 856 857 858 859 860 861 862 863 864 865
    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.image_scroll_top -> {
                scrollToTop()
            }
            R.id.tvSubject -> {
                props1.put("filtrate_first", "主题")
                hideSoftInput()
866 867
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
868 869 870 871 872 873 874
                    showSubjectPopupWindow()
                }, 300);

            }
            R.id.tvArea -> {
                props1.put("filtrate_first", "地区")
                hideSoftInput()
875 876
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
877 878 879 880 881 882 883
                    showAreaPopupWindow()
                }, 300);

            }
            R.id.tvSort -> {
                props1.put("filtrate_first", "排序")
                hideSoftInput()
884 885
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
886 887 888 889 890 891 892
                    showSortPopupWindow()
                }, 300);

            }
            R.id.tvFilter -> {
                props1.put("filtrate_first", "筛选")
                hideSoftInput()
893 894
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
洪国微 committed
895 896 897 898 899 900 901
                    showFilterPopupWindow()
                }, 300);

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

902
                val h5param = H5Params(HttpConfig.H5_URL + "help/consultation/", "咨询指南")
洪国微 committed
903 904 905 906 907 908 909 910 911 912
                h5param.isShowMenu = true
                NewH5Activity.start(context, h5param)
            }
            R.id.btn_call -> {
                ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_ONLINE_CUSTOMER_CLICK)

                ConsultantIn.startP2PXiaoYi(context)
            }
            R.id.rl_search -> {
                ARouter.getInstance()
913 914 915
                    .build("/consult/hot_search")
                    .withString(HOT_SEARCH_DOCTOR_NAME, tv_search_content.text.toString())
                    .navigation()
洪国微 committed
916 917 918 919 920 921
            }
        }
    }

    private fun scrollToTop() {
        if ((rvExperts.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 10) {
922 923
            rvExperts.scrollToPosition(10)
            rvExperts.smoothScrollToPosition(0)
洪国微 committed
924
        } else {
925
            rvExperts.smoothScrollToPosition(0)
洪国微 committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
        }
    }

    //显示筛选弹窗
    private fun showFilterPopupWindow() {
//        tempFilter.searchWord = etSearch.text.toString()
        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)
        tempFilter.enquiries.clear()
        tempFilter.enquiries.addAll(allFilter.enquiries)
        tempFilter.others.clear()
        tempFilter.others.addAll(allFilter.others)
        tempFilter.priceRanges = allFilter.priceRanges
        tempFilter.priceRangesView = allFilter.priceRangesView

        if (headData?.filters != null) {
            val filterPopupWindow = FilterPopupWindow(context, headData?.filters!!, tempFilter)
            filterPopupWindow.setOnDismissListener {
                //                viewDim.visibility = View.INVISIBLE
952 953 954 955 956
                viewDim_filter.visibility = View.GONE
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.title.size > 0 || !TextUtils.isEmpty(
                        allFilter.priceRanges?.minPrice
                    ) || !TextUtils.isEmpty(allFilter.priceRanges?.maxPrice)
                ) {
洪国微 committed
957 958 959 960
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
徐健 committed
961
                showConsultAssistantDialog()
洪国微 committed
962 963 964
            }
            filterPopupWindow.isClippingEnabled = false
            filterPopupWindow.showAtLocation(viewSep2.rootView, Gravity.TOP + Gravity.RIGHT, 0, 0)
徐健 committed
965
            hideConsultAssistantDialog()
洪国微 committed
966 967 968
            filterPopupWindow.onFilterConfirmListener = this
            updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
//            viewDim.visibility = View.VISIBLE
969
            viewDim_filter.visibility = View.VISIBLE
洪国微 committed
970 971 972 973 974 975 976 977 978
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //筛选确认回调
    override fun onFilterConfirmed() {
        updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
979 980 981 982 983 984 985 986 987 988 989 990 991
        LogUtil.d(
            "filter: " + tempFilter.showType.value + "," + tempFilter.enquiries.map { it.value }.joinToString(
                ","
            ) + "," + tempFilter.ages.map { it.value }.joinToString(",") + "," + tempFilter.others.map { it.value }.joinToString(
                ","
            )
        )
        props1.put(
            "filtrate_second",
            tempFilter.showType.value + "," + tempFilter.enquiries.map { it.value }.joinToString(",") + "," + tempFilter.ages.map { it.value }.joinToString(
                ","
            ) + "," + tempFilter.others.map { it.value }.joinToString(",")
        )
洪国微 committed
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
        BuryPointUtils.buryPoint("Filtrate", props1)


        allFilter.showType = tempFilter.showType
        allFilter.enquiries.clear()
        allFilter.enquiries.addAll(tempFilter.enquiries)
        allFilter.ages.clear()
        allFilter.ages.addAll(tempFilter.ages)
        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") {
1012
                        var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1013 1014 1015 1016 1017
                        activity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.enquiries) {
1018 1019 1020 1021 1022
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
洪国微 committed
1023 1024 1025 1026 1027 1028 1029 1030 1031
                                activity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "5") {
1032
                        var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1033 1034 1035 1036 1037
                        activity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.ages) {
1038 1039 1040 1041 1042
                            if (TextUtils.equals(
                                    bean.value.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
洪国微 committed
1043 1044 1045 1046 1047 1048 1049 1050 1051
                                activity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "6") {
1052
                        var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1053 1054 1055 1056 1057
                        activity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.others) {
1058 1059 1060 1061 1062
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
洪国微 committed
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
                                activity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }

                    if (headData!!.highlighter[index].type == "7") {
1073
                        var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1074 1075 1076 1077 1078
                        activity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.title) {
1079 1080 1081 1082 1083
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
洪国微 committed
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
                                activity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                }
            }
        }

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

    //筛选标题显示处理
    private fun filterLabelSet() {
        if ((allFilter.others.size + allFilter.ages.size + allFilter.enquiries.size + allFilter.title.size) == 1) {
            var text: String? = ""
            if (allFilter.others.size == 1) {
                text = allFilter.others[0].value
            } else if (allFilter.ages.size == 1) {
                text = allFilter.ages[0].value
            } else if (allFilter.enquiries.size == 1) {
                text = allFilter.enquiries[0].value
            } else if (allFilter.title.size == 1) {
                text = allFilter.title[0].value
            } else {
                text = "筛选"
            }
            if (text?.length ?: 0 > 4) {
1118
                tvFilter.text = text?.substring(0, 3) + "..."
洪国微 committed
1119
            } else {
1120
                tvFilter.text = text
洪国微 committed
1121 1122
            }
        } else {
1123
            tvFilter.text = "筛选"
洪国微 committed
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134
        }
    }


    private var sortPopup: SortPopupWindow? = null

    //显示排序弹窗
    private fun showSortPopupWindow() {
        if (headData?.reorder != null) {
            sortPopup = SortPopupWindow(activity, headData?.reorder!!, allFilter.reorder, this)
            sortPopup!!.setOnDismissListener {
1135
                viewDim.visibility = View.INVISIBLE
洪国微 committed
1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
                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)
1148
            viewDim.visibility = View.VISIBLE
洪国微 committed
1149 1150 1151 1152 1153 1154 1155 1156
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //排序选择回调
    override fun onSortItemSelected(sortItem: ReorderItem) {
1157 1158 1159 1160
        ActionCountUtils.count(
            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_SORT_CLICK, sortItem.value
                ?: ""
        )
洪国微 committed
1161 1162

        if (sortItem.value.equals("综合排序")) {
1163
            tvSort.text = "排序"
洪国微 committed
1164
        } else if (sortItem.value?.length ?: 0 > 4) {
1165
            tvSort.text = sortItem.value?.substring(0, 3) + "..."
洪国微 committed
1166
        } else {
1167
            tvSort.text = sortItem.value
洪国微 committed
1168 1169 1170 1171 1172 1173
        }

        //判断排序选中,判断热门筛选中是否也有该排序
        if (headData!!.highlighter.size > 0) {
            for (index in 0.until(headData!!.highlighter.size)) {
                if (headData!!.highlighter[index].type == "3") {
1174
                    var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
                    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) {
1200 1201 1202 1203
            val regionPopupWindow = AreaPopupWindow(
                activity, headData?.region
                    ?: ArrayList(), allFilter.region, allFilter.sub
            )
洪国微 committed
1204
            regionPopupWindow.showAsDropDown(viewSep2)
1205
            viewDim.visibility = View.VISIBLE
洪国微 committed
1206 1207
            updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
            regionPopupWindow.setOnDismissListener {
1208
                viewDim.visibility = View.INVISIBLE
洪国微 committed
1209 1210 1211 1212 1213 1214
                if (tvArea.text != "地区") {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)
                }
            }
1215 1216 1217 1218 1219 1220 1221
            regionPopupWindow.onRegionSelectedListener =
                object : AreaPopupWindow.OnRegionSelectedListener {
                    override fun onRegionSelected(region: RegionItem, sub: SubItem) {
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
                        allFilter.region = region
                        allFilter.sub = sub
                        if (region.key == null && sub.key == null) {
洪国微 committed
1222 1223 1224
//                        LogUtil.d("onRegionSelected: " + region.value)
//                        props1.put("filtrate_second", region.value)
//                        BuryPointUtils.buryPoint("Filtrate", props1)
1225 1226
                            tvArea.text = "地区"
                        } else if (region.key != null && sub.key == null) {
洪国微 committed
1227 1228 1229
//                        LogUtil.d("onRegionSelected: " + region.value)
//                        props1.put("filtrate_second", region.value)
//                        BuryPointUtils.buryPoint("Filtrate", props1)
1230 1231 1232 1233 1234
                            if (region.value?.length ?: 0 > 4) {
                                tvArea.text = region.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = region.value
                            }
洪国微 committed
1235 1236 1237 1238
                        } else {
//                        LogUtil.d("onRegionSelected: " + sub.value)
//                        props1.put("filtrate_second", sub.value)
//                        BuryPointUtils.buryPoint("Filtrate", props1)
1239 1240 1241 1242 1243
                            if (sub.value?.length ?: 0 > 4) {
                                tvArea.text = sub.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = sub.value
                            }
洪国微 committed
1244
                        }
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
                        ActionCountUtils.count(
                            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_AREA_CLICK,
                            region.value + "|" + sub.value
                        )

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

    private var categoryPopup: CategoryPopupWindow? = null

    //显示主题弹窗
    private fun showSubjectPopupWindow() {
        tempFilter.categories.clear()
        tempFilter.categories.addAll(allFilter.categories)
        val categories = headData?.cates
        if (categories != null) {
            categoryPopup = CategoryPopupWindow(activity, categories, tempFilter.categories)
            categoryPopup!!.setOnDismissListener {
1298
                viewDim.visibility = View.INVISIBLE
洪国微 committed
1299 1300 1301 1302 1303 1304 1305 1306 1307
                if (allFilter.categories.size > 1 || (allFilter.categories.size == 1 && allFilter.categories[0] != headData!!.cates[0])) {
                    updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvSubject, FILTER_STATUS_NORMAL)
                }
            }
            categoryPopup!!.onSubjectsSelectedListener = this
            categoryPopup!!.showAsDropDown(viewSep2)
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_OPEN)
1308
            viewDim.visibility = View.VISIBLE
洪国微 committed
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    /**
     * 主题选择确认回调
     *
     * 新增逻辑:当主题选择后,需要判断热门筛选中是否也有该主题,如果有,也需要同步更新选中状态
     */
    override fun onCategoriesSelected(categories: ArrayList<CateItem>) {
1321 1322 1323 1324
        ActionCountUtils.count(
            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_THEME_CLICK,
            categories.map { it.cateName }.joinToString("|")
        )
洪国微 committed
1325 1326
        if (categories.size == 1 && "全部" != categories[0].cateName) {
            //显示选中标题
1327
            tvSubject.text = categories[0].cateName
洪国微 committed
1328 1329
        } else {
            //显示主标题
1330
            tvSubject.text = "主题"
洪国微 committed
1331 1332 1333 1334 1335 1336
        }
        //判断主题选中,判断热门筛选中是否也有该主题
        Executors.newCachedThreadPool().execute {
            if (headData!!.highlighter.size > 0) {
                for (index in 0.until(headData!!.highlighter.size)) {
                    if (headData!!.highlighter[index].type == "1") {
1337
                        var textview = lin_filter2.getChildAt(index) as TextView
洪国微 committed
1338 1339 1340 1341 1342
                        activity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in categories) {
1343 1344 1345 1346 1347
                            if (TextUtils.equals(
                                    bean.cateName,
                                    headData!!.highlighter[index].value
                                )
                            ) {
洪国微 committed
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
                                activity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                }
            }
        }

        updateFilterTextViewStatus(tvSubject, FILTER_STATUS_OPEN)
//        LogUtil.d("theme callback: " + categories.map { it.cateName }.joinToString(","))
//        props1.put("filtrate_second", categories.map { it.cateName }.joinToString(","))
//        BuryPointUtils.buryPoint("Filtrate", props1)
        allFilter.categories.clear()
        allFilter.categories.addAll(categories)
        refresh()
        if (categories.size == 1) {
            doctorAdapter?.cateId = "${categories[0].cateId}"
        } else {
            doctorAdapter?.cateId = ""
        }
    }

1374 1375
    override fun onRefresh() {
        refresh(false)
徐健 committed
1376 1377
        recommendListView.requestData()

1378 1379
    }

洪国微 committed
1380 1381
    //刷新列表
    private fun refresh(isShowRefresh: Boolean? = true) {
1382 1383
        srlContainer.isRefreshing = isShowRefresh!!
        val key = tv_search_content.text.toString()
洪国微 committed
1384 1385 1386 1387 1388 1389 1390 1391
        if (!TextUtils.isEmpty(key.trim())) {
            allFilter.searchWord = key.trim()
        } else {
            allFilter.searchWord = null
        }
        curPage = 1
        onScrollListener.resetState()
        getPresenter().fetchListData(allFilter, curPage)
1392
        rvExperts.scrollToPosition(0)
洪国微 committed
1393 1394 1395 1396
    }

    //执行搜索
    private fun doSearch() {
1397
        image_scroll_top.visibility = View.GONE
洪国微 committed
1398 1399 1400 1401 1402 1403 1404
        hideSoftInput();
//        keyWord = etSearch.text.toString()
//        if (TextUtils.isEmpty(keyWord?.trim())) {
//            ToastUtil.toastShort(this, "请输入搜索内容")
//            return
//        }

1405 1406 1407 1408
        ActionCountUtils.count(
            ConsultBIConstants.UserMainEvent.YDL_USER_SEARCH_CLICK,
            keyWord ?: ""
        )
洪国微 committed
1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
        isDoSearch = true
        resetFilter()
        refresh()

    }

    //重置所有筛选
    private fun resetFilter() {
        allFilter.categories.clear()
        allFilter.categories.add(headData?.cates?.get(0) ?: CateItem())
        allFilter.reorder = headData?.reorder?.get(0) ?: ReorderItem()
        allFilter.region = RegionItem()
        allFilter.sub = SubItem()
        allFilter.enquiries.clear()
        allFilter.ages.clear()
        allFilter.others.clear()
        updateFilterTextViewStatus(tvSubject, FILTER_STATUS_NORMAL)
        updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)
        updateFilterTextViewStatus(tvSort, FILTER_STATUS_NORMAL)

        if (headData != null) {
            if (allFilter.showType != headData!!.filters.showType[1]) {
                updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
            } else {
                updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
            }
        }
    }

    //设置筛选点击按钮状态
    private fun updateFilterTextViewStatus(tv: TextView, status: Int) {
        when (status) {
            FILTER_STATUS_NORMAL -> {
                tv.typeface = Typeface.defaultFromStyle(Typeface.NORMAL)
                tv.setTextColor(ContextCompat.getColor(context, R.color.platform_colorTextDefault))
1444 1445 1446 1447 1448 1449
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
洪国微 committed
1450 1451 1452 1453
            }
            FILTER_STATUS_FILTERED -> {
                tv.typeface = Typeface.DEFAULT_BOLD
                tv.setTextColor(ContextCompat.getColor(context, R.color.consultant_main_theme))
1454 1455 1456 1457 1458 1459
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
洪国微 committed
1460 1461 1462 1463
            }
            FILTER_STATUS_OPEN -> {
                tv.typeface = Typeface.DEFAULT_BOLD
                tv.setTextColor(ContextCompat.getColor(context, R.color.platform_colorTextDefault))
1464 1465 1466 1467 1468 1469
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.consultant_ic_arrow_drop_down,
                    0
                )
洪国微 committed
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
            }
        }
    }

    private fun hideSoftInput() {
        val view = activity.currentFocus
        if (view != null) {
            val imm = activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
            imm.hideSoftInputFromWindow(view.windowToken, 0)
        }
    }

    /**
     * 事件埋点
     */
    fun bury(keyworks: String, isResult: Boolean, isRecommend: Boolean, location: String) {
        BuryPointUtils.getInstance().createMap()
1487 1488 1489 1490 1491
            .put("keyWord", keyworks)
            .put("hasResult", isResult)
            .put("isRecommend", isRecommend)
            .put("location", location)
            .burryPoint("search")
洪国微 committed
1492 1493 1494 1495
    }

    override fun onResume() {
        super.onResume()
konghaorui committed
1496
        refresh(false)
洪国微 committed
1497 1498 1499 1500 1501 1502 1503 1504 1505
        ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_PAGE_VISIT)

    }

    override fun onDestroy() {
        super.onDestroy()
        ConsultAssistantDialogUtils.INSTANCE.resetStatus()
    }
}