优化列表请求失败和没有网络的显示状态,优化渐变颜色展示
@@ -3,25 +3,18 @@ package com.ckkj.defense_device.adapter
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.ckkj.defense_device.R
|
||||
import com.ckkj.defense_device.bean.DeviceBean
|
||||
import com.ckkj.defense_device.databinding.ItemDeviceBinding
|
||||
|
||||
data class DeviceUi(
|
||||
val name: String,
|
||||
val status: String,
|
||||
val deviceId: String = ""
|
||||
) {
|
||||
val isOnline: Boolean
|
||||
get() = status == "1"
|
||||
}
|
||||
|
||||
class DeviceAdapter(
|
||||
private val onItemClick: (DeviceUi) -> Unit = {}
|
||||
private val onItemClick: (DeviceBean) -> Unit = {}
|
||||
) : RecyclerView.Adapter<DeviceAdapter.DeviceViewHolder>() {
|
||||
|
||||
private val items = mutableListOf<DeviceUi>()
|
||||
private val items = mutableListOf<DeviceBean>()
|
||||
|
||||
fun submitList(deviceList: List<DeviceUi>) {
|
||||
fun submitList(deviceList: List<DeviceBean>) {
|
||||
items.clear()
|
||||
items.addAll(deviceList)
|
||||
notifyDataSetChanged()
|
||||
@@ -33,15 +26,25 @@ class DeviceAdapter(
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: DeviceViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
holder.bind(items[position], position)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
private val defaultIcons = listOf(R.mipmap.img1, R.mipmap.img2, R.mipmap.img3)
|
||||
|
||||
inner class DeviceViewHolder(private val binding: ItemDeviceBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(item: DeviceUi) {
|
||||
fun bind(item: DeviceBean, position: Int) {
|
||||
if (item.deviceImg.isNullOrEmpty()) {
|
||||
val iconResId = defaultIcons[position % defaultIcons.size]
|
||||
binding.ivDeviceIcon.setImageResource(iconResId)
|
||||
} else {
|
||||
Glide.with(binding.root.context)
|
||||
.load(item.deviceImg)
|
||||
.into(binding.ivDeviceIcon)
|
||||
}
|
||||
binding.tvDeviceType.text = item.name
|
||||
when (item.status) {
|
||||
"1" -> {
|
||||
|
||||
@@ -27,4 +27,13 @@ data class DeviceBean(
|
||||
val wifiPassword: String? = null,//WiFi密码
|
||||
val workMode: String? = null,//工作模式 0-自动 1-半自动
|
||||
val optionPassword: String? = null, //操作密码
|
||||
)
|
||||
) {
|
||||
val deviceId: String
|
||||
get() = id ?: ""
|
||||
|
||||
val name: String
|
||||
get() = deviceName ?: ""
|
||||
|
||||
val isOnline: Boolean
|
||||
get() = status == "1"
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.ckkj.defense_device.R
|
||||
import com.ckkj.defense_device.adapter.DeviceAdapter
|
||||
import com.ckkj.defense_device.adapter.DeviceUi
|
||||
import com.ckkj.defense_device.adapter.FamilyAdapter
|
||||
import com.ckkj.defense_device.bean.DeviceBean
|
||||
import com.ckkj.defense_device.bean.FamilyBean
|
||||
@@ -200,8 +199,8 @@ class HomeMenuFragment : Fragment() {
|
||||
// 为 LinearLayout 设置渐变背景
|
||||
setGradientBackground(
|
||||
view = binding.gradientLayout,
|
||||
startColor = Color.parseColor("#EBDCED"),
|
||||
endColor = Color.parseColor("#CAF4FF")
|
||||
startColor = resources.getColor(R.color.gradientLayout1),
|
||||
endColor = resources.getColor(R.color.gradientLayout2)
|
||||
)
|
||||
binding.message.setOnClickListener {
|
||||
val intent = Intent(requireContext(), MessageActivity::class.java)
|
||||
@@ -404,7 +403,7 @@ class HomeMenuFragment : Fragment() {
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.rvDeviceList.visibility = View.GONE
|
||||
binding.layoutNoPermission.visibility = View.VISIBLE
|
||||
binding.layoutNoNetwork.visibility = View.VISIBLE
|
||||
Toast.makeText(requireContext(), R.string.network_error, Toast.LENGTH_SHORT).show()
|
||||
isLoading = false
|
||||
if (isLoadMore) {
|
||||
@@ -450,20 +449,16 @@ class HomeMenuFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun updateDeviceList() {
|
||||
val deviceUiList = deviceBeanList.map {
|
||||
DeviceUi(it.deviceName ?: "", it.status ?: "", it.id ?: "")
|
||||
}
|
||||
|
||||
if (deviceUiList.isEmpty()) {
|
||||
if (deviceBeanList.isEmpty()) {
|
||||
deviceAdapter.submitList(listOf(
|
||||
DeviceUi(getString(R.string.no_device), "0")
|
||||
DeviceBean(deviceName = getString(R.string.no_device), status = "0")
|
||||
))
|
||||
} else {
|
||||
deviceAdapter.submitList(deviceUiList)
|
||||
deviceAdapter.submitList(deviceBeanList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDeviceClicked(device: DeviceUi) {
|
||||
private fun onDeviceClicked(device: DeviceBean) {
|
||||
if (device.isOnline) {
|
||||
DeviceIdEvent.setDeviceId(device.deviceId)
|
||||
val intent = Intent(requireContext(), LiveVideoActivity::class.java)
|
||||
|
||||
@@ -125,7 +125,7 @@ class MessageActivity : AppCompatActivity() {
|
||||
e.printStackTrace()
|
||||
withContext(Dispatchers.Main) {
|
||||
if (allMessages.isEmpty()) {
|
||||
showEmptyState()
|
||||
noNetwork()
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@@ -151,6 +151,12 @@ class MessageActivity : AppCompatActivity() {
|
||||
binding.rvMessageList.visibility = View.VISIBLE
|
||||
binding.emptyLayout.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun noNetwork() {
|
||||
binding.rvMessageList.visibility = View.GONE
|
||||
binding.layoutNoNetwork.visibility = View.VISIBLE
|
||||
binding.tvNoMoreData.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun showNoMoreDataHint() {
|
||||
binding.tvNoMoreData.visibility = View.VISIBLE
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ckkj.defense_device.liveVideo
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@@ -95,19 +96,33 @@ class AddLinkedUserActivity : AppCompatActivity() {
|
||||
Toast.makeText(this@AddLinkedUserActivity, "暂无家庭成员数据", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} else {
|
||||
hide()
|
||||
Toast.makeText(this@AddLinkedUserActivity, "请求失败: ${response.msg}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("AddLinkedUserActivity", "网络请求异常", e)
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.swipeRefresh.isRefreshing = false
|
||||
noNetwork()
|
||||
Toast.makeText(this@AddLinkedUserActivity, "网络请求失败: ${e.message}", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun hide() {
|
||||
binding.searchLayout.visibility = View.GONE
|
||||
binding.rvAddLinkedUser.visibility = View.GONE
|
||||
binding.butting?.visibility = View.GONE
|
||||
binding.layoutNoPermission?.visibility = View.VISIBLE
|
||||
}
|
||||
private fun noNetwork() {
|
||||
binding.searchLayout.visibility = View.GONE
|
||||
binding.rvAddLinkedUser.visibility = View.GONE
|
||||
binding.butting?.visibility = View.GONE
|
||||
binding.layoutNoNetwork?.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
private fun updateFamilyMemberList(familyMembersList: List<FamilyMembersBean>) {
|
||||
fullUserItemList.clear()
|
||||
familyMembersList.forEach { member ->
|
||||
|
||||
@@ -265,8 +265,8 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
e.printStackTrace()
|
||||
withContext(Dispatchers.Main) {
|
||||
binding.swipeRefresh.isRefreshing = false
|
||||
hide()
|
||||
Toast.makeText(this@LinkedUserActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||
noNetwork()
|
||||
Toast.makeText(this@LinkedUserActivity, R.string.network_request_failed, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,6 +277,12 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
binding.butting?.visibility = View.GONE
|
||||
binding.layoutNoPermission?.visibility = View.VISIBLE
|
||||
}
|
||||
private fun noNetwork() {
|
||||
binding.searchLayout.visibility = View.GONE
|
||||
binding.rvLinkedUser.visibility = View.GONE
|
||||
binding.butting?.visibility = View.GONE
|
||||
binding.layoutNoNetwork?.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
private fun updateDeviceUserList(deviceUserList: List<DeviceUserBean>) {
|
||||
fullUserList.clear()
|
||||
|
||||
@@ -88,8 +88,41 @@
|
||||
android:paddingBottom="16dp"/>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<!-- 空页面 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutNoPermission"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="244dp"
|
||||
android:layout_height="131dp"
|
||||
android:src="@mipmap/default_page"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutNoNetwork"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="244dp"
|
||||
android:layout_height="131dp"
|
||||
android:src="@mipmap/no_network_img_name" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/butting"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="16dp"
|
||||
|
||||
@@ -168,6 +168,22 @@
|
||||
android:src="@mipmap/default_page" />
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutNoNetwork"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="244dp"
|
||||
android:layout_height="131dp"
|
||||
android:src="@mipmap/no_network_img_name" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
|
||||
@@ -112,6 +112,22 @@
|
||||
android:src="@mipmap/default_page"/>
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutNoNetwork"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="244dp"
|
||||
android:layout_height="131dp"
|
||||
android:src="@mipmap/no_network_img_name" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
@@ -58,7 +58,23 @@
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/no_message" />
|
||||
android:src="@mipmap/default_page_img_name" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/layoutNoNetwork"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="32dp"
|
||||
android:background="@color/white"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="244dp"
|
||||
android:layout_height="131dp"
|
||||
android:src="@mipmap/no_network_img_name" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
|
||||
BIN
app/src/main/res/mipmap-xhdpi/img1.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/res/mipmap-xhdpi/img2.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
app/src/main/res/mipmap-xhdpi/img3.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/default_page_img_name.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/img1.png
Normal file
|
After Width: | Height: | Size: 31 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/img2.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/img3.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/no_network_img_name.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/default_page_img_name.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/img1.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/img2.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/img3.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/no_network_img_name.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
@@ -20,5 +20,7 @@
|
||||
<color name="green_light">#E8F7F7</color>
|
||||
<color name="gray_divider">#E5E5E5</color>
|
||||
<color name="orange">#FF9800</color>
|
||||
<color name="gradientLayout1">#EBDCED</color>
|
||||
<color name="gradientLayout2">#CAF4FF</color>
|
||||
|
||||
</resources>
|
||||
|
||||