Search in sources :

Example 11 with User

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

the class CallManager method startIncomingCall.

@RequiresApi(api = Build.VERSION_CODES.M)
public void startIncomingCall(Call call) {
    if (context.checkSelfPermission(Manifest.permission.MANAGE_OWN_CALLS) == PackageManager.PERMISSION_GRANTED) {
        Bundle extras = new Bundle();
        Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getSessionId().substring(0, 11), null);
        extras.putString(UIKitConstants.IntentStrings.SESSION_ID, call.getSessionId());
        extras.putString(UIKitConstants.IntentStrings.TYPE, call.getReceiverType());
        extras.putString(UIKitConstants.IntentStrings.CALL_TYPE, call.getType());
        extras.putString(UIKitConstants.IntentStrings.ID, call.getReceiverUid());
        if (call.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP))
            extras.putString(UIKitConstants.IntentStrings.NAME, ((Group) call.getReceiver()).getName());
        else
            extras.putString(UIKitConstants.IntentStrings.NAME, ((User) call.getCallInitiator()).getName());
        if (call.getType().equalsIgnoreCase(CometChatConstants.CALL_TYPE_VIDEO))
            extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
        else
            extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_AUDIO_ONLY);
        extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
        extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
        extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
        boolean isCallPermitted = false;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            isCallPermitted = telecomManager.isIncomingCallPermitted(phoneAccountHandle);
        } else {
            isCallPermitted = true;
        }
        Log.e("CallManager", "is incoming call permited = " + isCallPermitted + "\n" + phoneAccountHandle.toString());
        try {
            telecomManager.addNewIncomingCall(phoneAccountHandle, extras);
        } catch (SecurityException e) {
            e.printStackTrace();
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "2").setSmallIcon(R.drawable.cc).setContentTitle(((User) call.getCallInitiator()).getName()).setContentText(call.getCallStatus().toUpperCase() + " " + call.getType().toUpperCase() + " " + context.getString(R.string.call)).setColor(context.getColor(R.color.colorPrimary)).setGroup("group_id").setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
            builder.setPriority(NotificationCompat.PRIORITY_HIGH);
            builder.setCategory(NotificationCompat.CATEGORY_CALL);
            builder.addAction(0, "Answers", PendingIntent.getBroadcast(context.getApplicationContext(), 0, getCallIntent("Answer_", call), PendingIntent.FLAG_UPDATE_CURRENT));
            builder.addAction(0, "Decline", PendingIntent.getBroadcast(context.getApplicationContext(), 1, getCallIntent("Decline_", call), PendingIntent.FLAG_UPDATE_CURRENT));
            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            notificationManager.notify(UIKitConstants.Notification.ID, builder.build());
        } catch (Exception e) {
            Log.e("CallManagerError: ", e.getMessage());
        }
    }
}
Also used : Group(com.cometchat.pro.models.Group) User(com.cometchat.pro.models.User) Bundle(android.os.Bundle) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) NotificationCompat(androidx.core.app.NotificationCompat) Uri(android.net.Uri) CometChatException(com.cometchat.pro.exceptions.CometChatException) RequiresApi(androidx.annotation.RequiresApi)

Example 12 with User

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

the class MessageAdapter method setActionData.

/**
 * This method is called whenever viewType of item is Action. It is used to bind
 * ActionMessageViewHolder contents with Action at a given position. It shows action message
 * or call status based on message category
 *
 * @param viewHolder is a object of ActionMessageViewHolder.
 * @param i is a position of item in recyclerView.
 * @see Action
 * @see Call
 * @see BaseMessage
 */
