lmw
2023-05-12 f67802a41f9e01444d1115f34ecc6e1beb05fc3b
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
package com.fuban.user.ui.mine
 
import android.app.Activity
import cn.sinata.xldutils.utils.isValidPhone
import cn.sinata.xldutils.utils.myToast
import com.fuban.user.R
import com.fuban.user.network.HttpManager
import com.fuban.user.network.request
import com.fuban.user.ui.TransparentStatusBarActivity
import kotlinx.android.synthetic.main.activity_set_emergency.*
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")
    }
 
    override fun initClick() {
        tv_action.setOnClickListener {
            val name = et_name.text.toString()
            if (name.isEmpty()){
                myToast("请输入姓名")
                return@setOnClickListener
            }
            val phone = et_phone.text.toString()
            if (!phone.isValidPhone()){
                myToast("请输入正确的电话号码")
                return@setOnClickListener
            }
            if (phone == myPhone){
                myToast("请勿设置本人手机号为紧急联系人")
                return@setOnClickListener
            }
            tv_action.isEnabled = false
            HttpManager.setEmergency(name,phone).request(this,success = {_,data->
                myToast("设置成功")
                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 = "紧急联系人"
        name = intent.getStringExtra("name")
        phone = intent.getStringExtra("phone")
 
        if (name.isNotEmpty()&&phone.isNotEmpty()){
            et_name.setText(name)
            et_phone.setText(phone)
        }
    }
}