【发布时间】:2019-10-12 00:43:37
【问题描述】:
您好,我正在将 Firestore 转换为 FirebaseDatabase,我能够完成大部分转换,除了我遇到的这个转换。我被困在 .getdocuments 和 Documentchanges 上。我认为.getdocuments 是.getchildren?我不知道实时火力库中 Documentchanges 的等价物是什么。请帮忙。提前谢谢你!
这是我要转换的代码
firestore.collection("Users")
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.getDocuments().isEmpty()) {
for (final DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
if (doc.getType() == DocumentChange.Type.ADDED) {
if (!doc.getDocument().getId().equals(mAuth.getCurrentUser().getUid())) {
Friends friends = doc.getDocument().toObject(Friends.class).withId(doc.getDocument().getString("id"));
usersList.add(friends);
usersAdapter.notifyDataSetChanged();
refreshLayout.setRefreshing(false);
}
}
}
if(usersList.isEmpty()){
refreshLayout.setRefreshing(false);
mView.findViewById(R.id.default_item).setVisibility(View.VISIBLE);
}
}else{
refreshLayout.setRefreshing(false);
mView.findViewById(R.id.default_item).setVisibility(View.VISIBLE);
}
}
})
【问题讨论】:
标签: android firebase-realtime-database google-cloud-firestore