18034727885
2026-08-07 237bd0e7494cb73bc351b2e6002831fa593eec4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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")*/
    }
}