use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction in project android-java-chat-push-notification-app by cometchat-pro.
the class EmojiAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = View.inflate(getContext(), R.layout.rsc_emoji_item, null);
ViewHolder viewHolder = new ViewHolder(view);
view.setTag(viewHolder);
}
if (null != getItem(position)) {
Reaction emoji = this.getItem(position);
ViewHolder holder = (ViewHolder) view.getTag();
holder.icon.setText(new String(Character.toChars(emoji.getCode())));
}
return view;
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method showBottomSheet.
private void showBottomSheet(CometChatMessageActions messageActionFragment) {
messageActionFragment.show(getFragmentManager(), messageActionFragment.getTag());
messageActionFragment.setMessageActionListener(new CometChatMessageActions.MessageActionListener() {
@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.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.TYPE, CometChatConstants.RECEIVER_TYPE_USER);
startActivity(intent);
if (getActivity() != null)
getActivity().finish();
}
}
@Override
public void onThreadMessageClick() {
}
@Override
public void onEditMessageClick() {
if (isParent)
editParentMessage();
else
editThreadMessage();
}
@Override
public void onReplyMessageClick() {
}
@Override
public void onReplyMessagePrivately() {
}
@Override
public void onForwardMessageClick() {
if (isParent)
startForwardThreadActivity();
else
startForwardMessageActivity();
}
@Override
public void onDeleteMessageClick() {
deleteMessage(baseMessage);
if (messageAdapter != null) {
messageAdapter.clearLongClickSelectedItem();
messageAdapter.notifyDataSetChanged();
}
}
@Override
public void onCopyMessageClick() {
String copyMessage = "";
if (isParent) {
copyMessage = message;
isParent = true;
} else {
for (BaseMessage bMessage : baseMessages) {
if (bMessage.getDeletedAt() == 0 && bMessage instanceof TextMessage) {
copyMessage = copyMessage + "[" + Utils.getLastMessageDate(context, bMessage.getSentAt()) + "] " + bMessage.getSender().getName() + ": " + ((TextMessage) bMessage).getText();
}
}
isParent = false;
}
Log.e(TAG, "onCopy: " + message);
ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("ThreadMessageAdapter", copyMessage);
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);
if (isParent) {
} else {
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 {
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);
if (isParent) {
body.put("msgId", parentId);
body.put("text", textMessage.getText().toString());
} else {
body.put("msgId", baseMessage.getId());
body.put("text", ((TextMessage) baseMessage).getText());
}
body.put("languages", languages);
CometChat.callExtension("message-translation", "POST", "/v2/translate", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
if (isParent) {
if (Extensions.isMessageTranslated(jsonObject, textMessage.getText().toString())) {
String translatedMessage = Extensions.getTextFromTranslatedMessage(jsonObject, textMessage.getText().toString());
textMessage.setText(translatedMessage);
} else {
CometChatSnackBar.show(context, rvChatListView, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
} else {
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, getString(R.string.no_translation_available), CometChatSnackBar.INFO);
}
}
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "message-translation"), CometChatSnackBar.ERROR);
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onRetryClick() {
}
});
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageActions method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_cometchat_message_actions, container, false);
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
BottomSheetDialog dialog = (BottomSheetDialog) getDialog();
// androidx should use: com.google.android.material.R.id.design_bottom_sheet
FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
behavior.setPeekHeight(0);
}
});
reactionsList = view.findViewById(R.id.initial_reactions);
List<Reaction> reactions = Extensions.getInitialReactions(INITIAL_REACTION_COUNT);
for (Reaction reaction : reactions) {
View vw = LayoutInflater.from(getContext()).inflate(R.layout.reaction_list_row, null);
TextView textView = vw.findViewById(R.id.reaction);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.leftMargin = 16;
params.rightMargin = 16;
params.bottomMargin = 8;
params.topMargin = 8;
textView.setLayoutParams(params);
textView.setText(reaction.getName());
reactionsList.addView(vw);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (messageActionListener != null)
messageActionListener.onReactionClick(reaction);
dismiss();
}
});
}
ImageView addEmojiView = new ImageView(getContext());
addEmojiView.setImageDrawable(getResources().getDrawable(R.drawable.ic_reactions));
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams((int) Utils.dpToPx(getContext(), 36), (int) Utils.dpToPx(getContext(), 36));
layoutParams.topMargin = 8;
layoutParams.leftMargin = 16;
addEmojiView.setLayoutParams(layoutParams);
reactionsList.addView(addEmojiView);
addEmojiView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (messageActionListener != null)
messageActionListener.onReactionClick(new Reaction("add_emoji", 0));
dismiss();
}
});
retryMessage = view.findViewById(R.id.retry_message);
translateMessage = view.findViewById(R.id.translate_message);
threadMessage = view.findViewById(R.id.start_thread);
editMessage = view.findViewById(R.id.edit_message);
replyMessage = view.findViewById(R.id.reply_message);
forwardMessage = view.findViewById(R.id.forward_message);
deleteMessage = view.findViewById(R.id.delete_message);
copyMessage = view.findViewById(R.id.copy_message);
shareMessage = view.findViewById(R.id.share_message);
messageInfo = view.findViewById(R.id.message_info);
messagePrivately = view.findViewById(R.id.reply_privately);
replyMessagePrivately = view.findViewById(R.id.reply_message_privately);
if (isPrivateReplyVisible)
messagePrivately.setVisibility(View.VISIBLE);
else
messagePrivately.setVisibility(View.GONE);
if (isReplyPrivatelyVisible)
replyMessagePrivately.setVisibility(View.VISIBLE);
else
replyMessagePrivately.setVisibility(View.GONE);
if (isPrivateReplyVisible)
messagePrivately.setVisibility(View.VISIBLE);
else
messagePrivately.setVisibility(View.GONE);
if (isRetryVisible)
retryMessage.setVisibility(View.VISIBLE);
else
retryMessage.setVisibility(View.GONE);
if (isTranslateVisible)
translateMessage.setVisibility(View.VISIBLE);
else
translateMessage.setVisibility(View.GONE);
if (isReactionsVisible)
reactionsList.setVisibility(View.VISIBLE);
else
reactionsList.setVisibility(View.GONE);
if (isThreadVisible)
threadMessage.setVisibility(View.VISIBLE);
else
threadMessage.setVisibility(View.GONE);
if (isCopyVisible)
copyMessage.setVisibility(View.VISIBLE);
else
copyMessage.setVisibility(View.GONE);
if (isEditVisible)
editMessage.setVisibility(View.VISIBLE);
else
editMessage.setVisibility(View.GONE);
if (isDeleteVisible)
deleteMessage.setVisibility(View.VISIBLE);
else
deleteMessage.setVisibility(View.GONE);
if (isReplyVisible)
replyMessage.setVisibility(View.VISIBLE);
else
replyMessage.setVisibility(View.GONE);
if (isForwardVisible)
forwardMessage.setVisibility(View.VISIBLE);
else
forwardMessage.setVisibility(View.GONE);
if (isShareVisible)
shareMessage.setVisibility(View.VISIBLE);
else
shareMessage.setVisibility(View.GONE);
if (isMessageInfoVisible)
messageInfo.setVisibility(View.VISIBLE);
else
messageInfo.setVisibility(View.GONE);
if (type != null && type.equals(CometChatThreadMessageListActivity.class.getName())) {
threadMessage.setVisibility(View.GONE);
}
replyMessagePrivately.setOnClickListener(v -> {
if (messageActionListener != null)
messageActionListener.onReplyMessagePrivately();
dismiss();
});
messagePrivately.setOnClickListener(v -> {
if (messageActionListener != null) {
messageActionListener.onPrivateReplyToUser();
dismiss();
}
});
retryMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onRetryClick();
dismiss();
}
});
translateMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (messageActionListener != null)
messageActionListener.onTranslateMessageClick();
dismiss();
}
});
threadMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onThreadMessageClick();
dismiss();
}
});
copyMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onCopyMessageClick();
dismiss();
}
});
editMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onEditMessageClick();
dismiss();
}
});
deleteMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onDeleteMessageClick();
dismiss();
}
});
replyMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onReplyMessageClick();
dismiss();
}
});
forwardMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onForwardMessageClick();
dismiss();
}
});
shareMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onShareMessageClick();
dismiss();
}
});
messageInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (messageActionListener != null)
messageActionListener.onMessageInfoClick();
dismiss();
}
});
return view;
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatThreadMessageList method initViewComponent.
/**
* This is a main method which is used to initialize the view for this fragment.
*
* @param view
*/
private void initViewComponent(View view) {
setHasOptionsMenu(true);
CometChatError.init(getContext());
nestedScrollView = view.findViewById(R.id.nested_scrollview);
noReplyMessages = view.findViewById(R.id.no_reply_layout);
ivMoreOption = view.findViewById(R.id.ic_more_option);
ivMoreOption.setOnClickListener(this);
ivForwardMessage = view.findViewById(R.id.ic_forward_option);
ivForwardMessage.setOnClickListener(this);
textMessage = view.findViewById(R.id.tv_textMessage);
imageMessage = view.findViewById(R.id.iv_imageMessage);
videoMessage = view.findViewById(R.id.vv_videoMessage);
fileMessage = view.findViewById(R.id.rl_fileMessage);
locationMessage = view.findViewById(R.id.rl_locationMessage);
mapView = view.findViewById(R.id.iv_mapView);
addressView = view.findViewById(R.id.tv_address);
fileName = view.findViewById(R.id.tvFileName);
fileSize = view.findViewById(R.id.tvFileSize);
fileExtension = view.findViewById(R.id.tvFileExtension);
stickerMessage = view.findViewById(R.id.iv_stickerMessage);
whiteboardMessage = view.findViewById(R.id.whiteboard_vw);
whiteBoardTxt = view.findViewById(R.id.whiteboard_message);
joinWhiteBoard = view.findViewById(R.id.join_whiteboard);
writeboardMessage = view.findViewById(R.id.writeboard_vw);
writeBoardTxt = view.findViewById(R.id.writeboard_message);
joinWriteBoard = view.findViewById(R.id.join_whiteboard);
pollMessage = view.findViewById(R.id.poll_message);
pollQuestionTv = view.findViewById(R.id.tv_question);
pollOptionsLL = view.findViewById(R.id.options_group);
totalCount = view.findViewById(R.id.total_votes);
if (messageType.equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
imageMessage.setVisibility(View.VISIBLE);
Glide.with(context).load(message).into(imageMessage);
} else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_VIDEO)) {
videoMessage.setVisibility(VISIBLE);
MediaController mediacontroller = new MediaController(getContext());
mediacontroller.setAnchorView(videoMessage);
videoMessage.setMediaController(mediacontroller);
videoMessage.setVideoURI(Uri.parse(message));
} else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_FILE) || messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
fileMessage.setVisibility(VISIBLE);
if (messageFileName != null)
fileName.setText(messageFileName);
if (messageExtension != null)
fileExtension.setText(messageExtension);
fileSize.setText(Utils.getFileSize(messageSize));
} else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
textMessage.setVisibility(View.VISIBLE);
textMessage.setText(message);
} else if (messageType.equals(UIKitConstants.IntentStrings.STICKERS)) {
ivForwardMessage.setVisibility(GONE);
stickerMessage.setVisibility(View.VISIBLE);
Glide.with(context).load(message).into(stickerMessage);
} else if (messageType.equals(UIKitConstants.IntentStrings.WHITEBOARD)) {
ivForwardMessage.setVisibility(GONE);
whiteboardMessage.setVisibility(View.VISIBLE);
if (name.equals(loggedInUser.getName()))
whiteBoardTxt.setText(getString(R.string.you_created_whiteboard));
else
whiteBoardTxt.setText(name + " " + getString(R.string.has_shared_whiteboard));
joinWhiteBoard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String boardUrl = message;
Intent intent = new Intent(context, CometChatWebViewActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.URL, boardUrl);
startActivity(intent);
}
});
} else if (messageType.equals(UIKitConstants.IntentStrings.WRITEBOARD)) {
ivForwardMessage.setVisibility(GONE);
writeboardMessage.setVisibility(View.VISIBLE);
if (name.equals(loggedInUser.getName()))
writeBoardTxt.setText(getString(R.string.you_created_document));
else
writeBoardTxt.setText(name + " " + getString(R.string.has_shared_document));
joinWriteBoard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String boardUrl = message;
Intent intent = new Intent(context, CometChatWebViewActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.URL, boardUrl);
startActivity(intent);
}
});
} else if (messageType.equals(UIKitConstants.IntentStrings.LOCATION)) {
initLocation();
locationMessage.setVisibility(VISIBLE);
addressView.setText(Utils.getAddress(context, parentMessageLatitude, parentMessageLongitude));
String mapUrl = UIKitConstants.MapUrl.MAPS_URL + parentMessageLatitude + "," + parentMessageLongitude + "&key=" + UIKitConstants.MapUrl.MAP_ACCESS_KEY;
Glide.with(context).load(mapUrl).diskCacheStrategy(DiskCacheStrategy.ALL).into(mapView);
} else if (messageType.equals(UIKitConstants.IntentStrings.POLLS)) {
ivForwardMessage.setVisibility(GONE);
pollMessage.setVisibility(VISIBLE);
totalCount.setText(voteCount + " Votes");
pollQuestionTv.setText(pollQuestion);
try {
JSONObject options = new JSONObject(pollOptions);
ArrayList<String> voterInfo = pollResult;
for (int k = 0; k < options.length(); k++) {
LinearLayout linearLayout = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
linearLayout.setPadding(8, 8, 8, 8);
linearLayout.setBackground(context.getResources().getDrawable(R.drawable.cc_message_bubble_right));
linearLayout.setBackgroundTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.textColorWhite)));
layoutParams.bottomMargin = (int) Utils.dpToPx(context, 8);
linearLayout.setLayoutParams(layoutParams);
TextView textViewPercentage = new TextView(context);
TextView textViewOption = new TextView(context);
textViewPercentage.setPadding(16, 4, 0, 4);
textViewOption.setPadding(16, 4, 0, 4);
textViewOption.setTextAppearance(context, R.style.TextAppearance_AppCompat_Medium);
textViewPercentage.setTextAppearance(context, R.style.TextAppearance_AppCompat_Medium);
textViewPercentage.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
textViewOption.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
String optionStr = options.getString(String.valueOf(k + 1));
if (voteCount > 0) {
int percentage = Math.round((Integer.parseInt(voterInfo.get(k)) * 100) / voteCount);
if (percentage > 0)
textViewPercentage.setText(percentage + "% ");
}
textViewOption.setText(optionStr);
int finalK = k;
if (pollOptionsLL.getChildCount() != options.length()) {
linearLayout.addView(textViewPercentage);
linearLayout.addView(textViewOption);
pollOptionsLL.addView(linearLayout);
}
textViewOption.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("vote", finalK + 1);
jsonObject.put("id", baseMessage.getId());
CometChat.callExtension("polls", "POST", "/v1/vote", jsonObject, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
// Voted successfully
Log.e(TAG, "onSuccess: " + jsonObject.toString());
CometChatSnackBar.show(context, rvChatListView, context.getString(R.string.voted_success), CometChatSnackBar.SUCCESS);
}
@Override
public void onError(CometChatException e) {
// Some error occured
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "polls"), CometChatSnackBar.ERROR);
}
});
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "onError: " + e.getMessage());
}
}
});
}
} catch (Exception e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "setPollsData: " + e.getMessage());
}
}
addReaction = view.findViewById(R.id.add_reaction);
reactionLayout = view.findViewById(R.id.reactions_layout);
if (reactionInfo.size() > 0)
reactionLayout.setVisibility(VISIBLE);
setReactionForParentMessage();
addReaction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CometChatReactionDialog reactionDialog = new CometChatReactionDialog();
reactionDialog.setOnEmojiClick(new OnReactionClickListener() {
@Override
public void onEmojiClicked(Reaction emojicon) {
JSONObject body = new JSONObject();
try {
body.put("msgId", parentId);
body.put("emoji", emojicon.getName());
} catch (Exception e) {
e.printStackTrace();
}
CometChat.callExtension("reactions", "POST", "/v1/react", body, new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject responseObject) {
reactionLayout.setVisibility(VISIBLE);
reactionDialog.dismiss();
Log.e(TAG, "onSuccess: " + responseObject);
// ReactionModel added successfully.
}
@Override
public void onError(CometChatException e) {
CometChatSnackBar.show(context, rvChatListView, CometChatError.Extension.localized(e, "reactions"), CometChatSnackBar.ERROR);
// Some error occured.
}
});
}
});
reactionDialog.show(getFragmentManager(), "ReactionThreadDialog");
}
});
bottomLayout = view.findViewById(R.id.bottom_layout);
composeBox = view.findViewById(R.id.message_box);
messageShimmer = view.findViewById(R.id.shimmer_layout);
composeBox = view.findViewById(R.id.message_box);
composeBox.usedIn(CometChatThreadMessageListActivity.class.getName());
composeBox.hidePollOption(true);
composeBox.hideStickerOption(true);
composeBox.hideWriteBoardOption(true);
composeBox.hideWhiteBoardOption(true);
composeBox.hideGroupCallOption(true);
composeBox.hideRecordOption(true);
composeBox.hideSendButton(false);
container = view.findViewById(R.id.reactions_container);
composeBox.liveReactionBtn.setOnTouchListener(new LiveReactionListener(700, 1000, new ReactionClickListener() {
@Override
public void onClick(View var1) {
container.setAlpha(1.0f);
sendLiveReaction();
}
@Override
public void onCancel(View var1) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (imageView != null && animation != null && animation.isRunning()) {
ObjectAnimator animator = ObjectAnimator.ofFloat(container, "alpha", 0.2f);
animator.setDuration(700);
animator.start();
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (imageView != null)
imageView.clearAnimation();
container.removeAllViews();
if (typingTimer != null)
typingTimer.schedule(new TimerTask() {
@Override
public void run() {
JSONObject metaData = new JSONObject();
try {
metaData.put("reaction", "heart");
} catch (JSONException e) {
e.printStackTrace();
}
TypingIndicator typingIndicator = new TypingIndicator(Id, type, metaData);
CometChat.endTyping(typingIndicator);
}
}, 2000);
}
});
}
}
}, 1400);
}
}));
setComposeBoxListener();
rvSmartReply = view.findViewById(R.id.rv_smartReply);
editMessageLayout = view.findViewById(R.id.editMessageLayout);
tvMessageTitle = view.findViewById(R.id.tv_message_layout_title);
tvMessageSubTitle = view.findViewById(R.id.tv_message_layout_subtitle);
ImageView ivMessageClose = view.findViewById(R.id.iv_message_close);
ivMessageClose.setOnClickListener(this);
replyMessageLayout = view.findViewById(R.id.replyMessageLayout);
replyTitle = view.findViewById(R.id.tv_reply_layout_title);
replyMessage = view.findViewById(R.id.tv_reply_layout_subtitle);
replyMedia = view.findViewById(R.id.iv_reply_media);
replyClose = view.findViewById(R.id.iv_reply_close);
replyClose.setOnClickListener(this);
senderAvatar = view.findViewById(R.id.av_sender);
setAvatar();
senderName = view.findViewById(R.id.tv_sender_name);
senderName.setText(name);
sentAt = view.findViewById(R.id.tv_message_time);
sentAt.setText(String.format(getString(R.string.sentattxt), Utils.getLastMessageDate(context, messageSentAt)));
tvReplyCount = view.findViewById(R.id.thread_reply_count);
rvChatListView = view.findViewById(R.id.rv_message_list);
if (parentMessageCategory.equals(CometChatConstants.CATEGORY_CUSTOM)) {
ivMoreOption.setVisibility(GONE);
}
if (replyCount > 0) {
tvReplyCount.setText(replyCount + " " + getString(R.string.replies));
noReplyMessages.setVisibility(GONE);
} else {
noReplyMessages.setVisibility(VISIBLE);
}
MaterialButton unblockUserBtn = view.findViewById(R.id.btn_unblock_user);
unblockUserBtn.setOnClickListener(this);
blockedUserName = view.findViewById(R.id.tv_blocked_user_name);
blockUserLayout = view.findViewById(R.id.blocked_user_layout);
tvName = view.findViewById(R.id.tv_name);
tvTypingIndicator = view.findViewById(R.id.tv_typing);
toolbar = view.findViewById(R.id.chatList_toolbar);
toolbar.setOnClickListener(this);
linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
tvName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
tvName.setText(String.format(getString(R.string.thread_in_name), conversationName));
setAvatar();
rvChatListView.setLayoutManager(linearLayoutManager);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (Utils.isDarkMode(context)) {
ivMoreOption.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
ivForwardMessage.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
bottomLayout.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
toolbar.setBackgroundColor(getResources().getColor(R.color.grey));
editMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border_dark));
replyMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border_dark));
composeBox.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
rvChatListView.setBackgroundColor(getResources().getColor(R.color.darkModeBackground));
tvName.setTextColor(getResources().getColor(R.color.textColorWhite));
} else {
ivMoreOption.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.primaryTextColor)));
ivForwardMessage.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.primaryTextColor)));
bottomLayout.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.textColorWhite)));
toolbar.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
editMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border));
replyMessageLayout.setBackground(getResources().getDrawable(R.drawable.left_border));
composeBox.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
rvChatListView.setBackgroundColor(getResources().getColor(R.color.textColorWhite));
tvName.setTextColor(getResources().getColor(R.color.primaryTextColor));
}
KeyBoardUtils.setKeyboardVisibilityListener(getActivity(), (View) rvChatListView.getParent(), keyboardVisible -> {
if (keyboardVisible) {
scrollToBottom();
}
});
// Uses to fetch next list of messages if rvChatListView (RecyclerView) is scrolled in downward direction.
rvChatListView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
// for toolbar elevation animation i.e stateListAnimator
toolbar.setSelected(rvChatListView.canScrollVertically(-1));
}
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (!isNoMoreMessages && !isInProgress) {
if (linearLayoutManager.findFirstVisibleItemPosition() == 10 || !rvChatListView.canScrollVertically(-1)) {
isInProgress = true;
fetchMessage();
}
}
}
});
rvSmartReply.setItemClickListener(new OnItemClickListener<String>() {
@Override
public void OnItemClick(String var, int position) {
if (!isSmartReplyClicked) {
isSmartReplyClicked = true;
rvSmartReply.setVisibility(GONE);
sendMessage(var);
}
}
});
// Check Ongoing Call
onGoingCallView = view.findViewById(R.id.ongoing_call_view);
onGoingCallClose = view.findViewById(R.id.close_ongoing_view);
onGoingCallTxt = view.findViewById(R.id.ongoing_call);
checkOnGoingCall();
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatReaction.model.Reaction 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());
}
}
});
}
Aggregations