Search in sources :

Example 21 with MediaMessage

use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatForwardMessageActivity method init.

/**
 * This method is used to initialize the views
 */
public void init() {
    // Inflate the layout
    MaterialToolbar toolbar = findViewById(R.id.forward_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (Utils.changeToolbarFont(toolbar) != null) {
        Utils.changeToolbarFont(toolbar).setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    }
    selectedUsers = findViewById(R.id.selected_user);
    forwardBtn = findViewById(R.id.btn_forward);
    rvConversationList = findViewById(R.id.rv_conversation_list);
    etSearch = findViewById(R.id.search_bar);
    clearSearch = findViewById(R.id.clear_search);
    etSearch.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.length() > 1)
                clearSearch.setVisibility(View.VISIBLE);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.toString().length() != 0) {
                if (conversationListAdapter != null)
                    conversationListAdapter.getFilter().filter(editable.toString());
            }
        }
    });
    etSearch.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_SEARCH) {
            if (conversationListAdapter != null)
                conversationListAdapter.getFilter().filter(textView.getText().toString());
            clearSearch.setVisibility(View.VISIBLE);
            return true;
        }
        return false;
    });
    clearSearch.setOnClickListener(view1 -> {
        etSearch.setText("");
        clearSearch.setVisibility(View.GONE);
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        // Hide the soft keyboard
        inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
    });
    rvConversationList.setItemClickListener(new OnItemClickListener<Conversation>() {

        @Override
        public void OnItemClick(Conversation conversation, int position) {
            if (userList != null && userList.size() < 5) {
                if (!userList.containsKey(conversation.getConversationId())) {
                    userList.put(conversation.getConversationId(), conversation);
                    Chip chip = new Chip(CometChatForwardMessageActivity.this);
                    if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER)) {
                        name = ((User) conversation.getConversationWith()).getName();
                        avatar = ((User) conversation.getConversationWith()).getAvatar();
                    } else {
                        name = ((Group) conversation.getConversationWith()).getName();
                        avatar = ((Group) conversation.getConversationWith()).getIcon();
                    }
                    chip.setText(name);
                    Glide.with(CometChatForwardMessageActivity.this).load(avatar).placeholder(R.drawable.ic_contacts).transform(new CircleCrop()).into(new SimpleTarget<Drawable>() {

                        @Override
                        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                            chip.setChipIcon(resource);
                        }
                    });
                    chip.setCloseIconVisible(true);
                    chip.setOnCloseIconClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View vw) {
                            userList.remove(conversation.getConversationId());
                            selectedUsers.removeView(vw);
                            checkUserList();
                        }
                    });
                    selectedUsers.addView(chip, 0);
                }
                checkUserList();
            } else {
                CometChatSnackBar.show(CometChatForwardMessageActivity.this, selectedUsers, getString(R.string.forward_to_5_at_a_time), CometChatSnackBar.WARNING);
            }
        }
    });
    // It sends message to selected users present in userList using thread. So UI thread doesn't get heavy.
    forwardBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (messageCategory.equals(CometChatConstants.CATEGORY_MESSAGE)) {
                if (messageType != null && messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                    new Thread(() -> {
                        for (int i = 0; i <= userList.size() - 1; i++) {
                            Conversation conversation = new ArrayList<>(userList.values()).get(i);
                            TextMessage message;
                            String uid;
                            String type;
                            Log.e(TAG, "run: " + conversation.getConversationId());
                            if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER)) {
                                uid = ((User) conversation.getConversationWith()).getUid();
                                type = CometChatConstants.RECEIVER_TYPE_USER;
                            } else {
                                uid = ((Group) conversation.getConversationWith()).getGuid();
                                type = CometChatConstants.RECEIVER_TYPE_GROUP;
                            }
                            message = new TextMessage(uid, textMessage, type);
                            sendMessage(message);
                            if (i == userList.size() - 1) {
                                Intent intent = new Intent(CometChatForwardMessageActivity.this, CometChatUI.class);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(intent);
                                finish();
                            }
                        }
                    }).start();
                } else if (messageType != null && (messageType.equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO) || messageType.equals(CometChatConstants.MESSAGE_TYPE_FILE) || messageType.equals(CometChatConstants.MESSAGE_TYPE_VIDEO))) {
                    new Thread(() -> {
                        for (int i = 0; i <= userList.size() - 1; i++) {
                            Conversation conversation = new ArrayList<>(userList.values()).get(i);
                            MediaMessage message;
                            String uid;
                            String type;
                            Log.e(TAG, "run: " + conversation.getConversationId());
                            if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER)) {
                                uid = ((User) conversation.getConversationWith()).getUid();
                                type = CometChatConstants.RECEIVER_TYPE_USER;
                            } else {
                                uid = ((Group) conversation.getConversationWith()).getGuid();
                                type = CometChatConstants.RECEIVER_TYPE_GROUP;
                            }
                            message = new MediaMessage(uid, null, messageType, type);
                            Attachment attachment = new Attachment();
                            attachment.setFileUrl(mediaMessageUrl);
                            attachment.setFileMimeType(mediaMessageMime);
                            attachment.setFileSize(mediaMessageSize);
                            attachment.setFileExtension(mediaMessageExtension);
                            attachment.setFileName(mediaMessageName);
                            message.setAttachment(attachment);
                            Log.e(TAG, "onClick: " + attachment.toString());
                            sendMediaMessage(message, i);
                        // if (i == userList.size() - 1) {
                        // Intent intent = new Intent(CometChatForwardMessageActivity.this, CometChatUI.class);
                        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        // startActivity(intent);
                        // finish();
                        // }
                        }
                    }).start();
                } else if (messageType != null && (messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_IMAGE_MESSAGE) || messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_VIDEO_MESSAGE) || messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_AUDIO_MESSAGE) || messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_FILE_MESSAGE))) {
                    new Thread(() -> {
                        for (int i = 0; i <= userList.size() - 1; i++) {
                            Conversation conversation = new ArrayList<>(userList.values()).get(i);
                            MediaMessage message = null;
                            String uid;
                            String type;
                            Log.e(TAG, "run: " + conversation.getConversationId());
                            if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER)) {
                                uid = ((User) conversation.getConversationWith()).getUid();
                                type = CometChatConstants.RECEIVER_TYPE_USER;
                            } else {
                                uid = ((Group) conversation.getConversationWith()).getGuid();
                                type = CometChatConstants.RECEIVER_TYPE_GROUP;
                            }
                            File file = MediaUtils.getRealPath(CometChatForwardMessageActivity.this, Uri.parse(mediaMessageUrl), true);
                            if (messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_IMAGE_MESSAGE))
                                message = new MediaMessage(uid, file, CometChatConstants.MESSAGE_TYPE_IMAGE, type);
                            else if (messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_VIDEO_MESSAGE))
                                message = new MediaMessage(uid, file, CometChatConstants.MESSAGE_TYPE_VIDEO, type);
                            else if (messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_AUDIO_MESSAGE))
                                message = new MediaMessage(uid, file, CometChatConstants.MESSAGE_TYPE_AUDIO, type);
                            else if (messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.INTENT_MEDIA_FILE_MESSAGE))
                                message = new MediaMessage(uid, file, CometChatConstants.MESSAGE_TYPE_FILE, type);
                            try {
                                JSONObject jsonObject = new JSONObject();
                                jsonObject.put("path", mediaMessageUrl);
                                message.setMetadata(jsonObject);
                            } catch (Exception e) {
                                Log.e(TAG, "onError: " + e.getMessage());
                            }
                            sendMediaMessage(message, i);
                        }
                    }).start();
                } else {
                    if (messageType != null && messageType.equalsIgnoreCase(UIKitConstants.IntentStrings.LOCATION)) {
                        new Thread(() -> {
                            for (int i = 0; i <= userList.size() - 1; i++) {
                                Conversation conversation = new ArrayList<>(userList.values()).get(i);
                                CustomMessage message;
                                String uid;
                                JSONObject customData = new JSONObject();
                                String type;
                                Log.e(TAG, "run: " + conversation.getConversationId());
                                if (conversation.getConversationType().equals(CometChatConstants.CONVERSATION_TYPE_USER)) {
                                    uid = ((User) conversation.getConversationWith()).getUid();
                                    type = CometChatConstants.RECEIVER_TYPE_USER;
                                } else {
                                    uid = ((Group) conversation.getConversationWith()).getGuid();
                                    type = CometChatConstants.RECEIVER_TYPE_GROUP;
                                }
                                try {
                                    customData = new JSONObject();
                                    customData.put("latitude", lat);
                                    customData.put("longitude", lon);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                message = new CustomMessage(uid, type, UIKitConstants.IntentStrings.LOCATION, customData);
                                sendLocationMessage(message);
                                if (i == userList.size() - 1) {
                                    Intent intent = new Intent(CometChatForwardMessageActivity.this, CometChatUI.class);
                                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                    startActivity(intent);
                                    finish();
                                }
                            }
                        }).start();
                    }
                }
            }
        }
    });
    rvConversationList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                makeConversationList();
            }
        }
    });
}
Also used : ChipGroup(com.google.android.material.chip.ChipGroup) Group(com.cometchat.pro.models.Group) User(com.cometchat.pro.models.User) MediaMessage(com.cometchat.pro.models.MediaMessage) ArrayList(java.util.ArrayList) InputMethodManager(android.view.inputmethod.InputMethodManager) Conversation(com.cometchat.pro.models.Conversation) Attachment(com.cometchat.pro.models.Attachment) Chip(com.google.android.material.chip.Chip) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) MaterialToolbar(com.google.android.material.appbar.MaterialToolbar) NonNull(androidx.annotation.NonNull) CustomMessage(com.cometchat.pro.models.CustomMessage) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Drawable(android.graphics.drawable.Drawable) JSONException(org.json.JSONException) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) CircleCrop(com.bumptech.glide.load.resource.bitmap.CircleCrop) JSONObject(org.json.JSONObject) Transition(com.bumptech.glide.request.transition.Transition) RecyclerView(androidx.recyclerview.widget.RecyclerView) File(java.io.File) Nullable(androidx.annotation.Nullable) TextMessage(com.cometchat.pro.models.TextMessage)

