Search in sources :

Example 1 with SearchAdapter

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

the class SearchActivity method searchFilter.

@SuppressLint("SetTextI18n")
private void searchFilter(String name) {
    List<User> temp = new ArrayList<>();
    if (name.length() == 0) {
        temp.addAll(users);
    } else {
        for (int i = 0; i < users.size(); i++) {
            if (users.get(i).getName().toLowerCase().contains(name.toLowerCase())) {
                temp.add(users.get(i));
            }
        }
    }
    if (temp.size() == 0) {
        binding.layoutNotFound.setVisibility(View.VISIBLE);
        binding.txtNotFound.setText("No matches were found for " + name + " .Try checking for typos or using complete words. ");
    } else {
        binding.layoutNotFound.setVisibility(View.GONE);
    }
    searchAdapter = new SearchAdapter(temp, SearchActivity.this);
    binding.userRecyclerView.setAdapter(searchAdapter);
    binding.userRecyclerView.setVisibility(View.VISIBLE);
}
Also used : User(com.tutuanle.chatapp.models.User) SearchAdapter(com.tutuanle.chatapp.adapters.SearchAdapter) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 2 with SearchAdapter

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

the class SearchActivity 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) {
            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) {
                searchAdapter = new SearchAdapter(users, SearchActivity.this);
                binding.userRecyclerView.setAdapter(searchAdapter);
                binding.userRecyclerView.setVisibility(View.VISIBLE);
            } else {
                showToast("Error");
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.tutuanle.chatapp.models.User) SearchAdapter(com.tutuanle.chatapp.adapters.SearchAdapter) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Aggregations

SearchAdapter (com.tutuanle.chatapp.adapters.SearchAdapter)2 User (com.tutuanle.chatapp.models.User)2 SuppressLint (android.annotation.SuppressLint)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 ArrayList (java.util.ArrayList)1