HomeBaseImpl.kt 20.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
package com.yidianling.home.event

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.RecyclerView
import android.text.TextUtils
import android.view.View
import com.alibaba.android.arouter.launcher.ARouter
import com.ydl.media.audio.AudioPlayer
import com.ydl.media.audio.model.Music
import com.ydl.media.view.PlayTypeEnum
import com.ydl.media.view.PlayerFloatHelper
import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams
import com.ydl.ydl_router.util.YDLRouterParamsUrls
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.base.config.HttpConfig
import com.ydl.ydlcommon.bean.ShareData
import com.ydl.ydlcommon.data.PlatformRamImpl
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
import com.ydl.ydlcommon.utils.Utils
import com.ydl.ydlcommon.utils.actionutil.ActionCountUtils
import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.ydl.ydlcommon.view.dialog.CommonDialog
konghaorui committed
31
import com.yidianling.home.constants.HomeBIConstants
32
import com.yidianling.home.R
徐健 committed
33
import com.yidianling.home.api.event.HomeModuleTabEvent
34 35
import com.yidianling.home.constract.IHomeContract
import com.yidianling.home.model.bean.*
36 37
import com.yidianling.im.api.bean.IMRequestCallback
import com.yidianling.im.api.service.IImService
38 39 40 41 42
import com.yidianling.tests.api.service.ITestsApiService
import com.yidianling.user.api.service.IUserService
import de.greenrobot.event.EventBus
import org.json.JSONObject

43
open class HomeBaseImpl : IHomeBaseEvent {
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

    val HOT_SEARCH_DOCTOR_NAME = "hot_search_doctor_name"
    override fun consultItemClick(linkUrl: String?, doctorId: String) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_EXPERT_INTRODUCTION_CLICK, doctorId)

        if (null == linkUrl || linkUrl.isEmpty()) {
            return
        }
        if (linkUrl.startsWith("http")) {
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_H5_H5,
59 60
                YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_URL, linkUrl), ""
            )
61 62 63 64 65 66 67 68 69 70 71 72
        } else {
            YDLRouterManager.router(linkUrl)
        }
    }

    override fun consultChatClick(doctorId: String?) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(
            HomeBIConstants.YDL_USER_PRIVATE_CHAT_CLICK, doctorId
73 74
                ?: ""
        )