Example 22 with MediaMessage

use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedMediaAdapter method setFileData.

private void setFileData(FileViewHolder viewHolder, int i) {
    BaseMessage message = messageArrayList.get(i);
    viewHolder.fileName.setText(((MediaMessage) message).getAttachment().getFileName());
    viewHolder.fileExtension.setText(((MediaMessage) message).getAttachment().getFileExtension());
    viewHolder.itemView.setOnClickListener(view -> {
        MediaUtils.openFile(((MediaMessage) message).getAttachment().getFileUrl(), context);
    });
    viewHolder.itemView.setTag(R.string.baseMessage, message);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 23 with MediaMessage

use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatSharedMediaAdapter method setImageData.

private void setImageData(ImageViewHolder viewHolder, int i) {
    BaseMessage message = messageArrayList.get(i);
    boolean isImageNotSafe = Extensions.getImageModeration(context, message);
    String smallUrl = Extensions.getThumbnailGeneration(context, message);
    if (smallUrl != null) {
        Glide.with(context).asBitmap().load(smallUrl).into(viewHolder.imageView);
    } else {
        Glide.with(context).asBitmap().load(((MediaMessage) message).getAttachment().getFileUrl()).into(viewHolder.imageView);
    }
    if (isImageNotSafe) {
        viewHolder.imageView.setAlpha(0.3f);
        viewHolder.sensitiveLayout.setVisibility(View.VISIBLE);
    } else {
        viewHolder.imageView.setAlpha(1f);
        viewHolder.sensitiveLayout.setVisibility(View.GONE);
    }
    viewHolder.imageView.setOnClickListener(view -> {
        if (isImageNotSafe) {
            AlertDialog.Builder alert = new AlertDialog.Builder(context);
            alert.setTitle("Unsafe Content");
            alert.setIcon(R.drawable.ic_hand);
            alert.setMessage("Are you surely want to see this unsafe content");
            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MediaUtils.openFile(((MediaMessage) message).getAttachment().getFileUrl(), context);
                }
            });
            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            alert.create().show();
        } else {
            Intent intent = new Intent(context, CometChatMediaViewActivity.class);
            intent.putExtra(UIKitConstants.IntentStrings.NAME, message.getSender().getName());
            intent.putExtra(UIKitConstants.IntentStrings.UID, message.getSender().getUid());
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, message.getSentAt());
            intent.putExtra(UIKitConstants.IntentStrings.INTENT_MEDIA_MESSAGE, ((MediaMessage) message).getAttachment().getFileUrl());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, message.getType());
            context.startActivity(intent);
        }
    });
    viewHolder.itemView.setTag(R.string.baseMessage, message);
}
Also used : AlertDialog(android.app.AlertDialog) MediaMessage(com.cometchat.pro.models.MediaMessage) BaseMessage(com.cometchat.pro.models.BaseMessage) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent)

