Search in sources :

Example 16 with User

use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatUsersAdapter method onBindHeaderViewHolder.

@Override
public void onBindHeaderViewHolder(InitialHolder var1, int var2, long var3) {
    User user = userArrayList.get(var2);
    char name = user.getName() != null && !user.getName().isEmpty() ? user.getName().substring(0, 1).toCharArray()[0] : '#';
    var1.textView.setText(String.valueOf(name));
}
Also used : User(com.cometchat.pro.models.User)

Example 17 with User

use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatUsersAdapter method onBindViewHolder.

/**
 * This method is used to bind the UserViewHolder contents with user at given
 * position. It set username userAvatar in respective UserViewHolder content.
 *
 * @param userViewHolder is a object of UserViewHolder.
 * @param i is a position of item in recyclerView.
 * @see User
 */
@Override
public void onBindViewHolder(@NonNull UserViewHolder userViewHolder, int i) {
    final User user = userArrayList.get(i);
    User user1 = i + 1 < userArrayList.size() ? userArrayList.get(i + 1) : null;
    if (user1 != null && user.getName().toLowerCase().substring(0, 1).toCharArray()[0] == user1.getName().substring(0, 1).toLowerCase().toCharArray()[0]) {
        userViewHolder.userListRowBinding.tvSeprator.setVisibility(View.GONE);
    } else {
        userViewHolder.userListRowBinding.tvSeprator.setVisibility(View.VISIBLE);
    }
    if (user.getStatus().equals(CometChatConstants.USER_STATUS_ONLINE))
        userViewHolder.userListRowBinding.statusIndicator.setVisibility(View.VISIBLE);
    userViewHolder.userListRowBinding.statusIndicator.setUserStatus(user.getStatus());
    userViewHolder.userListRowBinding.txtUserName.setText(user.getName());
    userViewHolder.userListRowBinding.executePendingBindings();
    userViewHolder.userListRowBinding.avUser.setBackgroundColor(context.getResources().getColor(R.color.colorPrimary));
    userViewHolder.userListRowBinding.getRoot().setTag(R.string.user, user);
    userViewHolder.userListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    if (user.getAvatar() == null || user.getAvatar().isEmpty()) {
        userViewHolder.userListRowBinding.avUser.setInitials(user.getName());
    } else {
        userViewHolder.userListRowBinding.avUser.setAvatar(user.getAvatar());
    }
    if (Utils.isDarkMode(context)) {
        userViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
        userViewHolder.userListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.grey));
    } else {
        userViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
        userViewHolder.userListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.light_grey));
    }
}
Also used : User(com.cometchat.pro.models.User)

Example 18 with User

use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatUserProfile method updateUserDialog.

private void updateUserDialog() {
    dialog = new AlertDialog.Builder(getContext());
    View view = LayoutInflater.from(getContext()).inflate(R.layout.cometchat_update_user_dialog, null);
    CometChatAvatar avatar = view.findViewById(R.id.user_avatar);
    avatar.setAvatar(CometChat.getLoggedInUser());
    TextInputEditText avatar_url = view.findViewById(R.id.avatar_url_edt);
    avatar_url.setText(CometChat.getLoggedInUser().getAvatar());
    TextInputEditText username = view.findViewById(R.id.username_edt);
    username.setText(CometChat.getLoggedInUser().getName());
    MaterialButton updateUserBtn = view.findViewById(R.id.updateUserBtn);
    MaterialButton cancelBtn = view.findViewById(R.id.cancelBtn);
    if (CometChat.getLoggedInUser().getAvatar() == null) {
        avatar.setVisibility(View.GONE);
        avatar_url.setVisibility(View.GONE);
    } else {
        avatar.setVisibility(View.VISIBLE);
        avatar_url.setVisibility(View.VISIBLE);
    }
    avatar_url.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (!s.toString().isEmpty()) {
                avatar.setVisibility(View.VISIBLE);
                avatar.setAvatar(s.toString());
            } else
                avatar.setVisibility(View.GONE);
        }
    });
    AlertDialog alertDialog = dialog.create();
    alertDialog.setView(view);
    updateUserBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            User user = new User();
            if (username.getText().toString().isEmpty())
                username.setError(getString(R.string.fill_this_field));
            else {
                user.setName(username.getText().toString());
                user.setUid(CometChat.getLoggedInUser().getUid());
                user.setAvatar(avatar_url.getText().toString());
                updateUser(user);
                alertDialog.dismiss();
            }
        }
    });
    cancelBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) User(com.cometchat.pro.models.User) View(android.view.View) MaterialButton(com.google.android.material.button.MaterialButton) TextInputEditText(com.google.android.material.textfield.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) CometChatAvatar(com.cometchat.pro.uikit.ui_components.shared.cometchatAvatar.CometChatAvatar)

Example 19 with User

use of com.cometchat.pro.models.User 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 20 with User

use of com.cometchat.pro.models.User in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatConversationsAdapter method setDeliveredReceipts.

public void setDeliveredReceipts(MessageReceipt deliveryReceipts) {
    for (int i = 0; i < filterConversationList.size() - 1; i++) {
        Conversation conversation = filterConversationList.get(i);
        if (conversation.getConversationType().equals(CometChatConstants.RECEIVER_TYPE_USER) && deliveryReceipts.getSender().getUid().equals(((User) conversation.getConversationWith()).getUid())) {
            BaseMessage baseMessage = filterConversationList.get(i).getLastMessage();
            if (baseMessage != null && baseMessage.getDeliveredAt() == 0) {
                baseMessage.setReadAt(deliveryReceipts.getDeliveredAt());
                int index = filterConversationList.indexOf(filterConversationList.get(i));
                filterConversationList.remove(index);
                conversation.setLastMessage(baseMessage);
                filterConversationList.add(index, conversation);
            }
        }
    }
    notifyDataSetChanged();
}
Also used : User(com.cometchat.pro.models.User) BaseMessage(com.cometchat.pro.models.BaseMessage) Conversation(com.cometchat.pro.models.Conversation)

Aggregations

User (com.cometchat.pro.models.User)28 CometChatException (com.cometchat.pro.exceptions.CometChatException)12 View (android.view.View)10 Intent (android.content.Intent)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)8 CometChat (com.cometchat.pro.core.CometChat)8 BaseMessage (com.cometchat.pro.models.BaseMessage)7 TextView (android.widget.TextView)6 Call (com.cometchat.pro.core.Call)6 Group (com.cometchat.pro.models.Group)6 Editable (android.text.Editable)5 TextWatcher (android.text.TextWatcher)5 ImageView (android.widget.ImageView)5 Conversation (com.cometchat.pro.models.Conversation)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ViewGroup (android.view.ViewGroup)4 InputMethodManager (android.view.inputmethod.InputMethodManager)4 UsersRequest (com.cometchat.pro.core.UsersRequest)4 KeyEvent (android.view.KeyEvent)3