From 2f204867ad034d3a95ba9acc112d6507f296447b Mon Sep 17 00:00:00 2001 From: lmw <125975490@qq.com> Date: 星期三, 23 十月 2024 18:20:43 +0800 Subject: [PATCH] save --- app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt | 118 +++++++++++++++++++++++++--------------------------------- 1 files changed, 51 insertions(+), 67 deletions(-) diff --git a/app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt b/app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt index 3013c46..41efe41 100644 --- a/app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt +++ b/app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt @@ -7,6 +7,7 @@ import android.os.Environment import android.provider.Settings import cn.sinata.xldutils.activity.SelectPhotoDialog +import cn.sinata.xldutils.gone import cn.sinata.xldutils.utils.myToast import com.sinata.xqmuse.R import com.sinata.xqmuse.dialog.* @@ -26,26 +27,19 @@ class UserInfoActivity:TransparentStatusBarActivity() { override fun setContentView() = R.layout.activity_user_info - private val userInfo by lazy { intent.getParcelableExtra<UserInfo>("user") } + private var userInfo:UserInfo? = null + private var changed = true override fun initClick() { iv_avatar.setOnClickListener { startActivityForResult<SelectPhotoDialog>(1) } - tv_name.clickDelay { - InputNameDialog.show(supportFragmentManager,userInfo?.name?:"",object :StringCallback{ - override fun onResult(rst: String) { - updateInfo(name = rst) - } - }) - } - tv_sex.clickDelay { - SingleWheelDialog.show(supportFragmentManager,null,null,object :StringCallback{ + ChoosSexDialog.show(supportFragmentManager,object :StringCallback{ override fun onResult(rst: String) { - tv_sex.text = rst - updateInfo(gender = if (rst == "男") 1 else 2) + userInfo?.gender = rst.toInt() + tv_sex.text = if (userInfo?.gender == 1) "男" else if (userInfo?.gender == 2) "女" else if (userInfo?.gender == 3) "保密" else "" } }) } @@ -54,76 +48,66 @@ val chooseBirthDialog = ChooseBirthDialog() chooseBirthDialog.setCallback(object : ChooseBirthDialog.Callback { override fun onOk(s: String) { + userInfo?.birthday = s tv_birth.text = s - updateInfo(birthday = s.replace(".","-")) } }) chooseBirthDialog.show(supportFragmentManager, "birth") } - tv_height.clickDelay { - InputHeightDialog.show(supportFragmentManager,userInfo?.height?:"","身高",object :StringCallback{ - override fun onResult(rst: String) { - tv_height.text = "${rst}cm" - updateInfo(height = rst.toInt()) - userInfo?.height = rst - } - }) - } - - tv_weight.clickDelay { - ChooseWeightDialog.show( - supportFragmentManager, - "设置体重",userInfo?.getUnitName()?:"", - if (userInfo?.weight.isNullOrEmpty()) null else userInfo?.weight, - object : StringCallback { - override fun onResult(rst: String) { - tv_weight.text = "${rst}${userInfo?.getUnitName()}" - userInfo?.weight = rst - updateInfo(weight = rst.toDouble()) - } - },"保存") - } - - tv_waistline.clickDelay { - InputHeightDialog.show(supportFragmentManager,userInfo?.waistline?:"","腰围",object :StringCallback{ - override fun onResult(rst: String) { - tv_waistline.text = "${rst}cm" - userInfo?.waistline = rst - updateInfo(waistline = rst.toInt()) - } - }) + iv_back.setOnClickListener { + onBackPressed() } } override fun initView() { - userInfo?.apply { - iv_avatar.setImageURI(headImg) - tv_name.text = name - tv_sex.text = if (gender == "1") "男" else if (gender == "2") "女" else "" - tv_birth.text = birthday.replace("-",".") - if (!weight.isNullOrEmpty()&&weight.toDouble() != 0.0){ - tv_weight.text = "${weight}${getUnitName()}" - } - if (!height.isNullOrEmpty()&&height.toDouble() != 0.0){ - tv_height.text = "${height}cm" - } - if (!waistline.isNullOrEmpty()&&waistline.toDouble() != 0.0){ - tv_waistline.text = "${waistline}cm" + titleBar.gone() + getInfo() + } + + private fun getInfo() { + HttpManager.getUserDetail().request(this){_,data-> + userInfo = data + data?.apply { + iv_avatar.setImageURI(avatar) + et_nick.setText(nickname) + et_name.setText("") //todo + et_sign.setText(signature) + tv_sex.text = if (gender == 1) "男" else if (gender == 2) "女" else if (gender == 3) "保密" else "" + tv_birth.text = birthday + et_edu.setText(education) + et_profess.setText(industry) + et_company.setText(company) + et_job.setText(occupation) + et_location.setText(location) + et_homeland.setText(hometown) + et_mail.setText(email) } } } + override fun onBackPressed() { + if (changed) + TipDialog.show(supportFragmentManager,"是否保存修改?",object :TipDialog.OnClickCallback{ + override fun onOk() { + updateInfo() + } + + override fun onCancel() { + finish() + } + },"保存","不保存") + else + super.onBackPressed() + } - private fun updateInfo(avatar:String?=null,name:String?=null,gender:Int?=null,birthday:String?=null,weight:Double?=null,height:Int?=null,waistline:Int?=null){ - HttpManager.updateInfo(name,gender, birthday, weight,waistline, height, avatar).request(this@UserInfoActivity,true){_,_-> - myToast("修改成功") - EventBus.getDefault().post(EmptyEvent(Const.EventCode.USER_INFO_CHANGED)) - if (!name.isNullOrEmpty()){ - tv_name.text = name - userInfo?.name = name - } + private fun updateInfo(){ + HttpManager.updateInfo(userInfo?.avatar,userInfo?.birthday,et_company.text.toString(),et_edu.text.toString(),et_mail.text.toString(),userInfo?.gender,et_homeland.text.toString(), + et_profess.text.toString(),et_location.text.toString(),et_nick.text.toString(),et_job.text.toString(),et_sign.text.toString(),et_name.text.toString()).request(this@UserInfoActivity,true){_,_-> + myToast("保存成功") + setResult(RESULT_OK) + finish() } } @@ -132,8 +116,8 @@ if (resultCode == Activity.RESULT_OK&&data!=null){ data.getStringExtra("path")!!.uploadWithCompress(this, object : StringCallback { override fun onResult(rst: String) { + userInfo?.avatar = rst iv_avatar.setImageURI(rst) - updateInfo(rst) } }) } -- Gitblit v1.7.1