Search in sources :

Example 1 with Users_Adapter

use of com.tutuanle.chatapp.adapters.Users_Adapter in project Chat-app by TuTuanLe.

the class ChatFragment method getUSer.

private void getUSer() {
    loading(true);
    FirebaseFirestore database = FirebaseFirestore.getInstance();
    database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
        loading(false);
        String currentUserId = preferenceManager.getString(Constants.KEY_USER_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.setName(queryDocumentSnapshot.getString(Constants.KEY_NAME));
                user.setEmail(queryDocumentSnapshot.getString(Constants.KEY_EMAIL));
                user.setProfileImage(queryDocumentSnapshot.getString(Constants.KEY_IMAGE));
                user.setToken(queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN));
                user.setUid(queryDocumentSnapshot.getId());
                user.setAvailability(queryDocumentSnapshot.getLong(Constants.KEY_AVAILABILITY));
                users.add(user);
            }
            if (users.size() > 0) {
                Users_Adapter users_adapter = new Users_Adapter(users, mainScreenActivity);
                RecyclerView temp = view.findViewById(R.id.userRecyclerView);
                temp.setAdapter(users_adapter);
                temp.setVisibility(View.VISIBLE);
            } else {
                showErrorMessage();
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.tutuanle.chatapp.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) Users_Adapter(com.tutuanle.chatapp.adapters.Users_Adapter) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 Users_Adapter (com.tutuanle.chatapp.adapters.Users_Adapter)1 User (com.tutuanle.chatapp.models.User)1 ArrayList (java.util.ArrayList)1