Search in sources :

Example 1 with User

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

the class MissedCall method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cometchat_missed_call, container, false);
    rvCallList = view.findViewById(R.id.callList_rv);
    CometChatError.init(getContext());
    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.LINK, user.getLink());
                intent.putExtra(UIKitConstants.IntentStrings.STATUS, user.getStatus());
                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_OWNER, group.getOwner());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_TYPE, group.getGroupType());
                intent.putExtra(UIKitConstants.IntentStrings.MEMBER_COUNT, group.getMembersCount());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_PASSWORD, group.getPassword());
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_DESC, group.getDescription());
                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 2 with User

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

the class CometChatStartCallActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    setContentView(R.layout.activity_cometchat_start_call);
    ongoingCallService = new OngoingCallService();
    mServiceIntent = new Intent(this, ongoingCallService.getClass());
    isDefaultCall = getIntent().getBooleanExtra(UIKitConstants.IntentStrings.IS_DEFAULT_CALL, false);
    if (isDefaultCall && !isMyServiceRunning(ongoingCallService.getClass())) {
        startService(mServiceIntent);
    }
    mainView = findViewById(R.id.call_view);
    connectingLayout = findViewById(R.id.connecting_to_call);
    sessionID = getIntent().getStringExtra(UIKitConstants.IntentStrings.SESSION_ID);
    type = getIntent().getStringExtra(UIKitConstants.IntentStrings.TYPE);
    if (type != null && type.equalsIgnoreCase(CometChatConstants.RECEIVER_TYPE_USER))
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).setMode(CallSettings.MODE_SINGLE).build();
    else
        callSettings = new CallSettings.CallSettingsBuilder(this, mainView).setSessionId(sessionID).build();
    CometChatError.init(this);
    Log.e("startCallActivity: ", sessionID + " " + type);
    CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {

        @Override
        public void onUserListUpdated(List<User> list) {
            Log.e("onUserListUpdated: ", list.toString());
        }

        @Override
        public void onAudioModesUpdated(List<AudioMode> list) {
            Log.e("onAudioModesUpdated: ", list.toString());
        }

        @Override
        public void onUserJoined(User user) {
            connectingLayout.setVisibility(View.GONE);
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_joined) + ":" + user.getName(), CometChatSnackBar.INFO);
            Log.e("onUserJoined: ", user.getUid());
        }

        @Override
        public void onUserLeft(User user) {
            if (user != null) {
                CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, getString(R.string.user_left) + ":" + user.getName(), CometChatSnackBar.INFO);
                Log.e("onUserLeft: ", user.getUid());
                if (callSettings.getMode().equals(CallSettings.MODE_SINGLE)) {
                    endCall();
                }
            } else {
                Log.e("onUserLeft: ", "triggered");
            }
        }

        @Override
        public void onError(CometChatException e) {
            stopService(mServiceIntent);
            Log.e("onstartcallError: ", e.getMessage());
            CometChatSnackBar.show(CometChatStartCallActivity.this, mainView, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }

        @Override
        public void onCallEnded(Call call) {
            stopService(mServiceIntent);
            Log.e("TAG", "onCallEnded: ");
            finish();
        }
    });
}
Also used : OngoingCallService(com.cometchat.pro.uikit.ui_components.calls.call_manager.ongoing_call.OngoingCallService) CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) Intent(android.content.Intent) CallSettings(com.cometchat.pro.core.CallSettings) AudioMode(com.cometchat.pro.models.AudioMode)

Example 3 with User

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

the class BlockedListAdapter method onBindViewHolder.

/**
 * This method is used to bind the BlockedViewHolder contents with user at given position.
 * It sets name and avatar field of a user with respective BlockedViewHolder content.
 *
 * @param blockedViewHolder is a object of BlockedViewHolder
 * @param i is a position of item in recyclerView
 * @see User
 */
