package com.igo.user.ui.mine
|
|
import MainActivityViewModel
|
import android.os.CountDownTimer
|
import android.widget.EditText
|
import android.widget.TextView
|
import androidx.activity.viewModels
|
import androidx.lifecycle.lifecycleScope
|
import cn.sinata.xldutils.utils.hidePhone
|
import cn.sinata.xldutils.utils.myToast
|
import cn.sinata.xldutils.utils.optInt
|
import com.google.recaptcha.sample.RecaptchaVisualException
|
import com.igo.user.IGoApplication
|
import com.igo.user.R
|
import com.igo.user.extension.extIsEmptyOrNull
|
import com.igo.user.network.HttpManager
|
import com.igo.user.network.request
|
import com.igo.user.ui.TransparentStatusBarActivity
|
import kotlinx.coroutines.launch
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.sdk27.coroutines.onClick
|
import org.jetbrains.anko.startActivity
|
|
class VerifyPhoneForUpdatePwdActivity : TransparentStatusBarActivity() {
|
private val title by lazy {
|
intent.getStringExtra("title")
|
}
|
|
override fun setContentView() = R.layout.activity_verify_phone_for_pwd
|
|
private val tv_get_code by lazy { find<TextView>(R.id.tv_get_code) }
|
private val tv_action by lazy { find<TextView>(R.id.tv_action) }
|
private val tv_phone by lazy { find<TextView>(R.id.tv_phone) }
|
private val et_code by lazy { find<EditText>(R.id.et_code) }
|
private val viewModel: MainActivityViewModel by viewModels()
|
|
// private lateinit var recaptcha: RecaptchaVisual
|
private val countDownTimer = object : CountDownTimer(60 * 1000, 1000) {
|
override fun onFinish() {
|
tv_get_code.text = getString(R.string.重新获取)
|
tv_get_code.isEnabled = true
|
}
|
|
override fun onTick(millisUntilFinished: Long) {
|
tv_get_code.text = getString(R.string.sms_code_countdown, millisUntilFinished / 1000)
|
}
|
}
|
private val phone by lazy {
|
intent.getStringExtra("phone") ?: ""
|
}
|
|
override fun initClick() {
|
tv_get_code.onClick {
|
sendSms()
|
}
|
tv_action.onClick {
|
val s = et_code.text.toString()
|
if (s.length != 4) {
|
myToast(getString(R.string.验证码输入有误))
|
} else {
|
HttpManager.checkCode(s, phone)
|
.request(this@VerifyPhoneForUpdatePwdActivity) { _, data ->
|
if (data?.optInt("ok") == 1) {
|
startActivity<ChangePwdActivity>("phone" to phone)
|
finish()
|
} else {
|
myToast(getString(R.string.验证码输入有误))
|
}
|
}
|
}
|
}
|
}
|
|
override fun initView() {
|
setTitle(title.extIsEmptyOrNull { getString(R.string.set_pwd) })
|
tv_phone.text = getString(R.string.设置密码需先验证您的手机号, phone.hidePhone())
|
// recaptcha = RecaptchaVisual(supportFragmentManager, WEB_SITE_KEY, BASE_URL)
|
}
|
|
private fun sendSms() {
|
|
lifecycleScope.launch {
|
try {
|
val token = ""
|
viewModel.onLoginButtonClicked(token)
|
|
HttpManager.sendSms(IGoApplication.phone, "", 4, token).request(
|
this@VerifyPhoneForUpdatePwdActivity,
|
success = { _, _ ->
|
myToast(getString(R.string.发送成功))
|
countDownTimer.start()
|
},
|
error = { _, _ ->
|
tv_get_code.isEnabled = true
|
})
|
} catch (error: RecaptchaVisualException) {
|
viewModel.onTokenError(error)
|
}
|
}
|
|
/* val imageCodeDialog = ImageCodeDialog()
|
imageCodeDialog.arguments = bundleOf("phone" to phone)
|
|
imageCodeDialog.setCallback(object : ImageCodeDialog.Callback{
|
override fun onOk(code: String) {
|
showDialog()
|
tv_get_code.isEnabled = false
|
HttpManager.sendSms(phone,code,4).request(this@VerifyPhoneForUpdatePwdActivity,success = { msg, _ ->
|
myToast(getString(R.string.发送成功))
|
countDownTimer.start()
|
}){_,_->
|
tv_get_code.isEnabled = true
|
}
|
}
|
})
|
imageCodeDialog.show(supportFragmentManager,"code")*/
|
}
|
}
|