Pu Zhibing
2025-12-11 ab0c19e49fabdb8cc6eea454ea455bce2efbb718
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
package com.igo.user.ui.mine
 
import android.app.Activity
import android.widget.EditText
import android.widget.TextView
import cn.sinata.xldutils.utils.myToast
import com.igo.user.R
import com.igo.user.network.HttpManager
import com.igo.user.network.request
import com.igo.user.ui.TransparentStatusBarActivity
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
 
class SetEmergencyActivity:TransparentStatusBarActivity() {
    override fun setContentView() = R.layout.activity_set_emergency
 
    private lateinit var name:String
    private lateinit var phone:String
 
    private val myPhone by lazy {
        intent.getStringExtra("myPhone")
    }
    private val tv_action by lazy { find<TextView>(R.id.tv_action) }
    private val et_name by lazy { find<EditText>(R.id.et_name) }
    private val et_phone by lazy { find<EditText>(R.id.et_phone) }
 
    override fun initClick() {
        tv_action.setOnClickListener {
            val name = et_name.text.toString()
            if (name.isEmpty()){
                myToast(getString(R.string.请输入姓名))
                return@setOnClickListener
            }
            val phone = et_phone.text.toString()
            if (phone.isEmpty()){
                myToast(getString(R.string.请填写手机号))
                return@setOnClickListener
            }
            if (phone == myPhone){
                myToast(getString(R.string.请勿设置本人手机号为紧急联系人))
                return@setOnClickListener
            }
            tv_action.isEnabled = false
            HttpManager.setEmergency(name,phone).request(this,success = {_,data->
                myToast(getString(R.string.设置成功))
                if (this.name.isEmpty()){ //安全页面进来,跳转编辑
                    startActivity<EditEmergencyActivity>("name" to name,"phone" to phone)
                    setResult(Activity.RESULT_OK)
                } else//编辑页面进来,返回编辑
                    setResult(Activity.RESULT_OK,intent.putExtra("name",name).putExtra("phone",phone))
                finish()
            },error = {_,_->
                tv_action.isEnabled = true
            })
        }
    }
 
    override fun initView() {
        title = getString(R.string.紧急联系人)
        name = intent.getStringExtra("name")?:""
        phone = intent.getStringExtra("phone")?:""
 
        if (name.isNotEmpty()&&phone.isNotEmpty()){
            et_name.setText(name)
            et_phone.setText(phone)
            title = getString(R.string.编辑)
        }
    }
}