ExpertSearchActivity.kt 65.8 KB
Newer Older
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.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Typeface
11
import android.os.Handler
12 13 14 15 16 17 18
import android.text.TextUtils
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
19 20 21 22
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
23 24
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
YKai committed
25
import com.google.android.material.appbar.AppBarLayout
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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.BaseMvpActivity
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.bean.StatusBarOptions
import com.ydl.ydlcommon.ui.LogoLoadingView
import com.ydl.ydlcommon.utils.BuryPointUtils
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
43
import com.yidianling.consultant.bean.FunctionWordConsultBean
44
import com.yidianling.consultant.constants.ConsultBIConstants
45
import com.yidianling.consultant.constants.ConsultBIConstants.ConsultEvent.Companion.YDL_USER_CONSULT_SEARCH_CLICK
46 47 48 49
import com.yidianling.consultant.listener.OnCategoriesSelectedListener
import com.yidianling.consultant.listener.OnFilterConfirmListener
import com.yidianling.consultant.listener.OnSortItemSelectedListener
import com.yidianling.consultant.model.bean.*
徐健 committed
50
import com.yidianling.consultant.modular.singlton.ConsultAssistantDialogUtils
51 52 53 54 55
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
57 58 59 60
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
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.*
65 66
import org.json.JSONObject
import java.util.concurrent.Executors
67
import java.util.concurrent.TimeUnit
68 69

@Route(path = "/consult/list")
70 71 72
class ExpertSearchActivity : BaseMvpActivity<IExpertSearchView, ExpertSearchPresenter>(),
    View.OnClickListener, IExpertSearchView,
    OnCategoriesSelectedListener, OnSortItemSelectedListener, OnFilterConfirmListener,
73
    SwipeRefreshLayout.OnRefreshListener {
74 75
    var bottomWordDisposable: Disposable? = null
    private lateinit var bottomWordlist: List<FunctionWordBean>
霍志良 committed
76
    private var searchWord: String? = ""
77 78 79 80 81
    override fun showImage(url: String?, imgView: ImageView) {
        YDLImageCacheManager.showImage(ExpertSearchActivity@ this, url, imgView)
    }

    override fun showImage(url: String?, imgView: ImageView, ops: SimpleImageOpConfiger) {
82
        YDLImageCacheManager.showImage(this, url, imgView, ops)
83 84
    }

fengquan committed
85 86 87
    override fun showPromptPayment(promptPaymentBean: PromptPaymentBean) {
    }

88 89 90 91 92 93 94
    override fun showImage(
        url: String?,
        imgView: ImageView,
        width: Int,
        heigh: Int,
        ops: SimpleImageOpConfiger
    ) {
95 96 97 98
        YDLImageCacheManager.showImage(ExpertSearchActivity@ this, url, imgView, width, heigh, ops)
    }

    override fun layoutResId(): Int {
99
        return R.layout.consultant_activity_expert_search_list
100 101 102 103 104
    }

    override fun initDataAndEvent() {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE or WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
        initViews()
105
        initData(intent, false)
ydl committed
106 107

        rl_hot_fix_for_huawei.visibility = View.VISIBLE
108 109 110
    }

    override fun getStatusViewOptions(): StatusBarOptions {
111
        return StatusBarOptions(true, true)
112 113 114 115 116 117 118 119 120 121
    }

    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"
upwork.021 committed
122
        private const val EXTRA_RELATED_WORD = "related_word"
123
        private const val EXTRA_IS_RECCOMMEND_WORD = "is_reccommend_word"
124 125 126 127 128 129
        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_ONLINE_EXPERT = 2

130 131 132 133 134 135
        fun newIntent(
            activity: Activity,
            category: String,
            showType: Int,
            isInitShowHot: Boolean
        ): Intent {
136 137 138 139 140 141 142
            val intent = Intent(activity, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_CATEGORY, category)
            intent.putExtra(EXTRA_SHOW_TYPE, showType)
            intent.putExtra(EXTRA_IS_SHOW_HOT, isInitShowHot)
            return intent
        }

143
        fun start(context: Context, category: String) {
144 145 146 147 148
            val intent = Intent(context, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_CATEGORY, category)
            context.startActivity(intent)
        }

149
        fun start(context: Context, category: String, categoryName: String, showType: Int) {
150 151 152 153 154 155 156
            val intent = Intent(context, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_CATEGORY, category)
            intent.putExtra(EXTRA_CATEGORY_NAME, categoryName)
            intent.putExtra(EXTRA_SHOW_TYPE, showType)
            context.startActivity(intent)
        }

upwork.021 committed
157
        /**
upwork.021 committed
158 159 160
         * 搜索页面过来的
         * @param sign2为14 仅用于埋点
         * @param relatedWord 搜索内容的关联词
161
         * @param isRecommendWords 是否是推荐词
upwork.021 committed
162
         */
163 164 165 166 167 168 169
        fun startSearch(
            context: Context,
            searchWord: String?,
            sign2: String,
            relatedWord: String,
            isRecommendWords: Boolean
        ) {
170 171
            val intent = Intent(context, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_SEARCH_WORD, searchWord)
upwork.021 committed
172
            intent.putExtra(EXTRA_RELATED_WORD, relatedWord)
173 174
            intent.putExtra(EXTRA_IS_RECCOMMEND_WORD, isRecommendWords)
            intent.putExtra("sign2", sign2)
175 176 177
            context.startActivity(intent)
        }

178
        fun start(context: Context, category: String, showType: Int, isFromSplash: Boolean) {
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
            val intent = Intent(context, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_CATEGORY, category)
            intent.putExtra(EXTRA_SHOW_TYPE, showType)
            intent.putExtra(EXTRA_IS_FROM_SPLASH, isFromSplash)
            context.startActivity(intent)
        }

        fun start(context: Context, isShowHot: Boolean, fromPageType: Int) {
            val intent = Intent(context, ExpertSearchActivity::class.java)
            intent.putExtra(EXTRA_IS_SHOW_HOT, isShowHot)
            intent.putExtra(EXTRA_FROM_PAGE, fromPageType)
            context.startActivity(intent)
        }

        fun start(context: Context) {
            val intent = Intent(context, ExpertSearchActivity::class.java)
            context.startActivity(intent)
        }
    }

    private val allFilter = AllFilter() //当前筛选
    private val tempFilter = AllFilter() //临时筛选,未确认状态
    private var curPage = 1
