关联用户1
This commit is contained in:
@@ -4,8 +4,10 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.base.BaseActivity
|
||||
import com.example.defenseapplication.bean.DeviceUserBean
|
||||
import com.example.defenseapplication.databinding.SettingsActivityBinding
|
||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||
import com.example.defenseapplication.utils.LanguageUtil
|
||||
@@ -146,14 +148,14 @@ class SettingsActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
||||
val deviceResponse = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
updateDeviceInfo(response.data)
|
||||
if (deviceResponse.code == 200 && deviceResponse.data != null) {
|
||||
updateDeviceInfo(deviceResponse.data)
|
||||
} else {
|
||||
Toast.makeText(this@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this@SettingsActivity, deviceResponse.msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
|
||||
Reference in New Issue
Block a user