如何返回 DocumentSnapShot 作为方法的结果?
一个自定义对象,其参数为 (DocumentSnapShot documentsnapShot)。也是Firebase中的一个内部对象,它检索快照并将值设置为我的自定义模型,也具有其参数(DocumentSnapShot documentsnapShot)。但是,我希望从Firebase获取数据并将其传递给我的自定义参数,因为我的参数不仅需要Firebase的多个数据。而且不可能在没有覆盖的情况下迭代Firestore。
代码如下:
public UserSettings getUserSettings(DocumentSnapshot documentSnapshot){
Log.d(TAG, "getUserSettings: retrieving user account settings from firestore");
DocumentReference mSettings = mFirebaseFirestore.collection("user_account_settings").document(userID);
mSettings.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
UserAccountSettings settings = documentSnapshot.toObject(UserAccountSettings.class);
settings.setDisplay_name(documentSnapshot.getString("display_name"));
settings.setUsername(documentSnapshot.getString("username"));
settings.setWebsite(documentSnapshot.getString("website"));
settings.setProfile_photo(documentSnapshot.getString("profile_photo"));
settings.setPosts(documentSnapshot.getLong("posts"));
settings.setFollowers(documentSnapshot.getLong("followers"));
settings.setFollowing(documentSnapshot.getLong("following"));
}
});
}