75 76 77 78 79 80 81 82 83 84 85 86

        if (!ModularServiceManager.provide(IUserService::class.java).isLogin()) {
            //跳转登录
            jumpToLogin()
            return
        }
        if (mContext is AppCompatActivity && !TextUtils.isEmpty(doctorId)) {
            //私聊
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_CHAT_PRIVATE,
                YDLRouterParams()
                    .putExtra(IYDLRouterConstant.EXTRA_TOUID, doctorId!!)
87 88
                    .putExtra(IYDLRouterConstant.EXTRA_USERTYPE, "1")
            )
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
        }
    }

    fun jumpToLogin() {
        ARouter.getInstance().build("/user/login")
            .navigation()
    }

    /**
     * 获取咨询列表数据
     * 最终调用
     * @see com.yidianling.home.ui.fragment.YdlHomeFragment.getConsultData
     *
     * @param type 倾述类型
     * @param selectPosition 选中的position
     */
    override fun getConsultData(type: HomeHeaderBean.ConsultCategoryDateBean, selectPosition: Int) {
        ActionCountUtils.count(
            HomeBIConstants.YDL_USER_CONSULT_TYPE_CLICK, type.name
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 142 143 144 145 146 147 148 149 150 151
        mHomeView!!.getConsultData(type.id.toString(), selectPosition)
    }


    private var headerView: View? = null
    var mContext: Context? = null
    var mHomeView: IHomeContract.View? = null
    var COURSE_DETAIL_H5 = HttpConfig.WEB_URL + "fe-app-yidianling/course/Detail/"


    constructor(context: Context, homeView: IHomeContract.View) {
        mContext = context
        this.mHomeView = homeView
    }

    override fun onPageScroll(view_rl_top_bg: View): RecyclerView.OnScrollListener? {
        return object : RecyclerView.OnScrollListener() {
            override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
                super.onScrolled(recyclerView, dx, dy)
                if (headerView == null) headerView = recyclerView?.getChildAt(0)
                val top = headerView?.top
                val height = Math.abs(top!!)
                var per = height.toFloat() / 500
                //最大比例为1
                if (per > 1f) {
                    per = 1f
                }
                val alpha = (per * 255).toInt()
//                Log.e("Tag", "alpha=$alpha--per=$per")
                view_rl_top_bg.background.mutate().alpha = alpha
            }
        }
    }


    override fun serviceCallClick() {
        try {
            if (Utils.isFastClick()) {
                //防止连击
                return
            }
            ActionCountUtils.count(HomeBIConstants.YDL_USER_TELEPHONE_CUSTOMER_SERVICE_CLICK)
152 153
            val tel =
                if (PlatformRamImpl.getInstance().getGlobalInfo() == null) "400-114-1010'" else PlatformRamImpl.getInstance().getGlobalInfo()!!.info.tel
154 155
            var con = "\n400-114-1010\n早8:30-凌晨2:00"
            if (PlatformRamImpl.getInstance().getGlobalInfo() != null && PlatformRamImpl.getInstance().getGlobalInfo()!!.info != null) {
156 157
                con =
                    PlatformRamImpl.getInstance().getGlobalInfo()?.info?.tel + "\n" + PlatformRamImpl.getInstance().getGlobalInfo()?.info?.work_time
158 159 160 161 162 163 164 165 166 167

            }
            val dialog = CommonDialog(mContext)
                .setTitle("欢迎致电壹点灵客服热线")
                .setMessage(con)
                .setLeftOnclick("取消") { v1 ->

                }.setRightClick("拨打") { v12 ->
                    val phoneIntent = Intent(
                        Intent.ACTION_DIAL,
168 169
                        Uri.parse("tel:$tel")
                    )
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
                    mContext?.startActivity(phoneIntent)
                }
            dialog.setMessageOnclick {

            }
            dialog.show()
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    override fun searchTvClick(text: String) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
187
        var doctorName =
konghaorui committed
188
            if (text != mContext?.resources?.getString(R.string.home_search_hint) && text != mContext?.resources?.getString(
189 190 191
                    R.string.platform_search
                )
            ) text else ""
192 193 194 195 196 197 198 199 200 201 202 203

        ARouter.getInstance()
            .build("/consult/hot_search")
            .withString(HOT_SEARCH_DOCTOR_NAME, doctorName)
            .navigation()
    }

    override fun consultMoreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
徐健 committed
204
        EventBus.getDefault().post(HomeModuleTabEvent(2))
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
        ActionCountUtils.count(HomeBIConstants.YDL_USER_CONSULT_MORE_CLICK)
    }


    override fun bannerClick(banner: HomeHeaderBean.FocusListBean) {
        ActionCountUtils.count(HomeBIConstants.YDL_USER_BANNER_CLICK, banner.focId.toString())
        linkTo(banner.linkUrl.toString())
    }


    override fun categoryClick(data: HomeHeaderBean.AskCategoryDataBean) {
//        linkTo(data.url.toString())
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(
222 223 224 225 226
            HomeBIConstants.YDL_USER_CONSULT_CLASSIFICATION_CLICK,
            data.cateId.toString(),
            data.cateTitle
                ?: ""
        )
227 228 229 230 231 232 233 234 235 236
        goExpertSearch(data)
    }

    private fun goExpertSearch(data: HomeHeaderBean.AskCategoryDataBean) {
        if (!TextUtils.isEmpty(data.url) && data.url!!.endsWith("?")) {
            data.url = data.url!!.substring(0, data.url!!.length - 1)
        }
        if ("全部类别" == data.cateTitle || "全部分类" == data.cateTitle) {
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_H5_H5,
237 238 239 240 241
                YDLRouterParams().putExtra(
                    IYDLRouterConstant.EXTRA_URL,
                    HttpConfig.H5_URL + "experts/cates"
                )
            )
242 243 244 245
        } else {
            //跳转咨询频道页 服务入口
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_CONSULT_LIST,
246 247 248 249 250 251 252 253 254
                YDLRouterParams().putExtra(
                    IYDLRouterConstant.EXTRA_CATEID,
                    data.cateId.toString()
                ).putExtra(
                    IYDLRouterConstant.EXTRA_CATETITLE, data.cateTitle!!
                ).putExtra(
                    IYDLRouterConstant.EXTRA_SHOWTYPE, "0"
                )
            )
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
        }
    }

    override fun linkTo(linkUrl: String) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        YDLRouterManager.router(linkUrl)
    }

    override fun reservationExpertsClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