upwork.021 committed
202
    private val doctorList = ArrayList<ExpertServiceItem>()
203
    private var hasMore = true
204
    private var initCategory = "0"
205 206 207 208 209 210
    private var initShowType: Int = 1
    private lateinit var doctorAdapter: ExpertSearchAdapter
    private lateinit var onScrollListener: EndlessRecyclerViewScrollListener
    private var headData: HeadData? = null //筛选数据
    private var isFromSplash = false
    private val props1 = JSONObject() //筛选标题埋点参数
211
    private var fromPageType: Int = 1 //从哪个页面跳转过来的
212
    private var isRecommend = false //埋点数据
upwork.021 committed
213 214
    private var cateName: String? = null
    private var mSign2: String = ""  // 用于搜索页面进来的埋点参数
215 216 217 218
    private var isDoSearch: Boolean = false //埋点判断是否通过搜索进入埋点的
    private var hasSelectedArea = false  //是否选择过地区
    private var hasSelectedSort = false  //是否选择过排序

219

220 221 222
    override fun createPresenter(): ExpertSearchPresenter = ExpertSearchPresenter()

    private fun initViews() {
konghaorui committed
223
        srlContainer.isEnabled = true
224 225 226 227 228 229 230
        tvSubject.setOnClickListener(this)
        tvArea.setOnClickListener(this)
        tvSort.setOnClickListener(this)
        tvFilter.setOnClickListener(this)
        btn_call.setOnClickListener(this)
        tv_guide.setOnClickListener(this)
        rl_search.setOnClickListener(this)
231
        srlContainer.setColorSchemeColors(ContextCompat.getColor(this, R.color.platform_main_theme))
232 233
        srlContainer.setProgressViewOffset(false, 0, 200)
        srlContainer.setOnRefreshListener(this)
234

235 236
        recommendListView.addViewPagerScrollStateListener(object :
            RecommendListView.ViewPagerScrollStateCallback {
徐健 committed
237 238 239 240 241 242
            override fun viewPagerScroll(isScrolling: Boolean) {
                //如果viewpager正在滚动,则禁止下拉刷新
                srlContainer.isEnabled = !isScrolling
            }
        })

YKai committed
243
        appbar_layout.addOnOffsetChangedListener(AppBarLayout.OnOffsetChangedListener { _, i ->
244
            srlContainer.isEnabled = i >= 0
YKai committed
245
        })
246 247 248 249 250 251 252
        initNetLossView()


        btn_back.setOnClickListener {
            onBackPressed()
        }
        doctorAdapter = ExpertSearchAdapter(this, this, doctorList)
253
        val layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
254
        rvExperts.layoutManager = layoutManager
255
        rvExperts.adapter = doctorAdapter
256
        doctorAdapter.setOnClickLister(object : ExpertSearchAdapter.OnClickLister {
257 258 259 260 261 262 263
            override fun onClick(searchWords: String) {
                allFilter.searchWord = searchWords

                refresh(false)
            }

        })
264 265 266
        onScrollListener = object : EndlessRecyclerViewScrollListener(layoutManager) {
            private var isBtnShow: Boolean = false
            private var sIsScrolling = false
YKai committed
267
            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
268 269 270
                super.onScrollStateChanged(recyclerView, newState)
                hideSoftInput()
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
271 272
                    //滚动
                    ConsultAssistantDialogUtils.INSTANCE.hideAssistantActivity()
273 274 275 276 277
                    sIsScrolling = true
                    if (!this@ExpertSearchActivity.isFinishing) {
//                        GlideApp.with(this@ExpertSearchActivity).pauseRequests()
                    }
                } else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
278
                    //没有滚动
279 280 281 282 283
                    ConsultAssistantDialogUtils.INSTANCE.fitRequest(
                        this@ExpertSearchActivity,
                        "doctor_list",
                        true
                    )
284 285 286 287 288 289 290 291 292 293
                    if (sIsScrolling) {
                        if (!this@ExpertSearchActivity.isFinishing) {
//                            GlideApp.with(this@ExpertSearchActivity).resumeRequests()
                        }
                    }
                    sIsScrolling = false;
                }
            }

            override fun onScrollTop() {
294 295 296 297
                val alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
                val animator =
298 299
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
300 301 302 303 304 305 306 307 308 309 310 311 312
                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
                }
313 314 315 316
                val alpha = PropertyValuesHolder.ofFloat("alpha", 0f, 1f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 0f, 1f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 0f, 1f)
                val animator =
317 318
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
319 320 321 322 323 324 325 326 327 328 329 330 331
                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
                }
332 333 334 335
                val alpha = PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
                val scaleX = PropertyValuesHolder.ofFloat("scaleX", 1f, 0f)
                val scaleY = PropertyValuesHolder.ofFloat("scaleY", 1f, 0f)
                val animator =
336 337
                    ObjectAnimator.ofPropertyValuesHolder(image_scroll_top, alpha, scaleX, scaleY)
                        .setDuration(200)
338 339 340 341 342 343 344 345 346 347 348
                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
