优化家庭状态
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.ckkj.defense_device.bean
|
||||
|
||||
data class UpdateFamilyUserRequest(
|
||||
val id: String,
|
||||
val optionPassword: String,
|
||||
val optionStatus: String,
|
||||
val status: String,
|
||||
)
|
||||
@@ -7,6 +7,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import com.ckkj.defense_device.R
|
||||
import com.ckkj.defense_device.bean.DeleteDeviceUserRequest
|
||||
import com.ckkj.defense_device.bean.ObtainInviterInformationRequest
|
||||
import com.ckkj.defense_device.bean.UpdateFamilyUserRequest
|
||||
import com.ckkj.defense_device.bean.VerifyOptionPasswordRequest
|
||||
import com.ckkj.defense_device.personal.PasswordInputDialog
|
||||
import com.ckkj.defense_device.utils.DeviceIdEvent
|
||||
@@ -26,6 +27,7 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
private var userId: String = ""
|
||||
private var isPasswordVerified: Boolean = false
|
||||
private lateinit var passwordDialog: PasswordInputDialog
|
||||
private var optionPassword: String = ""
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -87,10 +89,12 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
binding.swUserStatus.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (!isPasswordVerified) {
|
||||
binding.swUserStatus.isChecked = !isChecked
|
||||
showPasswordDialog {
|
||||
showPasswordDialog(isChecked) {
|
||||
isPasswordVerified = true
|
||||
binding.swUserStatus.isChecked = isChecked
|
||||
}
|
||||
} else {
|
||||
updateFamilyUserStatus(isChecked)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +103,7 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPasswordDialog(onVerified: () -> Unit) {
|
||||
private fun showPasswordDialog(status: Boolean, onVerified: () -> Unit) {
|
||||
passwordDialog = PasswordInputDialog(this).apply {
|
||||
setOnConfirmListener { inputPassword ->
|
||||
lifecycleScope.launch {
|
||||
@@ -109,6 +113,7 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200) {
|
||||
dismiss()
|
||||
updateFamilyUserStatus(status, inputPassword)
|
||||
onVerified()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
@@ -135,6 +140,48 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
|
||||
private fun updateFamilyUserStatus(status: Boolean) {
|
||||
updateFamilyUserStatus(status, optionPassword)
|
||||
}
|
||||
|
||||
private fun updateFamilyUserStatus(status: Boolean, password: String) {
|
||||
if (userId.isEmpty()) {
|
||||
Toast.makeText(this, "用户ID为空", Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
if (password.isNotEmpty()) {
|
||||
optionPassword = password
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val request = UpdateFamilyUserRequest(
|
||||
id = userId,
|
||||
optionPassword = optionPassword,
|
||||
optionStatus = "status",
|
||||
status = if (status) "1" else "0"
|
||||
)
|
||||
val response = RetrofitNetwork.getNetworkService().updateFamilyUser(request)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200) {
|
||||
Toast.makeText(this@UserDetailsActivity, "状态修改成功", Toast.LENGTH_SHORT).show()
|
||||
DeviceUserUpdateEvent.notifyUpdate()
|
||||
} else {
|
||||
Toast.makeText(this@UserDetailsActivity, response.msg ?: "状态修改失败", Toast.LENGTH_SHORT).show()
|
||||
binding.swUserStatus.isChecked = !status
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(this@UserDetailsActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||
binding.swUserStatus.isChecked = !status
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDeleteDialog() {
|
||||
val dialog = CustomDialogFragmentText()
|
||||
dialog.setTitle(getString(R.string.tip))
|
||||
@@ -146,7 +193,7 @@ class UserDetailsActivity : AppCompatActivity() {
|
||||
if (isPasswordVerified) {
|
||||
deleteDeviceUser()
|
||||
} else {
|
||||
showPasswordDialog {
|
||||
showPasswordDialog(false) {
|
||||
isPasswordVerified = true
|
||||
deleteDeviceUser()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.ckkj.defense_device.bean.MessageListResponse
|
||||
import com.ckkj.defense_device.bean.ObtainInviterInformationBean
|
||||
import com.ckkj.defense_device.bean.ObtainInviterInformationRequest
|
||||
import com.ckkj.defense_device.bean.SwitchFamilyRequest
|
||||
import com.ckkj.defense_device.bean.UpdateFamilyUserRequest
|
||||
import com.ckkj.defense_device.bean.UpdatePassword
|
||||
import com.ckkj.defense_device.bean.UpdateUserInfo
|
||||
import com.ckkj.defense_device.bean.UploadResponse
|
||||
@@ -250,7 +251,8 @@ interface ApiService {
|
||||
/**
|
||||
* 修改家庭用户状态
|
||||
*/
|
||||
//@POST("/app/updateFamilyUser")
|
||||
@POST("/app/updateFamilyUser")
|
||||
suspend fun updateFamilyUser(@Body request: UpdateFamilyUserRequest): GetCodeBean<Any>
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user