package com.driver.igotrip.ui.mine
|
|
import android.annotation.SuppressLint
|
import android.app.Activity
|
import android.content.Intent
|
import android.util.TypedValue
|
import android.view.View
|
import android.widget.EditText
|
import android.widget.TextView
|
import cn.sinata.xldutils.utils.SPUtils
|
import cn.sinata.xldutils.utils.clickDelay
|
import cn.sinata.xldutils.utils.getAreaCode
|
import cn.sinata.xldutils.utils.getContent
|
import cn.sinata.xldutils.utils.textColor
|
import com.driver.igotrip.R
|
import com.driver.igotrip.base.BaseEvent
|
import com.driver.igotrip.base.Const
|
import com.driver.igotrip.base.MyBaseActivity
|
import com.driver.igotrip.netUtls.Api
|
import com.driver.igotrip.netUtls.callNet
|
import com.driver.igotrip.netUtls.getMapByAny
|
import com.driver.igotrip.ui.DialogUtil
|
import com.driver.igotrip.ui.main.ChangPhoneActivity
|
import com.driver.igotrip.ui.pub.AreaCodeActivity
|
import com.driver.igotrip.ui.pub.LoginActivity
|
import com.driver.igotrip.utils.Cache.CacheKey
|
import com.driver.igotrip.utils.Cache.CacheUtil
|
import com.driver.igotrip.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 org.greenrobot.eventbus.EventBus
|
import org.jetbrains.anko.find
|
import org.jetbrains.anko.startActivity
|
import org.jetbrains.anko.startActivityForResult
|
import org.jetbrains.anko.toast
|
import java.util.concurrent.TimeUnit
|
|
class ChangePhoneOneActivity : MyBaseActivity() {
|
override fun setContentView() {
|
setContentView(R.layout.activity_change_one)
|
}
|
|
private val tv_phone by lazy { find<TextView>(R.id.tv_phone) }
|
private val tv_change_phone by lazy { find<TextView>(R.id.tv_change_phone) }
|
private var areaCode: TextView? = null
|
|
override fun initView() {
|
setTitleText(getString(R.string.修改手机号))
|
val lang = SPUtils.getString(Const.language)
|
if (lang == "fr") {
|
tv_title.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
|
}
|
showPhone()
|
}
|
|
fun showPhone(){
|
var phone = CacheKey.getUserInfo().phone
|
tv_phone.text = getString(R.string.您当前的手机号为, phone.substring(0, 3), phone.substring(7))
|
}
|
|
|
override fun setOnclick() {
|
tv_change_phone.setOnClickListener {
|
if(true){
|
startActivity<ChangPhoneActivity>("type" to "")
|
return@setOnClickListener
|
}
|
var dialog = DialogUtil.getDialog(
|
this,
|
R.layout.dialog_change_phone,
|
R.style.dialogFullScreen_not_float
|
)
|
var view = DialogUtil.getView(dialog)
|
val lang = SPUtils.getString(Const.language)
|
areaCode = view.find<TextView>(R.id.areaCode)
|
val et_login_code_send = view.find<TextView>(R.id.et_login_code_send)
|
val et_login_code = view.find<EditText>(R.id.et_login_code)
|
val et_login_phone = view.find<EditText>(R.id.et_login_phone)
|
val rl_container = view.find<View>(R.id.rl_container)
|
val view_hint_close_car = view.find<View>(R.id.view_hint_close_car)
|
val tv_operator = view.find<TextView>(R.id.tv_operator)
|
val tv_sure_car_num = view.find<TextView>(R.id.tv_sure_car_num)
|
if (lang == "fr") {
|
et_login_code_send.setTextSize(TypedValue.COMPLEX_UNIT_SP,11f)
|
et_login_code.setTextSize(TypedValue.COMPLEX_UNIT_SP,11f)
|
et_login_phone.setTextSize(TypedValue.COMPLEX_UNIT_SP,11f)
|
}
|
et_login_code_send.textColor(this,R.color.color_F02807)
|
areaCode!!.setOnClickListener {
|
startActivityForResult<AreaCodeActivity>(10086)
|
}
|
et_login_code_send.clickDelay {
|
if (et_login_phone.getContent().isEmpty()){
|
toast(getString(R.string.请输入手机号))
|
return@clickDelay
|
}
|
var maps = getMapByAny()
|
maps["phone"] = areaCode!!.getAreaCode() + et_login_phone.getContent().trim()
|
maps["type"] = 1
|
callNet(Api.queryCaptcha, maps){
|
toast(getString(R.string.发送成功))
|
}
|
refreshTime(et_login_code_send)
|
|
}
|
rl_container.clickDelay {
|
|
}
|
view_hint_close_car.setOnClickListener {
|
closeTime()
|
dialog.dismiss()
|
}
|
tv_operator.clickDelay {
|
val operator = tv_operator.text.toString()
|
DialogUtil.getColorListDialog(
|
arrayListOf("MTN", "TIGO", "TELECEL", "AIRTEL"),
|
tv_operator,
|
this,
|
if (operator.isEmpty()) "MTN" else operator
|
){
|
tv_operator.text = it
|
}
|
}
|
tv_sure_car_num.clickDelay {
|
closeTime()
|
if (tv_operator.text.toString().isEmpty()) {
|
toast(getString(R.string.请选择运营商))
|
return@clickDelay
|
}
|
if (et_login_code.getContent().isEmpty()){
|
toast(getString(R.string.请输入验证码))
|
return@clickDelay
|
}
|
if (et_login_phone.getContent().isEmpty()){
|
toast(getString(R.string.请输入手机号))
|
return@clickDelay
|
}
|
if (!PhoneCheckUtil.phoneCheck(et_login_phone.getContent())){
|
toast(getString(R.string.手机号格式错误))
|
return@clickDelay
|
}
|
var map = getMapByAny()
|
map["code"] = et_login_code.getContent()
|
map["phone"] = areaCode!!.getAreaCode() + et_login_phone.getContent()
|
map["phoneOperator"] = tv_operator.text.toString()
|
callNet(Api.checkCaptcha, map){
|
callNet(Api.updatePhone1, map){
|
toast(getString(R.string.修改成功))
|
var user = CacheKey.getUserInfo()
|
user.phone = areaCode!!.getAreaCode() + et_login_phone.getContent()
|
CacheKey.saveUserInfo(user)
|
showPhone()
|
dialog.dismiss()
|
CacheUtil.get().clear()
|
startActivity<LoginActivity>()
|
EventBus.getDefault().post(BaseEvent(BaseEvent.OFF_LINE))
|
|
}
|
}
|
}
|
}
|
}
|
|
|
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 = getString(R.string.获取验证码)
|
} else {
|
textView.isEnabled = false
|
textView.text = (maxTime - 1 - aLong).toString() + getString(R.string.s后重新获取)
|
}
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == Activity.RESULT_OK && requestCode == 10086) {
|
data?.getStringExtra("code")?.let {
|
areaCode?.text = it
|
}
|
}
|
}
|
}
|