优化布局样式,修改text的展示错误显示

This commit is contained in:
2026-07-21 17:46:48 +08:00
parent 7114e36165
commit f154f30e2d
15 changed files with 120 additions and 72 deletions

View File

@@ -1,23 +0,0 @@
package com.ckkj.defense_device.annotation
/**
* API 加密注解
*
* 用于标记需要加密的 API 接口
*
* @param response 是否同时加密响应体,默认 false仅加密请求
*
* 使用示例:
* - @ApiEncrypt // 仅加密请求
* - @ApiEncrypt(response = true) // 请求和响应都加密
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class ApiEncrypt(
/**
* 是否加密响应体
* - false (默认): 仅加密请求体
* - true: 请求体和响应体都加密
*/
val response: Boolean = false
)

View File

@@ -9,11 +9,11 @@ data class DeviceBean(
val deviceFamilyId: String? = null, val deviceFamilyId: String? = null,
val deviceImg: String? = null, val deviceImg: String? = null,
val deviceName: String? = null,//设备名称 val deviceName: String? = null,//设备名称
val deviceNo: String? = null,//设备编号 val deviceNo: String = "",//设备编号
val deviceSn: String? = null,//设备序列号 val deviceSn: String = "",//设备序列号
val endTime: String? = null,//自动布放结束时间 val endTime: String? = null,//自动布放结束时间
val expirationTime: String? = null, val expirationTime: String? = null,
val fwVer: String? = null,//固件版本 val fwVer: String= "",//固件版本
val id: String? = null, val id: String? = null,
val light: String? = null,//强光开启 val light: String? = null,//强光开启
val patternPerception: String? = null,//识别模式 val patternPerception: String? = null,//识别模式

View File

@@ -12,6 +12,7 @@ import com.ckkj.defense_device.databinding.MessageActivityBinding
import com.ckkj.defense_device.utils.MessageStatusManager import com.ckkj.defense_device.utils.MessageStatusManager
import com.ckkj.defense_device.utils.RetrofitNetwork import com.ckkj.defense_device.utils.RetrofitNetwork
import com.ckkj.defense_device.view.LoadingDialog import com.ckkj.defense_device.view.LoadingDialog
import com.ckkj.defense_device.view.PullRefreshLayout
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -48,6 +49,14 @@ class MessageActivity : AppCompatActivity() {
binding.rvMessageList.layoutManager = LinearLayoutManager(this) binding.rvMessageList.layoutManager = LinearLayoutManager(this)
binding.rvMessageList.adapter = messageAdapter binding.rvMessageList.adapter = messageAdapter
binding.swipeRefreshLayout.setOnRefreshListener(object : PullRefreshLayout.OnRefreshListener {
override fun onRefresh() {
currentPage = 1
hasMoreData = true
loadMessageList()
}
})
binding.rvMessageList.addOnScrollListener(object : RecyclerView.OnScrollListener() { binding.rvMessageList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy) super.onScrolled(recyclerView, dx, dy)
@@ -135,6 +144,7 @@ class MessageActivity : AppCompatActivity() {
if (currentPage == 1) { if (currentPage == 1) {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
hideLoading() hideLoading()
binding.swipeRefreshLayout.finishRefresh()
} }
} }
} }
@@ -149,30 +159,30 @@ class MessageActivity : AppCompatActivity() {
} }
private fun showLoading() { private fun showLoading() {
binding.rvMessageList.visibility = View.GONE binding.swipeRefreshLayout.visibility = View.GONE
binding.emptyLayout.visibility = View.GONE binding.emptyLayout.visibility = View.GONE
binding.layoutNoNetwork.visibility = View.GONE binding.layoutNoNetwork.visibility = View.GONE
loadingDialog.show() loadingDialog.show()
} }
private fun hideLoading() { private fun hideLoading() {
binding.rvMessageList.visibility = View.VISIBLE binding.swipeRefreshLayout.visibility = View.VISIBLE
loadingDialog.dismiss() loadingDialog.dismiss()
} }
private fun showEmptyState() { private fun showEmptyState() {
binding.rvMessageList.visibility = View.GONE binding.swipeRefreshLayout.visibility = View.GONE
binding.emptyLayout.visibility = View.VISIBLE binding.emptyLayout.visibility = View.VISIBLE
binding.tvNoMoreData.visibility = View.GONE binding.tvNoMoreData.visibility = View.GONE
} }
private fun hideEmptyState() { private fun hideEmptyState() {
binding.rvMessageList.visibility = View.VISIBLE binding.swipeRefreshLayout.visibility = View.VISIBLE
binding.emptyLayout.visibility = View.GONE binding.emptyLayout.visibility = View.GONE
} }
private fun noNetwork() { private fun noNetwork() {
binding.rvMessageList.visibility = View.GONE binding.swipeRefreshLayout.visibility = View.GONE
binding.layoutNoNetwork.visibility = View.VISIBLE binding.layoutNoNetwork.visibility = View.VISIBLE
binding.tvNoMoreData.visibility = View.GONE binding.tvNoMoreData.visibility = View.GONE
} }

