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