349
                    getPresenter().fetchListData(allFilter, getPresenter().mExtras)
350 351 352 353 354 355 356
                }
            }
        }
        rvExperts.addOnScrollListener(onScrollListener)
        rvExperts.addOnScrollListener(YDLImageRecyclerOnScrollListener(ExpertSearchActivity@ this))
        image_scroll_top.setOnClickListener(this)
//        initStatus()
徐健 committed
357

358
        ConsultAssistantDialogUtils.INSTANCE.fitRequest(this, "doctor_list", true)
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    }

    private fun initNetLossView() {
        v_loading.setListener(object : LogoLoadingView.LogoLoadingListener {
            override fun onDataResetClick() {
                rvExperts.visibility = View.GONE
                v_loading.visibility = View.VISIBLE
                ll_network_error.visibility = View.GONE
                v_loading.setViewType(LogoLoadingView.TYPE_LOADING, null)
                refresh(false)
            }

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

    override fun localData() {
    }

    //路由传递过来的参数
    private fun getRouterParam() {
        if (null != intent && intent.hasExtra("routerParam")) {
            val params = intent.getStringExtra("routerParam")
            val paramsJson = JSONObject(params)
385
            initCategory = paramsJson.getString("cateId")
upwork.021 committed
386 387
            cateName = paramsJson.getString("cateTitle")
            mSign2 = cateName!!
388 389 390 391
            initShowType = paramsJson.getString("showType").toInt()
        }
    }

392
    private fun initData(mIntent: Intent, isRefresh: Boolean) {
393
        fromPageType = mIntent.getIntExtra(EXTRA_FROM_PAGE, -1)
394
        initCategory = mIntent.getStringExtra(EXTRA_CATEGORY) ?: ""
395
        initShowType = mIntent.getIntExtra(EXTRA_SHOW_TYPE, 0)
upwork.021 committed
396
        val relatedWord = mIntent.getStringExtra(EXTRA_RELATED_WORD)       // 搜索内容的联想词
霍志良 committed
397
        searchWord = mIntent.getStringExtra(EXTRA_SEARCH_WORD)
398 399
        val isRecommendWords = mIntent.getBooleanExtra(EXTRA_IS_RECCOMMEND_WORD, false)
        if (!TextUtils.isEmpty(relatedWord)) {      // 判断搜索内容的联想词为空,则用搜索词进行搜索
upwork.021 committed
400
            allFilter.searchWord = relatedWord
401
        } else {
upwork.021 committed
402 403
            allFilter.searchWord = searchWord
        }
404
        mSign2 = mIntent.getStringExtra("sign2") ?: ""
405
        getRouterParam()
406

407
        allFilter.showType.key = initShowType
408
        if (!TextUtils.isEmpty(initCategory) && initCategory != "0") {
upwork.021 committed
409 410
            allFilter.categoryId2List.add(initCategory)
        }
411
        if (!TextUtils.isEmpty(cateName)) {
upwork.021 committed
412
            tvSubject.text = cateName
413
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
414 415
        }

416
        getPresenter().fetchListHead()
417
        recommendListView.requestData(initCategory)
418
        if (isRefresh) {
upwork.021 committed
419 420
            refresh(false)
        }
421

upwork.021 committed
422 423
        tv_search_content.text = searchWord
        // 判断搜索词和联想词不一样,则显示匹配结果
424 425 426 427
        LogUtil.e("searchWord:${searchWord}")
        LogUtil.e("relatedWord:${relatedWord}")
        if (!TextUtils.isEmpty(searchWord) && !TextUtils.isEmpty(relatedWord) && searchWord != relatedWord) {
            if (doctorList.size > 0 && doctorList[0].is_head_view) {
霍志良 committed
428
                doctorList[0] = ExpertServiceItem(true, searchWord.toString(), relatedWord)
429
            } else if (doctorList.size > 0) {
霍志良 committed
430
                doctorList.add(0, ExpertServiceItem(true, searchWord.toString(), relatedWord))
431
            } else {
霍志良 committed
432
                doctorList.add(ExpertServiceItem(true, searchWord.toString(), relatedWord))
433 434 435 436 437
            }
        } else {
            if (doctorList.size > 0 && doctorList[0].is_head_view) {
                doctorList.removeAt(0)
            }
upwork.021 committed
438
        }
439

440 441 442
        v_loading.visibility = View.VISIBLE
        v_loading.setViewType(LogoLoadingView.TYPE_LOADING, null)

443 444
        doctorAdapter.clickCount = 0
        doctorAdapter.setIsRecommendWords(isRecommendWords)
445
        doctorAdapter.setEntrance(1)
霍志良 committed
446
        getPresenter().fetchFunctionWord(2)
447 448 449 450
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
451
        initData(intent!!, true)
452 453 454 455 456 457
    }


    //返回键处理,热门搜索如果可见,则隐藏,来自启动页,则打开主界面
    override fun onBackPressed() {
        if (isFromSplash) {
konghaorui committed
458
            ConsultantIn.mainIntent(this)
459 460 461 462 463
        }
        finish()
    }


464
    //获取筛选数据
465 466 467
    override fun onHeadFetched(headData: HeadData?) {
        //头部数据获取到后初始化筛选数据
        this.headData = headData
468 469 470 471 472 473 474
        headData?.let { it ->
//            allFilter.reorder = it.reorder[0]
            allFilter.showType = it.filters.showType[initShowType]
            if (it.highlighter.size > 0) {
                //设置热门搜索
                initHotViews(lin_filter2, it.highlighter)
            }
475 476 477 478
            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)
479 480
                allFilter.childList.add(childrenBean)
            }
481 482 483 484
            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)
485 486
                allFilter.stressList.add(childrenBean)
            }
487 488 489 490
            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)