徐健 committed
271
        EventBus.getDefault().post(HomeModuleTabEvent(2))
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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
        ActionCountUtils.count(HomeBIConstants.YDL_USER_CONSULT_CLICK)
    }

    override fun nowConfideClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_TALK_IN_TIME_CLICK)

        //倾诉首页 ydl-user://confide/home
        YDLRouterManager.router(IYDLRouterConstant.ROUTER_CONFIDE_HOME)
    }

    override fun psychologyClassClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        //课程频道页 ydl-user://course/home
//        YDLRouterManager.router(IYDLRouterConstant.ROUTER_COURSE_HOME)
        //埋点
        ActionCountUtils.count(HomeBIConstants.YDL_USER_PSYCHOLOGICAL_CLASSROOM_CLICK)

        ARouter.getInstance().build("/course/home").navigation()
    }

    override fun psychologyTestClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_PSYCHOLOGICAL_TEST_CLICK)
        //测评频道首页 ydl-user://ceshi/home
        YDLRouterManager.router(IYDLRouterConstant.ROUTER_TEST_HOME)
    }

    override fun confideMoreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_LISTEN_MORE_CLICK)

        //倾诉首页 ydl-user://qingshu/home
        YDLRouterManager.router(IYDLRouterConstant.ROUTER_CONFIDE_HOME)
    }

    /**
     * 倾述咨询师点击
     * @param linkUrl 跳转地址
     */
    override fun confideClick(linkUrl: String?, doctorId: Int) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        if (null == linkUrl || linkUrl.isEmpty()) {
            return
        }

333 334 335 336
        ActionCountUtils.count(
            HomeBIConstants.YDL_USER_LISTENER_INTRODUCTION_CLICK,
            doctorId.toString()
        )
337 338 339 340

        if (linkUrl.startsWith("http")) {
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_H5_H5,
341 342
                YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_URL, linkUrl), ""
            )
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
        } else {
            YDLRouterManager.router(linkUrl)
        }
    }

    /**
     * 私聊
     */
    override fun toChatForMsg(doctorId: String?) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        if (!ModularServiceManager.provide(IUserService::class.java).isLogin()) {
            //跳转登录
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_MINE_LOGIN)
            return
        }
        if (mContext is AppCompatActivity && !TextUtils.isEmpty(doctorId)) {
            //私聊
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_CHAT_PRIVATE,
                YDLRouterParams()
                    .putExtra(IYDLRouterConstant.EXTRA_TOUID, doctorId!!)
367 368 369 370 371 372 373 374 375 376
                    .putExtra(IYDLRouterConstant.EXTRA_USERTYPE, "1")
            )
        }
        ModularServiceManager.provide(IImService::class.java)
            .createTextMessage(doctorId, "你好,我想找你倾诉,请尽快上线私聊我,我在等你。", object :
                IMRequestCallback<Void> {
                override fun onSuccess(aVoid: Void?) {
                    (mContext as BaseActivity).dismissProgressDialog()
                    ToastHelper.show("发送成功")
                }
377

378 379 380 381 382 383 384
                override fun onFailed(i: Int) {
                    (mContext as BaseActivity).dismissProgressDialog()
                    var message = "发送失败"
                    if (i == 7101) {
                        message = "您已被对方拉黑!"
                    }
                    ToastHelper.show(message)
385 386
                }

387 388 389 390 391
                override fun onException(throwable: Throwable?) {
                    (mContext as BaseActivity).dismissProgressDialog()
                    ToastHelper.show("发送异常")
                }
            })
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
    }


    override fun courseMreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        //课程频道页 ydl-user://course/home