private void setActionData(ActionMessageViewHolder viewHolder, int i) {
    BaseMessage baseMessage = messageList.get(i);
    if (Utils.isDarkMode(context))
        viewHolder.textView.setTextColor(context.getResources().getColor(R.color.textColorWhite));
    else
        viewHolder.textView.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
    viewHolder.textView.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    if (baseMessage instanceof Action) {
        String actionMessage = "";
        if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_JOINED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.joined);
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_MEMBER_ADDED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.added) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_KICKED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.kicked_by) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_BANNED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.ban) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_UNBANNED))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.unban) + " " + ((User) ((Action) baseMessage).getActionOn()).getName();
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_LEFT))
            actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.left);
        else if (((Action) baseMessage).getAction().equals(CometChatConstants.ActionKeys.ACTION_SCOPE_CHANGED))
            if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_MODERATOR)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.moderator);
            } else if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_ADMIN)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.admin);
            } else if (((Action) baseMessage).getNewScope().equals(CometChatConstants.SCOPE_PARTICIPANT)) {
                actionMessage = ((User) ((Action) baseMessage).getActioBy()).getName() + " " + context.getString(R.string.made) + " " + ((User) ((Action) baseMessage).getActionOn()).getName() + " " + context.getString(R.string.participant);
            } else
                actionMessage = ((Action) baseMessage).getMessage();
        viewHolder.textView.setText(actionMessage);
    } else if (baseMessage instanceof Call) {
        Call call = ((Call) baseMessage);
        String callMessageText = "";
        boolean isMissed = false, isIncoming = false, isVideo = false;
        if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_INITIATED)) {
            callMessageText = call.getSender().getName() + " " + context.getString(R.string.initiated);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
            callMessageText = context.getResources().getString(R.string.missed_call);
            isMissed = true;
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
            callMessageText = context.getResources().getString(R.string.rejected_call);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_ONGOING)) {
            callMessageText = context.getString(R.string.ongoing);
        } else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_ENDED)) {
            callMessageText = context.getString(R.string.ended);
        } else {
            callMessageText = call.getCallStatus();
        }
        if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
            isIncoming = false;
        } else {
            isIncoming = true;
        }
        if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
            callMessageText = callMessageText + " " + context.getResources().getString(R.string.video_call);
            isVideo = true;
        } else {
            callMessageText = callMessageText + " " + context.getResources().getString(R.string.audio_call);
            isVideo = false;
        }
        viewHolder.textView.setText(callMessageText);
    }
}
Also used : Call(com.cometchat.pro.core.Call) Action(com.cometchat.pro.models.Action) User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 13 with User

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

the class CometChatMessageList method setLongMessageClick.