@Override
public void onBindViewHolder(@NonNull BlockedViewHolder blockedViewHolder, int i) {
    // Take User which is at ith position in userArrayList
    final User user = userArrayList.get(i);
    User user1 = i + 1 < userArrayList.size() ? userArrayList.get(i + 1) : null;
    if (user1 != null && user.getName().substring(0, 1).toCharArray()[0] == user1.getName().substring(0, 1).toCharArray()[0]) {
        blockedViewHolder.userListRowBinding.tvSeprator.setVisibility(View.GONE);
    } else {
        blockedViewHolder.userListRowBinding.tvSeprator.setVisibility(View.VISIBLE);
    }
    blockedViewHolder.userListRowBinding.txtUserName.setText(user.getName());
    blockedViewHolder.userListRowBinding.getRoot().setTag(R.string.user, user);
    blockedViewHolder.userListRowBinding.txtUserScope.setVisibility(View.GONE);
    blockedViewHolder.userListRowBinding.unblockUser.setVisibility(View.VISIBLE);
    blockedViewHolder.userListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    if (user.getAvatar() == null || user.getAvatar().isEmpty()) {
        blockedViewHolder.userListRowBinding.avUser.setInitials(user.getName());
    } else {
        blockedViewHolder.userListRowBinding.avUser.setAvatar(user.getAvatar());
    }
    if (Utils.isDarkMode(context))
        blockedViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
    else
        blockedViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
}
Also used : User(com.cometchat.pro.models.User)

Example 4 with User

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

