use of com.example.clown.adapter.UsersAdapter in project Skool by NhatTruongK15.
the class UsersActivity method getUsers.
private void getUsers() {
loading(true);
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
loading(false);
String currentUserId = preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_ID);
if (task.isSuccessful() && task.getResult() != null) {
List<User> users = new ArrayList<>();
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (currentUserId.equals(queryDocumentSnapshot.getId())) {
continue;
}
User user = new User();
user.name = queryDocumentSnapshot.getString(Constants.KEY_NAME);
user.email = queryDocumentSnapshot.getString(Constants.KEY_EMAIL);
user.image = queryDocumentSnapshot.getString(Constants.KEY_IMAGE);
user.token = queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN);
user.id = queryDocumentSnapshot.getId();
users.add(user);
}
if (users.size() > 0) {
UsersAdapter usersAdapter = new UsersAdapter(users, this);
binding.userRecyclerView.setAdapter(usersAdapter);
binding.userRecyclerView.setVisibility(View.VISIBLE);
} else {
showError();
}
} else {
showError();
}
});
}
Aggregations