修改个人信息
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package com.example.defenseapplication.bean
|
||||||
|
|
||||||
|
data class UpdateUserInfo(
|
||||||
|
val userId: String?=null,
|
||||||
|
val nickName: String?=null,
|
||||||
|
val idCard: String?=null,
|
||||||
|
val userType: String?=null,
|
||||||
|
val phonenumber: String?=null,
|
||||||
|
val avatar: String?=null,
|
||||||
|
val password: String?=null,
|
||||||
|
val status: String?=null,
|
||||||
|
val faceAddr: String?=null,
|
||||||
|
val mac: String?=null,
|
||||||
|
val remark: String?=null,
|
||||||
|
val smsCoode: String?=null,
|
||||||
|
val optionPassword: String?=null,
|
||||||
|
val optionStatus: String?=null,
|
||||||
|
)
|
||||||
@@ -9,6 +9,7 @@ import android.view.ViewGroup
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
|
import com.example.defenseapplication.bean.UserInfoBean
|
||||||
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
import com.example.defenseapplication.databinding.PersonalFragmentBinding
|
||||||
import com.example.defenseapplication.liveVideo.LinkedUserActivity
|
import com.example.defenseapplication.liveVideo.LinkedUserActivity
|
||||||
import com.example.defenseapplication.personal.PasswordManagementActivity
|
import com.example.defenseapplication.personal.PasswordManagementActivity
|
||||||
@@ -44,9 +45,26 @@ class PersonalFragment : Fragment() {
|
|||||||
.circleCrop()
|
.circleCrop()
|
||||||
.into(binding.ivAvatar)
|
.into(binding.ivAvatar)
|
||||||
binding.headerLayout.setOnClickListener {
|
binding.headerLayout.setOnClickListener {
|
||||||
|
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)
|
val intent = Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
val intent = Intent(requireContext(), PersonalProfileActivity::class.java)
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// 更新当前语言显示
|
// 更新当前语言显示
|
||||||
updateCurrentLanguageDisplay()
|
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() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
_binding = null // 避免内存泄漏
|
_binding = null // 避免内存泄漏
|
||||||
|
|||||||
@@ -6,16 +6,23 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
|
import com.example.defenseapplication.bean.UpdateUserInfo
|
||||||
|
import com.example.defenseapplication.bean.UserInfoBean
|
||||||
import com.example.defenseapplication.databinding.PersonalProfileActivityBinding
|
import com.example.defenseapplication.databinding.PersonalProfileActivityBinding
|
||||||
|
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||||
import com.example.defenseapplication.view.CustomDialogFragmentText
|
import com.example.defenseapplication.view.CustomDialogFragmentText
|
||||||
import com.example.defenseapplication.view.PhoneModifyDialogFragment
|
import com.example.defenseapplication.view.PhoneModifyDialogFragment
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
//个人信息
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class PersonalProfileActivity : AppCompatActivity() {
|
class PersonalProfileActivity : AppCompatActivity() {
|
||||||
private lateinit var binding: PersonalProfileActivityBinding
|
private lateinit var binding: PersonalProfileActivityBinding
|
||||||
|
private var userInfo: UserInfoBean? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -25,6 +32,7 @@ class PersonalProfileActivity : AppCompatActivity() {
|
|||||||
.statusBarDarkFont(true)
|
.statusBarDarkFont(true)
|
||||||
.titleBar(binding.topBar)
|
.titleBar(binding.topBar)
|
||||||
.init()
|
.init()
|
||||||
|
userInfo = intent.getParcelableExtra("userInfo", UserInfoBean::class.java)
|
||||||
initView()
|
initView()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,13 +41,29 @@ class PersonalProfileActivity : AppCompatActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userInfo?.let { info ->
|
||||||
|
info.avatar?.let { avatarUrl ->
|
||||||
|
Glide.with(this)
|
||||||
|
.load(avatarUrl)
|
||||||
|
.circleCrop()
|
||||||
|
.into(binding.ivAvatar)
|
||||||
|
} ?: run {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(R.drawable.img)
|
.load(R.drawable.img)
|
||||||
.circleCrop()
|
.circleCrop()
|
||||||
.into(binding.ivAvatar)
|
.into(binding.ivAvatar)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.tvNickname.text = info.nickName ?: getString(R.string.nickname_default)
|
||||||
|
binding.tvPhone.text = info.phonenumber ?: "13589898989"
|
||||||
|
} ?: run {
|
||||||
|
Glide.with(this)
|
||||||
|
.load(R.drawable.img)
|
||||||
|
.circleCrop()
|
||||||
|
.into(binding.ivAvatar)
|
||||||
binding.tvNickname.text = getString(R.string.nickname_default)
|
binding.tvNickname.text = getString(R.string.nickname_default)
|
||||||
binding.tvPhone.text = "13589898989"
|
binding.tvPhone.text = "13589898989"
|
||||||
|
}
|
||||||
|
|
||||||
binding.itemNickname.setOnClickListener {
|
binding.itemNickname.setOnClickListener {
|
||||||
showNicknameDialog()
|
showNicknameDialog()
|
||||||
@@ -62,22 +86,73 @@ class PersonalProfileActivity : AppCompatActivity() {
|
|||||||
.setNegativeText("")
|
.setNegativeText("")
|
||||||
.setOnConfirmListener { newNickname ->
|
.setOnConfirmListener { newNickname ->
|
||||||
if (newNickname.isNotBlank()) {
|
if (newNickname.isNotBlank()) {
|
||||||
binding.tvNickname.text = newNickname
|
updateNickname(newNickname)
|
||||||
Toast.makeText(this, getString(R.string.operation_success), Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dialog.show(supportFragmentManager, "nickname_dialog")
|
dialog.show(supportFragmentManager, "nickname_dialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateNickname(newNickname: String) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val request = UpdateUserInfo(
|
||||||
|
userId = userInfo?.userId,
|
||||||
|
nickName = newNickname
|
||||||
|
)
|
||||||
|
val response = RetrofitNetwork.getNetworkService().updateUserInfo(request)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200) {
|
||||||
|
binding.tvNickname.text = newNickname
|
||||||
|
userInfo = userInfo?.copy(nickName = newNickname)
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.operation_success), Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.operation_failed), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.network_error), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showPhoneDialog() {
|
private fun showPhoneDialog() {
|
||||||
val dialog = PhoneModifyDialogFragment()
|
val dialog = PhoneModifyDialogFragment()
|
||||||
.setTitle(getString(R.string.modify_phone))
|
.setTitle(getString(R.string.modify_phone))
|
||||||
.setNegativeText(getString(R.string.cancel))
|
.setNegativeText(getString(R.string.cancel))
|
||||||
.setPositiveText(getString(R.string.verify_and_bind))
|
.setPositiveText(getString(R.string.verify_and_bind))
|
||||||
.setOnConfirmListener { phone, code ->
|
.setOnConfirmListener { phone, code ->
|
||||||
binding.tvPhone.text = phone
|
updatePhone(phone, code)
|
||||||
Toast.makeText(this, getString(R.string.operation_success), Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
}
|
||||||
dialog.show(supportFragmentManager, "phone_dialog")
|
dialog.show(supportFragmentManager, "phone_dialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updatePhone(phone: String, code: String) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val request = UpdateUserInfo(
|
||||||
|
userId = userInfo?.userId,
|
||||||
|
phonenumber = phone,
|
||||||
|
smsCoode = code
|
||||||
|
)
|
||||||
|
val response = RetrofitNetwork.getNetworkService().updateUserInfo(request)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200) {
|
||||||
|
binding.tvPhone.text = phone
|
||||||
|
userInfo = userInfo?.copy(phonenumber = phone)
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.operation_success), Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.operation_failed), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@PersonalProfileActivity, getString(R.string.network_error), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import com.example.defenseapplication.bean.DeleteDeviceUserRequest
|
|||||||
import com.example.defenseapplication.bean.FamilyMembersBean
|
import com.example.defenseapplication.bean.FamilyMembersBean
|
||||||
import com.example.defenseapplication.bean.MessageGroup
|
import com.example.defenseapplication.bean.MessageGroup
|
||||||
import com.example.defenseapplication.bean.SwitchFamilyRequest
|
import com.example.defenseapplication.bean.SwitchFamilyRequest
|
||||||
|
import com.example.defenseapplication.bean.UpdateUserInfo
|
||||||
|
import com.example.defenseapplication.bean.UserInfoBean
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@@ -130,5 +132,18 @@ interface ApiService {
|
|||||||
@POST("/app/addDeviceUser")
|
@POST("/app/addDeviceUser")
|
||||||
suspend fun addDeviceUser(@Body request: AddDeviceUserRequest): GetCodeBean<Any>
|
suspend fun addDeviceUser(@Body request: AddDeviceUserRequest): GetCodeBean<Any>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取登录用户个人信息
|
||||||
|
*/
|
||||||
|
@GET("/app/userInfo")
|
||||||
|
suspend fun getUserInfo(): GetCodeBean<UserInfoBean>
|
||||||
|
/**
|
||||||
|
* 修改个人信息
|
||||||
|
*/
|
||||||
|
@PUT("/app/updateUserInfo")
|
||||||
|
suspend fun updateUserInfo(@Body request: UpdateUserInfo): GetCodeBean<UpdateUserInfo>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import android.view.WindowManager
|
|||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
import com.example.defenseapplication.databinding.DialogPhoneModifyBinding
|
import com.example.defenseapplication.databinding.DialogPhoneModifyBinding
|
||||||
|
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
//手机号弹窗
|
//手机号弹窗
|
||||||
class PhoneModifyDialogFragment : DialogFragment() {
|
class PhoneModifyDialogFragment : DialogFragment() {
|
||||||
@@ -86,7 +91,7 @@ class PhoneModifyDialogFragment : DialogFragment() {
|
|||||||
ToastUtils.showToast(requireContext(), getString(R.string.invalid_phone))
|
ToastUtils.showToast(requireContext(), getString(R.string.invalid_phone))
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
startCountDown()
|
sendCode(phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnNegative.setOnClickListener {
|
binding.btnNegative.setOnClickListener {
|
||||||
@@ -109,6 +114,27 @@ class PhoneModifyDialogFragment : DialogFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sendCode(phone: String) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
try {
|
||||||
|
val response = RetrofitNetwork.getNetworkService().getCode(phone)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200) {
|
||||||
|
ToastUtils.showToast(requireContext(), getString(R.string.code_sent_success))
|
||||||
|
startCountDown()
|
||||||
|
} else {
|
||||||
|
ToastUtils.showToast(requireContext(), getString(R.string.code_send_failed))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
ToastUtils.showToast(requireContext(), getString(R.string.network_error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun startCountDown() {
|
private fun startCountDown() {
|
||||||
binding.tvSendCode.isEnabled = false
|
binding.tvSendCode.isEnabled = false
|
||||||
countDownTimer = object : CountDownTimer(60000, 1000) {
|
countDownTimer = object : CountDownTimer(60000, 1000) {
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
android:id="@+id/ivAvatar"
|
android:id="@+id/ivAvatar"
|
||||||
android:layout_width="60dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="60dp"
|
||||||
android:padding="2dp"
|
android:padding="2dp"/>
|
||||||
android:src="@mipmap/ic_launcher_round" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
|||||||
@@ -441,4 +441,6 @@
|
|||||||
<string name="modify_success">Modified successfully</string>
|
<string name="modify_success">Modified successfully</string>
|
||||||
<string name="modify_failed">Modification failed</string>
|
<string name="modify_failed">Modification failed</string>
|
||||||
<string name="network_request_failed">Network request failed</string>
|
<string name="network_request_failed">Network request failed</string>
|
||||||
|
<string name="code_sent_success">Verification code sent successfully</string>
|
||||||
|
<string name="code_send_failed">Failed to send verification code</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user