package com.zswc.creativity.activity

import android.os.Bundle
import android.view.KeyEvent
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.zswc.creativity.base.MBActivity
import com.zswc.creativity.config.ConfigRx
import com.zswc.creativity.databinding.ActivityOneloginBinding
import com.zswc.creativity.vmodel.OneLoginVModel
import com.ysnows.base.utils.KeySimulateUtils

/**
 * 一键登录
 *Created by shihuiyun
 *on 2020/9/9
 */
class OneLoginActivity : MBActivity<OneLoginVModel, ActivityOneloginBinding>() {

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        vm.cl=binding.cl
    }

    override fun binding(): ActivityOneloginBinding {
        return ActivityOneloginBinding.inflate(layoutInflater)
    }


    override fun title(): String? {
        return null
    }

    override fun vmClass(): Class<OneLoginVModel> {
        return OneLoginVModel::class.java
    }


    override val isRxbus: Boolean
        get() = true


    @Subscribe(tags = [Tag(ConfigRx.ADD_ONELOGIN)])
    fun setOneLogin(token: String) {
        vm.oneLogin(token)
    }

//    @Subscribe(tags = [Tag(ConfigRx.ONELOGIN_ERROR)])
//    fun setLoginError(bean: OneLoginBean) {
//        Log.d("-shy-", "00000 " )
//
//        if (bean.code === 2016) {
//            toast("当前网络环境不支持认证")
//            return
//        }
//        if (bean.code === 2017) {
//            toast("运营商配置错误")
//            return
//        }
//        if (bean.code === 2018) {
//            toast("本地不支持的运营商")
//            return
//        }
//        if (bean.code === 3002) {
//            toast("无效电话号码")
//
//            return
//        }
//        if (bean.code === 3003) {
//            toast("前后两次请求少于设定时间")
//
//            return
//        }
//        if (bean.code === 6002) {
//            //Toasts.toast(getContext(), "用户取消一键登录");
//            return
//        }
//        toast(bean.msg)
//
//    }

    @Subscribe(tags = [Tag(ConfigRx.ADD_SEND_CODE)])
    fun setLoginCode(code: String) {
        vm.login(code)
    }
    @Subscribe(tags = [Tag(ConfigRx.CLOSE_LOGIN)])
    fun setClose(code: String) {
       finish()
    }

    override fun transluent(): Boolean {
        return true
    }


    override fun onBackPressed() {
        KeySimulateUtils.simulate(KeyEvent.KEYCODE_HOME)
    }



}