//        YDLRouterManager.router(IYDLRouterConstant.ROUTER_COURSE_HOME)
        ActionCountUtils.count(HomeBIConstants.YDL_USER_COURSE_MORE_CLICK)
        ARouter.getInstance().build("/course/home").navigation()
    }

    override fun courseItemClick(bean: HomeCourseBean.ListBean) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_COURSE_CLICK, bean.id.toString())

413 414 415 416
        val h5Params = H5Params(
            COURSE_DETAIL_H5 + bean.id,
            mContext?.getString(R.string.platform_course_detail)
        )
417
        if (!TextUtils.isEmpty(bean.shareData?.shareUrl)) {
418 419 420 421 422 423
            val shareData = ShareData(
                bean.shareData?.shareUrl,
                bean.shareData?.title,
                bean.shareData?.cover,
                bean.shareData?.desc
            )
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
            h5Params.shareData = shareData
        }

        NewH5Activity.start(mContext, h5Params)
    }

    override fun askItemFocusClick(position: Int, id: String) {
        if (!ModularServiceManager.provide(IUserService::class.java).isLogin()) {
            //跳转登录
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_MINE_LOGIN)
            return
        }
        //关注用户
        mHomeView?.askFocus(position, id)
    }

    override fun askItemZanClick(position: Int, index: Int, id: String) {
        if (!ModularServiceManager.provide(IUserService::class.java).isLogin()) {
            //跳转登录
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_MINE_LOGIN)
            return
        }
        //问答动态点赞
        mHomeView?.askZan(position, index, id)
    }

    override fun askMoreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_ASK_MORE_CLICK)
        //心事动态频道页(首页--问答) ydl-user://answers/home
        YDLRouterManager.router(IYDLRouterConstant.ROUTER_ANSWERS_HOME)
    }

    override fun fmItemClick(bean: HomeFMBean.ListBean) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_RADIO_CLICK, bean.id.toString())
        //电台详情页面
        YDLRouterManager.router(
            IYDLRouterConstant.ROUTER_FM_DETAIL,
469 470
            YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_ID, bean.id.toString())
        )
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
    }

    override fun fmPlayClick(fmDetail: HomeFMBean.ListBean) {
        ActionCountUtils.count(HomeBIConstants.YDL_USER_RADIO_PLAY_CLICK, fmDetail.id.toString())

        if (!TextUtils.isEmpty(fmDetail.fmUrl)) {
            val music = Music()
            music.path = fmDetail.fmUrl
            music.album = fmDetail.imageUrl
            music.artist = fmDetail.author
            music.coverPath = fmDetail.imageUrl
            music.title = fmDetail.name
            AudioPlayer.get().singlePlay(music, false)
            PlayerFloatHelper.playingType = PlayTypeEnum.PLAY_TYPE_FM
        }

        PlayerFloatHelper.isCanClick = true
        if (PlayerFloatHelper.isShow(mContext!!)) {
            if (PlayerFloatHelper.playingType != PlayTypeEnum.PLAY_TYPE_FM) {
                PlayerFloatHelper.removeView(mContext!!)

                PlayerFloatHelper.show(mContext!!)
            } else {
                PlayerFloatHelper.setPlayingState(mContext!!)
            }

        } else {
            mContext?.let { PlayerFloatHelper.show(it) }
        }
    }

    override fun fmMoreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_HEART_RADIO_MORE_CLICK)
        //fm列表页  ydl-user://fm/list
        YDLRouterManager.router(IYDLRouterConstant.ROUTER_FM_LIST)
    }

    override fun articleItemClick(bean: HomeArticleBean.Bean?) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        if (bean == null) {
            return
        }

        ActionCountUtils.count(HomeBIConstants.YDL_USER_ARTICLE_CLICK, bean.id.toString())

        YDLRouterManager.router(
            IYDLRouterConstant.ROUTER_H5_H5,
525 526
            YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_URL, bean.gethUrl()!!), ""
        )
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
    }

    override fun articleMoreClick() {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_ARTICLE_MORE_CLICK)

        //文章列表页 ydl-user://article/list
        ARouter.getInstance().build("/article/list").navigation()
