From 75b8d6fd1b191b15b0cf6d5bb78e5e5c292fcd61 Mon Sep 17 00:00:00 2001 From: darshanbhanushali Date: Wed, 25 Nov 2020 03:19:59 +0530 Subject: [PATCH] Android UI Kit v2.1.5 --- uikit/src/main/AndroidManifest.xml | 6 +- .../src/main/java/adapter/MessageAdapter.java | 125 ++++- .../java/adapter/ReactionListAdapter.java | 162 ++++++ .../java/adapter/SmartReplyListAdapter.java | 6 +- .../main/java/adapter/StickerTabAdapter.java | 26 +- .../src/main/java/adapter/ThreadAdapter.java | 169 ++++-- .../pro/uikit/Reaction/model/Reaction.java | 50 ++ .../pro/uikit/Settings/UIKitSettings.java | 3 + .../pro/uikit/Settings/UISettings.java | 10 + .../main/java/constant/StringContract.java | 4 +- .../java/listeners/ComposeActionListener.java | 1 - ...istener.java => LiveReactionListener.java} | 6 +- .../CometChatReactionInfoScreenActivity.java | 57 ++ .../messagelist/CometChatMessageScreen.java | 82 ++- .../messagelist/MessageActionFragment.java | 44 +- .../CometChatThreadMessageScreen.java | 198 ++++++- uikit/src/main/java/utils/Extensions.java | 73 ++- uikit/src/main/java/utils/ReactionUtils.java | 501 ++++++++++++++++++ .../layout/activity_reaction_info_screen.xml | 29 + .../layout/cometchat_audio_layout_left.xml | 7 +- .../layout/cometchat_audio_layout_right.xml | 7 +- .../layout/cometchat_left_file_message.xml | 5 +- .../layout/cometchat_right_file_message.xml | 5 +- .../layout/fragment_composebox_actions.xml | 3 +- .../res/layout/fragment_message_actions.xml | 14 +- .../res/layout/fragment_thread_message.xml | 14 + .../res/layout/left_location_message_item.xml | 34 +- .../src/main/res/layout/left_message_item.xml | 5 +- .../res/layout/left_polls_message_item.xml | 32 +- .../res/layout/message_left_link_item.xml | 5 +- .../layout/message_left_list_image_item.xml | 5 +- .../layout/message_left_list_video_item.xml | 5 +- .../res/layout/message_left_sticker_item.xml | 5 +- .../res/layout/message_right_link_item.xml | 5 +- .../layout/message_right_list_image_item.xml | 5 +- .../layout/message_right_list_video_item.xml | 5 +- .../res/layout/message_right_sticker_item.xml | 5 +- .../src/main/res/layout/reaction_info_row.xml | 24 + .../src/main/res/layout/reaction_list_row.xml | 16 + .../layout/right_location_message_item.xml | 32 +- .../main/res/layout/right_message_item.xml | 7 +- .../res/layout/right_polls_message_item.xml | 32 +- .../layout/thread_location_message_item.xml | 11 +- .../layout/thread_message_audio_layout.xml | 79 +-- .../res/layout/thread_message_file_item.xml | 11 +- .../res/layout/thread_message_image_item.xml | 10 + .../main/res/layout/thread_message_item.xml | 21 +- .../res/layout/thread_message_link_item.xml | 10 + .../res/layout/thread_message_video_item.xml | 10 + uikit/src/main/res/values/attr.xml | 4 + uikit/src/main/res/values/strings.xml | 1 + 51 files changed, 1693 insertions(+), 293 deletions(-) create mode 100644 uikit/src/main/java/adapter/ReactionListAdapter.java create mode 100644 uikit/src/main/java/com/cometchat/pro/uikit/Reaction/model/Reaction.java rename uikit/src/main/java/listeners/{ReactionListener.java => LiveReactionListener.java} (91%) create mode 100644 uikit/src/main/java/screen/CometChatReactionInfoScreenActivity.java create mode 100644 uikit/src/main/java/utils/ReactionUtils.java create mode 100644 uikit/src/main/res/layout/activity_reaction_info_screen.xml create mode 100644 uikit/src/main/res/layout/reaction_info_row.xml create mode 100644 uikit/src/main/res/layout/reaction_list_row.xml diff --git a/uikit/src/main/AndroidManifest.xml b/uikit/src/main/AndroidManifest.xml index d3a5b360..78460629 100644 --- a/uikit/src/main/AndroidManifest.xml +++ b/uikit/src/main/AndroidManifest.xml @@ -11,14 +11,18 @@ + + - + + { @@ -905,6 +911,8 @@ public boolean onLongClick(View v) { return true; } }); + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } } @@ -949,12 +957,10 @@ private void setFileData(FileMessageViewHolder viewHolder, int i) { viewHolder.fileSize.setText(Utils.getFileSize(fileSize)); - viewHolder.lvReplyAvatar.setVisibility(View.GONE); if (baseMessage.getReplyCount()!=0 && UISettings.isEnableThreadedReplies()) { viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE); viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount()+" Replies"); } else { - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.tvThreadReplyCount.setVisibility(View.GONE); } viewHolder.tvThreadReplyCount.setOnClickListener(view -> { @@ -1017,6 +1023,9 @@ public boolean onLongClick(View v) { } }); } + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } @@ -1077,7 +1086,6 @@ private void setImageData(ImageMessageViewHolder viewHolder, int i) { viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE); viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount()+" Replies"); } else { - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.tvThreadReplyCount.setVisibility(View.GONE); } viewHolder.tvThreadReplyCount.setOnClickListener(view -> { @@ -1155,6 +1163,9 @@ public boolean onLongClick(View v) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } @@ -1290,6 +1301,9 @@ public boolean onLongClick(View v) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } @@ -1320,7 +1334,6 @@ private void setVideoData(VideoMessageViewHolder viewHolder, int i) { viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE); viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount()+" Replies"); } else { - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.tvThreadReplyCount.setVisibility(View.GONE); } viewHolder.tvThreadReplyCount.setOnClickListener(view -> { @@ -1383,6 +1396,10 @@ public void onClick(View view) { openMediaViewActivity(baseMessage); } }); + + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } @@ -1414,7 +1431,6 @@ private void setDeleteData(DeleteMessageViewHolder viewHolder, int i) { } if (baseMessage.getDeletedAt()!=0) { viewHolder.tvThreadReplyCount.setVisibility(View.GONE); - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.txtMessage.setText(R.string.message_deleted); viewHolder.txtMessage.setTextColor(context.getResources().getColor(R.color.secondaryTextColor)); viewHolder.txtMessage.setTypeface(null, Typeface.ITALIC); @@ -1521,10 +1537,6 @@ private void showMessageTime(RecyclerView.ViewHolder viewHolder, BaseMessage bas setStatusIcon(((AudioMessageViewHolder)viewHolder).txtTime, baseMessage); } else if (viewHolder instanceof LocationMessageViewHolder){ setStatusIcon(((LocationMessageViewHolder) viewHolder).txtTime, baseMessage); - } else if (viewHolder instanceof PollMessageViewHolder) { - setStatusIcon(((PollMessageViewHolder) viewHolder).txtTime, baseMessage); - } else if (viewHolder instanceof StickerMessageViewHolder) { - setStatusIcon(((StickerMessageViewHolder) viewHolder).txtTime,baseMessage); } } @@ -1683,7 +1695,6 @@ public boolean onLongClick(View view) { viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE); viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount()+" Replies"); } else { - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.tvThreadReplyCount.setVisibility(View.GONE); } viewHolder.tvThreadReplyCount.setOnClickListener(view -> { @@ -1793,10 +1804,63 @@ public boolean onLongClick(View view) { // return true; // } // }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); viewHolder.itemView.setTag(R.string.message, baseMessage); } } + private void setReactionSupport(BaseMessage baseMessage, ChipGroup reactionLayout) { + HashMap reactionOnMessage = Extensions.getReactionsOnMessage(baseMessage); + if (reactionOnMessage!=null && reactionOnMessage.size()>0) { + reactionLayout.setVisibility(View.VISIBLE); + reactionLayout.removeAllViews(); + for (String str : reactionOnMessage.keySet()) { +// if (reactionLayout.getChildCount()() { + @Override + public void onSuccess(JSONObject responseObject) { + // ReactionModel added successfully. + } + + @Override + public void onError(CometChatException e) { + // Some error occured. + } + }); + } + }); +// } + } + } + } private void setCustomData(CustomMessageViewHolder viewHolder, int i) { @@ -1953,7 +2017,6 @@ private void setLinkData(LinkMessageViewHolder viewHolder, int i) { viewHolder.tvThreadReplyCount.setVisibility(View.VISIBLE); viewHolder.tvThreadReplyCount.setText(baseMessage.getReplyCount()+" Replies"); } else { - viewHolder.lvReplyAvatar.setVisibility(View.GONE); viewHolder.tvThreadReplyCount.setVisibility(View.GONE); } viewHolder.tvThreadReplyCount.setOnClickListener(view -> { @@ -2038,6 +2101,8 @@ public boolean onLongClick(View view) { return true; } }); + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); viewHolder.itemView.setTag(R.string.message, baseMessage); } } @@ -2330,9 +2395,9 @@ class ImageMessageViewHolder extends RecyclerView.ViewHolder { public TextView txtTime,tvUser; private RelativeLayout rlMessageBubble; private TextView tvThreadReplyCount; - private LinearLayout lvReplyAvatar; private RelativeLayout sensitiveLayout; + private ChipGroup reactionLayout; public ImageMessageViewHolder(@NonNull View view) { super(view); @@ -2345,8 +2410,8 @@ public ImageMessageViewHolder(@NonNull View view) { ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); tvThreadReplyCount = view.findViewById(R.id.thread_reply_count); - lvReplyAvatar = view.findViewById(R.id.reply_avatar_layout); sensitiveLayout = view.findViewById(R.id.sensitive_layout); + reactionLayout = view.findViewById(R.id.reactions_layout); } } @@ -2371,7 +2436,7 @@ class VideoMessageViewHolder extends RecyclerView.ViewHolder { public TextView txtTime,tvUser; private RelativeLayout rlMessageBubble; private TextView tvThreadReplyCount; - private LinearLayout lvReplyAvatar; + private ChipGroup reactionLayout; public VideoMessageViewHolder(@NonNull View view) { super(view); @@ -2385,7 +2450,7 @@ public VideoMessageViewHolder(@NonNull View view) { ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); tvThreadReplyCount = view.findViewById(R.id.thread_reply_count); - lvReplyAvatar = view.findViewById(R.id.reply_avatar_layout); + reactionLayout = view.findViewById(R.id.reactions_layout); } } @@ -2401,7 +2466,7 @@ public class FileMessageViewHolder extends RecyclerView.ViewHolder { private RelativeLayout cvMessageView; private RelativeLayout rlMessageBubble; private TextView tvThreadReplyCount; - private LinearLayout lvReplyAvatar; + private ChipGroup reactionLayout; FileMessageViewHolder(@NonNull View itemView) { super(itemView); @@ -2414,7 +2479,7 @@ public class FileMessageViewHolder extends RecyclerView.ViewHolder { cvMessageView = itemView.findViewById(R.id.cv_message_container); rlMessageBubble = itemView.findViewById(R.id.rl_message); tvThreadReplyCount = itemView.findViewById(R.id.thread_reply_count); - lvReplyAvatar = itemView.findViewById(R.id.reply_avatar_layout); + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } } @@ -2444,7 +2509,6 @@ public class DeleteMessageViewHolder extends RecyclerView.ViewHolder { ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); tvThreadReplyCount = view.findViewById(R.id.thread_reply_count); - lvReplyAvatar = view.findViewById(R.id.reply_avatar_layout); this.view = view; } } @@ -2472,7 +2536,8 @@ public class TextMessageViewHolder extends RecyclerView.ViewHolder { private RelativeLayout replyLayout; //reply message layout private TextView replyUser; //reply message sender name private TextView replyMessage; //reply message text - private LinearLayout lvReplyAvatar; + + private ChipGroup reactionLayout; TextMessageViewHolder(@NonNull View view) { super(view); @@ -2489,9 +2554,9 @@ public class TextMessageViewHolder extends RecyclerView.ViewHolder { replyUser = view.findViewById(R.id.reply_user); replyMessage = view.findViewById(R.id.reply_message); tvThreadReplyCount = view.findViewById(R.id.thread_reply_count); - lvReplyAvatar = view.findViewById(R.id.reply_avatar_layout); sentimentVw = view.findViewById(R.id.sentiment_layout); viewSentimentMessage = view.findViewById(R.id.view_sentiment); + reactionLayout = view.findViewById(R.id.reactions_layout); this.view = view; } @@ -2531,6 +2596,7 @@ public class StickerMessageViewHolder extends RecyclerView.ViewHolder { public TextView txtTime; public TextView tvUser; public Avatar ivUser; + private ChipGroup reactionLayout; public int type; public View view; @@ -2545,7 +2611,7 @@ public StickerMessageViewHolder(View itemView) { ivUser = itemView.findViewById(R.id.iv_user); tvThreadReplyCount = itemView.findViewById(R.id.thread_reply_count); txtTime = itemView.findViewById(R.id.txt_time); - + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } @@ -2567,6 +2633,8 @@ public class LocationMessageViewHolder extends RecyclerView.ViewHolder { public TextView tvUser; public Avatar ivUser; + private ChipGroup reactionLayout; + public LocationMessageViewHolder(View itemView) { super(itemView); @@ -2582,6 +2650,7 @@ public LocationMessageViewHolder(View itemView) { tvThreadReplyCount = itemView.findViewById(R.id.thread_reply_count); senderTxt = itemView.findViewById(R.id.sender_location_txt); navigateBtn = itemView.findViewById(R.id.navigate_btn); + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } } @@ -2602,6 +2671,8 @@ public class PollMessageViewHolder extends RecyclerView.ViewHolder { public TextView tvUser; public Avatar ivUser; + private ChipGroup reactionLayout; + public PollMessageViewHolder(View itemView) { super(itemView); @@ -2617,6 +2688,7 @@ public PollMessageViewHolder(View itemView) { ivUser = itemView.findViewById(R.id.iv_user); loadingProgress = itemView.findViewById(R.id.loading_progressBar); tvThreadReplyCount = itemView.findViewById(R.id.thread_reply_count); + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } } @@ -2631,7 +2703,7 @@ public class AudioMessageViewHolder extends RecyclerView.ViewHolder { private RelativeLayout rlMessageBubble; private TextView txtTime; private TextView tvThreadReplyCount; - private LinearLayout lvReplyAvatar; + private ChipGroup reactionLayout; public AudioMessageViewHolder(@NonNull View itemView) { super(itemView); type = (int)itemView.getTag(); @@ -2642,7 +2714,7 @@ public AudioMessageViewHolder(@NonNull View itemView) { ivUser = itemView.findViewById(R.id.iv_user); txtTime = itemView.findViewById(R.id.txt_time); tvThreadReplyCount = itemView.findViewById(R.id.thread_reply_count); - lvReplyAvatar = itemView.findViewById(R.id.reply_avatar_layout); + reactionLayout = itemView.findViewById(R.id.reactions_layout); } } public class LinkMessageViewHolder extends RecyclerView.ViewHolder { @@ -2662,7 +2734,8 @@ public class LinkMessageViewHolder extends RecyclerView.ViewHolder { private Avatar ivUser; private RelativeLayout rlMessageBubble; private TextView tvThreadReplyCount; - private LinearLayout lvReplyAvatar; + + private ChipGroup reactionLayout; LinkMessageViewHolder(@NonNull View view) { super(view); @@ -2681,7 +2754,7 @@ public class LinkMessageViewHolder extends RecyclerView.ViewHolder { ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); tvThreadReplyCount = view.findViewById(R.id.thread_reply_count); - lvReplyAvatar = view.findViewById(R.id.reply_avatar_layout); + reactionLayout = view.findViewById(R.id.reactions_layout); this.view = view; } } diff --git a/uikit/src/main/java/adapter/ReactionListAdapter.java b/uikit/src/main/java/adapter/ReactionListAdapter.java new file mode 100644 index 00000000..627b1970 --- /dev/null +++ b/uikit/src/main/java/adapter/ReactionListAdapter.java @@ -0,0 +1,162 @@ +package adapter; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import com.cometchat.pro.uikit.R; +import com.cometchat.pro.uikit.Reaction.model.Reaction; + +import java.util.ArrayList; +import java.util.List; + +/** + * Purpose - ReactionListAdapter is a subclass of RecyclerView Adapter which is used to display + * the list of users. It helps to organize the users in recyclerView. + * + * Created on - 20th November 2020 + * + * Modified on - 20th November 2020 + * + */ + +public class ReactionListAdapter extends RecyclerView.Adapter { + + private Context context; + + private List reactionArrayList = new ArrayList<>(); + + private static final String TAG = "reactionListAdapter"; + + /** + * It is a contructor which is used to initialize wherever we needed. + * + * @param context is a object of Context. + */ + public ReactionListAdapter(Context context) { + this.context=context; + } + + /** + * It is constructor which takes reactionArrayList as parameter and bind it with reactionArrayList in adapter. + * + * @param context is a object of Context. + * @param reactionArrayList is a list of Reactions used in this adapter. + */ + public ReactionListAdapter(Context context, List reactionArrayList) { + this.reactionArrayList = reactionArrayList; + this.context= context; + } + + @NonNull + @Override + public ReactionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) { + + LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext()); + + View view = layoutInflater.inflate(R.layout.reaction_list_row, parent, false); + + return new ReactionViewHolder(view); + } + + /** + * This method is used to bind the ReactionViewHolder contents with user at given + * position. It set username userAvatar in respective ReactionViewHolder content. + * + * @param reactionViewHolder is a object of ReactionViewHolder. + * @param i is a position of item in recyclerView. + * @see Reaction + */ + @Override + public void onBindViewHolder(@NonNull ReactionViewHolder reactionViewHolder, int i) { + + Reaction reaction = reactionArrayList.get(i); + Log.e(TAG, "onBindViewHolder: "+reaction.getCode()); + reactionViewHolder.reaction.setText(reaction.getCode()); + reactionViewHolder.itemView.setTag(R.string.reaction,reaction); + } + + @Override + public int getItemCount() { + return reactionArrayList.size(); + } + + + /** + * This method is used to update the reactions of reactionArrayList in adapter. + * + * @param reactions is a list of updated reactions. + */ + public void updateList(List reactions) { + for (int i = 0; i < reactions.size(); i++) { + if (reactionArrayList.contains(reactions.get(i))){ + int index=reactionArrayList.indexOf(reactions.get(i)); + reactionArrayList.remove(index); + reactionArrayList.add(index,reactions.get(i)); + }else { + reactionArrayList.add(reactions.get(i)); + } + } + notifyDataSetChanged(); + } + + + /** + * This method is used to update particular user in userArrayList of adapter. + * + * @param reaction is a object of ReactionModel which will updated in reactionArrayList. + * @see Reaction + */ + public void updateReaction(Reaction reaction) { + if (reactionArrayList.contains(reaction)){ + int index=reactionArrayList.indexOf(reaction); + reactionArrayList.remove(index); + reactionArrayList.add(index,reaction); + notifyItemChanged(index); + }else { + reactionArrayList.add(reaction); + notifyItemInserted(getItemCount()-1); + } + } + + /** + * This method is used to remove particular reaction from reactionArrayList of adapter. + * + * @param reaction is a object of user which will be removed from reactionArrayList. + * @see Reaction + */ + public void remove(Reaction reaction) { + if (reactionArrayList.contains(reaction)) { + int index=reactionArrayList.indexOf(reaction); + this.reactionArrayList.remove(reaction); + notifyItemRemoved(index); + } + + } + + /** + * This method is used to add a reaction in reactionArrayList. + * @param reaction is a object of ReactionModel which will be added in reactionArrayList. + * @see Reaction + */ + public void add(Reaction reaction) { + updateReaction(reaction); + } + + + + class ReactionViewHolder extends RecyclerView.ViewHolder { + + TextView reaction; + ReactionViewHolder(View view) { + super(view); + reaction = view.findViewById(R.id.reaction); + } + + } +} diff --git a/uikit/src/main/java/adapter/SmartReplyListAdapter.java b/uikit/src/main/java/adapter/SmartReplyListAdapter.java index 02a60710..73010e19 100644 --- a/uikit/src/main/java/adapter/SmartReplyListAdapter.java +++ b/uikit/src/main/java/adapter/SmartReplyListAdapter.java @@ -69,10 +69,10 @@ public SmartReplyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) } /** - * This method is used to bind the UserViewHolder contents with user at given - * position. It set username userAvatar in respective UserViewHolder content. + * This method is used to bind the ReactionViewHolder contents with user at given + * position. It set username userAvatar in respective ReactionViewHolder content. * - * @param smartReplyViewHolder is a object of UserViewHolder. + * @param smartReplyViewHolder is a object of ReactionViewHolder. * @param i is a position of item in recyclerView. * @see User * diff --git a/uikit/src/main/java/adapter/StickerTabAdapter.java b/uikit/src/main/java/adapter/StickerTabAdapter.java index d154240c..b8a05148 100644 --- a/uikit/src/main/java/adapter/StickerTabAdapter.java +++ b/uikit/src/main/java/adapter/StickerTabAdapter.java @@ -55,31 +55,7 @@ public void addFragment(Fragment fragment, String title,String icon) { @Nullable @Override public CharSequence getPageTitle(int position) { - sb = new SpannableStringBuilder(""); // space added before text for convenience -// myDrawable = context.getResources().getDrawable(R.drawable.default_sticker); -// myDrawable.setBounds(5, 15, myDrawable.getIntrinsicWidth(), myDrawable.getIntrinsicHeight()); -// ImageSpan span = new ImageSpan(myDrawable, DynamicDrawableSpan.ALIGN_BASELINE); -// sb.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); -// Glide.with(context).load(mFragmentIconList.get(position)).into(new CustomTarget() { -// @Override -// public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) { -// myDrawable = resource; -// try { -// sb = new SpannableStringBuilder(" "); -// myDrawable.setBounds(5, 5, myDrawable.getIntrinsicWidth(), myDrawable.getIntrinsicHeight()); -// ImageSpan span = new ImageSpan(myDrawable, DynamicDrawableSpan.ALIGN_BASELINE); -// sb.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); -// } catch (Exception e) { -// Log.e("Icon: ", e.getMessage()); -// } -// } -// -// @Override -// public void onLoadCleared(@Nullable Drawable placeholder) { -// -// } -// }); - + sb = new SpannableStringBuilder(""); return sb; } @Override diff --git a/uikit/src/main/java/adapter/ThreadAdapter.java b/uikit/src/main/java/adapter/ThreadAdapter.java index 0a41e92c..d4267f63 100644 --- a/uikit/src/main/java/adapter/ThreadAdapter.java +++ b/uikit/src/main/java/adapter/ThreadAdapter.java @@ -11,6 +11,7 @@ import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.net.Uri; import android.text.Spannable; @@ -33,11 +34,13 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; import com.cometchat.pro.constants.CometChatConstants; import com.cometchat.pro.core.Call; import com.cometchat.pro.core.CometChat; +import com.cometchat.pro.exceptions.CometChatException; import com.cometchat.pro.models.Action; import com.cometchat.pro.models.BaseMessage; import com.cometchat.pro.models.CustomMessage; @@ -47,7 +50,10 @@ import com.cometchat.pro.models.User; import com.cometchat.pro.uikit.Avatar; import com.cometchat.pro.uikit.R; +import com.cometchat.pro.uikit.Settings.UISettings; import com.google.android.material.button.MaterialButton; +import com.google.android.material.chip.Chip; +import com.google.android.material.chip.ChipGroup; import org.json.JSONArray; import org.json.JSONException; @@ -60,6 +66,8 @@ import constant.StringContract; import listeners.StickyHeaderAdapter; +import screen.CometChatMediaViewActivity; +import screen.CometChatReactionInfoScreenActivity; import screen.threadconversation.CometChatThreadMessageActivity; import utils.Extensions; import utils.FontUtils; @@ -372,6 +380,9 @@ public boolean onLongClick(View view) { } }); + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); + } private void setLocationData(BaseMessage baseMessage, TextView tvAddress, ImageView ivMap) { @@ -447,6 +458,9 @@ public boolean onLongClick(View v) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } } @@ -507,6 +521,9 @@ public boolean onLongClick(View v) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } } @@ -533,25 +550,16 @@ private void setImageData(ImageMessageViewHolder viewHolder, int i) { String smallUrl = Extensions.getThumbnailGeneration(context,baseMessage); viewHolder.imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_defaulf_image)); if (smallUrl!=null) { - Glide.with(context).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).load(smallUrl).into(new SimpleTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - if (isImageNotSafe) - viewHolder.imageView.setImageBitmap(Utils.blur(context,resource)); - else - viewHolder.imageView.setImageBitmap(resource); - } - }); + if (((MediaMessage)baseMessage).getAttachment().getFileExtension().equalsIgnoreCase(".gif")) { + setImageDrawable(viewHolder,smallUrl,true,false); + } else { + setImageDrawable(viewHolder,smallUrl,false,isImageNotSafe); + } } else { - Glide.with(context).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).load(((MediaMessage)baseMessage).getAttachment().getFileUrl()).into(new SimpleTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - if (isImageNotSafe) - viewHolder.imageView.setImageBitmap(Utils.blur(context,resource)); - else - viewHolder.imageView.setImageBitmap(resource); - } - }); + if (((MediaMessage)baseMessage).getAttachment().getFileExtension().equalsIgnoreCase(".gif")) + setImageDrawable(viewHolder,((MediaMessage)baseMessage).getAttachment().getFileUrl(),true,false); + else + setImageDrawable(viewHolder,((MediaMessage)baseMessage).getAttachment().getFileUrl(),false,isImageNotSafe); } if (isImageNotSafe) { viewHolder.sensitiveLayout.setVisibility(View.VISIBLE); @@ -588,7 +596,7 @@ public void onClick(DialogInterface dialog, int which) { } else { setSelectedMessage(baseMessage.getId()); notifyDataSetChanged(); - MediaUtils.openFile(((MediaMessage) baseMessage).getAttachment().getFileUrl(), context); + openMediaViewActivity(baseMessage); } }); @@ -604,22 +612,44 @@ public boolean onLongClick(View v) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } - private void displayImage(BaseMessage baseMessage) { - Dialog imageDialog = new Dialog(context); - View messageVw = LayoutInflater.from(context).inflate(R.layout.image_dialog_view, null); - ZoomIv imageView = messageVw.findViewById(R.id.imageView); - Glide.with(context).asBitmap().load(((MediaMessage) baseMessage).getAttachment().getFileUrl()).into(new SimpleTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - imageView.setImageBitmap(resource); - } - }); - imageDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - imageDialog.setContentView(messageVw); - imageDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); - imageDialog.show(); + private void setImageDrawable(ImageMessageViewHolder viewHolder, String url, boolean gif, boolean isImageNotSafe) { + if (gif) { + Glide.with(context).asGif().diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true).load(url).into(viewHolder.imageView); + } else { + Glide.with(context).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE) + .skipMemoryCache(true).load(url).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + if (isImageNotSafe) + viewHolder.imageView.setImageBitmap(Utils.blur(context, resource)); + else + viewHolder.imageView.setImageBitmap(resource); + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + } + + } + + private void openMediaViewActivity(BaseMessage baseMessage) { + Intent intent = new Intent(context, CometChatMediaViewActivity.class); + intent.putExtra(StringContract.IntentStrings.NAME,baseMessage.getSender().getName()); + intent.putExtra(StringContract.IntentStrings.UID,baseMessage.getSender().getUid()); + intent.putExtra(StringContract.IntentStrings.SENTAT,baseMessage.getSentAt()); + intent.putExtra(StringContract.IntentStrings.INTENT_MEDIA_MESSAGE, + ((MediaMessage)baseMessage).getAttachment().getFileUrl()); + intent.putExtra(StringContract.IntentStrings.MESSAGE_TYPE,baseMessage.getType()); + context.startActivity(intent); } @@ -665,6 +695,9 @@ public void onClick(View view) { MediaUtils.openFile(((MediaMessage)baseMessage).getAttachment().getFileUrl(),context); } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); } @@ -862,6 +895,9 @@ public boolean onLongClick(View view) { return true; } }); + + viewHolder.reactionLayout.setVisibility(View.GONE); + setReactionSupport(baseMessage,viewHolder.reactionLayout); viewHolder.itemView.setTag(R.string.message, baseMessage); } } @@ -897,6 +933,57 @@ private void setCustomData(CustomMessageViewHolder viewHolder, int i) { } } + private void setReactionSupport(BaseMessage baseMessage, ChipGroup reactionLayout) { + HashMap reactionOnMessage = Extensions.getReactionsOnMessage(baseMessage); + if (reactionOnMessage!=null && reactionOnMessage.size()>0) { + reactionLayout.setVisibility(View.VISIBLE); + reactionLayout.removeAllViews(); + for (String str : reactionOnMessage.keySet()) { +// if (reactionLayout.getChildCount()() { + @Override + public void onSuccess(JSONObject responseObject) { + // ReactionModel added successfully. + } + + @Override + public void onError(CometChatException e) { + // Some error occured. + } + }); + } + }); +// } + } + } + } + private void setColorFilter(BaseMessage baseMessage,View view){ if (!longselectedItemList.contains(baseMessage)) @@ -1245,7 +1332,9 @@ class ImageMessageViewHolder extends RecyclerView.ViewHolder { public TextView txtTime,tvUser; private RelativeLayout rlMessageBubble; + private ChipGroup reactionLayout; private RelativeLayout sensitiveLayout; + public ImageMessageViewHolder(@NonNull View view) { super(view); int type = (int) view.getTag(); @@ -1257,6 +1346,7 @@ public ImageMessageViewHolder(@NonNull View view) { ivUser = view.findViewById(R.id.iv_user); sensitiveLayout = view.findViewById(R.id.sensitive_layout); rlMessageBubble = view.findViewById(R.id.rl_message); + reactionLayout = view.findViewById(R.id.reactions_layout); } } @@ -1280,6 +1370,7 @@ class VideoMessageViewHolder extends RecyclerView.ViewHolder { private Avatar ivUser; public TextView txtTime,tvUser; private RelativeLayout rlMessageBubble; + private ChipGroup reactionLayout; public VideoMessageViewHolder(@NonNull View view) { super(view); @@ -1292,6 +1383,7 @@ public VideoMessageViewHolder(@NonNull View view) { txtTime = view.findViewById(R.id.txt_time); ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); + reactionLayout = view.findViewById(R.id.reactions_layout); } } @@ -1305,6 +1397,7 @@ public class FileMessageViewHolder extends RecyclerView.ViewHolder { private View view; private Avatar ivUser; private RelativeLayout rlMessageBubble; + private ChipGroup reactionLayout; FileMessageViewHolder(@NonNull View itemView) { super(itemView); @@ -1315,6 +1408,7 @@ public class FileMessageViewHolder extends RecyclerView.ViewHolder { txtTime = itemView.findViewById(R.id.txt_time); fileName = itemView.findViewById(R.id.tvFileName); rlMessageBubble = itemView.findViewById(R.id.rl_message); + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } } @@ -1361,6 +1455,7 @@ public class TextMessageViewHolder extends RecyclerView.ViewHolder { private TextView replyMessage; private RelativeLayout sentimentVw; private TextView viewSentimentMessage; + private ChipGroup reactionLayout; TextMessageViewHolder(@NonNull View view) { super(view); @@ -1378,6 +1473,7 @@ public class TextMessageViewHolder extends RecyclerView.ViewHolder { replyMessage = view.findViewById(R.id.reply_message); sentimentVw = view.findViewById(R.id.sentiment_layout); viewSentimentMessage = view.findViewById(R.id.view_sentiment); + reactionLayout = view.findViewById(R.id.reactions_layout); this.view = view; } @@ -1425,7 +1521,7 @@ public class LocationMessageViewHolder extends RecyclerView.ViewHolder { public TextView txtTime; public TextView tvUser; public Avatar ivUser; - + public ChipGroup reactionLayout; public LocationMessageViewHolder(View itemView) { super(itemView); @@ -1440,6 +1536,7 @@ public LocationMessageViewHolder(View itemView) { ivUser = itemView.findViewById(R.id.iv_user); senderTxt = itemView.findViewById(R.id.sender_location_txt); navigateBtn = itemView.findViewById(R.id.navigate_btn); + reactionLayout = itemView.findViewById(R.id.reactions_layout); this.view = itemView; } } @@ -1453,6 +1550,7 @@ public class AudioMessageViewHolder extends RecyclerView.ViewHolder { private Avatar ivUser; private RelativeLayout rlMessageBubble; private TextView txtTime; + private ChipGroup reactionLayout; public AudioMessageViewHolder(@NonNull View itemView) { super(itemView); type = (int)itemView.getTag(); @@ -1462,6 +1560,7 @@ public AudioMessageViewHolder(@NonNull View itemView) { tvUser = itemView.findViewById(R.id.tv_user); ivUser = itemView.findViewById(R.id.iv_user); txtTime = itemView.findViewById(R.id.txt_time); + reactionLayout = itemView.findViewById(R.id.reactions_layout); } } public class LinkMessageViewHolder extends RecyclerView.ViewHolder { @@ -1480,6 +1579,7 @@ public class LinkMessageViewHolder extends RecyclerView.ViewHolder { private TextView tvUser; private Avatar ivUser; private RelativeLayout rlMessageBubble; + private ChipGroup reactionLayout; LinkMessageViewHolder(@NonNull View view) { super(view); @@ -1497,6 +1597,7 @@ public class LinkMessageViewHolder extends RecyclerView.ViewHolder { imgStatus = view.findViewById(R.id.img_pending); ivUser = view.findViewById(R.id.iv_user); rlMessageBubble = view.findViewById(R.id.rl_message); + reactionLayout = view.findViewById(R.id.reactions_layout); this.view = view; } } diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/Reaction/model/Reaction.java b/uikit/src/main/java/com/cometchat/pro/uikit/Reaction/model/Reaction.java new file mode 100644 index 00000000..2ca17b98 --- /dev/null +++ b/uikit/src/main/java/com/cometchat/pro/uikit/Reaction/model/Reaction.java @@ -0,0 +1,50 @@ +package com.cometchat.pro.uikit.Reaction.model; + +import android.os.Parcel; +import android.os.Parcelable; + +public class Reaction implements Parcelable { + String name; + String code; + + public Reaction(String name, String code) { + this.name = name; + this.code = code; + } + + protected Reaction(Parcel in) { + name = in.readString(); + code = in.readString(); + } + + public static final Creator CREATOR = new Creator() { + @Override + public Reaction createFromParcel(Parcel in) { + return new Reaction(in); + } + + @Override + public Reaction[] newArray(int size) { + return new Reaction[size]; + } + }; + + public String getName() { + return name; + } + + public String getCode() { + return code; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeString(name); + parcel.writeString(code); + } +} \ No newline at end of file diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UIKitSettings.java b/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UIKitSettings.java index 77303925..1d36ba57 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UIKitSettings.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UIKitSettings.java @@ -46,6 +46,9 @@ public static void setCallSoundEnable(boolean isEnable) { UISettings.enableCallSounds = isEnable; } + public static void enableLiveReaction(boolean isEnable) { + UISettings.liveReaction = isEnable; + } public static void setHyperLinkEmailColor(int color) { UISettings.emailColor = color; } diff --git a/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UISettings.java b/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UISettings.java index f7651908..dedacdd7 100644 --- a/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UISettings.java +++ b/uikit/src/main/java/com/cometchat/pro/uikit/Settings/UISettings.java @@ -52,6 +52,8 @@ public UISettings() {} protected static boolean enableCallSounds = true; protected static boolean hideGroupNotification = false; protected static boolean hideCallNotification = false; + protected static boolean liveReaction = true; + protected static boolean allowReactionOnMessage = true; protected static int emailColor = R.color.primaryTextColor; protected static int phoneColor = R.color.purple; protected static int urlColor = R.color.dark_blue; @@ -235,4 +237,12 @@ public static int getPhoneColor() { public static int getUrlColor() { return urlColor; } + + public static boolean showLiveReaction() { + return liveReaction; + } + + public static boolean isReactionVisible() { + return allowReactionOnMessage; + } } diff --git a/uikit/src/main/java/constant/StringContract.java b/uikit/src/main/java/constant/StringContract.java index d8567008..ada15ccc 100644 --- a/uikit/src/main/java/constant/StringContract.java +++ b/uikit/src/main/java/constant/StringContract.java @@ -112,6 +112,8 @@ public static class IntentStrings { public static final String STICKERS = "Sticker"; + public static final String REACTION_INFO = "reaction_info"; + public static String POLL_QUESTION = "poll_question"; public static String POLL_OPTION = "poll_option"; @@ -154,7 +156,7 @@ public static class MapUrl{ public static final String MAPS_URL = "https://maps.googleapis.com/maps/api/staticmap?zoom=16&size=380x220&markers=color:red|"; - public static final String MAP_ACCESS_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + public static final String MAP_ACCESS_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXX"; } diff --git a/uikit/src/main/java/listeners/ComposeActionListener.java b/uikit/src/main/java/listeners/ComposeActionListener.java index 1bf8e353..25ef59da 100644 --- a/uikit/src/main/java/listeners/ComposeActionListener.java +++ b/uikit/src/main/java/listeners/ComposeActionListener.java @@ -2,7 +2,6 @@ import android.text.Editable; import android.view.View; -import android.view.inputmethod.InputContentInfo; import android.widget.EditText; import android.widget.ImageView; diff --git a/uikit/src/main/java/listeners/ReactionListener.java b/uikit/src/main/java/listeners/LiveReactionListener.java similarity index 91% rename from uikit/src/main/java/listeners/ReactionListener.java rename to uikit/src/main/java/listeners/LiveReactionListener.java index a9193fa2..92f94548 100644 --- a/uikit/src/main/java/listeners/ReactionListener.java +++ b/uikit/src/main/java/listeners/LiveReactionListener.java @@ -4,7 +4,7 @@ import android.view.MotionEvent; import android.view.View; -public class ReactionListener implements View.OnTouchListener { +public class LiveReactionListener implements View.OnTouchListener { private Handler handler = new Handler(); @@ -28,8 +28,8 @@ public void run() { }; - public ReactionListener(int initialInterval, int normalInterval, - ReactionClickListener clickListener) { + public LiveReactionListener(int initialInterval, int normalInterval, + ReactionClickListener clickListener) { if (clickListener == null) throw new IllegalArgumentException("null runnable"); if (initialInterval < 0 || normalInterval < 0) diff --git a/uikit/src/main/java/screen/CometChatReactionInfoScreenActivity.java b/uikit/src/main/java/screen/CometChatReactionInfoScreenActivity.java new file mode 100644 index 00000000..b574cc6a --- /dev/null +++ b/uikit/src/main/java/screen/CometChatReactionInfoScreenActivity.java @@ -0,0 +1,57 @@ +package screen; + +import androidx.appcompat.app.AppCompatActivity; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.cometchat.pro.uikit.R; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import constant.StringContract; +import utils.Extensions; + +public class CometChatReactionInfoScreenActivity extends AppCompatActivity { + + private LinearLayout reactionInfoLayout; + + private JSONObject jsonObject; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_reaction_info_screen); + reactionInfoLayout = findViewById(R.id.reaction_info_layout); + if (getIntent().hasExtra(StringContract.IntentStrings.REACTION_INFO)) { + try { + jsonObject = new JSONObject(getIntent().getStringExtra(StringContract.IntentStrings.REACTION_INFO)); + } catch (JSONException e) { + e.printStackTrace(); + } + } + HashMap> reactionInfo = Extensions.getReactionsInfo(jsonObject); + for (String str : reactionInfo.keySet()) { + View view = LayoutInflater.from(this).inflate(R.layout.reaction_info_row,null); + TextView react = view.findViewById(R.id.react_tv); + TextView users = view.findViewById(R.id.users_tv); + react.setText(str); + List usernames = reactionInfo.get(str); + for (String uname : usernames) { + if (users.getText().toString().trim().isEmpty()) + users.setText(uname); + else + users.setText(users.getText().toString()+","+uname); + } + reactionInfoLayout.addView(view); + } + } +} diff --git a/uikit/src/main/java/screen/messagelist/CometChatMessageScreen.java b/uikit/src/main/java/screen/messagelist/CometChatMessageScreen.java index 2da74591..1003d089 100644 --- a/uikit/src/main/java/screen/messagelist/CometChatMessageScreen.java +++ b/uikit/src/main/java/screen/messagelist/CometChatMessageScreen.java @@ -37,8 +37,6 @@ import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; @@ -54,7 +52,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.fragment.app.Fragment; -import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -80,6 +77,7 @@ import com.cometchat.pro.models.TextMessage; import com.cometchat.pro.models.TypingIndicator; import com.cometchat.pro.models.User; +import com.cometchat.pro.uikit.Reaction.model.Reaction; import com.cometchat.pro.uikit.SmartReplyList; import com.cometchat.pro.uikit.Sticker.listener.StickerClickListener; import com.cometchat.pro.uikit.Sticker.StickerView; @@ -103,17 +101,14 @@ import java.util.TimerTask; import adapter.MessageAdapter; -import adapter.StickersAdapter; import constant.StringContract; -import listeners.ClickListener; import listeners.ComposeActionListener; import listeners.ExtensionResponseListener; import listeners.MessageActionCloseListener; import listeners.OnItemClickListener; import listeners.OnMessageLongClick; import listeners.ReactionClickListener; -import listeners.ReactionListener; -import listeners.RecyclerTouchListener; +import listeners.LiveReactionListener; import listeners.StickyHeaderDecoration; import com.cometchat.pro.uikit.Sticker.model.Sticker; import screen.CometChatForwardMessageScreenActivity; @@ -127,6 +122,7 @@ import utils.MediaUtils; import utils.KeyBoardUtils; import com.cometchat.pro.uikit.Settings.UISettings; + import utils.Utils; import static android.view.View.GONE; @@ -279,7 +275,6 @@ public class CometChatMessageScreen extends Fragment implements View.OnClickList double LONGITUDE = 0; private ArrayList optionsArrayList = new ArrayList<>(); - private StickerView stickersView; private RelativeLayout stickerLayout; private ImageView closeStickerView; @@ -349,7 +344,7 @@ private void initViewComponent(View view) { composeBox.setVisibility(View.VISIBLE); container = view.findViewById(R.id.reactions_container); - composeBox.liveReactionBtn.setOnTouchListener(new ReactionListener(700, 1000, new ReactionClickListener() { + composeBox.liveReactionBtn.setOnTouchListener(new LiveReactionListener(700, 1000, new ReactionClickListener() { @Override public void onClick(View var1) { container.setAlpha(1.0f); @@ -369,7 +364,8 @@ public void run() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); - imageView.clearAnimation(); + if (imageView!=null) + imageView.clearAnimation(); container.removeAllViews(); if (typingTimer!=null) typingTimer.schedule(new TimerTask() { @@ -1419,12 +1415,14 @@ public void onSuccess(User user) { if (getActivity() != null) { if (user.isBlockedByMe()) { + tvStatus.setVisibility(View.GONE); isBlockedByMe = true; rvSmartReply.setVisibility(GONE); toolbar.setSelected(false); blockedUserName.setText("You've blocked " + user.getName()); blockUserLayout.setVisibility(View.VISIBLE); } else { + tvStatus.setVisibility(View.VISIBLE); isBlockedByMe = false; blockUserLayout.setVisibility(GONE); avatarUrl = user.getAvatar(); @@ -1944,18 +1942,20 @@ private void checkSmartReply(BaseMessage lastMessage) { private void typingIndicator(TypingIndicator typingIndicator, boolean show) { if (messageAdapter != null) { if (show) { - if (UISettings.isShowTypingIndicators()) { - if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { - if (typingIndicator.getMetadata() == null) + if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { + if (typingIndicator.getMetadata() == null) { + if (UISettings.isShowTypingIndicators()) tvStatus.setText("is Typing..."); - else - setLiveReaction(); - } else { - if (typingIndicator.getMetadata() == null) + } + else + setLiveReaction(); + } else { + if (typingIndicator.getMetadata() == null) { + if (UISettings.isShowTypingIndicators()) tvStatus.setText(typingIndicator.getSender().getName() + " is Typing..."); - else - setLiveReaction(); } + else + setLiveReaction(); } } else { if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { @@ -1969,7 +1969,8 @@ private void typingIndicator(TypingIndicator typingIndicator, boolean show) { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); - imageView.clearAnimation(); + if (imageView!=null) + imageView.clearAnimation(); container.removeAllViews(); } }); @@ -1985,7 +1986,8 @@ public void onAnimationEnd(Animator animation) { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); - imageView.clearAnimation(); + if (imageView!=null) + imageView.clearAnimation(); container.removeAllViews(); } }); @@ -2256,6 +2258,7 @@ public void setLongMessageClick(List baseMessagesList) { boolean editVisible = UISettings.isEnableEditingMessage(); boolean deleteVisible = UISettings.isEnableDeleteMessage(); boolean forwardVisible = UISettings.isEnableShareCopyForward(); + boolean reactionVisible = UISettings.isReactionVisible(); List textMessageList = new ArrayList<>(); List mediaMessageList = new ArrayList<>(); List locationMessageList = new ArrayList<>(); @@ -2413,6 +2416,8 @@ public void setLongMessageClick(List baseMessagesList) { bundle.putBoolean("deleteVisible",deleteVisible); bundle.putBoolean("replyVisible",replyVisible); bundle.putBoolean("forwardVisible",forwardVisible); + if (CometChat.isExtensionEnabled("reactions")) + bundle.putBoolean("isReactionVisible",reactionVisible); if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) && baseMessage.getSender().getUid().equals(loggedInUser.getUid())) bundle.putBoolean("messageInfoVisible",true); @@ -2521,6 +2526,36 @@ public void onMessageInfoClick() { } context.startActivity(intent); } + + @Override + public void onReactionClick(Reaction reaction) { + if (reaction.getCode().equals("add_emoji")) { +// showReactionDialog(baseMessage.getId()); + } else { + JSONObject body = new JSONObject(); + try { + body.put("msgId", baseMessage.getId()); + body.put("emoji", reaction.getCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + + CometChat.callExtension("reactions", "POST", "/v1/react", body, + new CometChat.CallbackListener() { + @Override + public void onSuccess(JSONObject responseObject) { + Log.e(TAG, "onSuccess: " + responseObject.toString()); + // ReactionModel added successfully. + } + + @Override + public void onError(CometChatException e) { + Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); + Log.e(TAG, "onError: " + e.getCode() + e.getMessage() + e.getDetails()); + } + }); + } + } }); } @@ -2599,7 +2634,10 @@ private void sendLiveReaction() { } private void setLiveReaction() { - flyEmoji(R.drawable.heart_reaction); + if (UISettings.showLiveReaction()) { + container.setAlpha(1.0f); + flyEmoji(R.drawable.heart_reaction); + } } private void flyEmoji(final int resId) { diff --git a/uikit/src/main/java/screen/messagelist/MessageActionFragment.java b/uikit/src/main/java/screen/messagelist/MessageActionFragment.java index 8330f053..2e9a2325 100644 --- a/uikit/src/main/java/screen/messagelist/MessageActionFragment.java +++ b/uikit/src/main/java/screen/messagelist/MessageActionFragment.java @@ -8,17 +8,23 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; import com.cometchat.pro.uikit.R; +import com.cometchat.pro.uikit.Reaction.model.Reaction; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.bottomsheet.BottomSheetDialog; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; -import screen.messagelist.CometChatMessageListActivity; +import adapter.ReactionListAdapter; +import listeners.ClickListener; +import listeners.RecyclerTouchListener; import screen.threadconversation.CometChatThreadMessageActivity; +import utils.Extensions; public class MessageActionFragment extends BottomSheetDialogFragment { @@ -31,6 +37,11 @@ public class MessageActionFragment extends BottomSheetDialogFragment { private TextView messageInfo; private TextView shareMessage; + + private RecyclerView reactionsList; + private ReactionListAdapter reactionAdapter; + private ImageView showReactionDialog; + private boolean isShareVisible; private boolean isThreadVisible; private boolean isCopyVisible; @@ -39,6 +50,7 @@ public class MessageActionFragment extends BottomSheetDialogFragment { private boolean isForwardVisible; private boolean isReplyVisible; private boolean isMessageInfoVisible; + private boolean isReactionsVisible; private MessageActionListener messageActionListener; @@ -60,6 +72,7 @@ private void fetchArguments() { isForwardVisible = getArguments().getBoolean("forwardVisible"); isShareVisible = getArguments().getBoolean("shareVisible"); isMessageInfoVisible = getArguments().getBoolean("messageInfoVisible"); + isReactionsVisible = getArguments().getBoolean("isReactionVisible"); type = getArguments().getString("type"); } } @@ -81,6 +94,29 @@ public void onGlobalLayout() { behavior.setPeekHeight(0); } }); + reactionsList = view.findViewById(R.id.reactions); + reactionAdapter = new ReactionListAdapter(getContext(), Extensions.getRandomEmojis(15)); + reactionsList.setAdapter(reactionAdapter); + + reactionsList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), reactionsList, new ClickListener() { + @Override + public void onClick(View var1, int var2) { + Reaction reaction = (Reaction)var1.getTag(R.string.reaction); + if (messageActionListener != null) + messageActionListener.onReactionClick(reaction); + dismiss(); + } + })); +// showReactionDialog = view.findViewById(R.id.show_reaction_dialog); +// showReactionDialog.setVisibility(View.GONE); +// showReactionDialog.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// if (messageActionListener!=null) +// messageActionListener.onReactionClick(new Reaction("add_emoji","add_emoji")); +// dismiss(); +// } +// }); threadMessage = view.findViewById(R.id.start_thread); editMessage = view.findViewById(R.id.edit_message); replyMessage = view.findViewById(R.id.reply_message); @@ -90,6 +126,10 @@ public void onGlobalLayout() { shareMessage = view.findViewById(R.id.share_message); messageInfo = view.findViewById(R.id.message_info); + if (isReactionsVisible) + reactionsList.setVisibility(View.VISIBLE); + else + reactionsList.setVisibility(View.GONE); if (isThreadVisible) threadMessage.setVisibility(View.VISIBLE); else @@ -210,6 +250,8 @@ public interface MessageActionListener { void onCopyMessageClick(); void onShareMessageClick(); void onMessageInfoClick(); + + void onReactionClick(Reaction reaction); } @Override diff --git a/uikit/src/main/java/screen/threadconversation/CometChatThreadMessageScreen.java b/uikit/src/main/java/screen/threadconversation/CometChatThreadMessageScreen.java index 72caa183..79c1a07a 100644 --- a/uikit/src/main/java/screen/threadconversation/CometChatThreadMessageScreen.java +++ b/uikit/src/main/java/screen/threadconversation/CometChatThreadMessageScreen.java @@ -1,6 +1,10 @@ package screen.threadconversation; import android.Manifest; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ObjectAnimator; +import android.animation.ValueAnimator; import android.content.ClipData; import android.content.ClipboardManager; import android.content.ContentResolver; @@ -10,6 +14,7 @@ import android.content.pm.PackageManager; import android.content.res.ColorStateList; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; @@ -18,17 +23,21 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.provider.MediaStore; import android.provider.Settings; import android.text.Editable; import android.util.Log; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AccelerateDecelerateInterpolator; import android.widget.EditText; +import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.MediaController; @@ -67,6 +76,8 @@ import com.cometchat.pro.uikit.Avatar; import com.cometchat.pro.uikit.ComposeBox.ComposeBox; import com.cometchat.pro.uikit.R; +import com.cometchat.pro.uikit.Reaction.model.Reaction; +import com.cometchat.pro.uikit.Settings.UISettings; import com.cometchat.pro.uikit.SmartReplyList; import com.facebook.shimmer.ShimmerFrameLayout; import com.google.android.gms.location.FusedLocationProviderClient; @@ -89,9 +100,11 @@ import adapter.ThreadAdapter; import constant.StringContract; import listeners.ComposeActionListener; +import listeners.LiveReactionListener; import listeners.MessageActionCloseListener; import listeners.OnItemClickListener; import listeners.OnMessageLongClick; +import listeners.ReactionClickListener; import listeners.StickyHeaderDecoration; import screen.CometChatForwardMessageScreenActivity; import screen.CometChatGroupDetailScreenActivity; @@ -237,6 +250,10 @@ public class CometChatThreadMessageScreen extends Fragment implements View.OnCli private int voteCount; private MessageActionFragment messageActionFragment; + private ImageView imageView; + private FrameLayout container; + public ObjectAnimator animation; + public CometChatThreadMessageScreen() { // Required empty public constructor } @@ -448,7 +465,55 @@ public void onError(CometChatException e) { composeBox.isPollVisible = false; composeBox.isStickerVisible = false; composeBox.ivMic.setVisibility(GONE); - composeBox.ivSend.setVisibility(VISIBLE); + if (UISettings.isEnableSendingMessage()) + composeBox.ivSend.setVisibility(VISIBLE); + + 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); @@ -1535,6 +1600,7 @@ private void setTypingIndicator(TypingIndicator typingIndicator,boolean isShow) } private void onMessageReceived(BaseMessage message) { + noReplyMessages.setVisibility(GONE); MediaUtils.playSendSound(context,R.raw.incoming_message); if (message.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { if (Id != null && Id.equalsIgnoreCase(message.getSender().getUid())) { @@ -1610,17 +1676,44 @@ private void checkSmartReply(BaseMessage lastMessage) { private void typingIndicator(TypingIndicator typingIndicator, boolean show) { if (messageAdapter != null) { if (show) { - if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) - tvTypingIndicator.setText("is Typing..."); - else - tvTypingIndicator.setText(typingIndicator.getSender().getName() + " is Typing..."); + if (typingIndicator.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) { + if (typingIndicator.getMetadata() == null) { + if (UISettings.isShowTypingIndicators()) + tvTypingIndicator.setText("is Typing..."); + } + else + setLiveReaction(); + } else { + if (typingIndicator.getMetadata() == null) { + if (UISettings.isShowTypingIndicators()) + tvTypingIndicator.setText(typingIndicator.getSender().getName() + " is Typing..."); + } + else + setLiveReaction(); + } } else { - tvTypingIndicator.setVisibility(GONE); + if (typingIndicator.getMetadata() == null) + tvTypingIndicator.setVisibility(GONE); + else { + 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(); + } + }); + } } - } + } + /** * This method is used to remove message listener * @@ -1772,13 +1865,13 @@ public void setLongMessageClick(List baseMessagesList) { messageActionFragment = new MessageActionFragment(); replyMessageLayout.setVisibility(GONE); editMessageLayout.setVisibility(GONE); - boolean copyVisible = true; - boolean threadVisible = true; + boolean copyVisible = UISettings.isEnableShareCopyForward(); + boolean threadVisible = false; boolean replyVisible = false; - boolean editVisible = true; - boolean deleteVisible = true; - boolean forwardVisible = true; - boolean mapVisible = true; + boolean editVisible = UISettings.isEnableEditingMessage(); + boolean deleteVisible = UISettings.isEnableDeleteMessage(); + boolean forwardVisible = UISettings.isEnableShareCopyForward(); + boolean reactionVisible = true; List textMessageList = new ArrayList<>(); List mediaMessageList = new ArrayList<>(); List locationMessageList = new ArrayList<>(); @@ -1802,7 +1895,6 @@ else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) { baseMessage = basemessage; threadVisible = false; - mapVisible = false; if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { deleteVisible = true; editVisible = true; @@ -1827,7 +1919,6 @@ else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || baseMessage = basemessage; copyVisible = false; threadVisible = false; - mapVisible = false; if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { deleteVisible = true; editVisible = false; @@ -1854,7 +1945,6 @@ else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || replyVisible = false; forwardVisible = true; if (basemessage.getSender().getUid().equals(CometChat.getLoggedInUser().getUid())) { - mapVisible = true; deleteVisible = true; editVisible = false; } else { @@ -1863,7 +1953,6 @@ else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || } else { deleteVisible = false; } - mapVisible = true; editVisible = false; } } @@ -1877,7 +1966,8 @@ else if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE) || bundle.putBoolean("deleteVisible",deleteVisible); bundle.putBoolean("replyVisible",replyVisible); bundle.putBoolean("forwardVisible",forwardVisible); - bundle.putBoolean("mapVisible",mapVisible); + if (CometChat.isExtensionEnabled("reactions")) + bundle.putBoolean("isReactionVisible",reactionVisible); if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) && baseMessage.getSender().getUid().equals(loggedInUser.getUid())) bundle.putBoolean("messageInfoVisible",true); @@ -1984,6 +2074,36 @@ public void onMessageInfoClick() { } context.startActivity(intent); } + + @Override + public void onReactionClick(Reaction reaction) { + if (reaction.getCode().equals("add_emoji")) { +// showReactionDialog(baseMessage.getId()); + } else { + JSONObject body = new JSONObject(); + try { + body.put("msgId", baseMessage.getId()); + body.put("emoji", reaction.getCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + + CometChat.callExtension("reactions", "POST", "/v1/react", body, + new CometChat.CallbackListener() { + @Override + public void onSuccess(JSONObject responseObject) { + Log.e(TAG, "onSuccess: " + responseObject.toString()); + // ReactionModel added successfully. + } + + @Override + public void onError(CometChatException e) { + Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); + Log.e(TAG, "onError: " + e.getCode() + e.getMessage() + e.getDetails()); + } + }); + } + } }); } @@ -2140,6 +2260,48 @@ private void replyMessage() { } } + //Live Reactions + private void sendLiveReaction() { + try { + JSONObject metaData = new JSONObject(); + metaData.put("reaction", "heart"); + TypingIndicator typingIndicator = new TypingIndicator(Id, type, metaData); + CometChat.startTyping(typingIndicator); + setLiveReaction(); + } catch (Exception e) { + Log.e(TAG, "sendLiveReaction: "+e.getMessage()); + } + } + + private void setLiveReaction() { + if (UISettings.showLiveReaction()) { + container.setAlpha(1.0f); + flyEmoji(R.drawable.heart_reaction); + } + } + + private void flyEmoji(final int resId) { + imageView = new ImageView(getContext()); + + FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + layoutParams.gravity = Gravity.BOTTOM|Gravity.END; + layoutParams.rightMargin = 16; + imageView.setLayoutParams(layoutParams); + container.addView(imageView); + Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId); + if (bitmap!=null) { + Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int) (bitmap.getWidth() * 0.2f), (int) (bitmap.getHeight() * 0.2f), false); + imageView.setImageBitmap(scaledBitmap); + } + + animation = ObjectAnimator.ofFloat(imageView, "translationY", -700f); + animation.setInterpolator(new AccelerateDecelerateInterpolator()); + animation.setRepeatCount(ValueAnimator.INFINITE); + animation.setDuration(700); + animation.start(); + } + + @Override public void handleDialogClose(DialogInterface dialog) { if (messageAdapter!=null) diff --git a/uikit/src/main/java/utils/Extensions.java b/uikit/src/main/java/utils/Extensions.java index 5dd7cc0a..ee734ae2 100644 --- a/uikit/src/main/java/utils/Extensions.java +++ b/uikit/src/main/java/utils/Extensions.java @@ -15,9 +15,12 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import listeners.ExtensionResponseListener; + +import com.cometchat.pro.uikit.Reaction.model.Reaction; import com.cometchat.pro.uikit.Sticker.model.Sticker; public class Extensions { @@ -126,6 +129,9 @@ public static HashMap extensionCheck(BaseMessage baseMessage) if (extensionsObject!=null && extensionsObject.has("polls")) { extensionMap.put("polls",extensionsObject.getJSONObject("polls")); } + if (extensionsObject!=null && extensionsObject.has("reactions")) { + extensionMap.put("reactions",extensionsObject.getJSONObject("reactions")); + } } return extensionMap; } @@ -284,9 +290,9 @@ public static HashMap> extractStickersFromJSON(JSONObject j } if (dataObject.has("customStickers")) { JSONArray customSticker = dataObject.getJSONArray("customStickers"); - Log.d(TAG, "getStickersList: customStickersArray " + customSticker.length()); + Log.d(TAG, "getStickersList: customStickersArray " + customSticker.toString() ); for (int i = 0; i < customSticker.length(); i++) { - JSONObject stickerObject = defaultStickersArray.getJSONObject(i); + JSONObject stickerObject = customSticker.getJSONObject(i); String stickerOrder = stickerObject.getString("stickerOrder"); String stickerSetId = stickerObject.getString("stickerSetId"); String stickerUrl = stickerObject.getString("stickerUrl"); @@ -303,7 +309,7 @@ public static HashMap> extractStickersFromJSON(JSONObject j } HashMap> stickerMap = new HashMap(); - for (int i=0;i> extractStickersFromJSON(JSONObject j return stickerMap; } + public static List getRandomEmojis(int i) { + List randomReaction = new ArrayList<>(); + List fetchedReaction = ReactionUtils.getFeelList(); + for (int k=0;k getReactionsOnMessage(BaseMessage baseMessage) { + HashMap result = new HashMap<>(); + HashMap extensionList = Extensions.extensionCheck(baseMessage); + if (extensionList!=null) { + try { + if (extensionList.containsKey("reactions")) { + JSONObject data = extensionList.get("reactions"); + Iterator keys= data.keys(); + while (keys.hasNext()) + { + String keyValue = (String)keys.next(); + JSONObject react = data.getJSONObject(keyValue); + String reactCount = react.length()+""; + result.put(keyValue,reactCount); + Log.e(TAG, "getReactionsOnMessage: "+keyValue+"="+reactCount); + } + } + }catch (Exception e) { e.printStackTrace(); } + } + return result; + } + + public static HashMap> getReactionsInfo(JSONObject jsonObject) { + HashMap> result = new HashMap<>(); + if (jsonObject!=null) { + try { + JSONObject injectedObject = jsonObject.getJSONObject("@injected"); + if (injectedObject != null && injectedObject.has("extensions")) { + JSONObject extensionsObject = injectedObject.getJSONObject("extensions"); + if (extensionsObject.has("reactions")) { + JSONObject data = extensionsObject.getJSONObject("reactions"); + Iterator keys = data.keys(); + while (keys.hasNext()) { + List reactionUser = new ArrayList<>(); + String keyValue = (String) keys.next(); + JSONObject react = data.getJSONObject(keyValue); + Iterator uids = react.keys(); + while (uids.hasNext()) { + String uid = (String) uids.next(); + JSONObject user = react.getJSONObject(uid); + reactionUser.add(user.getString("name")); + Log.e(TAG, "getReactionsOnMessage: " + keyValue + "=" + user.getString("name")); + } + result.put(keyValue, reactionUser); + } + } + } + }catch (Exception e) { e.printStackTrace(); } + } + return result; + } // public static List extractStickersFromJSON(JSONObject jsonObject) { // List stickers = new ArrayList<>(); diff --git a/uikit/src/main/java/utils/ReactionUtils.java b/uikit/src/main/java/utils/ReactionUtils.java new file mode 100644 index 00000000..0d12e67b --- /dev/null +++ b/uikit/src/main/java/utils/ReactionUtils.java @@ -0,0 +1,501 @@ +package utils; + +import com.cometchat.pro.uikit.Reaction.model.Reaction; + +import java.util.ArrayList; +import java.util.List; + +public class ReactionUtils { + static String[] feel = { + "😄", + "😍", + "👍", + "💙", + "😊", + "😂", + "😃", + "😀", + "☺", + "😉", + "😘", + "😚", + "😗", + "😙", + "😜", + "😝", + "😛", + "😳", + "😁", + "😔", + "😌", + "😒", + "😞", + "😣", + "😢", + "😭", + "😪", + "😥", + "😰", + "😅", + "😓", + "😩", + "😫", + "😨", + "😱", + "😠", + "😡", + "😤", + "😖", + "😆", + "😋", + "😷", + "😎", + "😴", + "😵", + "😲", + "😟", + "😦", + "😧", + "😈", + "👿", + "😮", + "😬", + "😐", + "😕", + "😯", + "😶", + "😇", + "😏", + "😑", + "👲", + "👳", + "👮", + "👷", + "💂", + "👶", + "👦", + "👧", + "👨", + "👩", + "👴", + "👵", + "👱", + "👼", + "👸", + "😺", + "😸", + "😻", + "😽", + "😼", + "🙀", + "😿", + "😹", + "😾", + "👹", + "👺", + "🙈", + "🙉", + "🙊", + "💀", + "👽", + "💩", + "🔥", + "✨", + "🌟", + "💫", + "💥", + "💢", + "💦", + "💧", + "💤", + "💨", + "👂", + "👀", + "👃", + "👅", + "👄", + "👎", + "👌", + "👊", + "✊", + "✌", + "👋", + "✋", + "👐", + "👆", + "👇", + "👉", + "👈", + "🙌", + "🙏", + "☝", + "👏", + "💪", + "🚶", + "🏃", + "💃", + "👫", + "👪", + "👬", + "👭", + "💏", + "💑", + "👯", + "🙆", + "🙅", + "💁", + "🙋", + "💆", + "💇", + "💅", + "👰", + "🙎", + "🙍", + "🙇", + "🎩", + "👑", + "👒", + "👟", + "👞", + "👡", + "👠", + "👢", + "👕", + "👔", + "👚", + "👗", + "🎽", + "👖", + "👘", + "👙", + "💼", + "👜", + "👝", + "👛", + "👓", + "🎀", + "🌂", + "💄", + "💛", + "💜", + "💚", + "❤", + "💔", + "💗", + "💓", + "💕", + "💖", + "💞", + "💘", + "💌", + "💋", + "💍", + "💎", + "👤", + "👥", + "💬", + "👣", + "💭"}; + + static String[] flags = { + "🇦🇨", + "🇦🇩", + "🇦🇪", + "🇦🇫", + "🇦🇬", + "🇦🇮", + "🇦🇱", + "🇦🇲", + "🇦🇴", + "🇦🇶", + "🇦🇷", + "🇦🇸", + "🇦🇹", + "🇦🇺", + "🇦🇼", + "🇦🇽", + "🇦🇿", + "🇦", + "🇧🇦", + "🇧🇧", + "🇧🇩", + "🇧🇪", + "🇧🇫", + "🇧🇬", + "🇧🇭", + "🇧🇮", + "🇧🇯", + "🇧🇱", + "🇧🇲", + "🇧🇳", + "🇧🇴", + "🇧🇶", + "🇧🇷", + "🇧🇸", + "🇧🇹", + "🇧🇻", + "🇧🇼", + "🇧🇾", + "🇧🇿", + "🇧", + "🇨🇦", + "🇨🇨", + "🇨🇩", + "🇨🇫", + "🇨🇬", + "🇨🇭", + "🇨🇮", + "🇨🇰", + "🇨🇱", + "🇨🇲", + "🇨🇳", + "🇨🇴", + "🇨🇵", + "🇨🇷", + "🇨🇺", + "🇨🇻", + "🇨🇼", + "🇨🇽", + "🇨🇾", + "🇨🇿", + "🇨", + "🇩🇪", + "🇩🇬", + "🇩🇯", + "🇩🇰", + "🇩🇲", + "🇩🇴", + "🇩🇿", + "🇩", + "🇪🇦", + "🇪🇨", + "🇪🇪", + "🇪🇬", + "🇪🇭", + "🇪🇷", + "🇪🇸", + "🇪🇹", + "🇪🇺", + "🇪", + "🇫🇮", + "🇫🇯", + "🇫🇰", + "🇫🇲", + "🇫🇴", + "🇫🇷", + "🇫", + "🇬🇦", + "🇬🇧", + "🇬🇩", + "🇬🇪", + "🇬🇫", + "🇬🇬", + "🇬🇭", + "🇬🇮", + "🇬🇱", + "🇬🇲", + "🇬🇳", + "🇬🇵", + "🇬🇶", + "🇬🇷", + "🇬🇸", + "🇬🇹", + "🇬🇺", + "🇬🇼", + "🇬🇾", + "🇬", + "🇭🇰", + "🇭🇲", + "🇭🇳", + "🇭🇷", + "🇭🇹", + "🇭🇺", + "🇭", + "🇮🇨", + "🇮🇩", + "🇮🇪", + "🇮🇱", + "🇮🇲", + "🇮🇳", + "🇮🇴", + "🇮🇶", + "🇮🇷", + "🇮🇸", + "🇮🇹", + "🇮", + "🇯🇪", + "🇯🇲", + "🇯🇴", + "🇯🇵", + "🇯", + "🇰🇪", + "🇰🇬", + "🇰🇭", + "🇰🇮", + "🇰🇲", + "🇰🇳", + "🇰🇵", + "🇰🇷", + "🇰🇼", + "🇰🇾", + "🇰🇿", + "🇰", + "🇱🇦", + "🇱🇧", + "🇱🇨", + "🇱🇮", + "🇱🇰", + "🇱🇷", + "🇱🇸", + "🇱🇹", + "🇱🇺", + "🇱🇻", + "🇱🇾", + "🇱", + "🇲🇦", + "🇲🇨", + "🇲🇩", + "🇲🇪", + "🇲🇫", + "🇲🇬", + "🇲🇭", + "🇲🇰", + "🇲🇱", + "🇲🇲", + "🇲🇳", + "🇲🇴", + "🇲🇵", + "🇲🇶", + "🇲🇷", + "🇲🇸", + "🇲🇹", + "🇲🇺", + "🇲🇻", + "🇲🇼", + "🇲🇽", + "🇲🇾", + "🇲🇿", + "🇲", + "🇳🇦", + "🇳🇨", + "🇳🇪", + "🇳🇫", + "🇳🇬", + "🇳🇮", + "🇳🇱", + "🇳🇴", + "🇳🇵", + "🇳🇷", + "🇳🇺", + "🇳🇿", + "🇳", + "🇴🇲", + "🇴", + "🇵🇦", + "🇵🇪", + "🇵🇫", + "🇵🇬", + "🇵🇭", + "🇵🇰", + "🇵🇱", + "🇵🇲", + "🇵🇳", + "🇵🇷", + "🇵🇸", + "🇵🇹", + "🇵🇼", + "🇵🇾", + "🇵", + "🇶🇦", + "🇶", + "🇷🇪", + "🇷🇴", + "🇷🇸", + "🇷🇺", + "🇷🇼", + "🇷", + "🇸🇦", + "🇸🇧", + "🇸🇨", + "🇸🇩", + "🇸🇪", + "🇸🇬", + "🇸🇭", + "🇸🇮", + "🇸🇯", + "🇸🇰", + "🇸🇱", + "🇸🇲", + "🇸🇳", + "🇸🇴", + "🇸🇷", + "🇸🇸", + "🇸🇹", + "🇸🇻", + "🇸🇽", + "🇸🇾", + "🇸🇿", + "🇸", + "🇹🇦", + "🇹🇨", + "🇹🇩", + "🇹🇫", + "🇹🇬", + "🇹🇭", + "🇹🇯", + "🇹🇰", + "🇹🇱", + "🇹🇲", + "🇹🇳", + "🇹🇴", + "🇹🇷", + "🇹🇹", + "🇹🇻", + "🇹🇼", + "🇹🇿", + "🇹", + "🇺🇦", + "🇺🇬", + "🇺🇲", + "🇺🇳", + "🇺🇸", + "🇺🇾", + "🇺🇿", + "🇺", + "🇻🇦", + "🇻🇨", + "🇻🇪", + "🇻🇬", + "🇻🇮", + "🇻🇳", + "🇻🇺", + "🇻", + "🇼🇫", + "🇼🇸", + "🇼", + "🇽🇰", + "🇽", + "🇾🇪", + "🇾🇹", + "🇾", + "🇿🇦", + "🇿🇲" + }; + + public static List getFeelList() { + List resultList = new ArrayList<>(); + for (int i=0;i getFlagList() { + List resultList = new ArrayList<>(); + for (int i=0;i + + + + + \ No newline at end of file diff --git a/uikit/src/main/res/layout/cometchat_audio_layout_left.xml b/uikit/src/main/res/layout/cometchat_audio_layout_left.xml index 5b2ed62b..8123627c 100644 --- a/uikit/src/main/res/layout/cometchat_audio_layout_left.xml +++ b/uikit/src/main/res/layout/cometchat_audio_layout_left.xml @@ -61,17 +61,20 @@ - - - - + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> - + + + + - + android:orientation="vertical" + android:layout_height="wrap_content"> + + + - - + android:layout_height="wrap_content"> + + + - - - - - - - - + + + + \ No newline at end of file diff --git a/uikit/src/main/res/layout/reaction_list_row.xml b/uikit/src/main/res/layout/reaction_list_row.xml new file mode 100644 index 00000000..b980e760 --- /dev/null +++ b/uikit/src/main/res/layout/reaction_list_row.xml @@ -0,0 +1,16 @@ + + + + diff --git a/uikit/src/main/res/layout/right_location_message_item.xml b/uikit/src/main/res/layout/right_location_message_item.xml index de4a2e2b..3e132eaa 100644 --- a/uikit/src/main/res/layout/right_location_message_item.xml +++ b/uikit/src/main/res/layout/right_location_message_item.xml @@ -83,18 +83,30 @@ android:textStyle="bold" tools:visibility="visible" android:visibility="gone"/> - + android:layout_height="wrap_content"> + + + \ No newline at end of file diff --git a/uikit/src/main/res/layout/right_message_item.xml b/uikit/src/main/res/layout/right_message_item.xml index cc028660..07b58b1a 100644 --- a/uikit/src/main/res/layout/right_message_item.xml +++ b/uikit/src/main/res/layout/right_message_item.xml @@ -46,19 +46,20 @@ android:padding="10dp" android:maxEms="12" android:textColor="@color/textColorWhite" - tools:text="@tools:sample/lorem/random" /> + tools:text="@tools:sample/lorem" /> - - + android:layout_height="wrap_content"> + + + \ No newline at end of file diff --git a/uikit/src/main/res/layout/thread_location_message_item.xml b/uikit/src/main/res/layout/thread_location_message_item.xml index 97be21a9..5eb2c21d 100644 --- a/uikit/src/main/res/layout/thread_location_message_item.xml +++ b/uikit/src/main/res/layout/thread_location_message_item.xml @@ -85,7 +85,16 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + - - + + + + + + + diff --git a/uikit/src/main/res/values/strings.xml b/uikit/src/main/res/values/strings.xml index c906ad25..dc56f534 100644 --- a/uikit/src/main/res/values/strings.xml +++ b/uikit/src/main/res/values/strings.xml @@ -246,6 +246,7 @@ Delete Group Send Stickers Shared a Sticker + reaction Public Group Private Group