View File

@@ -55,8 +55,8 @@ class DeviceInfoActivity : AppCompatActivity() {
} }
private fun updateDeviceInfo(device: com.ckkj.defense_device.bean.DeviceBean) { private fun updateDeviceInfo(device: com.ckkj.defense_device.bean.DeviceBean) {
binding.tvDeviceModelValue.text = device.deviceNo.toString() binding.tvDeviceModelValue.text = device.deviceNo?.toString()?: ""
binding.tvDeviceNoValue.text = device.deviceSn.toString() binding.tvDeviceNoValue.text = device.deviceSn?.toString() ?: ""
binding.tvFwVersionValue.text = device.fwVer.toString() binding.tvFwVersionValue.text = device.fwVer?.toString()?: ""
} }
} }

View File

@@ -24,6 +24,7 @@ import com.ckkj.defense_device.utils.DeviceIdEvent
import com.ckkj.defense_device.utils.DeviceUserUpdateEvent import com.ckkj.defense_device.utils.DeviceUserUpdateEvent
import com.ckkj.defense_device.utils.RetrofitNetwork import com.ckkj.defense_device.utils.RetrofitNetwork
import com.ckkj.defense_device.view.CustomDialogFragmentText import com.ckkj.defense_device.view.CustomDialogFragmentText
import com.ckkj.defense_device.view.PullRefreshLayout
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import com.yanzhenjie.recyclerview.SwipeMenuItem import com.yanzhenjie.recyclerview.SwipeMenuItem
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@@ -95,9 +96,11 @@ class LinkedUserActivity : AppCompatActivity() {
(binding.rvLinkedUser as RecyclerView).layoutManager = LinearLayoutManager(this) (binding.rvLinkedUser as RecyclerView).layoutManager = LinearLayoutManager(this)
binding.swipeRefresh.setOnRefreshListener { binding.swipeRefresh.setOnRefreshListener(object : PullRefreshLayout.OnRefreshListener {
fetchUserList() override fun onRefresh() {
} fetchUserList()
}
})
binding.rvLinkedUser.setSwipeMenuCreator { leftMenu, rightMenu, position -> binding.rvLinkedUser.setSwipeMenuCreator { leftMenu, rightMenu, position ->
if (mode == MODE_SETTINGS) { if (mode == MODE_SETTINGS) {
@@ -229,7 +232,6 @@ class LinkedUserActivity : AppCompatActivity() {
} }
private fun fetchUserList() { private fun fetchUserList() {
binding.swipeRefresh.isRefreshing = true
lifecycleScope.launch { lifecycleScope.launch {
try { try {
var deviceId: String? = null var deviceId: String? = null
@@ -238,7 +240,7 @@ class LinkedUserActivity : AppCompatActivity() {
if (deviceId.isNullOrEmpty()) { if (deviceId.isNullOrEmpty()) {
Toast.makeText(this@LinkedUserActivity, "设备 ID 为空", Toast.LENGTH_SHORT).show() Toast.makeText(this@LinkedUserActivity, "设备 ID 为空", Toast.LENGTH_SHORT).show()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false binding.swipeRefresh.finishRefresh()
} }
return@launch return@launch
} }
@@ -249,7 +251,7 @@ class LinkedUserActivity : AppCompatActivity() {
RetrofitNetwork.getNetworkService().getFamilyMembers() RetrofitNetwork.getNetworkService().getFamilyMembers()
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false binding.swipeRefresh.finishRefresh()
if (response.code == 200 && response.data != null) { if (response.code == 200 && response.data != null) {
if (mode == MODE_SETTINGS) { if (mode == MODE_SETTINGS) {
updateDeviceUserList(response.data as List<DeviceUserBean>) updateDeviceUserList(response.data as List<DeviceUserBean>)
@@ -264,7 +266,7 @@ class LinkedUserActivity : AppCompatActivity() {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false binding.swipeRefresh.finishRefresh()
noNetwork() noNetwork()
Toast.makeText(this@LinkedUserActivity, R.string.network_request_failed, Toast.LENGTH_SHORT).show() Toast.makeText(this@LinkedUserActivity, R.string.network_request_failed, Toast.LENGTH_SHORT).show()
} }

View File

@@ -75,7 +75,7 @@ class UserDetailsActivity : AppCompatActivity() {
} }
private fun updateUI(data: com.ckkj.defense_device.bean.ObtainInviterInformationBean) { private fun updateUI(data: com.ckkj.defense_device.bean.ObtainInviterInformationBean) {
binding.tvContactName.text = data.nickName ?: "未知用户" binding.tvContactName.text = data.nickName ?: ""
binding.tvPhone.text = data.phonenumber ?: "" binding.tvPhone.text = data.phonenumber ?: ""
binding.tvIdCard.text = data.idCard ?: "" binding.tvIdCard.text = data.idCard ?: ""
binding.tvMacAddress.text = data.mac ?: "" binding.tvMacAddress.text = data.mac ?: ""

View File

@@ -7,6 +7,7 @@ import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import com.ckkj.defense_device.databinding.SettingsMenusActivityBinding import com.ckkj.defense_device.databinding.SettingsMenusActivityBinding
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import java.io.File
class SettingsMenusActivity : AppCompatActivity() { class SettingsMenusActivity : AppCompatActivity() {
private lateinit var binding: SettingsMenusActivityBinding private lateinit var binding: SettingsMenusActivityBinding
@@ -25,6 +26,8 @@ class SettingsMenusActivity : AppCompatActivity() {
val versionName = packageManager.getPackageInfo(packageName, 0).versionName val versionName = packageManager.getPackageInfo(packageName, 0).versionName
binding.tvVersion.text = versionName binding.tvVersion.text = versionName
// 显示缓存大小
displayCacheSize()
setupClickListeners() setupClickListeners()
} }
@@ -42,8 +45,9 @@ class SettingsMenusActivity : AppCompatActivity() {
// 清除缓存 // 清除缓存
binding.itemClearCache.setOnClickListener { binding.itemClearCache.setOnClickListener {
clearCache()
displayCacheSize() // 更新缓存大小显示
Toast.makeText(this, "缓存已清除", Toast.LENGTH_SHORT).show() Toast.makeText(this, "缓存已清除", Toast.LENGTH_SHORT).show()
binding.tvCacheSize.text = "0 KB"
} }
// 用户协议 // 用户协议
@@ -62,4 +66,46 @@ class SettingsMenusActivity : AppCompatActivity() {
startActivity(intent) startActivity(intent)
} }
} }
//缓存方法
private fun displayCacheSize() {
val cacheSize = getCacheSize()
val sizeString = when {
cacheSize >= 1024 * 1024 -> String.format("%.2f MB", cacheSize / (1024.0 * 1024.0))
else -> String.format("%d KB", cacheSize / 1024)
}
binding.tvCacheSize.text = sizeString
}
private fun getCacheSize(): Long {
val cacheDir = cacheDir
return getFolderSize(cacheDir)
}
private fun getFolderSize(dir: File?): Long {
var size = 0L
if (dir != null && dir.isDirectory) {
dir.listFiles()?.forEach { file ->
size += if (file.isFile) {
file.length()
} else {
getFolderSize(file)
}
}
}
return size
}
private fun clearCache() {
val cacheDir = cacheDir
deleteDir(cacheDir)
}
private fun deleteDir(dir: File?): Boolean {
if (dir != null && dir.isDirectory) {
dir.listFiles()?.forEach { file ->
deleteDir(file)
}
}
return dir?.delete() ?: false
}
} }

View File

@@ -14,8 +14,8 @@ import java.util.concurrent.TimeUnit
object RetrofitNetwork { object RetrofitNetwork {
private const val DEFAULT_TIMEOUT = 30L private const val DEFAULT_TIMEOUT = 30L
const val BASE_URL = "https://stem-boozy-margarine.ngrok-free.dev" //const val BASE_URL = "https://stem-boozy-margarine.ngrok-free.dev"
//const val BASE_URL = "http://service.reinkun.com:8001" const val BASE_URL = "http://service.reinkun.com:8001"
private var retrofit: Retrofit? = null private var retrofit: Retrofit? = null
private val gson = Gson() private val gson = Gson()

View File

@@ -73,7 +73,7 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<!-- 列表区域 --> <!-- 列表区域 -->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <com.ckkj.defense_device.view.PullRefreshLayout
android:id="@+id/swipeRefresh" android:id="@+id/swipeRefresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
@@ -84,8 +84,10 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingHorizontal="16dp" android:paddingHorizontal="16dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="16dp"/> android:paddingBottom="16dp"
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> android:clipToPadding="false"
android:overScrollMode="never"/>
</com.ckkj.defense_device.view.PullRefreshLayout>
<!-- 底部按钮 --> <!-- 底部按钮 -->
<LinearLayout <LinearLayout

View File

@@ -6,11 +6,11 @@
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_marginStart="30dp" android:layout_marginStart="20dp"
android:layout_marginEnd="30dp" android:layout_marginEnd="20dp"
android:layout_marginTop="20dp" android:layout_marginTop="10dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="30dp"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
@@ -21,6 +21,7 @@
android:text="@string/cancel" android:text="@string/cancel"
android:textColor="@color/gray" android:textColor="@color/gray"
android:textSize="14dp" android:textSize="14dp"
android:textStyle="bold"
android:clickable="true" android:clickable="true"
android:focusable="true" /> android:focusable="true" />
@@ -37,6 +38,7 @@
android:text="@string/confirm" android:text="@string/confirm"
android:textColor="@color/green" android:textColor="@color/green"
android:textSize="14dp" android:textSize="14dp"
android:textStyle="bold"
android:clickable="true" android:clickable="true"
android:focusable="true" /> android:focusable="true" />
</LinearLayout> </LinearLayout>
@@ -45,6 +47,7 @@
android:id="@+id/rvMessageList" android:id="@+id/rvMessageList"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:maxHeight="150dp"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingStart="14dp" android:paddingStart="14dp"
android:paddingTop="12dp" android:paddingTop="12dp"

View File

@@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@mipmap/home_back" android:background="@mipmap/home_back"
tools:context=".home.HomeMenuFragment"> tools:context=".home.HomeMenuFragment">
@@ -37,15 +38,13 @@
<TextView <TextView
android:id="@+id/tvCurrentFamily" android:id="@+id/tvCurrentFamily"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/my_family_home" android:text="@string/my_family_home"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="20dp"
android:maxLines="1" android:maxLines="1"
android:ellipsize="end" android:textSize="20sp"
android:textStyle="bold" /> android:textStyle="bold" />
<ImageView <ImageView
android:id="@+id/ivFamilyArrow" android:id="@+id/ivFamilyArrow"
@@ -55,11 +54,6 @@
android:src="@mipmap/triangle" /> android:src="@mipmap/triangle" />
</LinearLayout> </LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -3,16 +3,17 @@
android:id="@+id/itemFamily1" android:id="@+id/itemFamily1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:gravity="center" android:gravity="center"
android:layout_height="30dp"> android:layout_height="wrap_content">
<TextView <TextView
android:paddingVertical="10dp"
android:id="@+id/tvFamilyName" android:id="@+id/tvFamilyName"
android:gravity="center" android:gravity="center"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/my_family" android:text="@string/my_family"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="16dp" /> android:textSize="14dp" />
</LinearLayout> </LinearLayout>

View File

@@ -85,7 +85,7 @@
android:layout_weight="1"> android:layout_weight="1">
<!-- 列表 --> <!-- 列表 -->
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <com.ckkj.defense_device.view.PullRefreshLayout
android:id="@+id/swipeRefresh" android:id="@+id/swipeRefresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@@ -93,8 +93,11 @@
<com.yanzhenjie.recyclerview.SwipeRecyclerView <com.yanzhenjie.recyclerview.SwipeRecyclerView
android:id="@+id/rvLinkedUser" android:id="@+id/rvLinkedUser"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> android:clipToPadding="false"
android:overScrollMode="never"
android:paddingBottom="16dp"/>
</com.ckkj.defense_device.view.PullRefreshLayout>
<!-- 空页面 --> <!-- 空页面 -->
<LinearLayout <LinearLayout

View File

@@ -39,13 +39,23 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView <com.ckkj.defense_device.view.PullRefreshLayout
android:id="@+id/rvMessageList" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp" android:layout_marginStart="20dp"
android:layout_marginEnd="20dp" android:layout_marginEnd="20dp"
tools:listitem="@layout/item_message_notice" /> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvMessageList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingBottom="16dp"
tools:listitem="@layout/item_message_notice" />
</com.ckkj.defense_device.view.PullRefreshLayout>
<LinearLayout <LinearLayout
android:id="@+id/emptyLayout" android:id="@+id/emptyLayout"

View File

@@ -99,7 +99,7 @@
android:id="@+id/tv_cache_size" android:id="@+id/tv_cache_size"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="11Kb" android:text=""
android:textColor="#999999" android:textColor="#999999"
android:textSize="13sp" /> android:textSize="13sp" />