//        YDLRouterManager.router(IYDLRouterConstant.ROUTER_ARTICLE_LIST)
    }

    override fun askItemClick(bean: HomeAskBean.DataBean) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        ActionCountUtils.count(HomeBIConstants.YDL_USER_ASK_COMMENT_CLICK, bean.id.toString())
        val bundle = Bundle()
        bundle.putInt("trend_id", bean.id)
        bundle.putInt("comment_count", bean.commentsCount)
        bundle.putBoolean("is_comment", false)

        //动态详情
        ARouter.getInstance().build("/trends/detail")
            .withBundle("bundle", bundle)
            .navigation()
    }

    override fun publishTrendClick() {

        val bundle = Bundle()
        bundle.putString("publish_type", "topic_publish")
        bundle.putString("topic_id", "44")
        bundle.putString("topic_title", "今日打卡")

        //发布动态
        ARouter.getInstance().build("/trend/publish")
            .withBundle("bundle", bundle)
            .navigation()
    }


    /**
     * 获取倾述列表数据
     * 最终调用
     * @see com.yidianling.home.ui.fragment.YdlHomeFragment.getConfideData
     *
     * @param type 倾述类型
     * @param selectPosition 选中的position
     */
    override fun getConfideData(type: HomeHeaderBean.ListenCategoryDateBean, selectPosition: Int) {
        ActionCountUtils.count(
            HomeBIConstants.YDL_USER_LISTEN_TYPE_CLICK, type.name
583 584
                ?: ""
        )
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
        mHomeView!!.getConfideData(type.id.toString(), selectPosition)
    }

    override fun testItemClick(linkUrl: String?) {
        if (Utils.isFastClick()) {
            //防止连击
            return
        }
        if (null == linkUrl || linkUrl.isEmpty()) {
            return
        }
        if (linkUrl.startsWith("app")) {
            val uri = Uri.parse(linkUrl)
            if ("ceshi" == uri.host) {
                val id = uri.getQueryParameter("id")
                ModularServiceManager.provide(ITestsApiService::class.java).testDetailH5(id)
            }
        } else if (linkUrl.startsWith("http")) {
            YDLRouterManager.router(
                IYDLRouterConstant.ROUTER_H5_H5,
605 606
                YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_URL, linkUrl), ""
            )
607 608 609
        } else if (linkUrl.contains("ceshi/detail?")) {
            val routerParamsUrls = YDLRouterParamsUrls(linkUrl)
            val jsonObject = JSONObject(routerParamsUrls.getParams())
610 611
            ModularServiceManager.provide(ITestsApiService::class.java)
                .testDetailH5(jsonObject.getString("id").toString())
612 613 614 615 616 617 618 619 620
        } else {
            YDLRouterManager.router(linkUrl)
        }
    }

    override fun testMoreClick() {
        psychologyTestClick()
    }
}