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);
}
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");
}
}
});
}
Aggregations