ConfideHomeEventImpl.kt 18 KB
Newer Older
洪国微 committed
1 2 3 4
package com.ydl.confide.home.event

import android.app.Activity
import android.content.Context
洪国微 committed
5
import android.content.Intent
洪国微 committed
6 7
import android.net.Uri
import android.text.TextUtils
万齐军 committed
8
import android.view.View
霍志良 committed
9
import androidx.appcompat.app.AppCompatActivity
10
import androidx.fragment.app.FragmentActivity
11
import com.alibaba.fastjson.JSON
12
import com.ydl.confide.api.ConfideRoute
13
import com.ydl.confide.home.ConfideBottomSheetDialogFragment
洪国微 committed
14
import com.ydl.confide.home.ConfideHomeActivity
洪国微 committed
15 16 17 18 19 20 21 22 23 24 25 26
import com.ydl.confide.home.adapter.ConfideHomeAdapter
import com.ydl.confide.home.bean.ConfideHomeAllFiltersBean
import com.ydl.confide.home.bean.ConfideHomeBodyBean
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.config.IConfideHomeConfig
import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.popwindow.ConfideHomeGoodPopupWindow
import com.ydl.confide.home.popwindow.ConfideHomeSexAgePopupWindow
import com.ydl.confide.home.popwindow.ConfideHomeSortPopupWindow
import com.ydl.confide.home.util.ConfideHomeUtils
import com.ydl.confide.home.widget.ConfideHomeFilterView
import com.ydl.confide.router.PhoneCallIn
洪国微 committed
27 28 29 30
import com.ydl.media.audio.AudioPlayer
import com.ydl.media.audio.model.Music
import com.ydl.media.view.PlayerFloatHelper
import com.ydl.media.view.PlayerFloatView
konghaorui committed
31 32
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams
洪国微 committed
33
import com.ydl.ydlcommon.base.BaseActivity
万齐军 committed
34
import com.ydl.ydlcommon.base.config.HttpConfig
万齐军 committed
35
import com.ydl.ydlcommon.modular.route
洪国微 committed
36
import com.ydl.ydlcommon.router.IYDLRouterConstant
洪国微 committed
37
import com.ydl.ydlcommon.utils.remind.ToastHelper
konghaorui committed
38 39
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.bean.IMRequestCallback
洪国微 committed
40

41

洪国微 committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
/**
 * @author yuanwai
 * @描述:倾诉首页事件处理类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/8/10
 */
class ConfideHomeEventImpl(context: Context, var confideHomeView: IConfideHomeContract.View) : IConfideHomeEvent {

    private var mContext: Context? = null
    private var floatViewClickListener: PlayerFloatView.FloatViewPlayListener? = null

    init {
        mContext = context
    }

    /**
     * 跳转我的
     */
    override fun jumpMine() {
        ConfideHomeUtils.buildJumpMine(mContext!!)
    }

    /**
     * banner点击事件
     * @param linkUrl 跳转地址
     * @param position 点击索引
     * @param title banner 标题
     */
    override fun bannerClick(linkUrl: String?, position: Int?, title: String?) {
        link(linkUrl)
    }

    /**
     * 最近倾诉--继续倾诉
     */
    override fun latelyConfideClick(linkUrl: String?) {

        link(linkUrl)
    }