491 492
                allFilter.loveEmotionList.add(childrenBean)
            }
493 494 495 496
            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)
497 498
                allFilter.marriedFamilyList.add(childrenBean)
            }
499 500 501 502
            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)
503 504
                allFilter.personalGrowthList.add(childrenBean)
            }
505 506 507 508
            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)
509 510
                allFilter.interpersonalRelationshipList.add(childrenBean)
            }
511 512 513 514
            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)
515 516
                allFilter.careerDevelopmentList.add(childrenBean)
            }
517 518 519 520
            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)
521
                allFilter.mentalHealthList.add(childrenBean)
522 523 524 525
            }
        }
    }

霍志良 committed
526
    override fun onFunctionWordFetched(wordBean: MutableList<FunctionWordBean>) {
527
        //获取底纹词
霍志良 committed
528
        bottomWordlist = wordBean
529
        if (bottomWordlist.isNullOrEmpty()) return
霍志良 committed
530 531
        if (!searchWord.isNullOrEmpty()) {
            tv_search_content.text = searchWord
532
        } else {
霍志良 committed
533 534 535 536 537 538 539 540 541 542 543
            if (bottomWordlist.size == 1) {
                tv_search_content.text = bottomWordlist[0].word
            } else {
                bottomWordDisposable = Observable.interval(0, 3, TimeUnit.SECONDS)
                    .subscribeOn(Schedulers.computation())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({
                        tv_search_content.text =
                            bottomWordlist[(it % bottomWordlist.size).toInt()].word
                    }, {
                    }, {
544 545

                })
霍志良 committed
546
            }
547 548 549
        }
    }

550 551 552 553 554 555 556
    /**
     * 热门
     */
    private fun initHotViews(view: LinearLayout, hotData: List<HighlighterItem>) {
        if (view.childCount > 0) {
            return
        }
557
        for (hot in hotData) {
558 559
            val tv =
                View.inflate(mContext, R.layout.consultant_item_filter_online, null) as TextView
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
            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
576
                    // 埋点
577 578 579 580 581 582 583
                    ActionCountUtils.baiDuCountSign3(
                        ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
                        ConsultBIConstants.ConsultEvent.POSITION_CHOICE_FILTER_CLICK,
                        hot.value!!,
                        "app",
                        ""
                    )
584 585 586
                }
                filterLabelSet()
                //开始筛选数据
upwork.021 committed
587
                refresh()
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
            }
            view.addView(textView)
        }
    }


    /**
     * 处理热门搜索的选中逻辑
     * * 1:主题
     * 2:省
     * 3:排序
     * 4:咨询方式
     * 5:年龄选择
     * 6:其他选择
     * 7:资质选择
     * 8.市
     *
     * @param isAdd 是否是添加
     */
    private fun dealHotSelect(hotData: HighlighterItem, isAdd: Boolean) {
        when (hotData.type) {
            "1" -> {
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
//                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) {
//                        //显示选中标题
//                        tvSubject.text = allFilter.categories[0].cateName
//                    } else {
//                        //显示主标题
//                        tvSubject.text = "主题"
//                    }
//                }
                updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
637 638 639
            }
            "2" -> {//省
                if (headData?.region!!.size > 0) {
upwork.021 committed
640
                    val bean = RegionItem()
641 642 643 644 645
                    if (isAdd) {
                        //热门中如果选择过地区、要把其他已选中的置位未选中
                        if (hasSelectedArea) {
                            for ((index, bean) in headData!!.highlighter.withIndex()) {
                                if (bean.type == "2" || bean.type == "8") {
646
                                    val textview = lin_filter2.getChildAt(index) as TextView
647 648 649 650 651
                                    textview.isSelected = false
                                    textview.paint.isFakeBoldText = false
                                }
                            }
                        }
652
                        bean.code = hotData.id
653 654
                        bean.value = hotData.value
                        for (headBean in headData!!.region) {
655
                            if (TextUtils.equals(headBean.code, bean.code)) {
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
                                bean.sub = headBean.sub
                                break
                            }
                        }
                        allFilter.region = bean
                        if (allFilter.region.value?.length ?: 0 > 4) {
                            tvArea.text = allFilter.region.value?.substring(0, 3) + "..."
                        } else {
                            tvArea.text = allFilter.region.value
                        }
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)

                        hasSelectedArea = true
                    } else {
                        allFilter.region = RegionItem()
                        tvArea.text = "地区"
                        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") {
                                            var textview = lin_filter2.getChildAt(index) as TextView
                                            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 {
                        allFilter.reorder.value.equals("综合排序") -> tvSort.text = "排序"
708 709
                        allFilter.reorder.value?.length ?: 0 > 4 -> tvSort.text =
                            allFilter.reorder.value?.substring(0, 3) + "..."
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
                        else -> tvSort.text = allFilter.reorder.value
                    }
                }
            }
            "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)
                            }
                        }
                    }
                }
727
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size > 0) {
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
                    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)
                            }
                        }
                    }
                }
747
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size > 0) {
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
                    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)
                            }
                        }
                    }
                }
767
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size > 0) {
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
                    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)
                            }
                        }
                    }
                }
