列表网络错误显示
This commit is contained in:
@@ -4,7 +4,7 @@ package com.ckkj.defense_device.bean
|
||||
* 统一返回数据基类(根据你的后端实际字段调整)
|
||||
*/
|
||||
data class BaseInfo(
|
||||
val message: String? = null,
|
||||
val msg: String? = null,
|
||||
val code: Int = 0,
|
||||
val data: Any? = null
|
||||
)
|
||||
@@ -320,18 +320,22 @@ class HomeMenuFragment : Fragment() {
|
||||
Log.d("HomeMenuFragment", "canViewDevice = $canViewDevice")
|
||||
if (canViewDevice) {
|
||||
binding.tvDeviceTitle.visibility = View.VISIBLE
|
||||
binding.swipeRefreshLayout.visibility = View.VISIBLE
|
||||
binding.rvDeviceList.visibility = View.VISIBLE
|
||||
binding.message.visibility = View.VISIBLE
|
||||
binding.addFamily.visibility = View.VISIBLE
|
||||
binding.add.visibility = View.VISIBLE
|
||||
binding.layoutNoPermission.visibility = View.GONE
|
||||
binding.layoutNoNetwork.visibility = View.GONE
|
||||
} else {
|
||||
binding.tvDeviceTitle.visibility = View.GONE
|
||||
binding.swipeRefreshLayout.visibility = View.GONE
|
||||
binding.rvDeviceList.visibility = View.GONE
|
||||
binding.message.visibility = View.GONE
|
||||
binding.addFamily.visibility = View.GONE
|
||||
binding.add.visibility = View.GONE
|
||||
binding.layoutNoPermission.visibility = View.VISIBLE
|
||||
binding.layoutNoNetwork.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,11 +393,12 @@ class HomeMenuFragment : Fragment() {
|
||||
hasMore = newDevices.size >= pageSize
|
||||
}
|
||||
Log.d("DeviceList", "deviceBeanList size = ${deviceBeanList.size}")
|
||||
showDeviceContent()
|
||||
updateDeviceList()
|
||||
} else {
|
||||
binding.rvDeviceList.visibility = View.GONE
|
||||
binding.layoutNoPermission.visibility = View.VISIBLE
|
||||
Toast.makeText(requireContext(), response.msg, Toast.LENGTH_SHORT).show()
|
||||
noNetwork()
|
||||
val errorMsg = response.msg.ifBlank { getString(R.string.network_error) }
|
||||
Toast.makeText(requireContext(), errorMsg, Toast.LENGTH_SHORT).show()
|
||||
if (isLoadMore) {
|
||||
hasMore = false
|
||||
}
|
||||
@@ -402,8 +407,7 @@ class HomeMenuFragment : Fragment() {
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.rvDeviceList.visibility = View.GONE
|
||||
binding.layoutNoNetwork.visibility = View.VISIBLE
|
||||
noNetwork()
|
||||
Toast.makeText(requireContext(), R.string.network_error, Toast.LENGTH_SHORT).show()
|
||||
isLoading = false
|
||||
if (isLoadMore) {
|
||||
@@ -448,6 +452,20 @@ class HomeMenuFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDeviceContent() {
|
||||
binding.swipeRefreshLayout.visibility = View.VISIBLE
|
||||
binding.rvDeviceList.visibility = View.VISIBLE
|
||||
binding.layoutNoPermission.visibility = View.GONE
|
||||
binding.layoutNoNetwork.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun noNetwork() {
|
||||
binding.swipeRefreshLayout.visibility = View.GONE
|
||||
binding.rvDeviceList.visibility = View.GONE
|
||||
binding.layoutNoPermission.visibility = View.GONE
|
||||
binding.layoutNoNetwork.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
private fun updateDeviceList() {
|
||||
if (deviceBeanList.isEmpty()) {
|
||||
deviceAdapter.submitList(listOf(
|
||||
|
||||
@@ -138,7 +138,7 @@ object ApiConfig {
|
||||
*/
|
||||
private fun buildFakeErrorResponse(request: Request, msg: String, code: Int = 1): Response {
|
||||
val baseInfo = BaseInfo(
|
||||
message = msg,
|
||||
msg = msg,
|
||||
code = code,
|
||||
data = null,
|
||||
)
|
||||
|
||||
@@ -67,7 +67,6 @@
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
|
||||
Reference in New Issue
Block a user