优化布局样式,修改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 deviceImg: String? = null,
val deviceName: String? = null,//设备名称
val deviceNo: String? = null,//设备编号
val deviceSn: String? = null,//设备序列号
val deviceNo: String = "",//设备编号
val deviceSn: String = "",//设备序列号
val endTime: String? = null,//自动布放结束时间
val expirationTime: String? = null,
val fwVer: String? = null,//固件版本
val fwVer: String= "",//固件版本
val id: String? = null,
val light: 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.RetrofitNetwork
import com.ckkj.defense_device.view.LoadingDialog
import com.ckkj.defense_device.view.PullRefreshLayout
import com.gyf.immersionbar.ImmersionBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -48,6 +49,14 @@ class MessageActivity : AppCompatActivity() {
binding.rvMessageList.layoutManager = LinearLayoutManager(this)
binding.rvMessageList.adapter = messageAdapter
binding.swipeRefreshLayout.setOnRefreshListener(object : PullRefreshLayout.OnRefreshListener {
override fun onRefresh() {
currentPage = 1
hasMoreData = true
loadMessageList()
}
})
binding.rvMessageList.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
@@ -135,6 +144,7 @@ class MessageActivity : AppCompatActivity() {
if (currentPage == 1) {
withContext(Dispatchers.Main) {
hideLoading()
binding.swipeRefreshLayout.finishRefresh()
}
}
}
@@ -149,30 +159,30 @@ class MessageActivity : AppCompatActivity() {
}
private fun showLoading() {
binding.rvMessageList.visibility = View.GONE
binding.swipeRefreshLayout.visibility = View.GONE
binding.emptyLayout.visibility = View.GONE
binding.layoutNoNetwork.visibility = View.GONE
loadingDialog.show()
}
private fun hideLoading() {
binding.rvMessageList.visibility = View.VISIBLE
binding.swipeRefreshLayout.visibility = View.VISIBLE
loadingDialog.dismiss()
}
private fun showEmptyState() {
binding.rvMessageList.visibility = View.GONE
binding.swipeRefreshLayout.visibility = View.GONE
binding.emptyLayout.visibility = View.VISIBLE
binding.tvNoMoreData.visibility = View.GONE
}
private fun hideEmptyState() {
binding.rvMessageList.visibility = View.VISIBLE
binding.swipeRefreshLayout.visibility = View.VISIBLE
binding.emptyLayout.visibility = View.GONE
}
private fun noNetwork() {
binding.rvMessageList.visibility = View.GONE
binding.swipeRefreshLayout.visibility = View.GONE
binding.layoutNoNetwork.visibility = View.VISIBLE
binding.tvNoMoreData.visibility = View.GONE
}

View File

@@ -55,8 +55,8 @@ class DeviceInfoActivity : AppCompatActivity() {
}
private fun updateDeviceInfo(device: com.ckkj.defense_device.bean.DeviceBean) {
binding.tvDeviceModelValue.text = device.deviceNo.toString()
binding.tvDeviceNoValue.text = device.deviceSn.toString()
binding.tvFwVersionValue.text = device.fwVer.toString()
binding.tvDeviceModelValue.text = device.deviceNo?.toString()?: ""
binding.tvDeviceNoValue.text = device.deviceSn?.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.RetrofitNetwork
import com.ckkj.defense_device.view.CustomDialogFragmentText
import com.ckkj.defense_device.view.PullRefreshLayout
import com.gyf.immersionbar.ImmersionBar
import com.yanzhenjie.recyclerview.SwipeMenuItem
import kotlinx.coroutines.CoroutineScope
@@ -95,9 +96,11 @@ class LinkedUserActivity : AppCompatActivity() {
(binding.rvLinkedUser as RecyclerView).layoutManager = LinearLayoutManager(this)
binding.swipeRefresh.setOnRefreshListener {
binding.swipeRefresh.setOnRefreshListener(object : PullRefreshLayout.OnRefreshListener {
override fun onRefresh() {
fetchUserList()
}
})
binding.rvLinkedUser.setSwipeMenuCreator { leftMenu, rightMenu, position ->
if (mode == MODE_SETTINGS) {
@@ -229,7 +232,6 @@ class LinkedUserActivity : AppCompatActivity() {
}
private fun fetchUserList() {
binding.swipeRefresh.isRefreshing = true
lifecycleScope.launch {
try {
var deviceId: String? = null
@@ -238,7 +240,7 @@ class LinkedUserActivity : AppCompatActivity() {
if (deviceId.isNullOrEmpty()) {
Toast.makeText(this@LinkedUserActivity, "设备 ID 为空", Toast.LENGTH_SHORT).show()
withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false
binding.swipeRefresh.finishRefresh()
}
return@launch
}
@@ -249,7 +251,7 @@ class LinkedUserActivity : AppCompatActivity() {
RetrofitNetwork.getNetworkService().getFamilyMembers()
}
withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false
binding.swipeRefresh.finishRefresh()
if (response.code == 200 && response.data != null) {
if (mode == MODE_SETTINGS) {
updateDeviceUserList(response.data as List<DeviceUserBean>)
@@ -264,7 +266,7 @@ class LinkedUserActivity : AppCompatActivity() {
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
binding.swipeRefresh.isRefreshing = false
binding.swipeRefresh.finishRefresh()
noNetwork()
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) {
binding.tvContactName.text = data.nickName ?: "未知用户"
binding.tvContactName.text = data.nickName ?: ""
binding.tvPhone.text = data.phonenumber ?: ""
binding.tvIdCard.text = data.idCard ?: ""
binding.tvMacAddress.text = data.mac ?: ""

View File

@@ -7,6 +7,7 @@ import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.ckkj.defense_device.databinding.SettingsMenusActivityBinding
import com.gyf.immersionbar.ImmersionBar
import java.io.File
class SettingsMenusActivity : AppCompatActivity() {
private lateinit var binding: SettingsMenusActivityBinding
@@ -25,6 +26,8 @@ class SettingsMenusActivity : AppCompatActivity() {
val versionName = packageManager.getPackageInfo(packageName, 0).versionName
binding.tvVersion.text = versionName
// 显示缓存大小
displayCacheSize()
setupClickListeners()
}
@@ -42,8 +45,9 @@ class SettingsMenusActivity : AppCompatActivity() {
// 清除缓存
binding.itemClearCache.setOnClickListener {
clearCache()
displayCacheSize() // 更新缓存大小显示
Toast.makeText(this, "缓存已清除", Toast.LENGTH_SHORT).show()
binding.tvCacheSize.text = "0 KB"
}
// 用户协议
@@ -62,4 +66,46 @@ class SettingsMenusActivity : AppCompatActivity() {
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 {
private const val DEFAULT_TIMEOUT = 30L
const val BASE_URL = "https://stem-boozy-margarine.ngrok-free.dev"
//const val BASE_URL = "http://service.reinkun.com:8001"
//const val BASE_URL = "https://stem-boozy-margarine.ngrok-free.dev"
const val BASE_URL = "http://service.reinkun.com:8001"
private var retrofit: Retrofit? = null
private val gson = Gson()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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