787
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size > 0) {
788 789 790 791 792 793 794 795 796
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
                filterLabelSet()
            }
            "8" -> {
                //市
                if (headData?.region!!.size > 0) {
797
                    val bean = SubItem()
798 799 800 801 802 803 804 805 806 807 808 809
                    if (isAdd) {
                        //热门中如果选择过地区、要把其他已选中的置位未选中
                        if (hasSelectedArea) {
                            for ((index, bean) in headData!!.highlighter.withIndex()) {
                                if (bean.type == "2" || bean.type == "8") {
                                    var textview = lin_filter2.getChildAt(index) as TextView
                                    textview.isSelected = false
                                    textview.paint.isFakeBoldText = false
                                }
                            }
                        }

810
                        bean.code = hotData.id
811 812
                        bean.value = hotData.value
                        for (headBean in headData!!.region) {
813
                            if (TextUtils.equals(
814 815
                                    headBean.code!!.substring(0, 2),
                                    bean.code!!.substring(0, 2)
816 817
                                )
                            ) {
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
                                allFilter.region = headBean
                                break
                            }
                        }
                        allFilter.sub = bean
                        if (allFilter.sub.value?.length ?: 0 > 4) {
                            tvArea.text = allFilter.sub.value?.substring(0, 3) + "..."
                        } else {
                            tvArea.text = allFilter.sub.value
                        }
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)

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

                        tvArea.text = "地区"
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)

                        hasSelectedArea = false
                    }
                }
            }
        }
    }


    //用于侧滑筛选过来更新快捷筛选选中状态
upwork.021 committed
847
    private fun updateOtherViews(otherData: List<OtherItem>) {
848 849 850 851 852 853 854 855
        if (lin_filter2.childCount > 0) {
            //清空选中
            for (i in 0.until(lin_filter2.childCount)) {
                val textView = lin_filter2.getChildAt(i) as TextView
                textView.isSelected = false
                textView.paint.isFakeBoldText = false
            }
            //重置选中状态
upwork.021 committed
856
            for (other in otherData) {
857 858 859 860 861 862 863 864 865 866 867
                for (i in 0 until lin_filter2.childCount) {
                    val textView = lin_filter2.getChildAt(i) as TextView
                    if (textView.text == other.value) {
                        textView.isSelected = true
                        textView.paint.isFakeBoldText = true
                    }
                }
            }
        }
    }

868 869 870
    /**
     * 获取专家列表数据
     */
871 872 873 874 875
    override fun onDoctorListFetched(
        data: MutableList<ExpertServiceItem>,
        extras: Extras?,
        curPage: Int
    ) {
876 877 878 879
        if (rvExperts.adapter != doctorAdapter) {
            rvExperts.adapter = doctorAdapter
        }

880
        // 如果是第一页
881 882
        if (curPage == 1) {
            if (data.size >= 10) {
883 884
                hasMore = true
                doctorAdapter.hasMore = true
885
            } else {
886 887 888
                hasMore = false
                doctorAdapter.hasMore = false
            }
889
            if (doctorList.size > 0 && doctorList[0].is_head_view) {
890 891 892
                val expertServiceItem = doctorList[0]
                doctorList.clear()
                doctorList.add(expertServiceItem)
893
            } else {
894 895
                doctorList.clear()
            }
upwork.021 committed
896
        }
897

898
        if (data.size == 0) {     // data的长度为0的时候为最后一页
899 900
            hasMore = false
            doctorAdapter.hasMore = false
901
        } else {
902 903
            doctorList.addAll(data)
        }
904 905 906 907
        doctorAdapter.notifyDataSetChanged()
        isDoSearch = false
        isRecommend = false

908

909 910 911 912 913
        v_loading.visibility = View.GONE
        ll_network_error.visibility = View.GONE

        rvExperts.visibility = View.VISIBLE
        srlContainer.isRefreshing = false
upwork.021 committed
914 915

        // 埋点
916 917 918 919 920 921 922 923
        val sign1 = data.joinToString(",") { it.id }
        ActionCountUtils.baiDuCountSign3(
            ConsultBIConstants.PART_ID_CONSULT_COUNSELOR_LIST_PAGE,
            ConsultBIConstants.POSITION_CONSULT_COUNSELOR_LIST_PAGE_VISIT,
            sign1,
            mSign2,
            "app"
        )
924 925 926 927 928 929 930
    }

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

        if (curPage == 1) {
931 932 933 934
            v_loading.setViewType(
                LogoLoadingView.TYPE_NET_LOSS,
                getString(R.string.consultant_reload_hint)
            )
935 936 937 938 939 940 941 942 943 944 945 946 947 948
            v_loading.visibility = View.VISIBLE

            ll_network_error.visibility = View.GONE
        } else {
            ToastHelper.show("网络不给力")
        }
        dismissProgressDialog()
        srlContainer.isRefreshing = false
    }

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

949 950 951 952 953
        if (doctorList.size > 0 && doctorList[0].is_head_view) {
            val expertServiceItem = doctorList[0]
            doctorList.clear()
            doctorList.add(expertServiceItem)
            doctorAdapter.notifyDataSetChanged()
954

955 956
            v_loading.visibility = View.GONE
            ll_network_error.visibility = View.GONE
957

958 959 960 961 962 963 964 965 966 967 968
            rvExperts.visibility = View.VISIBLE
        } else {
            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)

            rvExperts.visibility = View.GONE
            dismissProgressDialog()
            srlContainer.isRefreshing = false
        }
upwork.021 committed
969

970 971 972 973 974 975 976 977
    }

    override fun fetchFailed(msg: String?) {
        isDoSearch = false
        isRecommend = false
        if (msg != null) {
            ToastUtil.toastShort(msg)
        }
978 979 980 981
        v_loading.setViewType(
            LogoLoadingView.TYPE_NET_LOSS,
            getString(R.string.consultant_reload_hint)
        )
982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
        v_loading.visibility = View.VISIBLE

        ll_network_error.visibility = View.GONE

        rvExperts.visibility = View.GONE
        appbar_layout.setExpanded(false)
        dismissProgressDialog()
    }

    override fun showRefreshLayout() {
        srlContainer.isRefreshing = true
    }


    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.image_scroll_top -> {
                scrollToTop()
            }
            R.id.tvSubject -> {
                props1.put("filtrate_first", "主题")
                hideSoftInput()
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
                    showSubjectPopupWindow()
upwork.021 committed
1007
                }, 300)
