use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatCallsAdapter method onBindViewHolder.
/**
* This method is used to bind the ConversationViewHolder contents with conversation at given
* position. It set avatar, name, lastMessage, unreadMessageCount and messageTime of conversation
* in a respective ConversationViewHolder content. It checks whether conversation type is user
* or group and set name and avatar as accordingly. It also checks whether last message is text, media
* or file and modify txtUserMessage view accordingly.
*
* @param callViewHolder is a object of ConversationViewHolder.
* @param position is a position of item in recyclerView.
*
* @see Conversation
*/
@Override
public void onBindViewHolder(@NonNull CallViewHolder callViewHolder, int position) {
BaseMessage baseMessage = callList.get(position);
Call call = (Call) baseMessage;
String avatar;
String uid;
String type;
boolean isIncoming, isVideo, isMissed = false;
String name;
String callMessageText;
String callType;
String callCategory;
if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
String callName = ((User) call.getCallReceiver()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((User) call.getCallReceiver()).getAvatar());
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.outgoing);
uid = ((User) call.getCallReceiver()).getUid();
isIncoming = false;
} else {
String callName = ((User) call.getCallInitiator()).getName();
callViewHolder.callListRowBinding.callSenderName.setText(callName);
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar((User) call.getCallInitiator());
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED) || call.getCallStatus().equals(CometChatConstants.CALL_STATUS_CANCELLED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
uid = call.getSender().getUid();
isIncoming = true;
}
type = CometChatConstants.RECEIVER_TYPE_USER;
} else {
callViewHolder.callListRowBinding.callSenderName.setText(((Group) call.getCallReceiver()).getName());
callViewHolder.callListRowBinding.callSenderAvatar.setAvatar(((Group) call.getCallReceiver()));
if (((User) call.getCallInitiator()).getUid().equals(loggedInUser)) {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = false;
} else {
if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_UNANSWERED)) {
callMessageText = context.getResources().getString(R.string.missed_call);
isMissed = true;
} else if (call.getCallStatus().equals(CometChatConstants.CALL_STATUS_REJECTED)) {
callMessageText = context.getResources().getString(R.string.rejected_call);
} else
callMessageText = context.getResources().getString(R.string.incoming);
isIncoming = true;
}
uid = ((Group) call.getCallReceiver()).getGuid();
type = CometChatConstants.RECEIVER_TYPE_GROUP;
}
if (call.getType().equals(CometChatConstants.CALL_TYPE_VIDEO)) {
callMessageText = callMessageText + " " + context.getResources().getString(R.string.video_call);
isVideo = true;
} else {
callMessageText = callMessageText + " " + context.getResources().getString(R.string.audio_call);
isVideo = false;
}
if (isVideo) {
if (isIncoming) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_video_call, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_video_call, 0, 0, 0);
}
} else {
if (isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_incoming_24dp, 0, 0, 0);
} else if (isIncoming && !isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_incoming_call, 0, 0, 0);
} else if (!isIncoming && isMissed) {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_call_missed_outgoing_24dp, 0, 0, 0);
} else {
callViewHolder.callListRowBinding.callMessage.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_outgoing_call, 0, 0, 0);
}
}
callViewHolder.callListRowBinding.calltimeTv.setText(Utils.getLastMessageDate(context, call.getInitiatedAt()));
callViewHolder.callListRowBinding.callMessage.setText(callMessageText);
callViewHolder.callListRowBinding.getRoot().setTag(R.string.call, call);
if (call.getReceiverType().equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER)) {
// if(FeatureRestriction.isOneOnOneAudioCallEnabled() ||
// FeatureRestriction.isOneOnOneVideoCallEnabled())
callViewHolder.callListRowBinding.callIv.setVisibility(View.VISIBLE);
// else
// callViewHolder.callListRowBinding.callIv.setVisibility(View.GONE);
}
callViewHolder.callListRowBinding.callIv.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
}
use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class CometChatGroupsAdapter method onBindViewHolder.
/**
* This method is used to bind the GroupViewHolder contents with group at given
* position. It set group icon, group name in a respective GroupViewHolder content.
*
* @param groupViewHolder is a object of GroupViewHolder.
* @param position is a position of item in recyclerView.
* @see Group
*/
@Override
public void onBindViewHolder(@NonNull GroupViewHolder groupViewHolder, int position) {
Group group = groupList.get(position);
groupViewHolder.groupListRowBinding.setGroup(group);
groupViewHolder.groupListRowBinding.executePendingBindings();
groupViewHolder.groupListRowBinding.txtUserMessage.setText(context.getString(R.string.members) + ": " + group.getMembersCount());
if (group.getGroupType().equals(CometChatConstants.GROUP_TYPE_PRIVATE))
groupViewHolder.groupListRowBinding.txtUserName.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_security_24dp, 0);
else if (group.getGroupType().equals(CometChatConstants.GROUP_TYPE_PASSWORD))
groupViewHolder.groupListRowBinding.txtUserName.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_lock_24dp, 0);
else
groupViewHolder.groupListRowBinding.txtUserName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
groupViewHolder.groupListRowBinding.executePendingBindings();
groupViewHolder.groupListRowBinding.avGroup.setBackgroundColor(Color.parseColor(UIKitSettings.getColor()));
groupViewHolder.groupListRowBinding.getRoot().setTag(R.string.group, group);
groupViewHolder.groupListRowBinding.txtUserMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));
groupViewHolder.groupListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
if (Utils.isDarkMode(context)) {
groupViewHolder.groupListRowBinding.txtUserName.setCompoundDrawableTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.grey)));
groupViewHolder.groupListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
groupViewHolder.groupListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.grey));
} else {
groupViewHolder.groupListRowBinding.txtUserName.setCompoundDrawableTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.message_bubble_grey)));
groupViewHolder.groupListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
groupViewHolder.groupListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.light_grey));
}
}
use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class AllCall method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cometchat_all_call, container, false);
fetchSettings();
CometChatError.init(getContext());
rvCallList = view.findViewById(R.id.callList_rv);
linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
rvCallList.setLayoutManager(linearLayoutManager);
noCallView = view.findViewById(R.id.no_call_vw);
rvCallList.setItemClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
if (var.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
User user;
if (((User) var.getCallInitiator()).getUid().equals(CometChat.getLoggedInUser().getUid())) {
user = ((User) var.getCallReceiver());
} else {
user = (User) var.getCallInitiator();
}
Intent intent = new Intent(getContext(), CometChatUserDetailScreenActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.UID, user.getUid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, user.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, user.getAvatar());
intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
intent.putExtra(UIKitConstants.IntentStrings.LINK, user.getLink());
intent.putExtra(UIKitConstants.IntentStrings.IS_BLOCKED_BY_ME, user.isBlockedByMe());
intent.putExtra(UIKitConstants.IntentStrings.FROM_CALL_LIST, true);
startActivity(intent);
} else {
Group group;
group = ((Group) var.getCallReceiver());
Intent intent = new Intent(getContext(), CometChatGroupDetailActivity.class);
intent.putExtra(UIKitConstants.IntentStrings.GUID, group.getGuid());
intent.putExtra(UIKitConstants.IntentStrings.NAME, group.getName());
intent.putExtra(UIKitConstants.IntentStrings.AVATAR, group.getIcon());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_SCOPE, group.getScope());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, group.getOwner());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
startActivity(intent);
}
}
});
rvCallList.setItemCallClickListener(new OnItemClickListener<Call>() {
@Override
public void OnItemClick(Call var, int position) {
checkOnGoingCall(var);
}
});
rvCallList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (!rvCallList.canScrollVertically(1)) {
getCallList();
}
}
});
return view;
}
use of com.cometchat.pro.models.Group in project android-java-chat-push-notification-app by cometchat-pro.
the class MyFirebaseMessagingService method showNotifcation.
private void showNotifcation(BaseMessage baseMessage) {
try {
int m = (int) ((new Date().getTime()));
String GROUP_ID = "group_id";
Intent messageIntent = new Intent(getApplicationContext(), CometChatMessageListActivity.class);
messageIntent.putExtra(UIKitConstants.IntentStrings.TYPE, baseMessage.getReceiverType());
if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, baseMessage.getSender().getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.UID, baseMessage.getSender().getUid());
messageIntent.putExtra(UIKitConstants.IntentStrings.AVATAR, baseMessage.getSender().getAvatar());
messageIntent.putExtra(UIKitConstants.IntentStrings.STATUS, baseMessage.getSender().getStatus());
} else if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP)) {
messageIntent.putExtra(UIKitConstants.IntentStrings.GUID, ((Group) baseMessage.getReceiver()).getGuid());
messageIntent.putExtra(UIKitConstants.IntentStrings.NAME, ((Group) baseMessage.getReceiver()).getName());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, ((Group) baseMessage.getReceiver()).getDescription());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, ((Group) baseMessage.getReceiver()).getGroupType());
messageIntent.putExtra(UIKitConstants.IntentStrings.GROUP_OWNER, ((Group) baseMessage.getReceiver()).getOwner());
messageIntent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, ((Group) baseMessage.getReceiver()).getMembersCount());
}
PendingIntent messagePendingIntent = PendingIntent.getActivity(getApplicationContext(), 0123, messageIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "2").setSmallIcon(R.drawable.cc).setContentTitle(json.getString("title")).setContentText(json.getString("alert")).setColor(getResources().getColor(R.color.colorPrimary)).setLargeIcon(getBitmapFromURL(baseMessage.getSender().getAvatar())).setGroup(GROUP_ID).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (baseMessage.getType().equals(CometChatConstants.MESSAGE_TYPE_IMAGE)) {
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(getBitmapFromURL(((MediaMessage) baseMessage).getAttachment().getFileUrl())));
}
NotificationCompat.Builder summaryBuilder = new NotificationCompat.Builder(this, "2").setContentTitle("CometChat").setContentText(count + " messages").setSmallIcon(R.drawable.cc).setGroup(GROUP_ID).setGroupSummary(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
if (isCall) {
builder.setGroup(GROUP_ID + "Call");
if (json.getString("alert").equals("Incoming audio call") || json.getString("alert").equals("Incoming video call")) {
builder.setOngoing(true);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_call);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
builder.setSound(notification);
builder.addAction(0, "Answers", PendingIntent.getBroadcast(getApplicationContext(), REQUEST_CODE, getCallIntent("Answers"), PendingIntent.FLAG_UPDATE_CURRENT));
builder.addAction(0, "Decline", PendingIntent.getBroadcast(getApplicationContext(), 1, getCallIntent("Decline"), PendingIntent.FLAG_UPDATE_CURRENT));
}
if (UIKitApplication.isBackground)
notificationManager.notify(05, builder.build());
} else {
// Person person = createPerson(baseMessage);
// builder.setStyle(new NotificationCompat.MessagingStyle(person)
// .setGroupConversation(true)
// .setConversationTitle(json.getString("title"))
// .addMessage(json.getString("alert"),
// currentTimeMillis(), person));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setContentIntent(messagePendingIntent);
builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);
// Uri notification = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.incoming_message);
builder.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(baseMessage.getId(), builder.build());
notificationManager.notify(0, summaryBuilder.build());
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations