切换家庭联动

This commit is contained in:
2026-05-16 17:18:05 +08:00
parent a8f202a906
commit 4c53c43f7b
23 changed files with 515 additions and 121 deletions

View File

@@ -38,13 +38,13 @@ class DeviceAdapter(
RecyclerView.ViewHolder(binding.root) {
fun bind(item: DeviceUi) {
binding.tvDeviceName.text = item.name
binding.tvDeviceType.text = item.name
if (item.isOnline) {
binding.tvDeviceName.text = "\u25CF 正在运行"
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.green))
binding.tvDeviceName.text = "\u25CF 正在运行"
} else {
binding.tvDeviceName.text = "\u25CF 离线"
binding.tvDeviceName.setTextColor(binding.root.context.getColor(R.color.red))
binding.tvDeviceName.text = "\u25CF 离线"
}
binding.root.setOnClickListener {
onItemClick(item)

View File

@@ -37,7 +37,12 @@ class FamilyAdapter(
RecyclerView.ViewHolder(binding.root) {
fun bind(item: FamilyBean) {
binding.tvFamilyName.text = item.parentName
val isAdmin = item.role == "appadmin"
if (isAdmin) {
binding.tvFamilyName.text = binding.root.context.getString(R.string.my_family)
} else {
binding.tvFamilyName.text = "${item.parentName}${binding.root.context.getString(R.string.family_with_normal)}"
}
binding.tvFamilyRole.text = getRoleText(item.role)
val isSelected = item.parentName == selectedFamily
@@ -48,7 +53,7 @@ class FamilyAdapter(
private fun getRoleText(role: String): String {
return when (role) {
"appadmin" ->binding.root.context.getString(R.string.admin_user)
"appadmin" -> binding.root.context.getString(R.string.admin_user)
else -> binding.root.context.getString(R.string.normal_user)
}
}

View File

@@ -9,12 +9,18 @@ import com.example.defenseapplication.databinding.ItemSwitchFamilyBinding
import com.example.defenseapplication.model.FamilyItem
class FamilySwitchAdapter(
private val familyList: List<FamilyItem>,
private var familyList: List<FamilyItem>,
private val onItemClickListener: (FamilyItem) -> Unit
) : RecyclerView.Adapter<FamilySwitchAdapter.FamilyViewHolder>() {
private var selectedPosition = 0
fun updateList(newList: List<FamilyItem>) {
familyList = newList
selectedPosition = 0
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FamilyViewHolder {
val binding = ItemSwitchFamilyBinding.inflate(
LayoutInflater.from(parent.context),