1008 1009 1010 1011 1012 1013 1014 1015

            }
            R.id.tvArea -> {
                props1.put("filtrate_first", "地区")
                hideSoftInput()
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
                    showAreaPopupWindow()
upwork.021 committed
1016
                }, 300)
1017 1018 1019 1020 1021 1022 1023 1024

            }
            R.id.tvSort -> {
                props1.put("filtrate_first", "排序")
                hideSoftInput()
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
                    showSortPopupWindow()
upwork.021 committed
1025
                }, 300)
1026 1027 1028 1029 1030 1031 1032 1033

            }
            R.id.tvFilter -> {
                props1.put("filtrate_first", "筛选")
                hideSoftInput()
                appbar_layout.setExpanded(false)
                appbar_layout.postDelayed({
                    showFilterPopupWindow()
upwork.021 committed
1034
                }, 300)
1035 1036 1037 1038 1039

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

1040
                val h5param = H5Params(HttpConfig.H5_URL + "help/consultation/", "咨询指南")
1041 1042 1043 1044 1045 1046 1047 1048 1049
                h5param.isShowMenu = true
                NewH5Activity.start(this, h5param)
            }
            R.id.btn_call -> {
                ActionCountUtils.count(ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_ONLINE_CUSTOMER_CLICK)

                ConsultantIn.startP2PXiaoYi(this)
            }
            R.id.rl_search -> {
1050
                ActionCountUtils.count(YDL_USER_CONSULT_SEARCH_CLICK)
1051
                ARouter.getInstance()
1052
                    .build("/consult/hot_search")
1053
                    .withString(HOT_SEARCH_DOCTOR_NAME, tv_search_content.text.toString())
1054
                    .navigation()
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
            }
        }
    }

    private fun scrollToTop() {
        if ((rvExperts.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() > 10) {
            rvExperts.scrollToPosition(10)
            rvExperts.smoothScrollToPosition(0)
        } else {
            rvExperts.smoothScrollToPosition(0)
        }
    }

    //显示筛选弹窗
    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)
1079 1080 1081
        //学历
        tempFilter.doctorEdu.clear()
        tempFilter.doctorEdu.addAll(allFilter.doctorEdu)
1082 1083
        tempFilter.enquiries.clear()
        tempFilter.enquiries.addAll(allFilter.enquiries)
1084 1085 1086
        // 擅长人群添加数据
        tempFilter.specialityCrowd.clear()
        tempFilter.specialityCrowd.addAll(allFilter.specialityCrowd)
1087 1088 1089 1090 1091 1092 1093 1094
        tempFilter.others.clear()
        tempFilter.others.addAll(allFilter.others)
        tempFilter.priceRanges = allFilter.priceRanges
        tempFilter.priceRangesView = allFilter.priceRangesView

        if (headData?.filters != null) {
            val filterPopupWindow = FilterPopupWindow(this, headData?.filters!!, tempFilter)
            filterPopupWindow.setOnDismissListener {
upwork.021 committed
1095
                viewDim.visibility = View.INVISIBLE
1096
                viewDim_filter.visibility = View.GONE
1097
                if (allFilter.others.size + allFilter.enquiries.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.title.size > 0 || !TextUtils.isEmpty(
1098 1099
                        allFilter.priceRanges?.min_price
                    ) || !TextUtils.isEmpty(allFilter.priceRanges?.max_price)
1100
                ) {
1101 1102 1103 1104
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvFilter, FILTER_STATUS_NORMAL)
                }
1105
                ConsultAssistantDialogUtils.INSTANCE.fitRequest(this, "doctor_list", true)
1106 1107
            }
            filterPopupWindow.isClippingEnabled = false
upwork.021 committed
1108
            filterPopupWindow.showAsDropDown(viewSep2)
1109
            ConsultAssistantDialogUtils.INSTANCE.hideAssistantActivity()
1110 1111
            filterPopupWindow.onFilterConfirmListener = this
            updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
upwork.021 committed
1112
            viewDim.visibility = View.VISIBLE
1113 1114 1115 1116 1117 1118 1119 1120 1121
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //筛选确认回调
    override fun onFilterConfirmed() {
        updateFilterTextViewStatus(tvFilter, FILTER_STATUS_OPEN)
1122 1123 1124 1125 1126 1127 1128
        LogUtil.d(
            "filter: " + tempFilter.showType.value + ","
                    + tempFilter.enquiries.map { it.value }.joinToString(",") + ","
                    + tempFilter.ages.map { it.value }.joinToString(",") + ","
                    + tempFilter.others.map { it.value }.joinToString(",") + ","
                    + tempFilter.doctorEdu.map { it.value }.joinToString(",")
        )
1129 1130
        props1.put(
            "filtrate_second",
1131
            tempFilter.showType.value + ","
刘鹏 committed
1132 1133
                    + tempFilter.enquiries.map { it.value }.joinToString(",") + ","
                    + tempFilter.ages.map { it.value }.joinToString(",") + ","
1134
                    + tempFilter.others.map { it.value }.joinToString(",") + ","
1135
                    + tempFilter.doctorEdu.map { it.value }.joinToString(",")
1136
        )
1137 1138
        BuryPointUtils.buryPoint("Filtrate", props1)

upwork.021 committed
1139
        // 埋点
1140 1141 1142 1143 1144 1145 1146 1147 1148
        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
1149 1150
        }

1151 1152 1153 1154 1155 1156

        allFilter.showType = tempFilter.showType
        allFilter.enquiries.clear()
        allFilter.enquiries.addAll(tempFilter.enquiries)
        allFilter.ages.clear()
        allFilter.ages.addAll(tempFilter.ages)
