Search in sources :

Example 1 with User

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();
        }
    });
}
Also used : UsersGCAdapter(com.example.clown.adapter.UsersGCAdapter) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.clown.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Example 2 with User

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();
        }
    });
}
Also used : UsersAdapter(com.example.clown.adapter.UsersAdapter) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.clown.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 3 with User

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());
}
Also used : User(com.example.clown.models.User) NotificationManager(android.app.NotificationManager) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NotificationChannel(android.app.NotificationChannel) Random(java.util.Random) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

User (com.example.clown.models.User)3 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)2 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)2 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (androidx.core.app.NotificationCompat)1 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)1 UsersAdapter (com.example.clown.adapter.UsersAdapter)1 UsersGCAdapter (com.example.clown.adapter.UsersGCAdapter)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1