MoreClickView.kt 4.6 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 12 13 14 15 16 17 18 19 20 21
import com.ydl.webview.R
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;
 */
22 23
class MoreClickView(context: Context, jtoJHandle: IJavascriptHandler) : RelativeLayout(context), View.OnClickListener {
    private var mJtoJHandle: IJavascriptHandler?= jtoJHandle
24 25 26
    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
27
    private val tel = if (PlatformDataManager.getRam().getGlobalInfo() == null) "400-765-1010" else PlatformDataManager.getRam().getGlobalInfo()?.info?.tel
28 29

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

    internal fun init() {
        fl_main.setOnClickListener(this)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
        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)
        }
56 57 58 59 60 61
/*        if (YdlCommonRouterManager.getYdlCommonRoute().isHasUnread()) {
            msg_new.setVisibility(View.VISIBLE)
        } else {
            msg_new.setVisibility(View.INVISIBLE)
        }*/

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

    }


    override fun onClick(view: View) {
        if (mPopupWindow != null && mPopupWindow!!.isShowing) {
            mPopupWindow!!.dismiss()
        }
        when (view.id) {
            R.id.fl_main -> {
            }
84 85 86 87 88 89 90 91 92 93 94 95
            R.id.more_msg -> {
                setMoreMsg()
            }
            R.id.more_homepage -> {
                setMoreHomePage()
            }
            R.id.more_service -> {
                setMoreService()
            }
            R.id.more_ray -> {
                    setMoreRay()
            }
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        }

    }

    private fun setMoreMsg() {
        if (PlatformDataManager.getRam().getChannelName().startsWith("ATK_3")) {
            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)
118
                .setMessage("欢迎致电壹点灵客服热线\n$tel\n服务时间:$work_time")
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                .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
    }
}