use of com.tutuanle.chatapp.models.User 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.models.User 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");
}
}
});
}
use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class SetupProfileActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivitySetupProfileBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
dialog = new ProgressDialog(this);
dialog.setMessage("Updating profile ...");
dialog.setCancelable(false);
getSupportActionBar().hide();
database = FirebaseDatabase.getInstance();
storage = FirebaseStorage.getInstance();
auth = FirebaseAuth.getInstance();
binding.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, 45);
}
});
binding.continueBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = binding.nameBox.getText().toString();
if (name.isEmpty()) {
binding.nameBox.setError("Please type a name");
return;
}
dialog.show();
if (selectedImage != null) {
StorageReference reference = storage.getReference().child("Profile").child(auth.getUid());
reference.putFile(selectedImage).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
reference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String imageUrl = uri.toString();
String uid = auth.getUid();
String phone = auth.getCurrentUser().getPhoneNumber();
String name = binding.nameBox.getText().toString();
User user = new User(uid, name, phone, imageUrl);
database.getReference().child("users").child(uid).setValue(user).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void unused) {
dialog.dismiss();
Intent intent = new Intent(SetupProfileActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
});
}
});
}
}
});
}
}
});
}
use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class UsersAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull UsersViewHolder holder, int position) {
User user = users.get(position);
String senderId = FirebaseAuth.getInstance().getUid();
String senderRoom = senderId + user.getUid();
FirebaseDatabase.getInstance().getReference().child("Chats").child(senderRoom).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
String lastMsg = snapshot.child("lastMsg").getValue(String.class);
long time = snapshot.child("lastMsgTime").getValue(Long.class);
SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm a");
holder.binding.msgTime.setText(dateFormat.format(new Date(time)));
holder.binding.lastMsg.setText(lastMsg);
} else {
holder.binding.lastMsg.setText("Tap to Chat");
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
holder.binding.username.setText(user.getName());
Glide.with(context).load(user.getProfileImage()).placeholder(R.drawable.avatar).into(holder.binding.profile);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, ChatActivity.class);
intent.putExtra("name", user.getName());
intent.putExtra("uid", user.getUid());
context.startActivity(intent);
}
});
}
Aggregations