package com.fuban.driver.ui.mine
|
|
import android.annotation.SuppressLint
|
import android.widget.TextView
|
import cn.sinata.xldutils.utils.clickDelay
|
import cn.sinata.xldutils.utils.getContent
|
import com.fuban.driver.R
|
import com.fuban.driver.base.MyBaseActivity
|
import com.fuban.driver.netUtls.Api
|
import com.fuban.driver.netUtls.callNet
|
import com.fuban.driver.netUtls.getMapByAny
|
import com.fuban.driver.ui.DialogUtil
|
import com.fuban.driver.ui.pub.LoginActivity
|
import com.fuban.driver.utils.Cache.CacheKey
|
import com.fuban.driver.utils.Cache.CacheUtil
|
import com.fuban.driver.utils.PhoneCheckUtil
|
import com.trello.rxlifecycle3.android.ActivityEvent
|
import io.reactivex.Observable
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
import io.reactivex.disposables.Disposable
|
import io.reactivex.schedulers.Schedulers
|
import kotlinx.android.synthetic.main.activity_change_one.*
|
import kotlinx.android.synthetic.main.dialog_change_phone.view.*
|
import kotlinx.android.synthetic.main.include_login_code.view.*
|
import kotlinx.android.synthetic.main.include_login_phone.view.*
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.toast
|
import java.util.concurrent.TimeUnit
|
|
class ChangePhoneOneActivity : MyBaseActivity() {
|
override fun setContentView() {
|
setContentView(R.layout.activity_change_one)
|
}
|
|
override fun initView() {
|
setTitleText("修改手机号")
|
showPhone()
|
}
|
|
fun showPhone(){
|
var phone = CacheKey.getUserInfo().phone
|
tv_phone.text = "您当前的手机号为"+phone.substring(0,3)+"****"+phone.substring(7)
|
}
|
|
|
override fun setOnclick() {
|
tv_change_phone.setOnClickListener {
|
var dialog = DialogUtil.getDialog(this, R.layout.dialog_change_phone,R.style.dialogFullScreen_not_float)
|
var view = DialogUtil.getView(dialog)
|
view.et_login_phone.hint = "请输入未注册手机号"
|
view.et_login_code_send.clickDelay {
|
if (view.et_login_phone.getContent().isEmpty()){
|
toast("请输入手机号")
|
return@clickDelay
|
}
|
var maps = getMapByAny()
|
maps["phone"] = view.et_login_phone.getContent().trim()
|
maps["type"] = 1
|
callNet(Api.queryCaptcha,maps){
|
toast("发送成功")
|
}
|
refreshTime(view.et_login_code_send)
|
|
}
|
view.rl_container.clickDelay {
|
|
}
|
view.view_hint_close_car.setOnClickListener {
|
closeTime()
|
dialog.dismiss()
|
}
|
|
view.tv_sure_car_num.clickDelay {
|
closeTime()
|
if (view.et_login_code.getContent().isEmpty()){
|
toast("请输入验证码")
|
return@clickDelay
|
}
|
if (view.et_login_phone.getContent().isEmpty()){
|
toast("请输入手机号")
|
return@clickDelay
|
}
|
if (!PhoneCheckUtil.phoneCheck(view.et_login_phone.getContent())){
|
toast("手机号格式错误")
|
return@clickDelay
|
}
|
var map = getMapByAny()
|
map["code"] = view.et_login_code.getContent()
|
map["phone"] = view.et_login_phone.getContent()
|
callNet(Api.checkCaptcha,map){
|
callNet(Api.updatePhone,map){
|
toast("修改成功")
|
var user = CacheKey.getUserInfo()
|
user.phone = view.et_login_phone.getContent()
|
CacheKey.saveUserInfo(user)
|
showPhone()
|
dialog.dismiss()
|
CacheUtil.get().clear()
|
startActivity<LoginActivity>()
|
}
|
}
|
}
|
}
|
}
|
|
|
fun closeTime() {
|
if (null != timeDisposable && !timeDisposable!!.isDisposed) {
|
timeDisposable!!.dispose()
|
}
|
}
|
|
var maxTime = 60 //配置倒计时时间
|
private var timeDisposable: Disposable? = null
|
@SuppressLint("SetTextI18n")
|
public fun refreshTime(textView: TextView) {
|
if (null != timeDisposable && !timeDisposable!!.isDisposed) {
|
timeDisposable!!.dispose()
|
}
|
timeDisposable = Observable
|
.interval(1, TimeUnit.SECONDS)
|
.take(maxTime.toLong())
|
.subscribeOn(Schedulers.computation())
|
.observeOn(AndroidSchedulers.mainThread())
|
.compose(bindUntilEvent(ActivityEvent.DESTROY))
|
.subscribe { aLong ->
|
if (aLong == maxTime - 1.toLong()) {
|
textView.isEnabled = true
|
textView.text = "获取验证码"
|
} else {
|
textView.isEnabled = false
|
textView.text = (maxTime - 1 - aLong).toString() + "s后重新获取"
|
}
|
}
|
}
|
}
|