use of com.example.clown.models.User in project Skool by NhatTruongK15.
the class GroupChatActivity method getUsers.
private void getUsers() {
loading(true);
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
loading(false);
String currentUserId = preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_ID);
if (task.isSuccessful() && task.getResult() != null) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (currentUserId.equals(queryDocumentSnapshot.getId())) {
continue;
}
User user = new User();
user.name = queryDocumentSnapshot.getString(Constants.KEY_NAME);
user.email = queryDocumentSnapshot.getString(Constants.KEY_EMAIL);
user.image = queryDocumentSnapshot.getString(Constants.KEY_IMAGE);
user.token = queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN);
user.id = queryDocumentSnapshot.getId();
users.add(user);
}
if (users.size() > 0) {
UsersGCAdapter usersGCAdapter = new UsersGCAdapter(users, GroupChatActivity.this);
binding.listFriend.setAdapter(usersGCAdapter);
binding.listFriend.setVisibility(View.VISIBLE);
} else {
showError();
}
} else {
showError();
}
});
}
use of com.example.clown.models.User in project Skool by NhatTruongK15.
the class UsersActivity method getUsers.
private void getUsers() {
loading(true);
FirebaseFirestore database = FirebaseFirestore.getInstance();
database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
loading(false);
String currentUserId = preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_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.name = queryDocumentSnapshot.getString(Constants.KEY_NAME);
user.email = queryDocumentSnapshot.getString(Constants.KEY_EMAIL);
user.image = queryDocumentSnapshot.getString(Constants.KEY_IMAGE);
user.token = queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN);
user.id = queryDocumentSnapshot.getId();
users.add(user);
}
if (users.size() > 0) {
UsersAdapter usersAdapter = new UsersAdapter(users, this);
binding.userRecyclerView.setAdapter(usersAdapter);
binding.userRecyclerView.setVisibility(View.VISIBLE);
} else {
showError();
}
} else {
showError();
}
});
}
use of com.example.clown.models.User in project Skool by NhatTruongK15.
the class MessagingService method onMessageReceived.
@Override
public void onMessageReceived(@NonNull RemoteMessage message) {
super.onMessageReceived(message);
User user = new User();
user.id = message.getData().get(Constants.KEY_DOCUMENT_REFERENCE_ID);
user.name = message.getData().get(Constants.KEY_NAME);
user.token = message.getData().get(Constants.KEY_FCM_TOKEN);
int notificationId = new Random().nextInt();
String channelId = "chat_message";
Intent intent = new Intent(this, ChatActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(Constants.KEY_USER, user);
int flags;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags = FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE;
} else
flags = FLAG_UPDATE_CURRENT;
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, flags);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
builder.setSmallIcon(R.drawable.ic_notification);
builder.setContentTitle(user.name);
builder.setContentText(message.getData().get(Constants.KEY_MESSAGE));
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 notifications";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
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());
}
Aggregations