    /**
     * 最近倾诉--更多
     */
    override fun latelyConfideMore(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 分类点击事件
     * @param linkUrl
     */
    override fun categoryClick(linkUrl: String?) {

        link(linkUrl)
    }

    /**
     * 为你推荐--向TA倾诉
     * @param linkUrl 跳转地址
     */
    override fun recommendClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 为你推荐--更多
     * @param linkUrl 跳转地址
     */
    override fun recommendMoreClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 听声寻人--向TA倾诉
     * @param linkUrl 跳转地址
     */
    override fun soundClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 听声寻人--更多
     * @param linkUrl 跳转地址
     */
    override fun soundMoreClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 最佳倾诉榜单--点我倾诉
     * @param linkUrl 跳转地址
     */
135
    override fun consultantClick(doctorId: String?, confideId: String?, uid: String?,listenFree : Boolean?, expertUrl:String?) {
136 137 138 139 140 141 142 143 144
        doctorId?.let { doctorId ->
            confideId?.let {confideId ->
                ConfideBottomSheetDialogFragment()
                    .showBottomSheetDialog(
                        mContext as FragmentActivity,
                        HttpConfig.MH5_URL + ConfideRoute.h5ConfideIntro(confideId),
                        doctorId, uid = uid, listenFree = listenFree ?: false,expertUrl = expertUrl?:""
                    )
            }
万齐军 committed
145
        }
洪国微 committed
146
    }
147

148

149 150
    override fun videoShowClick(index: Int, data: List<ConfideHomeBodyBean>?) {
        val dataJson = if (data != null) JSON.toJSONString(data) else null
151
        AudioPlayer.get().playOrPause()
万齐军 committed
152
        PlayerFloatHelper.updatePlayState()
万齐军 committed
153
        route(mContext, ConfideRoute.R_VIDEO_SHOW, "initPos" to index, "initData" to dataJson)
154 155
    }

洪国微 committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    /**
     * 最佳倾诉榜单--更多情感恋爱专家
     * @param linkUrl 跳转地址
     */
    override fun consultantMoreClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 播放音频文件
     * @param type   当前模块数据类型
     * @param index 当前的模块里的数据索引位置
     * @param playUrl 播放地址
     */
    override fun playVoice(type: Int?, index: Int?, playUrl: String?) {

洪国微 committed
172 173 174
        val mu = Music()
        mu.path = playUrl
        AudioPlayer.get().singlePlay(mu)
洪国微 committed
175 176 177 178 179 180
        umengPlayVoice(type)
        confideHomeView.updataPlayStatu(type, index!!, 0, true)
        initCache(type, index!!, 0, playUrl)
        initConfidePlayerListener()
    }

181
    override fun playVoice(type: Int?, index: Int?, recommendId: Int, playUrl: String?, name: String?,confideIcon:String?) {
洪国微 committed
182 183 184
        val mu = Music()
        mu.title = name
        mu.path = playUrl
185
        mu.coverPath=confideIcon
洪国微 committed
186
        AudioPlayer.get().singlePlay(mu)
187
        if (PlayerFloatHelper.isShow()) {
洪国微 committed
188
            if (AudioPlayer.get().playMode.value() == 1) {
189
                PlayerFloatHelper.removeView()
洪国微 committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

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

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

        umengPlayVoice(type)
        confideHomeView.updataPlayStatu(type, index!!, recommendId, true)
        initCache(type, index!!, recommendId, playUrl)
        initConfidePlayerListener()
    }

    private fun initConfidePlayerListener() {
        if (floatViewClickListener == null) {
            floatViewClickListener = object : PlayerFloatView.FloatViewPlayListener {
                override fun onStartClick() {
                    confideHomeView.updataPlayStatu(cacheType, cacheIndex!!, cacheSubIndex, true)
                }

                override fun onPlayFinish() {
                    confideHomeView.updataPlayStatu(9999, 0, 0, false)
                }

                override fun onPauseClick() {
                    confideHomeView.updataPlayStatu(9999, 0, 0, false)
                }

            }

            PlayerFloatHelper.addClickListener(floatViewClickListener as PlayerFloatView.FloatViewPlayListener);
        }
    }

    private fun initCache(type: Int?, index: Int?, sub_index: Int, playUrl: String?) {
        cachePlayUrl = playUrl
        cacheType = type
        cacheIndex = index
        cacheSubIndex = sub_index
    }

    //友盟统计埋点
    private fun umengPlayVoice(type: Int?) {
        when (type) {
            //为你推荐
            IConfideHomeConfig.TYPE_RECOMMEND -> {
            }
            //听声寻人
            IConfideHomeConfig.TYPE_SOUND -> {
            }
        }
    }

    /**
     * 播放缓存变量 用于重播使用
     */
    private var cachePlayUrl: String? = null
    private var cacheType: Int? = -1
    private var cacheIndex: Int? = -1
    private var cacheSubIndex: Int = -1

    override fun rePlayVoice() {
        if (TextUtils.isEmpty(cachePlayUrl)) {
            return
        }
258
        AudioPlayer.get().playOrPause()
洪国微 committed
259 260 261 262 263 264 265
        confideHomeView.updataPlayStatu(cacheType, cacheIndex!!, cacheSubIndex, true)
    }

    /**
     * 暂停播放音频文件
     */
    override fun pauseVoice() {
266
        AudioPlayer.get().playOrPause()
洪国微 committed
267 268 269 270 271 272
        PlayerFloatHelper.updatePlayState()
        //因为9999 类型不存在 所以就能把状态全部置为暂停状态了 偷个懒
        confideHomeView.updataPlayStatu(9999, 0, 0, false)
    }

    override fun destoryPlayer() {
273
        PlayerFloatHelper.removeResetView()
洪国微 committed
274 275 276 277 278 279 280
        floatViewClickListener?.let { PlayerFloatHelper.removeClickListener(it) };
    }

    /**
     * 私聊
     */
    override fun toChatForMsg(doctorId: String?) {
万齐军 committed
281 282 283 284
        if (null != mContext && mContext is Activity) {
            if (!PhoneCallIn.loginByOneKeyLogin(mContext as Activity, true)) {
                return
            }
洪国微 committed
285 286 287 288
        }
        if (mContext is AppCompatActivity && !TextUtils.isEmpty(doctorId)) {
            PhoneCallIn.startChat(mContext as AppCompatActivity, doctorId!!, 0x001, 0)
        }
konghaorui committed
289 290
        PhoneCallIn.getImService().createTextMessage(doctorId, "你好,我想找你倾诉,请尽快上线私聊我,我在等你。", object :
            IMRequestCallback<Void> {
洪国微 committed
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
            override fun onSuccess(aVoid: Void?) {
                (mContext as BaseActivity).dismissProgressDialog()
                ToastHelper.show("发送成功")
            }

            override fun onFailed(i: Int) {
                (mContext as BaseActivity).dismissProgressDialog()
                var message = "发送失败"
                if (i == 7101) {
                    message = "您已被对方拉黑!"
                }
                ToastHelper.show(message)
            }

            override fun onException(throwable: Throwable?) {
                (mContext as BaseActivity).dismissProgressDialog()
                ToastHelper.show("发送异常")
            }
        })
    }

    private fun link(linkUrl: String?) {
        if (null == linkUrl || linkUrl.isEmpty()) {
            return
        }
        if (linkUrl!!.startsWith("app")) {
            var uri = Uri.parse(linkUrl)
            //app://listen/list    列表
            //app://listen/lately  最近倾诉列表
            //因为android本地 没有最近倾诉列表 故都跳转 倾诉列表
            if ("listen" == uri.host) {
                var tabIndex = uri.getQueryParameter("type")
                if (TextUtils.isEmpty(tabIndex)) {
洪国微 committed
324 325
                    val intent1 = Intent(mContext, ConfideHomeActivity::class.java)
                    mContext?.startActivity(intent1)
洪国微 committed
326
                } else {
洪国微 committed
327 328
                    val intent1 = Intent(mContext, ConfideHomeActivity::class.java)
                    mContext?.startActivity(intent1)
洪国微 committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
                }
            }
        } else if (linkUrl.startsWith("http")) {
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_H5_H5,
                    YDLRouterParams().putExtra(IYDLRouterConstant.EXTRA_URL, linkUrl), "")
        } else {
            YDLRouterManager.router(linkUrl)
        }
    }

    /**
     * 显示综合排序弹窗
     * @param v_line_top      显示弹窗的位置
     * @param filterView      隐藏的筛选栏View
     * @param bodyBean        数据bean
     * @param allFiltersBean  已选择的筛选bean
     * @param mConfideAdapter section适配器
     */
    override fun showSortPopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter) {
        if (null == bodyBean) {
            return
        }
        var sortPopup: ConfideHomeSortPopupWindow? = null
万齐军 committed
352
        if (bodyBean.group != null && !bodyBean.group!!.isEmpty() && null != bodyBean.group!![0].data && !bodyBean.group!![0].data!!.isEmpty()) {
洪国微 committed
353
            ConfideHomeUtils.synchroTextDrawable(mContext!!, 1, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
万齐军 committed
354
            sortPopup = ConfideHomeSortPopupWindow(mContext!!, bodyBean.group!![0].data!!, allFiltersBean!!.selectSort!!, object : ConfideHomeSortPopupWindow.OnSortItemSelectedListener {
洪国微 committed
355 356 357 358 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 385 386
                override fun onSortItemSelected(sortItem: ConfideHomeFiterItemBean) {

                    //更改小图标
                    ConfideHomeUtils.synchroTextDrawable(mContext!!, 1, IConfideHomeConfig.FILTER_STATUS_NORMAL, filterView, mConfideAdapter)
                    allFiltersBean.selectSort = sortItem
                    confideHomeView.recommendList(1)
                    sortPopup!!.dismiss()
                }
            })

            sortPopup.setOnDismissListener {
                ConfideHomeUtils.synchroTextDrawable(mContext!!, 1, IConfideHomeConfig.FILTER_STATUS_NORMAL, filterView, mConfideAdapter)
            }
            if (sortPopup!!.selectedSort != allFiltersBean.selectSort) {
                sortPopup!!.selectedSort = allFiltersBean.selectSort!!
                sortPopup!!.notifyDataSetChanged()
            }
            sortPopup!!.showAsDropDown(v_line_top)
        } else {
            ToastUtil.toastShort("数据初始化失败,请重新下拉刷新")
        }
    }

    /**
     * 显示性别年龄弹窗
     * @param v_line_top      显示弹窗的位置
     * @param filterView      隐藏的筛选栏View
     * @param bodyBean        数据bean
     * @param allFiltersBean  已选择的筛选bean
     * @param mConfideAdapter section适配器
     */
    override fun showSexAgePopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter) {
万齐军 committed
387
        if (null == bodyBean || ((null == bodyBean.group || bodyBean.group!!.isEmpty()) && (null == bodyBean.group!![0].data || bodyBean.group!![0].data!!.isEmpty()))) {
洪国微 committed
388 389 390 391
            ToastUtil.toastShort( "数据初始化失败,请重新下拉刷新")
            return
        }
        val sexData = ArrayList<ConfideHomeFiterItemBean>()
万齐军 committed
392 393
        if (null != bodyBean.group!![0].data) {
            sexData.addAll(bodyBean.group!![0].data!!)
洪国微 committed
394 395
        }
        val ageData = ArrayList<ConfideHomeFiterItemBean>()
万齐军 committed
396 397
        if (1 < bodyBean.group!!.size && null != bodyBean.group!![1].data) {
            ageData.addAll(bodyBean.group!![1].data!!)
洪国微 committed
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
        }
        val categoryPopup = ConfideHomeSexAgePopupWindow(mContext!!, sexData, ageData, allFiltersBean)
        ConfideHomeUtils.synchroStyle(mContext!!, 2, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
        categoryPopup!!.setOnDismissListener {
            if (allFiltersBean.selectSex!!.id != "-1" || allFiltersBean.selectAgeData!!.size > 0) {
                ConfideHomeUtils.synchroTextColor(mContext!!, 2, IConfideHomeConfig.FILTER_STATUS_FILTERED, filterView, mConfideAdapter)
            } else {
                ConfideHomeUtils.synchroTextColor(mContext!!, 2, IConfideHomeConfig.FILTER_STATUS_NORMAL, filterView, mConfideAdapter)
            }
        }
        categoryPopup!!.onGoodSelectedListener = object : ConfideHomeSexAgePopupWindow.OnSexAgeSelectedListener {
            override fun onSexAgeSelected(sexData: ConfideHomeFiterItemBean, ageData: ArrayList<ConfideHomeFiterItemBean>) {
                var ageBuild = StringBuilder()
                if (ageData != null) {
                    for (data in ageData) {
                        ageBuild.append("${data.name};")
                    }
                }

                ConfideHomeUtils.synchroTextColor(mContext!!, 2, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
                allFiltersBean.selectSex!!.name = sexData.name
                allFiltersBean.selectSex!!.id = sexData.id
                allFiltersBean.selectAgeData!!.clear()
                allFiltersBean.selectAgeData!!.addAll(ageData)
                confideHomeView.recommendList(1)
                categoryPopup.dismiss()
            }
        }
        categoryPopup!!.showAsDropDown(v_line_top)
    }

    /**
     * 显示擅长方向弹窗
     * @param v_line_top      显示弹窗的位置
     * @param filterView      隐藏的筛选栏View
     * @param bodyBean        数据bean
     * @param allFiltersBean  已选择的筛选bean
     * @param mConfideAdapter section适配器
     */
    override fun showGoodPopupWindow(v_line_top: View, filterView: ConfideHomeFilterView, bodyBean: ConfideHomeBodyBean?, allFiltersBean: ConfideHomeAllFiltersBean, mConfideAdapter: ConfideHomeAdapter) {
万齐军 committed
438 439
        if (bodyBean != null && null != bodyBean.group && !bodyBean.group!!.isEmpty() && null != bodyBean.group!![0].data && !bodyBean.group!![0].data!!.isEmpty()) {
            val categoryPopup = ConfideHomeGoodPopupWindow(mContext!!, bodyBean.group!![0].data!!, allFiltersBean.selectGoodData!!)
洪国微 committed
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
            ConfideHomeUtils.synchroStyle(mContext!!, 3, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
            categoryPopup!!.setOnDismissListener {
                if (allFiltersBean.selectGoodData!!.size > 1 || (allFiltersBean.selectGoodData!!.size == 1 && allFiltersBean!!.selectGoodData!![0] != bodyBean.group!![0].data!![0])) {
                    ConfideHomeUtils.synchroTextColor(mContext!!, 3, IConfideHomeConfig.FILTER_STATUS_FILTERED, filterView, mConfideAdapter)
                } else {
                    ConfideHomeUtils.synchroTextColor(mContext!!, 3, IConfideHomeConfig.FILTER_STATUS_NORMAL, filterView, mConfideAdapter)
                }
            }
            categoryPopup!!.onGoodSelectedListener = object : ConfideHomeGoodPopupWindow.OnGoodSelectedListener {
                override fun onGoodSelected(selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>) {
                    var ageBuild = StringBuilder()
                    if (selectedGoodsList != null) {
                        for (data in selectedGoodsList) {
                            ageBuild.append("${data.name};")
                        }
                    }

                    ConfideHomeUtils.synchroTextColor(mContext!!, 3, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
                    allFiltersBean.selectGoodData.clear()
                    allFiltersBean.selectGoodData.addAll(selectedGoodsList)
                    confideHomeView.recommendList(1)
                    categoryPopup.dismiss()
                }
            }
            categoryPopup!!.showAsDropDown(v_line_top)
        } else {
            ToastUtil.toastShort("数据初始化失败,请重新下拉刷新")
        }
    }
}