Example 24 with MediaMessage

use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class PushNotificationActivity method sendMediaMessage.

private void sendMediaMessage(File file, String messageType) {
    // subscribePushNotification();
    progressDialog.show();
    MediaMessage mediaMessage = new MediaMessage(uid.getText().toString(), file, messageType, receiver);
    sendMessage(mediaMessage);
}
Also used : MediaMessage(com.cometchat.pro.models.MediaMessage)

Example 25 with MediaMessage

use of com.cometchat.pro.models.MediaMessage in project android-java-chat-push-notification-app by cometchat-pro.

the class MyFirebaseMessagingService method showNotifcation.

private void showNotifcation(BaseMessage baseMessage) {
    try {
        int m = (int) ((new Date().getTime()));
        String GROUP_ID = "group_id";
        Intent messageIntent = new Intent(getApplicationContext(), CometChatMessageListActivity.class);
        messageIntent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
        if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
            messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
            messageIntent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
            messageIntent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
            messageIntent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage.getSender().getStatus());
        } else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
            messageIntent.putExtra(UIKitConstants.IntentStrings.GUID, ((Group) baseMessage.getReceiver()).getGuid());
            messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, ((Group) baseMessage.getReceiver()).getName());
            messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, ((Group) baseMessage.getReceiver()).getDescription());
            messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, ((Group) baseMessage.getReceiver()).getGroupType());
            messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, ((Group) baseMessage.getReceiver()).getOwner());
            messageIntent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, ((Group) baseMessage.getReceiver()).getMembersCount());
        }
        PendingIntent messagePendingIntent = PendingIntent.getActivity(getApplicationContext(), 0123, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "2").setSmallIcon(R.drawable.cc).setContentTitle(json.getString("title")).setContentText(json.getString("alert")).setColor(getResources().getColor(R.color.colorPrimary)).setLargeIcon(getBitmapFromURL(baseMessage.getSender().getAvatar())).setGroup(GROUP_ID).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
            builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(getBitmapFromURL(((MediaMessage) baseMessage).getAttachment().getFileUrl())));
        }
        NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(this, "2").setContentTitle("CometChat").setContentText(count + " messages").setSmallIcon(R.drawable.cc).setGroup(GROUP_ID).setGroupSummary(true);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        if (isCall) {
            builder.setGroup(GROUP_ID + "Call");
            if (json.getString("alert").equals("Incoming audio call") || json.getString("alert").equals("Incoming video call")) {
                builder.setOngoing(true);
                builder.setPriority(NotificationCompat.PRIORITY_HIGH);
                Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_call);
                builder.setCategory(NotificationCompat.CATEGORY_CALL);
                builder.setSound(notification);
                builder.addAction(0, "Answers", PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, getCallIntent("Answers"), PendingIntent.FLAG_UPDATE_CURRENT));
                builder.addAction(0, "Decline", PendingIntent.getBroadcast(getApplicationContext(), 1, getCallIntent("Decline"), PendingIntent.FLAG_UPDATE_CURRENT));
            }
            if (UIKitApplication.isBackground)
                notificationManager.notify(05, builder.build());
        } else {
            // Person person = createPerson(baseMessage);
            // builder.setStyle(new NotificationCompat.MessagingStyle(person)
            // .setGroupConversation(true)
            // .setConversationTitle(json.getString("title"))
            // .addMessage(json.getString("alert"),
            // currentTimeMillis(), person));
            builder.setPriority(NotificationCompat.PRIORITY_HIGH);
            builder.setContentIntent(messagePendingIntent);
            builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
            // Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_message);
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
            notificationManager.notify(baseMessage.getId(), builder.build());
            notificationManager.notify(0, summaryBuilder.build());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Group(com.cometchat.pro.models.Group) MediaMessage(com.cometchat.pro.models.MediaMessage) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) Date(java.util.Date) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) IOException(java.io.IOException) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

MediaMessage (com.cometchat.pro.models.MediaMessage)25 Intent (android.content.Intent)16 BaseMessage (com.cometchat.pro.models.BaseMessage)14 JSONException (org.json.JSONException)11 View (android.view.View)10 ImageView (android.widget.ImageView)10 RecyclerView (androidx.recyclerview.widget.RecyclerView)10 CometChatException (com.cometchat.pro.exceptions.CometChatException)10 TextView (android.widget.TextView)9 CardView (androidx.cardview.widget.CardView)9 MaterialCardView (com.google.android.material.card.MaterialCardView)9 JSONObject (org.json.JSONObject)8 Attachment (com.cometchat.pro.models.Attachment)6 FeatureRestriction (com.cometchat.pro.uikit.ui_settings.FeatureRestriction)6 TextMessage (com.cometchat.pro.models.TextMessage)5 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)3