From 718f31c92e2029d05260810435a2c70cef6e6ce5 Mon Sep 17 00:00:00 2001
From: lmw <125975490@qq.com>
Date: 星期四, 24 四月 2025 10:45:55 +0800
Subject: [PATCH] save

---
 app/src/main/java/com/sinata/xqmuse/ui/mine/UserInfoActivity.kt |  120 ++++++++++++++++++++++++++---------------------------------
 1 files changed, 53 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..963d2c8 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
@@ -6,7 +6,11 @@
 import android.os.Build
 import android.os.Environment
 import android.provider.Settings
+import android.text.Editable
+import android.text.TextWatcher
+import androidx.core.os.bundleOf
 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.*
@@ -23,107 +27,88 @@
 import org.greenrobot.eventbus.EventBus
 import org.jetbrains.anko.startActivityForResult
 
-class UserInfoActivity:TransparentStatusBarActivity() {
+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 = false
 
     override fun initClick() {
         iv_avatar.setOnClickListener {
             startActivityForResult<SelectPhotoDialog>(1)
         }
 
-        tv_name.clickDelay {
-            InputNameDialog.show(supportFragmentManager,userInfo?.name?:"",object :StringCallback{
+        tv_sex.clickDelay {
+            ChoosSexDialog.show(supportFragmentManager,object :StringCallback{
                 override fun onResult(rst: String) {
-                    updateInfo(name = rst)
+                    userInfo?.gender = rst.toInt()
+                    changed = true
+                    tv_sex.text = if (userInfo?.gender == 1) "男" else if (userInfo?.gender == 2) "女" else if (userInfo?.gender == 3) "保密" else ""
                 }
             })
         }
 
-        tv_sex.clickDelay {
-            SingleWheelDialog.show(supportFragmentManager,null,null,object :StringCallback{
-                override fun onResult(rst: String) {
-                    tv_sex.text = rst
-                    updateInfo(gender = if (rst == "男") 1 else 2)
-                }
-            })
+        tv_save.setOnClickListener {
+            updateInfo()
         }
 
         tv_birth.clickDelay {
             val chooseBirthDialog = ChooseBirthDialog()
+            chooseBirthDialog.arguments = bundleOf("data" to userInfo?.birthday)
             chooseBirthDialog.setCallback(object : ChooseBirthDialog.Callback {
                 override fun onOk(s: String) {
+                    userInfo?.birthday = s
+                    changed = true
                     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 {
+            finish()
         }
     }
 
     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(realname)
+                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)
             }
         }
     }
 
 
+    private fun updateInfo(){
+        HttpManager.updateInfo(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()
+        }
+    }
 
-    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 updateAvatar(){
+        HttpManager.updateUserAvatar(userInfo?.avatar?:"").request(this@UserInfoActivity,true){_,_->
+            setResult(RESULT_OK)
         }
     }
 
@@ -132,8 +117,9 @@
         if (resultCode == Activity.RESULT_OK&&data!=null){
             data.getStringExtra("path")!!.uploadWithCompress(this, object : StringCallback {
                 override fun onResult(rst: String) {
+                    userInfo?.avatar = rst
+                    updateAvatar()
                     iv_avatar.setImageURI(rst)
-                    updateInfo(rst)
                 }
             })
         }

--
Gitblit v1.7.1