ConfideHomeEventImpl.kt 17.1 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 8 9
import android.net.Uri
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
洪国微 committed
10
import com.ydl.confide.home.ConfideHomeActivity
洪国微 committed
11 12 13 14 15 16 17 18 19 20 21 22
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
23 24 25 26
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
27 28
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydl_router.manager.YDLRouterParams
洪国微 committed
29 30
import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.router.IYDLRouterConstant
洪国微 committed
31
import com.ydl.ydlcommon.utils.remind.ToastHelper
konghaorui committed
32 33
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.api.bean.IMRequestCallback
洪国微 committed
34 35 36 37 38 39 40 41 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 135 136 137 138 139 140 141 142 143 144 145 146 147

/**
 * @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 跳转地址
     */
    override fun consultantClick(linkUrl: String?) {
        link(linkUrl)
    }

    /**
     * 最佳倾诉榜单--更多情感恋爱专家
     * @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
148 149 150
        val mu = Music()
        mu.path = playUrl
        AudioPlayer.get().singlePlay(mu)
洪国微 committed
151 152 153 154 155 156 157
        umengPlayVoice(type)
        confideHomeView.updataPlayStatu(type, index!!, 0, true)
        initCache(type, index!!, 0, playUrl)
        initConfidePlayerListener()
    }

    override fun playVoice(type: Int?, index: Int?, recommendId: Int, playUrl: String?, name: String?) {
洪国微 committed
158 159 160 161
        val mu = Music()
        mu.title = name
        mu.path = playUrl
        AudioPlayer.get().singlePlay(mu)
洪国微 committed
162
        if (PlayerFloatHelper.isShow(mContext!!)) {
洪国微 committed
163
            if (AudioPlayer.get().playMode.value() == 1) {
洪国微 committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 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
                PlayerFloatHelper.removeView(mContext!!)

                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 -> {
            }
            //咨询师推荐
            IConfideHomeConfig.TYPE_CONSULTANT -> {
            }
        }
    }

    /**
     * 播放缓存变量 用于重播使用
     */
    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
        }
洪国微 committed
236
        AudioPlayer.get().playPause()
洪国微 committed
237 238 239 240 241 242 243
        confideHomeView.updataPlayStatu(cacheType, cacheIndex!!, cacheSubIndex, true)
    }

    /**
     * 暂停播放音频文件
     */
    override fun pauseVoice() {
洪国微 committed
244
        AudioPlayer.get().playPause()
洪国微 committed
245 246 247 248 249 250 251
        PlayerFloatHelper.updatePlayState()
        //因为9999 类型不存在 所以就能把状态全部置为暂停状态了 偷个懒
        confideHomeView.updataPlayStatu(9999, 0, 0, false)
    }

    override fun destoryPlayer() {
        PlayerFloatHelper.hide()
洪国微 committed
252 253
        PlayerFloatHelper.playTempData = hashMapOf<String,String>()
        AudioPlayer.get().stopPlayer()
洪国微 committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        floatViewClickListener?.let { PlayerFloatHelper.removeClickListener(it) };
    }

    /**
     * 私聊
     */
    override fun toChatForMsg(doctorId: String?) {

        if (!PhoneCallIn.isLogin() && null != mContext && mContext is Activity) {
            mContext!!.startActivity(PhoneCallIn.loginWayIntent(mContext as Activity))
            return
        }
        if (mContext is AppCompatActivity && !TextUtils.isEmpty(doctorId)) {
            PhoneCallIn.startChat(mContext as AppCompatActivity, doctorId!!, 0x001, 0)
        }
konghaorui committed
269 270
        PhoneCallIn.getImService().createTextMessage(doctorId, "你好,我想找你倾诉,请尽快上线私聊我,我在等你。", object :
            IMRequestCallback<Void> {
洪国微 committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
            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
304 305
                    val intent1 = Intent(mContext, ConfideHomeActivity::class.java)
                    mContext?.startActivity(intent1)
洪国微 committed
306
                } else {
洪国微 committed
307 308
                    val intent1 = Intent(mContext, ConfideHomeActivity::class.java)
                    mContext?.startActivity(intent1)
洪国微 committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 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 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
                }
            }
        } 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
        if (bodyBean.group != null && !bodyBean.group.isEmpty() && null != bodyBean.group[0].data && !bodyBean.group[0].data!!.isEmpty()) {
            ConfideHomeUtils.synchroTextDrawable(mContext!!, 1, IConfideHomeConfig.FILTER_STATUS_OPEN, filterView, mConfideAdapter)
            sortPopup = ConfideHomeSortPopupWindow(mContext!!, bodyBean.group[0].data!!, allFiltersBean!!.selectSort!!, object : ConfideHomeSortPopupWindow.OnSortItemSelectedListener {
                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) {
        if (null == bodyBean || ((null == bodyBean.group || bodyBean.group.isEmpty()) && (null == bodyBean.group!![0].data || bodyBean.group[0].data!!.isEmpty()))) {
            ToastUtil.toastShort( "数据初始化失败,请重新下拉刷新")
            return
        }
        val sexData = ArrayList<ConfideHomeFiterItemBean>()
        if (null != bodyBean.group[0].data) {
            sexData.addAll(bodyBean.group[0].data!!)
        }
        val ageData = ArrayList<ConfideHomeFiterItemBean>()
        if (1 < bodyBean.group.size && null != bodyBean.group[1].data) {
            ageData.addAll(bodyBean.group[1].data!!)
        }
        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) {
        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!!)
            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("数据初始化失败,请重新下拉刷新")
        }
    }
}