切换家庭联动
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user