Search in sources :

Example 1 with UsersAdapter

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();
        }
    });
}
Also used : UsersAdapter(com.example.clown.adapter.UsersAdapter) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.clown.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Aggregations

UsersAdapter (com.example.clown.adapter.UsersAdapter)1 User (com.example.clown.models.User)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 ArrayList (java.util.ArrayList)1