android - 如何检查firestore中的条目列表
问题描述
我正在尝试制作一个应用程序,在该应用程序中我必须只显示那些存在于 firestore 中的用户联系人,我当前的逻辑是从设备中获取所有联系人,然后在 firestore 中单独检查它们并更新数据适配器。
但我想要做的是获取所有设备联系人,一旦所有设备都被查找,然后只更新适配器,但使用 firestore get() 我无法做到这一点,有没有办法做到这一点?
我当前的代码
private fun refreshContacts() {
val list = getContacts() // this return a list of all contacts on device
adapter.deleteAllData() // delete current data
list.forEach { // for each contact check if it is in firestore
firestore.collection("users").document(it.number)
.get().addOnSuccessListener { res ->
if (res.exists()) {
val image = res.getString("image")
val uid = res.getString("uid")
val model = ContactsModel(it.name, it.number, uid!!, image!!)
adapter.updateData(model)
adapter.notifyDataSetChanged()
}
}
}
}
我想要的是
private fun refreshContacts() {
val list = getContacts() // this return a list of all contacts on device
adapter.deleteAllData() // delete current data
// code which gives a list of contacts that were present in firestore
adapter.updateData(newData)
aapter.notifyDataSetChanged()
}
解决方案
我不知道它是否完美,但您可以在 Firebase 中为您放置与用户联系人匹配的合同的每个用户添加一个节点。第一次检查所有联系人并将其放在节点上。然后你可以从那里得到它。然后您可以在后台更新节点,Firebase 将实时给出更新结果。
推荐阅读
- python - Jupyter 实验室:在内核重启时执行析构函数
- python - (discord.py) 向不和谐机器人发布的嵌入添加反应
- javascript - Javscript 在日历中将第一天设置为星期一
- python - 从 2 个字典中选择最大值
- postgresql - 同一查询 postgresql/jpa 中的不同结果
- java - 如何动态设置类的通用参数?
- python - 从数据框行创建数组
- javascript - 单击内部链接/按钮时取消/防止 Bootstrap5 崩溃
- python - 关于 PyFlink 使用 execute_sql 选择表并使用 table.print() 的问题
- azure - Azure DevOps Release Pipelines 已停止无法下载工件