Search in sources :

Example 26 with User

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

the class CometChatUserList method searchUser.

/**
 * This method is used to search users present in your App_ID.
 * For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-users-retrieve-users#section-retrieve-list-of-users" }
 *
 * @param s is a string used to get users matches with this string.
 * @see UsersRequest
 */
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) {
            // set the users to rvUserList i.e CometChatUserList Component.
            rvUserList.searchUserList(users);
        }

        @Override
        public void onError(CometChatException e) {
            CometChatSnackBar.show(context, rlSearchBox, 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)

Example 27 with User

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

the class CometChatUserList method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_cometchat_userlist, container, false);
    title = view.findViewById(R.id.tv_title);
    title.setTypeface(FontUtils.getInstance(getActivity()).getTypeFace(FontUtils.robotoMedium));
    rvUserList = view.findViewById(R.id.rv_user_list);
    noUserLayout = view.findViewById(R.id.no_user_layout);
    etSearch = view.findViewById(R.id.search_bar);
    clearSearch = view.findViewById(R.id.clear_search);
    rlSearchBox = view.findViewById(R.id.rl_search_box);
    swipeRefreshLayout = view.findViewById(R.id.swipe_refresh);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            usersRequest = null;
            rvUserList.clear();
            fetchUsers();
        }
    });
    CometChatError.init(getContext());
    shimmerFrameLayout = view.findViewById(R.id.shimmer_layout);
    if (Utils.isDarkMode(getContext())) {
        title.setTextColor(getResources().getColor(R.color.textColorWhite));
    } else {
        title.setTextColor(getResources().getColor(R.color.primaryTextColor));
    }
    FeatureRestriction.isUserSearchEnabled(new FeatureRestriction.OnSuccessListener() {

        @Override
        public void onSuccess(Boolean booleanVal) {
            if (booleanVal)
                etSearch.setVisibility(View.VISIBLE);
            else
                etSearch.setVisibility(View.GONE);
        }
    });
    isTitleVisible();
    etSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (editable.length() == 0) {
                // if etSearch is empty then fetch all users.
                usersRequest = null;
                rvUserList.clear();
                fetchUsers();
            } else {
                // Search users based on text in etSearch field.
                searchUser(editable.toString());
            }
        }
    });
    etSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH) {
                searchUser(textView.getText().toString());
                clearSearch.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }
    });
    clearSearch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            etSearch.setText("");
            clearSearch.setVisibility(View.GONE);
            searchUser(etSearch.getText().toString());
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            // Hide the soft keyboard
            inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
        }
    });
    // Uses to fetch next list of user if rvUserList (RecyclerView) is scrolled in upward direction.
    rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() {

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

        @Override
        public void OnItemClick(User user, int position) {
            if (events != null)
                events.OnItemClick(user, position);
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) User(com.cometchat.pro.models.User) InputMethodManager(android.view.inputmethod.InputMethodManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) KeyEvent(android.view.KeyEvent) FeatureRestriction(com.cometchat.pro.uikit.ui_settings.FeatureRestriction) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 28 with User

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

the class CallUtils method initiateCall.

/**
 * This method is used to initiate a call for user or a group.
 * @param context is a object of Context
 * @param recieverID is String - It can be either uid or guid
 * @param receiverType is String - It can be either user or group
 *                     [<code>CometChatConstants.RECEIVER_TYPE_USER</code> or
 *                     <code>CometChatConstants.RECEIVER_TYPE_GROUP</code>]
 * @param callType is String -  It can be either audio or video
 *                 [<code>CometChatConstants.CALL_TYPE_AUDIO</code> or
 *                 <code>CometChatConstants.CALL_TYPE_VIDEO</code>]
 *
 * @see CometChat#initiateCall(Call, CometChat.CallbackListener)
 */
public static void initiateCall(Context context, String recieverID, String receiverType, String callType) {
    Call call = new Call(recieverID, receiverType, callType);
    CometChat.initiateCall(call, new CometChat.CallbackListener<Call>() {

        @Override
        public void onSuccess(Call call) {
            if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_USER))
                startCallIntent(context, ((User) call.getCallReceiver()), call.getType(), true, call.getSessionId());
            else if (receiverType.equalsIgnoreCase(com.cometchat.pro.constants.CometChatConstants.RECEIVER_TYPE_GROUP))
                startGroupCallIntent(context, ((Group) call.getCallReceiver()), call.getType(), true, call.getSessionId());
        }

        @Override
        public void onError(CometChatException e) {
            Log.e(TAG, "onError: " + e.getMessage());
            Snackbar.make(((Activity) context).getWindow().getDecorView().getRootView(), context.getResources().getString(R.string.call_initiate_error) + ":" + e.getMessage(), Snackbar.LENGTH_LONG).show();
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) Call(com.cometchat.pro.core.Call) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat)

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