关联用户1
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.example.defenseapplication.databinding.ItemLinkedUserBinding
|
import com.example.defenseapplication.databinding.ItemLinkedUserBinding
|
||||||
|
|
||||||
data class LinkedUser(
|
data class LinkedUser(
|
||||||
|
val userId: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val phone: String,
|
val phone: String,
|
||||||
val idCard: String,
|
val idCard: String,
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.example.defenseapplication.bean
|
||||||
|
|
||||||
|
data class DeleteDeviceUserRequest(
|
||||||
|
val userId: String,
|
||||||
|
val deviceId: String
|
||||||
|
)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.example.defenseapplication.bean
|
||||||
|
|
||||||
|
data class DeviceUserBean(
|
||||||
|
val createDept: String? = null, //创建部门
|
||||||
|
val createBy: String? = null, //创建人
|
||||||
|
val updateBy: String? = null, //更新者
|
||||||
|
val updateTime: String? = null, //更新时间
|
||||||
|
val paramskeykey: String? = null,
|
||||||
|
val deviceId: String? = null, // 设备 ID
|
||||||
|
val deviceNo: String? = null, // 设备编号
|
||||||
|
val deviceName: String? = null, // 设备名称
|
||||||
|
val userId: String? = null, // 用户 ID
|
||||||
|
val nickName: String? = null, // 用户昵称
|
||||||
|
val idCard: String? = null, // 身份证号
|
||||||
|
val phonenumber: String? = null, // 手机号码
|
||||||
|
val createTime: String? = null // 创建时间
|
||||||
|
)
|
||||||
@@ -2,17 +2,27 @@ package com.example.defenseapplication.liveVideo
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper
|
import androidx.recyclerview.widget.ItemTouchHelper
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
import com.example.defenseapplication.adapter.LinkedUser
|
import com.example.defenseapplication.adapter.LinkedUser
|
||||||
import com.example.defenseapplication.adapter.LinkedUserAdapter
|
import com.example.defenseapplication.adapter.LinkedUserAdapter
|
||||||
|
import com.example.defenseapplication.bean.DeleteDeviceUserRequest
|
||||||
|
import com.example.defenseapplication.bean.DeviceUserBean
|
||||||
import com.example.defenseapplication.databinding.LinkedUserActivityBinding
|
import com.example.defenseapplication.databinding.LinkedUserActivityBinding
|
||||||
|
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||||
|
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||||
import com.example.defenseapplication.view.CustomDialogFragmentText
|
import com.example.defenseapplication.view.CustomDialogFragmentText
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
import com.gyf.immersionbar.ImmersionBar
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
//关联用户页面
|
//关联用户页面
|
||||||
class LinkedUserActivity : AppCompatActivity() {
|
class LinkedUserActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@@ -152,9 +162,7 @@ class LinkedUserActivity : AppCompatActivity() {
|
|||||||
dialog.setPositiveText(getString(R.string.confirm))
|
dialog.setPositiveText(getString(R.string.confirm))
|
||||||
dialog.setNegativeText(getString(R.string.cancel))
|
dialog.setNegativeText(getString(R.string.cancel))
|
||||||
dialog.setOnConfirmListener {
|
dialog.setOnConfirmListener {
|
||||||
userList.removeAt(position)
|
deleteDeviceUser(user, position)
|
||||||
adapter.removeItem(position)
|
|
||||||
resetSwipeState()
|
|
||||||
}
|
}
|
||||||
dialog.setOnDismissListener {
|
dialog.setOnDismissListener {
|
||||||
resetSwipeState()
|
resetSwipeState()
|
||||||
@@ -162,6 +170,41 @@ class LinkedUserActivity : AppCompatActivity() {
|
|||||||
dialog.show(supportFragmentManager, "UnlinkDialog")
|
dialog.show(supportFragmentManager, "UnlinkDialog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun deleteDeviceUser(user: LinkedUser, position: Int) {
|
||||||
|
val deviceId = DeviceIdEvent.getDeviceId()
|
||||||
|
if (deviceId.isNullOrEmpty() || user.userId.isEmpty()) {
|
||||||
|
Toast.makeText(this, "参数错误", Toast.LENGTH_SHORT).show()
|
||||||
|
resetSwipeState()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
try {
|
||||||
|
val request = DeleteDeviceUserRequest(
|
||||||
|
userId = user.userId,
|
||||||
|
deviceId = deviceId
|
||||||
|
)
|
||||||
|
val response = RetrofitNetwork.getNetworkService().deleteDeviceUser(request)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200) {
|
||||||
|
userList.removeAt(position)
|
||||||
|
adapter.removeItem(position)
|
||||||
|
Toast.makeText(this@LinkedUserActivity, "删除成功", Toast.LENGTH_SHORT).show()
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this@LinkedUserActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
resetSwipeState()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@LinkedUserActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||||
|
resetSwipeState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun resetSwipeState() {
|
private fun resetSwipeState() {
|
||||||
if (currentSwipePosition >= 0 && currentSwipeHeld) {
|
if (currentSwipePosition >= 0 && currentSwipeHeld) {
|
||||||
binding.rvLinkedUser.post {
|
binding.rvLinkedUser.post {
|
||||||
@@ -179,10 +222,48 @@ class LinkedUserActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initData() {
|
private fun initData() {
|
||||||
|
fetchDeviceUserList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchDeviceUserList() {
|
||||||
|
val deviceId = DeviceIdEvent.getDeviceId()
|
||||||
|
if (deviceId.isNullOrEmpty()) {
|
||||||
|
Toast.makeText(this, "设备 ID 为空", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
try {
|
||||||
|
val response = RetrofitNetwork.getNetworkService().getDeviceUserList(deviceId)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200 && response.data != null) {
|
||||||
|
updateDeviceUserList(response.data)
|
||||||
|
} else {
|
||||||
|
Toast.makeText(this@LinkedUserActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(this@LinkedUserActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateDeviceUserList(deviceUserList: List<DeviceUserBean>) {
|
||||||
userList.clear()
|
userList.clear()
|
||||||
userList.add(LinkedUser("张三", "12388888888", "123456789012345678", "2026-05-06 16:03:26"))
|
deviceUserList.forEach { deviceUser ->
|
||||||
userList.add(LinkedUser("李四", "13899999999", "987654321098765432", "2026-05-05 14:20:15"))
|
userList.add(
|
||||||
userList.add(LinkedUser("王五", "15977777777", "456123789012345678", "2026-05-04 10:15:30"))
|
LinkedUser(
|
||||||
|
userId = deviceUser.userId ?: "",
|
||||||
|
name = deviceUser.nickName ?: "未知用户",
|
||||||
|
phone = deviceUser.phonenumber ?: "",
|
||||||
|
idCard = deviceUser.idCard ?: "",
|
||||||
|
time = deviceUser.createTime ?: ""
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
adapter.submitList(userList)
|
adapter.submitList(userList)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +303,7 @@ class LinkedUserActivity : AppCompatActivity() {
|
|||||||
if (requestCode == REQUEST_CODE_SEARCH && resultCode == RESULT_OK) {
|
if (requestCode == REQUEST_CODE_SEARCH && resultCode == RESULT_OK) {
|
||||||
data?.getStringExtra(EXTRA_SEARCH_RESULT)?.let { result ->
|
data?.getStringExtra(EXTRA_SEARCH_RESULT)?.let { result ->
|
||||||
val newUser = LinkedUser(
|
val newUser = LinkedUser(
|
||||||
|
userId = "",
|
||||||
name = result,
|
name = result,
|
||||||
phone = "13800000000",
|
phone = "13800000000",
|
||||||
idCard = "110101199001011234",
|
idCard = "110101199001011234",
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
import com.example.defenseapplication.base.BaseActivity
|
import com.example.defenseapplication.base.BaseActivity
|
||||||
|
import com.example.defenseapplication.bean.DeviceUserBean
|
||||||
import com.example.defenseapplication.databinding.SettingsActivityBinding
|
import com.example.defenseapplication.databinding.SettingsActivityBinding
|
||||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||||
import com.example.defenseapplication.utils.LanguageUtil
|
import com.example.defenseapplication.utils.LanguageUtil
|
||||||
@@ -146,14 +148,14 @@ class SettingsActivity : BaseActivity() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
val response = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
val deviceResponse = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (response.code == 200 && response.data != null) {
|
if (deviceResponse.code == 200 && deviceResponse.data != null) {
|
||||||
updateDeviceInfo(response.data)
|
updateDeviceInfo(deviceResponse.data)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@SettingsActivity, deviceResponse.msg, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -163,6 +165,32 @@ class SettingsActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchDeviceUserList()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun fetchDeviceUserList() {
|
||||||
|
val deviceId = DeviceIdEvent.getDeviceId()
|
||||||
|
if (deviceId.isNullOrEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
try {
|
||||||
|
val response = RetrofitNetwork.getNetworkService().getDeviceUserList(deviceId)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (response.code == 200 && response.data != null) {
|
||||||
|
updateRelatedUsersCount(response.data.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRelatedUsersCount(count: Int) {
|
||||||
|
binding.tvRelatedUsers.text = "$count 人"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
|
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ package com.example.defenseapplication.utils
|
|||||||
|
|
||||||
import bean.ForgotRequest
|
import bean.ForgotRequest
|
||||||
import com.example.defenseapplication.bean.DeviceBean
|
import com.example.defenseapplication.bean.DeviceBean
|
||||||
|
import com.example.defenseapplication.bean.DeviceUserBean
|
||||||
import com.example.defenseapplication.bean.FamilyBean
|
import com.example.defenseapplication.bean.FamilyBean
|
||||||
import com.example.defenseapplication.bean.GetCodeBean
|
import com.example.defenseapplication.bean.GetCodeBean
|
||||||
import bean.LoginBean
|
import bean.LoginBean
|
||||||
import bean.LoginRequest
|
import bean.LoginRequest
|
||||||
import bean.RegisterRequest
|
import bean.RegisterRequest
|
||||||
import com.example.defenseapplication.bean.DeleteBean
|
import com.example.defenseapplication.bean.DeleteBean
|
||||||
|
import com.example.defenseapplication.bean.DeleteDeviceUserRequest
|
||||||
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 retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
@@ -82,5 +84,25 @@ interface ApiService {
|
|||||||
@POST("/app/deleteDevice")
|
@POST("/app/deleteDevice")
|
||||||
suspend fun deleteDevice(@Body deleteBean: DeleteBean): GetCodeBean<DeleteBean>
|
suspend fun deleteDevice(@Body deleteBean: DeleteBean): GetCodeBean<DeleteBean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查看设备关联用户列表
|
||||||
|
*/
|
||||||
|
@GET("/app/deviceUser/list/{deviceId}")
|
||||||
|
suspend fun getDeviceUserList(
|
||||||
|
@retrofit2.http.Path("deviceId") deviceId: String,
|
||||||
|
@Query("deviceNo") deviceNo: String? = null,
|
||||||
|
@Query("deviceName") deviceName: String? = null,
|
||||||
|
@Query("userId") userId: String? = null,
|
||||||
|
@Query("nickName") nickName: String? = null,
|
||||||
|
@Query("idCard") idCard: String? = null,
|
||||||
|
@Query("phonenumber") phonenumber: String? = null
|
||||||
|
): GetCodeBean<List<DeviceUserBean>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关联用户
|
||||||
|
*/
|
||||||
|
@POST("/app/deleteDeviceUser")
|
||||||
|
suspend fun deleteDeviceUser(@Body request: DeleteDeviceUserRequest): GetCodeBean<Any>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -303,9 +303,9 @@
|
|||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/tvRelatedUsers"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="3"
|
|
||||||
android:textColor="@color/gray"
|
android:textColor="@color/gray"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user