@Override
public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
    Log.e(TAG, "setLongMessageClick: " + baseMessagesList);
    isReply = false;
    isEdit = false;
    messageActionFragment = new CometChatMessageActions();
    replyMessageLayout.setVisibility(GONE);
    editMessageLayout.setVisibility(GONE);
    fetchSettings();
    List<BaseMessage> textMessageList = new ArrayList<>();
    List<BaseMessage> mediaMessageList = new ArrayList<>();
    List<BaseMessage> locationMessageList = new ArrayList<>();
    List<BaseMessage> pollsMessageList = new ArrayList<>();
    List<BaseMessage> stickerMessageList = new ArrayList<>();
    List<BaseMessage> whiteBoardMessageList = new ArrayList<>();
    List<BaseMessage> writeBoardMessageList = new ArrayList<>();
    List<BaseMessage> meetingMessageList = new ArrayList<>();
    for (BaseMessage baseMessage : baseMessagesList) {
        if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
            textMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_VIDEO) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_FILE) || baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
            mediaMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
            locationMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
            stickerMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.POLLS)) {
            pollsMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
            whiteBoardMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
            writeBoardMessageList.add(baseMessage);
        } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
            meetingMessageList.add(baseMessage);
        }
    }
    if (textMessageList.size() == 1) {
        BaseMessage basemessage = textMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    editVisible = false;
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
                if (basemessage.getSentAt() == -1) {
                    translateVisible = false;
                    threadVisible = false;
                    deleteVisible = false;
                    editVisible = false;
                    copyVisible = false;
                    forwardVisible = false;
                    reactionVisible = false;
                    replyVisible = false;
                    shareVisible = false;
                    retryVisible = true;
                }
            }
        }
    }
    if (mediaMessageList.size() == 1) {
        translateVisible = false;
        BaseMessage basemessage = mediaMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                copyVisible = false;
                // }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                    editVisible = false;
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                    editVisible = false;
                }
            }
            if (basemessage.getSentAt() == -1) {
                translateVisible = false;
                threadVisible = false;
                deleteVisible = false;
                editVisible = false;
                copyVisible = false;
                forwardVisible = false;
                reactionVisible = false;
                replyVisible = false;
                shareVisible = false;
                retryVisible = true;
            }
        }
    }
    if (locationMessageList.size() == 1) {
        translateVisible = false;
        BaseMessage basemessage = locationMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                copyVisible = false;
                FeatureRestriction.isMessageRepliesEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        replyVisible = booleanVal;
                    }
                });
                shareVisible = false;
                FeatureRestriction.isShareCopyForwardMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                    @Override
                    public void onSuccess(Boolean booleanVal) {
                        forwardVisible = booleanVal;
                    }
                });
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                    editVisible = false;
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                    editVisible = false;
                }
            }
            if (basemessage.getSentAt() == -1) {
                translateVisible = false;
                threadVisible = false;
                deleteVisible = false;
                editVisible = false;
                copyVisible = false;
                forwardVisible = false;
                reactionVisible = false;
                replyVisible = false;
                shareVisible = false;
                retryVisible = true;
            }
        }
    }
    if (pollsMessageList.size() == 1) {
        forwardVisible = false;
        translateVisible = false;
        copyVisible = false;
        editVisible = false;
        shareVisible = false;
        BaseMessage basemessage = pollsMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (stickerMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        translateVisible = false;
        shareVisible = false;
        BaseMessage basemessage = stickerMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (whiteBoardMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        translateVisible = false;
        editVisible = false;
        shareVisible = false;
        BaseMessage basemessage = whiteBoardMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (writeBoardMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        translateVisible = false;
        shareVisible = false;
        BaseMessage basemessage = writeBoardMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getReplyCount() > 0)
                    threadVisible = false;
                else {
                    FeatureRestriction.isThreadedMessagesEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            threadVisible = booleanVal;
                        }
                    });
                }
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    if (meetingMessageList.size() == 1) {
        forwardVisible = false;
        copyVisible = false;
        editVisible = false;
        shareVisible = false;
        replyVisible = true;
        translateVisible = false;
        threadVisible = false;
        BaseMessage basemessage = meetingMessageList.get(0);
        if (basemessage != null && basemessage.getSender() != null) {
            if (basemessage.getDeletedAt() == 0) {
                baseMessage = basemessage;
                if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    FeatureRestriction.isDeleteMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                        @Override
                        public void onSuccess(Boolean booleanVal) {
                            deleteVisible = booleanVal;
                        }
                    });
                } else {
                    if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                        FeatureRestriction.isDeleteMemberMessageEnabled(new FeatureRestriction.OnSuccessListener() {

                            @Override
                            public void onSuccess(Boolean booleanVal) {
                                deleteVisible = booleanVal;
                            }
                        });
                    } else {
                        deleteVisible = false;
                    }
                }
            }
        }
    }
    baseMessages = baseMessagesList;
    Bundle bundle = new Bundle();
    bundle.putBoolean("copyVisible", copyVisible);
    bundle.putBoolean("threadVisible", threadVisible);
    bundle.putBoolean("shareVisible", shareVisible);
    bundle.putBoolean("editVisible", editVisible);
    bundle.putBoolean("deleteVisible", deleteVisible);
    bundle.putBoolean("replyVisible", replyVisible);
    bundle.putBoolean("forwardVisible", forwardVisible);
    bundle.putBoolean("translateVisible", translateVisible);
    bundle.putBoolean("retryVisible", retryVisible);
    bundle.putBoolean("isReactionVisible", reactionVisible);
    if (baseMessage.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP) && !baseMessage.getSender().getUid().equalsIgnoreCase(loggedInUser.getUid())) {
        bundle.putBoolean("privateReplyVisible", replyPrivately);
        bundle.putBoolean("replyPrivatelyVisible", replyVisible);
    }
    if (CometChat.isExtensionEnabled("reactions")) {
        bundle.putBoolean("isReactionVisible", true);
    } else {
        bundle.putBoolean("isReactionVisible", false);
    }
    if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) && baseMessage.getSender().getUid().equals(loggedInUser.getUid())) {
        FeatureRestriction.isDeliveryReceiptsEnabled(new FeatureRestriction.OnSuccessListener() {

            @Override
            public void onSuccess(Boolean booleanVal) {
                if (booleanVal)
                    bundle.putBoolean("messageInfoVisible", true);
            }
        });
    }
    bundle.putString("type", CometChatMessageListActivity.class.getName());
    messageActionFragment.setArguments(bundle);
    if (baseMessage.getSentAt() != 0) {
        if (retryVisible || editVisible || copyVisible || threadVisible || shareVisible || deleteVisible || replyVisible || forwardVisible || reactionVisible) {
            messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
        }
    }
    messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {

        @Override
        public void onReplyMessagePrivately() {
            if (baseMessage != null) {
                User user = baseMessage.getSender();
                Intent intent = new Intent(context, CometChatMessageListActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE, baseMessage.getRawMessage().toString());
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @Override
        public void onPrivateReplyToUser() {
            if (baseMessage != null) {
                User user = baseMessage.getSender();
                Intent intent = new Intent(context, CometChatMessageListActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
                startActivity(intent);
                if (getActivity() != null)
                    getActivity().finish();
            }
        }

        @Override
        public void onThreadMessageClick() {
            startThreadActivity();
        }

        @Override
        public void onEditMessageClick() {
            if (baseMessage != null && baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                isEdit = true;
                isReply = false;
                tvMessageTitle.setText(getResources().getString(R.string.edit_message));
                tvMessageSubTitle.setText(((TextMessage) baseMessage).getText());
                composeBox.ivMic.setVisibility(GONE);
                composeBox.ivSend.setVisibility(View.VISIBLE);
                editMessageLayout.setVisibility(View.VISIBLE);
                composeBox.etComposeBox.setText(((TextMessage) baseMessage).getText());
                if (messageAdapter != null) {
                    messageAdapter.setSelectedMessage(baseMessage.getId());
                    messageAdapter.notifyDataSetChanged();
                }
            }
        }

        @Override
        public void onReplyMessageClick() {
            replyMessage();
        }

        @Override
        public void onForwardMessageClick() {
            startForwardMessageActivity();
        }

        @Override
        public void onDeleteMessageClick() {
            deleteMessage(baseMessage);
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onCopyMessageClick() {
            String message = "";
            for (BaseMessage bMessage : baseMessages) {
                if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
                    message = message + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
                }
            }
            Log.e(TAG, "onCopy: " + message);
            ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("MessageAdapter", message);
            clipboardManager.setPrimaryClip(clipData);
            Toast.makeText(context, getResources().getString(R.string.text_copied), Toast.LENGTH_LONG).show();
            if (messageAdapter != null) {
                messageAdapter.clearLongClickSelectedItem();
                messageAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onShareMessageClick() {
            shareMessage();
        }

        @Override
        public void onMessageInfoClick() {
            Intent intent = new Intent(context, CometChatMessageInfoScreenActivity.class);
            intent.putExtra(UIKitConstants.IntentStrings.ID, baseMessage.getId());
            intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, baseMessage.getType());
            intent.putExtra(UIKitConstants.IntentStrings.SENTAT, baseMessage.getSentAt());
            if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
                intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.checkProfanityMessage(context, baseMessage));
            } else if (baseMessage.getCategory().equals(CometChatConstants.CATEGORY_CUSTOM)) {
                if (((CustomMessage) baseMessage).getCustomData() != null)
                    intent.putExtra(UIKitConstants.IntentStrings.CUSTOM_MESSAGE, ((CustomMessage) baseMessage).getCustomData().toString());
                if (baseMessage.getType().equals(UIKitConstants.IntentStrings.LOCATION)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.LOCATION);
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.STICKERS)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.STICKERS);
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WHITEBOARD);
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWhiteBoardUrl(baseMessage));
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.WRITEBOARD);
                    intent.putExtra(UIKitConstants.IntentStrings.TEXTMESSAGE, Extensions.getWriteBoardUrl(baseMessage));
                } else if (baseMessage.getType().equals(UIKitConstants.IntentStrings.GROUP_CALL)) {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.GROUP_CALL);
                } else {
                    intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE, UIKitConstants.IntentStrings.POLLS);
                }
            } else {
                boolean isImageNotSafe = Extensions.getImageModeration(context, baseMessage);
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_URL, ((MediaMessage) baseMessage).getAttachment().getFileUrl());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_NAME, ((MediaMessage) baseMessage).getAttachment().getFileName());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_SIZE, ((MediaMessage) baseMessage).getAttachment().getFileSize());
                intent.putExtra(UIKitConstants.IntentStrings.MESSAGE_TYPE_IMAGE_EXTENSION, ((MediaMessage) baseMessage).getAttachment().getFileExtension());
                intent.putExtra(UIKitConstants.IntentStrings.IMAGE_MODERATION, isImageNotSafe);
            }
            context.startActivity(intent);
        }

        @Override
        public void onReactionClick(Reaction reaction) {
            if (reaction.getName().equals("add_emoji")) {
                CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
                reactionDialog.setOnEmojiClick(new OnReactionClickListener() {

                    @Override
                    public void onEmojiClicked(Reaction emojicon) {
                        sendReaction(emojicon);
                        reactionDialog.dismiss();
                    }
                });
                reactionDialog.show(getFragmentManager(), "ReactionDialog");
            } else {
                sendReaction(reaction);
            }
        }

        @Override
        public void onTranslateMessageClick() {
            try {
                String localeLanguage = Locale.getDefault().getLanguage();
                JSONObject body = new JSONObject();
                JSONArray languages = new JSONArray();
                languages.put(localeLanguage);
                body.put("msgId", baseMessage.getId());
                body.put("languages", languages);
                body.put("text", ((TextMessage) baseMessage).getText());
                CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {

                    @Override
                    public void onSuccess(JSONObject jsonObject) {
                        if (Extensions.isMessageTranslated(jsonObject, ((TextMessage) baseMessage).getText())) {
                            if (baseMessage.getMetadata() != null) {
                                JSONObject meta = baseMessage.getMetadata();
                                try {
                                    meta.accumulate("values", jsonObject);
                                    baseMessage.setMetadata(meta);
                                    updateMessage(baseMessage);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            } else {
                                baseMessage.setMetadata(jsonObject);
                                updateMessage(baseMessage);
                            }
                        } else {
                            CometChatSnackBar.show(context, rvChatListView, context.getString(R.string.no_translation_available), CometChatSnackBar.WARNING);
                        }
                    }

                    @Override
                    public void onError(CometChatException e) {
                        Toast.makeText(context, e.getCode(), Toast.LENGTH_LONG).show();
                    }
                });
            } catch (Exception e) {
                Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onRetryClick() {
            if (baseMessage != null) {
                messageAdapter.remove(baseMessage);
                if (baseMessage.getType().equalsIgnoreCase(CometChatConstants.MESSAGE_TYPE_TEXT))
                    sendMessage(((TextMessage) baseMessage).getText());
            }
        }
    });
}
Also used : OnReactionClickListener(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.listener.OnReactionClickListener) CometChatException(com.cometchat.pro.exceptions.CometChatException) Action(com.cometchat.pro.models.Action) User(com.cometchat.pro.models.User) MediaMessage(com.cometchat.pro.models.MediaMessage) ArrayList(java.util.ArrayList) CometChatReactionDialog(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.CometChatReactionDialog) BaseMessage(com.cometchat.pro.models.BaseMessage) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) ClipboardManager(android.content.ClipboardManager) Bundle(android.os.Bundle) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Intent(android.content.Intent) Reaction(com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) CometChatMessageInfoScreenActivity(com.cometchat.pro.uikit.ui_components.messages.message_information.CometChatMessageInfoScreenActivity) CometChatMessageActions(com.cometchat.pro.uikit.ui_components.messages.message_actions.CometChatMessageActions) ClipData(android.content.ClipData) TextMessage(com.cometchat.pro.models.TextMessage)