the class CometChatConversationList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    view = inflater.inflate(R.layout.fragment_cometchat_conversationlist, container, false);
    rvConversationList = view.findViewById(R.id.rv_conversation_list);
    noConversationView = view.findViewById(R.id.no_conversation_view);
    searchEdit = view.findViewById(R.id.search_bar);
    tvTitle = view.findViewById(R.id.tv_title);
    tvTitle.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
    rlSearchBox = view.findViewById(R.id.rl_search_box);
    conversationShimmer = view.findViewById(R.id.shimmer_layout);
    checkDarkMode();
    CometChatError.init(getContext());
    startConversation = view.findViewById(R.id.start_conversation);
    FeatureRestriction.isStartConversationEnabled(new FeatureRestriction.OnSuccessListener() {

        @Override
        public void onSuccess(Boolean booleanVal) {
            if (booleanVal)
                startConversation.setVisibility(View.VISIBLE);
            else
                startConversation.setVisibility(View.GONE);
        }
    });
    startConversation.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            CometChatStartConversation.launch(getContext());
        }
    });
    searchEdit.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_SEARCH) {
            if (!textView.getText().toString().isEmpty()) {
                progressDialog = ProgressDialog.show(getContext(), "", getString(R.string.search));
                refreshConversation(new CometChat.CallbackListener<List<Conversation>>() {

                    @Override
                    public void onSuccess(List<Conversation> conversationList) {
                        if (progressDialog != null)
                            progressDialog.dismiss();
                        rvConversationList.searchConversation(textView.getText().toString());
                    }

                    @Override
                    public void onError(CometChatException e) {
                        if (progressDialog != null)
                            progressDialog.dismiss();
                        CometChatSnackBar.show(getContext(), rvConversationList, CometChatError.localized(e), CometChatSnackBar.ERROR);
                    }
                });
            }
            return true;
        }
        return false;
    });
    // clearSearch.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View view) {
    // searchEdit.setText("");
    // clearSearch.setVisibility(View.GONE);
    // refreshConversation();
    // InputMethodManager inputMethodManager = (InputMethodManager)
    // getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    // // Hide the soft keyboard
    // inputMethodManager.hideSoftInputFromWindow(searchEdit.getWindowToken(),0);
    // }
    // });
    // Uses to fetch next list of conversations if rvConversationList (RecyclerView) is scrolled in upward direction.
    rvConversationList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                makeConversationList();
            }
        }
    });
    // Used to trigger event on click of conversation item in rvConversationList (RecyclerView)
    rvConversationList.setItemClickListener(new OnItemClickListener<Conversation>() {

        @Override
        public void OnItemClick(Conversation conversation, int position) {
            if (events != null)
                events.OnItemClick(conversation, position);
        }
    });
    RecyclerViewSwipeListener swipeHelper = new RecyclerViewSwipeListener(getContext()) {

        @Override
        public void instantiateUnderlayButton(RecyclerView.ViewHolder viewHolder, List<UnderlayButton> underlayButtons) {
            Bitmap deleteBitmap = Utils.drawableToBitmap(getResources().getDrawable(R.drawable.ic_delete_conversation));
            FeatureRestriction.isDeleteConversationEnabled(new FeatureRestriction.OnSuccessListener() {

                @Override
                public void onSuccess(Boolean booleanVal) {
                    if (booleanVal) {
                        underlayButtons.add(new RecyclerViewSwipeListener.UnderlayButton("Delete", deleteBitmap, getResources().getColor(R.color.red), new RecyclerViewSwipeListener.UnderlayButtonClickListener() {

                            @Override
                            public void onClick(final int pos) {
                                Conversation conversation = rvConversationList.getConversation(pos);
                                if (conversation != null) {
                                    String conversationUid = "";
                                    String type = "";
                                    if (conversation.getConversationType().equalsIgnoreCase(CometChatConstants.CONVERSATION_TYPE_GROUP)) {
                                        conversationUid = ((Group) conversation.getConversationWith()).getGuid();
                                        type = CometChatConstants.CONVERSATION_TYPE_GROUP;
                                    } else {
                                        conversationUid = ((User) conversation.getConversationWith()).getUid();
                                        type = CometChatConstants.CONVERSATION_TYPE_USER;
                                    }
                                    String finalConversationUid = conversationUid;
                                    String finalType = type;
                                    new CustomAlertDialogHelper(getContext(), getString(R.string.delete_conversation_message), null, getString(R.string.yes), "", getString(R.string.no), new OnAlertDialogButtonClickListener() {

                                        @Override
                                        public void onButtonClick(AlertDialog alertDialog, View v, int which, int popupId) {
                                            if (which == DialogInterface.BUTTON_POSITIVE) {
                                                ProgressDialog progressDialog = ProgressDialog.show(getContext(), null, getString(R.string.deleting_conversation));
                                                CometChat.deleteConversation(finalConversationUid, finalType, new CometChat.CallbackListener<String>() {

                                                    @Override
                                                    public void onSuccess(String s) {
                                                        Handler handler = new Handler();
                                                        handler.postDelayed(new Runnable() {

                                                            public void run() {
                                                                alertDialog.dismiss();
                                                                progressDialog.dismiss();
                                                            }
                                                        }, 1500);
                                                        rvConversationList.remove(conversation);
                                                    }

                                                    @Override
                                                    public void onError(CometChatException e) {
                                                        progressDialog.dismiss();
                                                        e.printStackTrace();
                                                    }
                                                });
                                            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                                                alertDialog.dismiss();
                                            }
                                        }
                                    }, 1, true);
                                }
                            }
                        }));
                    }
                }
            });
        }
    };
    swipeHelper.attachToRecyclerView(rvConversationList);
    return view;
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) AlertDialog(androidx.appcompat.app.AlertDialog) ViewGroup(android.view.ViewGroup) Group(com.cometchat.pro.models.Group) User(com.cometchat.pro.models.User) Conversation(com.cometchat.pro.models.Conversation) ProgressDialog(android.app.ProgressDialog) Bitmap(android.graphics.Bitmap) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) CustomAlertDialogHelper(com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.CustomAlertDialogHelper) List(java.util.List) ArrayList(java.util.ArrayList) OnAlertDialogButtonClickListener(com.cometchat.pro.uikit.ui_resources.utils.custom_alertDialog.OnAlertDialogButtonClickListener) CometChat(com.cometchat.pro.core.CometChat) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerViewSwipeListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerViewSwipeListener) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 5 with User

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

the class CometChatAddMembers method searchUser.

private void searchUser(String s) {
    UsersRequest usersRequest = new UsersRequest.UsersRequestBuilder().setSearchKeyword(s).setLimit(100).build();
    usersRequest.fetchNext(new CometChat.CallbackListener<List<User>>() {

        @Override
        public void onSuccess(List<User> users) {
            if (userListAdapter != null)
                userListAdapter.searchUser(users);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(getContext(), rvUserList, CometChatError.localized(e), CometChatSnackBar.ERROR);
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) ArrayList(java.util.ArrayList) List(java.util.List) UsersRequest(com.cometchat.pro.core.UsersRequest)

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