package com.driver.igotrip.ui.mine
|
|
import android.util.TypedValue
|
import android.widget.EditText
|
import android.widget.TextView
|
import androidx.lifecycle.lifecycleScope
|
import cn.sinata.xldutils.utils.SPUtils
|
import cn.sinata.xldutils.utils.clickDelay
|
import cn.sinata.xldutils.utils.getContent
|
import com.driver.emanagercar.ui.base.Local.BaseLoginActivity
|
import com.driver.igotrip.R
|
import com.driver.igotrip.base.BaseEvent
|
import com.driver.igotrip.base.Const
|
import com.driver.igotrip.netUtls.Api
|
import com.driver.igotrip.netUtls.callNet
|
import com.driver.igotrip.netUtls.getMapByAny
|
import com.driver.igotrip.utils.Cache.CacheKey
|
import com.google.recaptcha.sample.RecaptchaVisual
|
import com.google.recaptcha.sample.RecaptchaVisualException
|
import com.lljjcoder.style.citylist.Toast.ToastUtils
|
import kotlinx.coroutines.launch
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
|
class SafeVerifyActivity: BaseLoginActivity() {
|
|
|
companion object {
|
const val WEB_SITE_KEY = "6LdZdPErAAAAAM5YvB_2ElX5VR4bG2hcNhAOO5cU"
|
const val BASE_URL = "https://gopost.ci"
|
}
|
|
private val et_login_code_send by lazy { find<TextView>(R.id.et_login_code_send) }
|
private val et_login_pwd by lazy { find<EditText>(R.id.et_login_pwd) }
|
private val tv_phone by lazy { find<TextView>(R.id.tv_phone) }
|
private val tv_next by lazy { find<TextView>(R.id.tv_next) }
|
|
private lateinit var recaptcha: RecaptchaVisual
|
|
override fun tvInit(tv_code: TextView) {
|
et_login_code_send.text = getString(R.string.获取验证码)
|
}
|
|
override fun tvIniting(tv_code: TextView, time: String) {
|
et_login_code_send.text = getString(R.string.秒后重新获取,time)
|
}
|
|
override fun setContentView() {
|
setContentView(R.layout.activity_safe_verify)
|
}
|
|
override fun initView() {
|
setTitleText(getString(R.string.安全验证))
|
val lang = SPUtils.getString(Const.language)
|
if (lang == "fr") {
|
et_login_pwd.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
|
et_login_code_send.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
|
}
|
recaptcha = RecaptchaVisual(supportFragmentManager, WEB_SITE_KEY, BASE_URL)
|
}
|
|
override fun onResume() {
|
super.onResume()
|
showPhone()
|
}
|
|
fun showPhone(){
|
var phone = CacheKey.getUserInfo().phone
|
tv_phone.text = getString(R.string.设置密码需先验证您的手机号,phone.substring(0,3),phone.substring(7))
|
}
|
|
override fun setOnclick() {
|
et_login_code_send.setOnClickListener {
|
sendSms()
|
}
|
|
tv_next.clickDelay {
|
if (et_login_pwd.getContent().isEmpty()){
|
toast(getString(R.string.请输入验证码))
|
return@clickDelay
|
}
|
var phone = CacheKey.getUserInfo().phone
|
var map = getMapByAny()
|
map["code"] = et_login_pwd.getContent()
|
map["phone"] = phone
|
callNet(Api.checkCaptcha,map){
|
startActivity<SettingLoginPwdActivity>()
|
}
|
}
|
}
|
|
private fun sendSms() {
|
lifecycleScope.launch {
|
try {
|
val token = recaptcha.runCaptcha().await()
|
|
var map = getMapByAny()
|
map["phone"] = CacheKey.getUserInfo().phone
|
map["kaptcha"] = "kaptcha"
|
map["type"] = 4
|
map["token"] = token
|
callNet(Api.queryCaptcha, map) {
|
refreshTime(et_login_code_send)
|
}
|
|
} catch (error: RecaptchaVisualException) {
|
ToastUtils.showShortToast(this@SafeVerifyActivity,error.message)
|
}
|
}
|
}
|
|
|
override fun onEventMainThread(event: BaseEvent?) {
|
super.onEventMainThread(event)
|
when(event?.code){
|
BaseEvent.CLOSE_ACT_SAFE_VER -> {
|
finish()
|
}
|
}
|
}
|
}
|