【发布时间】:2022-01-07 14:23:47
【问题描述】:
我正在尝试在我的应用中实现消息页面。我从 Firestore 接收消息。当用户单击 RecyclerView 项时,isMessageRead 值更改为 true。一切正常,但问题是当使用模型类从 Firestore 读取布尔值时,所有值都变为 false。我错过了什么?谢谢。
class NotificationAdapter(
var notificationList: List<NotificationModelClass>,
private val clickListener: (NotificationModelClass) -> Unit
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var notifications: List<NotificationModelClass> = ArrayList()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val myView = LayoutInflater.from(parent.context)
.inflate(R.layout.notification_layout, parent, false)
return ChaplainsViewHolder(myView)
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder as ChaplainsViewHolder).bind(notifications[position], clickListener)
}
override fun getItemCount(): Int {
return notifications.size
}
fun submitList(notificationList: List<NotificationModelClass>) {
notifications = notificationList
}
class ChaplainsViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val notificationTitle = itemView.title
private val notificationMessage = itemView.message
private val notificationTime = itemView.messageTime
private val notificationImage = itemView.logo
private val notificationCardView = itemView.notificationCardView
private val notificationMessageRead = itemView.imageViewMessageRead
fun bind(
notificationInfo: NotificationModelClass,
clickListener: (NotificationModelClass) -> Unit
) {
notificationTitle.text = notificationInfo.title
notificationMessage.text = notificationInfo.body
val messageTime = notificationInfo.dateSent
val dateFormatLocalZone = SimpleDateFormat("HH:mm - MMM dd, yyyy")
dateFormatLocalZone.timeZone = TimeZone.getDefault()
val timeRangeFirst = dateFormatLocalZone.format(Date(messageTime!!.toLong()))
//notificationTime.text = timeRangeFirst.toString()
Picasso.get().load(R.drawable.logo).into(notificationImage)
notificationTime.text = notificationInfo.isMessageRead.toString()
/*if (isMessageRead == "no"){
notificationMessageRead.setImageResource(R.drawable.ic_baseline_mic_24)
}*/
notificationCardView.setOnClickListener {
clickListener(notificationInfo)
}
}
}
}
【问题讨论】:
标签: android firebase kotlin google-cloud-platform google-cloud-firestore