Example 14 with User

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

the class CometChatAddMembers method init.

public void init(View view) {
    // Inflate the layout
    setHasOptionsMenu(true);
    rvUserList = view.findViewById(R.id.rv_user_list);
    etSearch = view.findViewById(R.id.search_bar);
    toolbar = view.findViewById(R.id.add_member_toolbar);
    CometChatError.init(getContext());
    setToolbar(toolbar);
    checkDarkMode();
    clearSearch = view.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() > 0)
                clearSearch.setVisibility(View.VISIBLE);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    etSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH) {
                searchUser(textView.getText().toString());
                clearSearch.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }
    });
    clearSearch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            etSearch.setText("");
            clearSearch.setVisibility(View.GONE);
            searchUser(etSearch.getText().toString());
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            // Hide the soft keyboard
            if (inputMethodManager != null)
                inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
        }
    });
    rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                fetchUsers();
            }
        }
    });
    rvUserList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rvUserList, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            User user = (User) var1.getTag(R.string.user);
            if (getActivity() != null) {
                Intent intent = new Intent(getActivity(), CometChatUserDetailScreenActivity.class);
                intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
                intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
                intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.IS_BLOCKED_BY_ME, user.isBlockedByMe());
                intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_GROUP);
                intent.putExtra(UIKitConstants.IntentStrings.GUID, guid);
                intent.putExtra(UIKitConstants.IntentStrings.IS_ADD_MEMBER, true);
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_NAME, groupName);
                getActivity().finish();
                startActivity(intent);
            }
        }

        @Override
        public void onLongClick(View var1, int var2) {
        }
    }));
}
Also used : EditText(android.widget.EditText) RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) User(com.cometchat.pro.models.User) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Example 15 with User

use of com.cometchat.pro.models.User 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)

Aggregations

User (com.cometchat.pro.models.User)28 CometChatException (com.cometchat.pro.exceptions.CometChatException)12 View (android.view.View)10 Intent (android.content.Intent)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 CometChat (com.cometchat.pro.core.CometChat)8 BaseMessage (com.cometchat.pro.models.BaseMessage)7 TextView (android.widget.TextView)6 Call (com.cometchat.pro.core.Call)6 Group (com.cometchat.pro.models.Group)6 Editable (android.text.Editable)5 TextWatcher (android.text.TextWatcher)5 ImageView (android.widget.ImageView)5 Conversation (com.cometchat.pro.models.Conversation)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ViewGroup (android.view.ViewGroup)4 InputMethodManager (android.view.inputmethod.InputMethodManager)4 UsersRequest (com.cometchat.pro.core.UsersRequest)4 KeyEvent (android.view.KeyEvent)3