MoreClickView.kt 4.67 KB
Newer Older
1 2 3 4 5 6 7 8 9
package com.ydl.view

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.text.TextUtils
import android.view.View
import android.widget.PopupWindow
import android.widget.RelativeLayout
10
import com.ydl.webview.IJavascriptHandler
11
import com.ydl.webview.R
12
import com.ydl.ydlcommon.base.config.ChannelConfig
13 14 15 16 17 18 19 20 21 22
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.YdlCommonRouterManager
import com.ydl.ydlcommon.view.dialog.CommonDialog
import com.yidianling.im.api.service.IImService
import kotlinx.android.synthetic.main.web_ui_new_more.view.*

/**
 * Created by Wi1ls on 2016/10/17;
 */
23 24
class MoreClickView(context: Context, jtoJHandle: IJavascriptHandler) : RelativeLayout(context), View.OnClickListener {
    private var mJtoJHandle: IJavascriptHandler?= jtoJHandle
25 26 27
    private var mPopupWindow: PopupWindow? = null

    private val work_time = if (PlatformDataManager.getRam().getGlobalInfo() == null) "早8:30-凌晨2:00" else PlatformDataManager.getRam().getGlobalInfo()?.info?.work_time
28
    private val tel = if (PlatformDataManager.getRam().getGlobalInfo() == null) "400-765-1010" else PlatformDataManager.getRam().getGlobalInfo()?.info?.tel
29 30

    init {
31
        View.inflate(context, R.layout.web_ui_new_more, this)
32 33 34 35 36
        init()
    }

    internal fun init() {
        fl_main.setOnClickListener(this)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        if(mJtoJHandle?.setMoreMsg()!=null){
            more_msg.setOnClickListener(mJtoJHandle?.setMoreMsg())
        }else{
            more_msg.setOnClickListener(this)
        }
        if(mJtoJHandle?.setMoreHomePage()!=null){
            more_homepage.setOnClickListener(mJtoJHandle?.setMoreHomePage())
        }else{
            more_homepage.setOnClickListener(this)
        }
        if(mJtoJHandle?.setMoreService()!=null){
            more_service.setOnClickListener(mJtoJHandle?.setMoreService())
        }else{
            more_service.setOnClickListener(this)
        }
        if(mJtoJHandle?.setMoreCall()!=null){
            more_ray.setOnClickListener(mJtoJHandle?.setMoreCall())
        }else{
            more_ray.setOnClickListener(this)
        }
57 58 59 60 61 62
/*        if (YdlCommonRouterManager.getYdlCommonRoute().isHasUnread()) {
            msg_new.setVisibility(View.VISIBLE)
        } else {
            msg_new.setVisibility(View.INVISIBLE)
        }*/

徐健 committed
63 64 65 66 67
        var unreadNum = ModularServiceManager.provide(IImService::class.java).getAllUnReadNum()
        if (unreadNum <= 0) {
            un_read_num.visibility = View.GONE
        }
        else {
徐健 committed
68 69 70 71 72
            if (unreadNum > 99) {
                un_read_num.text = "${unreadNum}+"
            } else {
                un_read_num.text = unreadNum.toString()
            }
徐健 committed
73
        }
74 75 76 77 78 79 80 81 82 83 84

    }


    override fun onClick(view: View) {
        if (mPopupWindow != null && mPopupWindow!!.isShowing) {
            mPopupWindow!!.dismiss()
        }
        when (view.id) {
            R.id.fl_main -> {
            }
85 86 87 88 89 90 91 92 93 94 95 96
            R.id.more_msg -> {
                setMoreMsg()
            }
            R.id.more_homepage -> {
                setMoreHomePage()
            }
            R.id.more_service -> {
                setMoreService()
            }
            R.id.more_ray -> {
                    setMoreRay()
            }
97 98 99 100 101
        }

    }

    private fun setMoreMsg() {
102
        if (PlatformDataManager.getRam().getChannelName().startsWith(ChannelConfig.ATK_3.name)) {
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            YdlCommonRouterManager.getYdlCommonRoute().startMain(context, 2, null)
        } else {
            YdlCommonRouterManager.getYdlCommonRoute().startMain(context, 3, null)
        }
    }

    private fun setMoreHomePage() {
        YdlCommonRouterManager.getYdlCommonRoute().startMain(context, 0, null)
    }

    private fun setMoreService() {
        YdlCommonRouterManager.getYdlCommonRoute().setMoreService(context)
    }

    private fun setMoreRay() {
        CommonDialog(context)
119
                .setMessage("欢迎致电壹点灵客服热线\n$tel\n服务时间:$work_time")
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
                .setLeftOnclick("取消", null)
                .setRightClick("拨打") {
                    if (null != tel && !TextUtils.isEmpty(tel)) {
                        val phoneIntent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:$tel"))
                        context.startActivity(phoneIntent)
                    }
                }.show()
    }

    private var callBack: CallPhoneCallBack? = null

    fun setCallPhoneCallBack(callBack: CallPhoneCallBack) {
        this.callBack = callBack
    }

    interface CallPhoneCallBack {
        fun call(tel: String, action: String)
    }

    fun setPopupWindow(popupWindow: PopupWindow) {
        mPopupWindow = popupWindow
    }
}