use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class MyPhoneNumberActivity method getUserWithNumberPhone.
private void getUserWithNumberPhone() {
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).whereEqualTo(Constants.KEY_NUMBER_PHONE, binding.phoneBox.getText().toString()).get().addOnCompleteListener(task -> {
if (task.isSuccessful() && task.getResult() != null && task.getResult().getDocuments().size() > 0) {
DocumentSnapshot snapshot = task.getResult().getDocuments().get(0);
user = new User();
user.setUid(snapshot.getId());
user.setName(snapshot.getString(Constants.KEY_NAME));
user.setProfileImage(snapshot.getString(Constants.KEY_IMAGE));
user.setPhoneNumber(snapshot.getString(Constants.KEY_NUMBER_PHONE));
user.setEmail(snapshot.getString(Constants.KEY_EMAIL));
user.setPassword(snapshot.getString(Constants.KEY_EMAIL));
getAuthPhone();
} else {
Toast.makeText(this, "Doesn't exist number phone ...", Toast.LENGTH_SHORT).show();
loading(false);
}
});
}
use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class OTPScreenActivity method setUpOTPInput.
private void setUpOTPInput() {
String phoneNumber = getIntent().getStringExtra("phoneNumber");
String verificationId = getIntent().getStringExtra("verificationId");
User user = (User) getIntent().getSerializableExtra(Constants.KEY_USER);
binding.textView.setText("Check your SMS messages , we have sent your pin at + " + phoneNumber);
binding.inputCode1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode2.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
binding.inputCode2.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode3.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
binding.inputCode3.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode4.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
binding.inputCode4.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode5.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
binding.inputCode5.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode6.requestFocus();
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
binding.inputCode6.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (!charSequence.toString().trim().isEmpty()) {
binding.inputCode6.onEditorAction(EditorInfo.IME_ACTION_DONE);
loading(true);
String code = binding.inputCode1.getText().toString() + binding.inputCode2.getText().toString() + binding.inputCode3.getText().toString() + binding.inputCode4.getText().toString() + binding.inputCode5.getText().toString() + binding.inputCode6.getText().toString();
PhoneAuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(verificationId, code);
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential).addOnSuccessListener(v -> {
Toast.makeText(OTPScreenActivity.this, "login successfully", Toast.LENGTH_SHORT).show();
preferenceManager.putBoolean(Constants.KEY_IS_SIGNED_IN, true);
preferenceManager.putString(Constants.KEY_USER_ID, user.getUid());
preferenceManager.putString(Constants.KEY_NAME, user.getName());
preferenceManager.putString(Constants.KEY_IMAGE, user.getProfileImage());
preferenceManager.putString(Constants.KEY_EMAIL, user.getEmail());
preferenceManager.putString(Constants.KEY_NUMBER_PHONE, user.getPhoneNumber());
preferenceManager.putString(Constants.KEY_PASSWORD, user.getPassword());
Intent intent = new Intent(getApplicationContext(), MainScreenActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
loading(false);
}).addOnFailureListener(v -> {
Toast.makeText(OTPScreenActivity.this, "get OTP fail", Toast.LENGTH_SHORT).show();
loading(false);
});
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
dialog = new ProgressDialog(this);
dialog.setMessage("upLoading Image ...");
dialog.setCancelable(false);
database = FirebaseDatabase.getInstance();
users = new ArrayList<User>();
usersAdapter = new UsersAdapter(this, users);
userStatuses = new ArrayList<>();
database.getReference().child("users").child(FirebaseAuth.getInstance().getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
user = snapshot.getValue(User.class);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
statusAdapter = new TopStatusAdapter(this, userStatuses);
// binding.statusList.setLayoutManager((new LinearLayoutManager(this)));
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(RecyclerView.HORIZONTAL);
binding.statusList.setLayoutManager(layoutManager);
// binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
binding.statusList.setAdapter(statusAdapter);
binding.recyclerView.setAdapter(usersAdapter);
database.getReference().child("users").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
users.clear();
for (DataSnapshot snapshot1 : snapshot.getChildren()) {
User user = snapshot1.getValue(User.class);
Log.d("log", user.toString());
users.add(user);
}
usersAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
database.getReference().child("stories").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists()) {
userStatuses.clear();
for (DataSnapshot storySnapshot : snapshot.getChildren()) {
UserStatus status = new UserStatus();
status.setName(storySnapshot.child("name").getValue(String.class));
status.setProfileImage(storySnapshot.child("profileImage").getValue(String.class));
status.setLastUpdated(storySnapshot.child("lastUpdate").getValue(Long.class));
ArrayList<Status> statuses = new ArrayList<>();
for (DataSnapshot statusSnapshot : storySnapshot.child("statuses").getChildren()) {
Status sampleStatus = statusSnapshot.getValue(Status.class);
statuses.add(sampleStatus);
}
status.setStatuses(statuses);
userStatuses.add(status);
}
statusAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
binding.BottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch(item.getItemId()) {
case R.id.status:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 75);
break;
}
;
return false;
}
});
}
use of com.tutuanle.chatapp.models.User in project Chat-app by TuTuanLe.
the class MessagingService method onMessageReceived.
@SuppressLint("UnspecifiedImmutableFlag")
@RequiresApi(api = Build.VERSION_CODES.N)
public void onMessageReceived(@NonNull RemoteMessage message) {
String type = message.getData().get(Constants.REMOTE_MSG_TYPE);
Log.d("TAG_TYPE", "setUpVideoCall: ");
super.onMessageReceived(message);
setUpVideoCall(message);
User user = new User();
user.setUid(message.getData().get(Constants.KEY_USER_ID));
user.setName(message.getData().get(Constants.KEY_NAME));
user.setToken(message.getData().get(Constants.KEY_FCM_TOKEN));
int notificationID = new Random().nextInt();
String channelId = "chat_message";
Intent intent = new Intent(this, ChatScreenActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Constants.KEY_USER, user);
PendingIntent pendingIntent = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_MUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
}
// custom notification
@SuppressLint("RemoteViewLayout") RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.custom_notification);
// notificationLayout.setTextViewText(R.id.username, user.getName());
// notificationLayout.setTextViewText(R.id.message, message.getData().get(Constants.KEY_MESSAGE));
// notificationLayout.setImageViewBitmap();
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
builder.setSmallIcon(R.drawable.ic_baseline_toys_24);
builder.setContentTitle(user.getName());
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(message.getData().get(Constants.KEY_MESSAGE)));
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence channelName = "Chat Message ";
String channelDescription = "This notification channel is used for chat message notification";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
channel.setDescription(channelDescription);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(notificationID, builder.build());
}
use of com.tutuanle.chatapp.models.User 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();
}
}
});
}
Aggregations