1157 1158 1159
        //学历
        allFilter.doctorEdu.clear()
        allFilter.doctorEdu.addAll(tempFilter.doctorEdu)
1160 1161 1162
        // 擅长人群
        allFilter.specialityCrowd.clear()
        allFilter.specialityCrowd.addAll(tempFilter.specialityCrowd)
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
        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") {
                        var textview = lin_filter2.getChildAt(index) as TextView
                        this@ExpertSearchActivity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.enquiries) {
1181 1182 1183 1184 1185
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
                                this@ExpertSearchActivity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "5") {
                        var textview = lin_filter2.getChildAt(index) as TextView
                        this@ExpertSearchActivity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.ages) {
1201 1202 1203 1204 1205
                            if (TextUtils.equals(
                                    bean.value.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
                                this@ExpertSearchActivity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                    if (headData!!.highlighter[index].type == "6") {
                        var textview = lin_filter2.getChildAt(index) as TextView
                        this@ExpertSearchActivity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.others) {
1221 1222 1223 1224 1225
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
                                this@ExpertSearchActivity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }

                    if (headData!!.highlighter[index].type == "7") {
                        var textview = lin_filter2.getChildAt(index) as TextView
                        this@ExpertSearchActivity.runOnUiThread {
                            textview.isSelected = false
                            textview.paint.isFakeBoldText = false
                        }
                        for (bean in allFilter.title) {
1242 1243 1244 1245 1246
                            if (TextUtils.equals(
                                    bean.key.toString(),
                                    headData!!.highlighter[index].id
                                )
                            ) {
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
                                this@ExpertSearchActivity.runOnUiThread {
                                    textview.isSelected = true
                                    textview.paint.isFakeBoldText = true
                                }
                                break
                            }
                        }
                    }
                }
            }
        }

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

    //筛选标题显示处理
    private fun filterLabelSet() {
1267
        if ((allFilter.others.size + allFilter.ages.size + allFilter.doctorEdu.size + allFilter.enquiries.size + allFilter.title.size + allFilter.specialityCrowd.size) == 1) {
1268
            var text: String? = ""
upwork.021 committed
1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
            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
                }
                allFilter.specialityCrowd.size == 1 -> {
                    text = allFilter.specialityCrowd[0].value
                }
                allFilter.doctorEdu.size == 1 -> {
                    //学历
                    text = allFilter.doctorEdu[0].value
                }
                else -> {
                    text = "筛选"
                }
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
            }
            if (text?.length ?: 0 > 4) {
                tvFilter.text = text?.substring(0, 3) + "..."
            } else {
                tvFilter.text = text
            }
        } else {
            tvFilter.text = "筛选"
        }
    }


    private var sortPopup: SortPopupWindow? = null

    //显示排序弹窗
    private fun showSortPopupWindow() {
        if (headData?.reorder != null) {
            sortPopup = SortPopupWindow(this, headData?.reorder!!, allFilter.reorder, this)
            sortPopup!!.setOnDismissListener {
                viewDim.visibility = View.INVISIBLE
                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)
            viewDim.visibility = View.VISIBLE
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

    //排序选择回调
    override fun onSortItemSelected(sortItem: ReorderItem) {
1333 1334 1335 1336
        ActionCountUtils.count(
            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_SORT_CLICK, sortItem.value
                ?: ""
        )
1337

upwork.021 committed
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
        when {
            sortItem.value.equals("综合排序") -> {
                tvSort.text = "排序"
            }
            sortItem.value?.length ?: 0 > 4 -> {
                tvSort.text = sortItem.value?.substring(0, 3) + "..."
            }
            else -> {
                tvSort.text = sortItem.value
            }
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 1374 1375 1376 1377 1378 1379
        }

        //判断排序选中,判断热门筛选中是否也有该排序
        if (headData!!.highlighter.size > 0) {
            for (index in 0.until(headData!!.highlighter.size)) {
                if (headData!!.highlighter[index].type == "3") {
                    var textview = lin_filter2.getChildAt(index) as TextView
                    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) {
1380 1381 1382 1383
            val regionPopupWindow = AreaPopupWindow(
                this, headData?.region
                    ?: ArrayList(), allFilter.region, allFilter.sub
            )
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394
            regionPopupWindow.showAsDropDown(viewSep2)
            viewDim.visibility = View.VISIBLE
            updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
            regionPopupWindow.setOnDismissListener {
                viewDim.visibility = View.INVISIBLE
                if (tvArea.text != "地区") {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_FILTERED)
                } else {
                    updateFilterTextViewStatus(tvArea, FILTER_STATUS_NORMAL)
                }
            }
1395 1396 1397 1398 1399 1400
            regionPopupWindow.onRegionSelectedListener =
                object : AreaPopupWindow.OnRegionSelectedListener {
                    override fun onRegionSelected(region: RegionItem, sub: SubItem) {
                        updateFilterTextViewStatus(tvArea, FILTER_STATUS_OPEN)
                        allFilter.region = region
                        allFilter.sub = sub
1401
                        if (TextUtils.isEmpty(region.code) && TextUtils.isEmpty(sub.code)) {
1402
                            tvArea.text = "地区"
1403
                        } else if (!TextUtils.isEmpty(region.code) && !TextUtils.isEmpty(sub.code)) {
1404 1405 1406 1407 1408
                            if (region.value?.length ?: 0 > 4) {
                                tvArea.text = region.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = region.value
                            }
1409
                        } else {
1410 1411 1412 1413 1414
                            if (sub.value?.length ?: 0 > 4) {
                                tvArea.text = sub.value?.substring(0, 3) + "..."
                            } else {
                                tvArea.text = sub.value
                            }
1415
                        }
1416 1417 1418 1419 1420 1421 1422
                        ActionCountUtils.count(
                            ConsultBIConstants.ConsultEvent.APP_CONSULT_LIST_AREA_CLICK,
                            region.value + "|" + sub.value
                        )

                        //更新热门搜索显示状态
                        if (headData!!.highlighter.size > 0) {
1423
                            for ((index, hot) in headData!!.highlighter.withIndex()) {
1424 1425 1426
                                if (hot.type == "2" || hot.type == "8") {
                                    var textview = lin_filter2.getChildAt(index) as TextView
                                    //有选择城市
1427 1428
                                    if (!TextUtils.isEmpty(sub.code)) {
                                        if (TextUtils.equals(sub.code, hot.id)) {
1429 1430 1431 1432 1433 1434 1435
                                            textview.isSelected = true
                                            textview.paint.isFakeBoldText = true
                                            hasSelectedArea = true
                                        } else {
                                            textview.isSelected = false
                                            textview.paint.isFakeBoldText = false
                                        }
1436
                                    } else {
1437
                                        if (TextUtils.equals(region.code, hot.id)) {
1438 1439 1440 1441 1442 1443 1444
                                            textview.isSelected = true
                                            textview.paint.isFakeBoldText = true
                                            hasSelectedArea = true
                                        } else {
                                            textview.isSelected = false
                                            textview.paint.isFakeBoldText = false
                                        }
1445 1446 1447 1448
                                    }
                                }
                            }
                        }
1449 1450
                        regionPopupWindow.dismiss()
                        refresh()
1451 1452 1453 1454 1455 1456 1457 1458
                    }
                }
        } else {
            ToastUtil.toastShort("数据初始化失败,请重试")
            getPresenter().fetchListHead()
        }
    }

1459 1460
    private var mHandler: Handler? = null

1461 1462 1463
    /**
     * 显示主题弹窗
     */
1464
    private fun showSubjectPopupWindow() {
1465 1466 1467 1468 1469 1470 1471 1472
        val categoryPopup = CategoryPopupWindow(this, allFilter)
        mHandler = Handler()
        mHandler!!.post {
            categoryPopup.updateData()
        }
        categoryPopup.setOnDismissListener {
            viewDim.visibility = View.INVISIBLE
            ConsultAssistantDialogUtils.INSTANCE.fitRequest(this, "doctor_list", true)
1473
        }
1474 1475 1476 1477 1478
        ConsultAssistantDialogUtils.INSTANCE.hideAssistantActivity()
        categoryPopup.onSubjectsSelectedListener = this
        categoryPopup.showAsDropDown(viewSep2)
        updateFilterTextViewStatus(tvSubject, FILTER_STATUS_OPEN)
        viewDim.visibility = View.VISIBLE
1479 1480 1481 1482 1483 1484 1485
    }

    /**
     * 主题选择确认回调
     *
     * 新增逻辑:当主题选择后,需要判断热门筛选中是否也有该主题,如果有,也需要同步更新选中状态
     */
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    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
1496
        }
1497

1498
        if (allFilter.categoryId2List.size > 0 || allFilter.categoryId3List.size > 0) {
1499
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_FILTERED)
1500
        } else {
1501 1502
            updateFilterTextViewStatus(tvSubject, FILTER_STATUS_NORMAL)
        }
upwork.021 committed
1503
        refresh()
1504 1505
    }

