package com.fuban.user.ui.login
|
|
import android.app.Activity
|
import android.os.CountDownTimer
|
import cn.sinata.xldutils.utils.*
|
import com.fuban.user.R
|
import com.fuban.user.network.HttpManager
|
import com.fuban.user.network.request
|
import com.fuban.user.ui.TransparentStatusBarActivity
|
import com.fuban.user.utils.Const
|
import kotlinx.android.synthetic.main.activity_bind_phone.*
|
|
class BindPhoneActivity : TransparentStatusBarActivity() {
|
override fun setContentView() = R.layout.activity_bind_phone
|
|
private val timer by lazy {
|
object : CountDownTimer(60000, 1000) {
|
override fun onFinish() {
|
tv_code.text = "获取验证码"
|
tv_code.isEnabled = true
|
}
|
|
override fun onTick(millisUntilFinished: Long) {
|
tv_code.text = "已发送${millisUntilFinished / 1000}s"
|
}
|
}
|
}
|
|
override fun initClick() {
|
tv_code.setOnClickListener {
|
val phone = et_phone.text.toString()
|
if (!phone.isValidPhone()) {
|
myToast("请输入正确的手机号码")
|
return@setOnClickListener
|
}
|
tv_code.isEnabled = false
|
HttpManager.sendSms(phone,1).request(this,success = { _, _ ->
|
timer.start()
|
myToast("发送成功")
|
},error = {_,_->
|
tv_code.isEnabled = true
|
})
|
}
|
|
tv_action.setOnClickListener {
|
val phone = et_phone.text.toString()
|
if (!phone.isValidPhone()) {
|
myToast("请输入正确的手机号码")
|
return@setOnClickListener
|
}
|
val code = et_code.text.toString()
|
if (code.isEmpty()) {
|
myToast("请输入短信验证码")
|
return@setOnClickListener
|
}
|
if (code.length<4) {
|
myToast("请输入4位数验证码")
|
return@setOnClickListener
|
}
|
HttpManager.bindingPhone(code, phone).request(this){_,data->
|
data?.let {
|
myToast("绑定成功")
|
SPUtils.instance().put(Const.User.NO_PHONE, false).apply()
|
if (it.optString("appid").isNotEmpty()){
|
SPUtils.instance().put(Const.User.APP_ID, it.optString("appid"))
|
.put(Const.User.TOKEN, it.optString("token"))
|
.put(Const.User.USER_ID, it.optInt("id")).apply()
|
}
|
setResult(Activity.RESULT_OK)
|
finish()
|
}
|
}
|
}
|
}
|
|
override fun initView() {
|
title = "完善手机号"
|
}
|
|
}
|