use of com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.model.Sticker in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatMessageList 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());
backIcon = view.findViewById(R.id.back_action);
infoAction = view.findViewById(R.id.info_action);
audioCallAction = view.findViewById(R.id.audio_call_action);
videoCallAction = view.findViewById(R.id.video_call_action);
backIcon.setOnClickListener(this);
infoAction.setOnClickListener(this);
audioCallAction.setOnClickListener(this);
videoCallAction.setOnClickListener(this);
bottomLayout = view.findViewById(R.id.bottom_layout);
messageShimmer = view.findViewById(R.id.shimmer_layout);
composeBox = view.findViewById(R.id.message_box);
composeBox.usedIn(CometChatMessageListActivity.class.getName());
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
composeBox.hideGroupCallOption(true);
setComposeBoxListener();
if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
FeatureRestriction.isOneOnOneChatEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
composeBox.setVisibility(View.VISIBLE);
else
composeBox.setVisibility(View.GONE);
}
});
} else if (type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_GROUP)) {
FeatureRestriction.isGroupChatEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal)
composeBox.setVisibility(View.VISIBLE);
else
composeBox.setVisibility(GONE);
}
});
}
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);
}
}));
newMessageLayout = view.findViewById(R.id.new_message_layout);
newMessageLayoutText = view.findViewById(R.id.new_message_tv);
newMessageLayout.setVisibility(GONE);
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);
stickersView = view.findViewById(R.id.stickersView);
stickerLayout = view.findViewById(R.id.sticker_layout);
closeStickerView = view.findViewById(R.id.close_sticker_layout);
closeStickerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stickerLayout.setVisibility(GONE);
}
});
stickersView.setStickerClickListener(new StickerClickListener() {
@Override
public void onClickListener(Sticker sticker) {
JSONObject stickerData = new JSONObject();
try {
stickerData.put("sticker_url", sticker.getUrl());
stickerData.put("sticker_name", sticker.getName());
} catch (JSONException e) {
e.printStackTrace();
}
sendCustomMessage(UIKitConstants.IntentStrings.STICKERS, stickerData);
stickerLayout.setVisibility(GONE);
}
});
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);
if (repliedMessage != null) {
baseMessage = repliedMessage;
replyMessage();
}
rvChatListView = view.findViewById(R.id.rv_message_list);
MaterialButton unblockUserBtn = view.findViewById(R.id.btn_unblock_user);
unblockUserBtn.setOnClickListener(this);
blockedUserName = view.findViewById(R.id.tv_blocked_user_name);
unblockBtn = view.findViewById(R.id.btn_unblock_user);
blockUserLayout = view.findViewById(R.id.blocked_user_layout);
tvName = view.findViewById(R.id.tv_name);
tvStatus = view.findViewById(R.id.tv_status);
userAvatar = view.findViewById(R.id.iv_chat_avatar);
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(name);
setAvatar();
rvChatListView.setLayoutManager(linearLayoutManager);
if (Utils.isDarkMode(context)) {
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 {
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 -> {
isKeyboardVisible = keyboardVisible;
if (keyboardVisible) {
scrollToBottom();
composeBox.ivMic.setVisibility(GONE);
composeBox.ivSend.setVisibility(View.VISIBLE);
} else {
if (isEdit) {
composeBox.ivMic.setVisibility(GONE);
composeBox.ivSend.setVisibility(View.VISIBLE);
} else {
FeatureRestriction.isVoiceNotesEnabled(new FeatureRestriction.OnSuccessListener() {
@Override
public void onSuccess(Boolean booleanVal) {
if (booleanVal) {
composeBox.ivMic.setVisibility(View.VISIBLE);
composeBox.ivSend.setVisibility(GONE);
} else {
composeBox.ivMic.setVisibility(GONE);
composeBox.ivSend.setVisibility(View.VISIBLE);
}
}
});
}
}
});
// 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();
}
}
if (messageAdapter != null && ((messageAdapter.getItemCount() - 1) - linearLayoutManager.findLastVisibleItemPosition() < 5)) {
newMessageLayout.setVisibility(GONE);
newMessageCount = 0;
}
}
});
rvSmartReply.setItemClickListener(new OnItemClickListener<String>() {
@Override
public void OnItemClick(String var, int position) {
if (!isSmartReplyClicked) {
isSmartReplyClicked = true;
rvSmartReply.setVisibility(GONE);
sendMessage(var);
}
}
});
fetchSettings();
// 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.cometchatStickers.model.Sticker in project android-java-chat-push-notification-app by cometchat-pro.
the class Extensions method extractStickersFromJSON.
public static HashMap<String, List<Sticker>> extractStickersFromJSON(JSONObject jsonObject) {
List<Sticker> stickers = new ArrayList<>();
if (jsonObject != null) {
try {
JSONObject dataObject = jsonObject.getJSONObject("data");
JSONArray defaultStickersArray = dataObject.getJSONArray("defaultStickers");
Log.d(TAG, "getStickersList: defaultStickersArray " + defaultStickersArray.length());
for (int i = 0; i < defaultStickersArray.length(); i++) {
JSONObject stickerObject = defaultStickersArray.getJSONObject(i);
String stickerOrder = stickerObject.getString("stickerOrder");
String stickerSetId = stickerObject.getString("stickerSetId");
String stickerUrl = stickerObject.getString("stickerUrl");
String stickerSetName = stickerObject.getString("stickerSetName");
String stickerName = stickerObject.getString("stickerName");
Sticker sticker = new Sticker(stickerName, stickerUrl, stickerSetName);
stickers.add(sticker);
}
if (dataObject.has("customStickers")) {
JSONArray customSticker = dataObject.getJSONArray("customStickers");
Log.d(TAG, "getStickersList: customStickersArray " + customSticker.toString());
for (int i = 0; i < customSticker.length(); i++) {
JSONObject stickerObject = customSticker.getJSONObject(i);
String stickerOrder = stickerObject.getString("stickerOrder");
String stickerSetId = stickerObject.getString("stickerSetId");
String stickerUrl = stickerObject.getString("stickerUrl");
String stickerSetName = stickerObject.getString("stickerSetName");
String stickerName = stickerObject.getString("stickerName");
Sticker sticker = new Sticker(stickerName, stickerUrl, stickerSetName);
stickers.add(sticker);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
HashMap<String, List<Sticker>> stickerMap = new HashMap();
for (int i = 0; i < stickers.size(); i++) {
if (stickerMap.containsKey(stickers.get(i).getSetName())) {
stickerMap.get(stickers.get(i).getSetName()).add(stickers.get(i));
} else {
List<Sticker> list = new ArrayList<>();
list.add(stickers.get(i));
stickerMap.put(stickers.get(i).getSetName(), list);
}
}
return stickerMap;
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.model.Sticker in project android-java-chat-push-notification-app by cometchat-pro.
the class StickerFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_stickers_view, container, false);
rvStickers = view.findViewById(R.id.rvStickers);
rvStickers.setLayoutManager(new GridLayoutManager(getContext(), 4));
Id = this.getArguments().getString("Id");
type = this.getArguments().getString("type");
List<Sticker> list = this.getArguments().getParcelableArrayList("stickerList");
stickers = list;
Log.e("onStickerView: ", stickers.get(0).getSetName());
adapter = new StickersAdapter(getContext(), stickers);
rvStickers.setAdapter(adapter);
rvStickers.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rvStickers, new ClickListener() {
@Override
public void onClick(View var1, int var2) {
Sticker sticker = (Sticker) var1.getTag(R.string.sticker);
stickerClickListener.onClickListener(sticker);
}
}));
return view;
}
use of com.cometchat.pro.uikit.ui_components.shared.cometchatStickers.model.Sticker in project android-java-chat-push-notification-app by cometchat-pro.
the class StickersAdapter method setStickerData.
private void setStickerData(ImageViewHolder viewHolder, int i) {
Sticker sticker = stickerArrayList.get(i);
Glide.with(context).asBitmap().load(sticker.getUrl()).into(viewHolder.imageView);
viewHolder.itemView.setTag(R.string.sticker, sticker);
}
Aggregations