修改个人信息
This commit is contained in:
@@ -9,6 +9,7 @@ import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import com.bumptech.glide.Glide
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.bean.UserInfoBean
|
||||
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
||||
import com.example.defenseapplication.liveVideo.LinkedUserActivity
|
||||
import com.example.defenseapplication.personal.PasswordManagementActivity
|
||||
@@ -44,8 +45,25 @@ class PersonalFragment : Fragment() {
|
||||
.circleCrop()
|
||||
.into(binding.ivAvatar)
|
||||
binding.headerLayout.setOnClickListener {
|
||||
val intent= Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getUserInfo()
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
val intent = Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
intent.putExtra("userInfo", response.data)
|
||||
startActivity(intent)
|
||||
} else {
|
||||
val intent = Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
val intent = Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 更新当前语言显示
|
||||
updateCurrentLanguageDisplay()
|
||||
@@ -157,6 +175,48 @@ class PersonalFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
fetchUserInfo()
|
||||
}
|
||||
|
||||
private fun fetchUserInfo() {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getUserInfo()
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
updateUserUI(response.data)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUserUI(userInfo: UserInfoBean) {
|
||||
userInfo.nickName?.let {
|
||||
binding.tvNickname.text = it
|
||||
}
|
||||
userInfo.phonenumber?.let {
|
||||
binding.tvPhone.text = it
|
||||
}
|
||||
userInfo.avatar?.let {
|
||||
Glide.with(this)
|
||||
.load(it)
|
||||
.circleCrop()
|
||||
.into(binding.ivAvatar)
|
||||
}
|
||||
userInfo.role?.let {
|
||||
binding.tvRoleTag.text = if (it == "appadmin") {
|
||||
getString(R.string.admin)
|
||||
} else {
|
||||
getString(R.string.member)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null // 避免内存泄漏
|
||||
|
||||
Reference in New Issue
Block a user