Search in sources :

Example 11 with Group

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())));
}
Also used : Call(com.cometchat.pro.core.Call) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage)

Example 12 with Group

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));
    }
}
Also used : Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup)

Example 13 with Group

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;
}
Also used : Call(com.cometchat.pro.core.Call) Group(com.cometchat.pro.models.Group) ViewGroup(android.view.ViewGroup) User(com.cometchat.pro.models.User) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CometChatGroupDetailActivity(com.cometchat.pro.uikit.ui_components.groups.group_details.CometChatGroupDetailActivity) RecyclerView(androidx.recyclerview.widget.RecyclerView) CometChatUserDetailScreenActivity(com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity)

Example 14 with Group

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();
    }
}
Also used : Group(com.cometchat.pro.models.Group) MediaMessage(com.cometchat.pro.models.MediaMessage) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Uri(android.net.Uri) Date(java.util.Date) CometChatException(com.cometchat.pro.exceptions.CometChatException) JSONException(org.json.JSONException) IOException(java.io.IOException) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

Group (com.cometchat.pro.models.Group)14 ViewGroup (android.view.ViewGroup)10 Intent (android.content.Intent)6 View (android.view.View)6 RecyclerView (androidx.recyclerview.widget.RecyclerView)6 CometChatException (com.cometchat.pro.exceptions.CometChatException)6 User (com.cometchat.pro.models.User)6 ImageView (android.widget.ImageView)4 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 TextView (android.widget.TextView)3 Call (com.cometchat.pro.core.Call)3 CometChat (com.cometchat.pro.core.CometChat)3 Conversation (com.cometchat.pro.models.Conversation)3 ArrayList (java.util.ArrayList)3 ProgressDialog (android.app.ProgressDialog)2 Uri (android.net.Uri)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 NotificationCompat (androidx.core.app.NotificationCompat)2 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)2