1506 1507
    override fun onRefresh() {
        refresh(false)
1508
        recommendListView.requestData(initCategory)
1509 1510
    }

1511 1512 1513 1514
    //刷新列表
    private fun refresh(isShowRefresh: Boolean? = true) {
        srlContainer.isRefreshing = isShowRefresh!!
        onScrollListener.resetState()
1515
        getPresenter().mExtras = null
upwork.021 committed
1516
        getPresenter().fetchListData(allFilter, getPresenter().mExtras)
1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
        rvExperts.scrollToPosition(0)
    }

    //重置所有筛选
    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()
1529
        allFilter.doctorEdu.clear()
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
        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)
konghaorui committed
1549
                tv.setTextColor(ContextCompat.getColor(this, R.color.platform_colorTextDefault))
1550 1551 1552 1553 1554 1555
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
1556 1557 1558
            }
            FILTER_STATUS_FILTERED -> {
                tv.typeface = Typeface.DEFAULT_BOLD
1559
                tv.setTextColor(ContextCompat.getColor(this, R.color.platform_main_theme))
1560 1561 1562 1563 1564 1565
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
                    R.drawable.platform_ic_arrow_drop_down_grey_500_18dp,
                    0
                )
1566 1567 1568
            }
            FILTER_STATUS_OPEN -> {
                tv.typeface = Typeface.DEFAULT_BOLD
konghaorui committed
1569
                tv.setTextColor(ContextCompat.getColor(this, R.color.platform_colorTextDefault))
1570 1571 1572
                tv.setCompoundDrawablesWithIntrinsicBounds(
                    0,
                    0,
1573
                    R.drawable.platform_arrow_drop_down_en,
1574 1575
                    0
                )
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
            }
        }
    }

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


    override fun onResume() {
        super.onResume()
1591
        ActionCountUtils.count(ConsultBIConstants.ConsultSearchListEvent.APP_CONSULT_SEARCH_LIST_PAGE_VISIT)
1592 1593 1594

    }

徐健 committed
1595 1596
    override fun onDestroy() {
        super.onDestroy()
1597
        mHandler = null
1598
        bottomWordDisposable?.dispose()
1599
        ConsultAssistantDialogUtils.INSTANCE.expertSearchResetStatus()
1600 1601
    }
}