Search in sources :

Example 21 with User

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

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

the class CometChatNewCallList 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) {
            rvUserList.searchUserList(users);
        }

        @Override
        public void onError(CometChatException e) {
            if (rvUserList != null)
                CometChatSnackBar.show(CometChatNewCallList.this, 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) ColorStateList(android.content.res.ColorStateList) List(java.util.List) UsersRequest(com.cometchat.pro.core.UsersRequest)

Example 23 with User

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

the class CometChatNewCallList method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_cometchat_userlist);
    fetchSettings();
    title = findViewById(R.id.tv_title);
    CometChatError.init(this);
    ImageView imageView = new ImageView(this);
    imageView.setImageDrawable(getResources().getDrawable(R.drawable.ic_back_arrow_selected));
    if (UIKitSettings.getColor() != null) {
        getWindow().setStatusBarColor(Color.parseColor(UIKitSettings.getColor()));
        imageView.setImageTintList(ColorStateList.valueOf(Color.parseColor(UIKitSettings.getColor())));
    } else
        imageView.setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));
    imageView.setClickable(true);
    imageView.setPadding(8, 8, 8, 8);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.ALIGN_START);
    layoutParams.setMargins(16, 32, 16, 16);
    layoutParams.addRule(RelativeLayout.CENTER_VERTICAL);
    imageView.setLayoutParams(layoutParams);
    addContentView(imageView, layoutParams);
    imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    RelativeLayout.LayoutParams titleLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    titleLayoutParams.setMargins(16, 32, 16, 48);
    titleLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    title.setLayoutParams(titleLayoutParams);
    title.setTextAppearance(R.style.TextAppearance_AppCompat_Large);
    title.setText(getResources().getString(R.string.new_call));
    rvUserList = findViewById(R.id.rv_user_list);
    etSearch = findViewById(R.id.search_bar);
    clearSearch = findViewById(R.id.clear_search);
    rlSearchBox = findViewById(R.id.rl_search_box);
    shimmerFrameLayout = findViewById(R.id.shimmer_layout);
    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;
                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) 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();
            }
        }
    });
    rvUserList.setItemClickListener(new OnItemClickListener<User>() {

        @Override
        public void OnItemClick(User var, int position) {
            User user = var;
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(CometChatNewCallList.this);
            alertDialog.setMessage(getString(R.string.initiate_a_call));
            if (audioCallEnabled) {
                alertDialog.setPositiveButton(getString(R.string.audio_call), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        initiateCall(user.getUid(), CometChatConstants.RECEIVER_TYPE_USER, CometChatConstants.CALL_TYPE_AUDIO);
                    }
                });
            }
            if (videoCallEnabled) {
                alertDialog.setNegativeButton(getString(R.string.video_call), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        initiateCall(user.getUid(), CometChatConstants.RECEIVER_TYPE_USER, CometChatConstants.CALL_TYPE_VIDEO);
                    }
                });
            }
            alertDialog.create();
            alertDialog.show();
        }
    });
    fetchUsers();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) User(com.cometchat.pro.models.User) DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ImageView(android.widget.ImageView) EditText(android.widget.EditText) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RelativeLayout(android.widget.RelativeLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 24 with User

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

the class CreateUserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_user);
    inputUid = findViewById(R.id.inputUID);
    inputName = findViewById(R.id.inputName);
    title = findViewById(R.id.tvTitle);
    des1 = findViewById(R.id.tvDes1);
    des2 = findViewById(R.id.tvDes2);
    progressBar = findViewById(R.id.createUser_pb);
    uid = findViewById(R.id.etUID);
    name = findViewById(R.id.etName);
    createUserBtn = findViewById(R.id.create_user_btn);
    createUserBtn.setTextColor(getResources().getColor(R.color.textColorWhite));
    createUserBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uid.getText().toString().isEmpty())
                uid.setError(getResources().getString(R.string.fill_this_field));
            else if (name.getText().toString().isEmpty())
                name.setError(getResources().getString(R.string.fill_this_field));
            else {
                progressBar.setVisibility(View.VISIBLE);
                createUserBtn.setClickable(false);
                User user = new User();
                user.setUid(uid.getText().toString());
                user.setName(name.getText().toString());
                CometChat.createUser(user, AppConfig.AppDetails.AUTH_KEY, new CometChat.CallbackListener<User>() {

                    @Override
                    public void onSuccess(User user) {
                        login(user);
                    }

                    @Override
                    public void onError(CometChatException e) {
                        createUserBtn.setClickable(true);
                        Toast.makeText(CreateUserActivity.this, "Failed to create user", Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
    });
    checkDarkMode();
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) User(com.cometchat.pro.models.User) CometChat(com.cometchat.pro.core.CometChat) TextView(android.widget.TextView) View(android.view.View)

Example 25 with User

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

the class CometChatBlockUserList 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_block_user, container, false);
    setHasOptionsMenu(true);
    rvUserList = view.findViewById(R.id.rv_blocked_user_list);
    noBlockUserLayout = view.findViewById(R.id.no_block_user);
    MaterialToolbar toolbar = view.findViewById(R.id.toolbar_blocked_user);
    setToolbar(toolbar);
    CometChatError.init(getContext());
    rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                fetchBlockedUser();
            }
        }
    });
    // It unblock users when click on item in rvUserList
    rvUserList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rvUserList, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            User user = (User) var1.getTag(R.string.user);
            if (getActivity() != null) {
                MaterialAlertDialogBuilder alert = new MaterialAlertDialogBuilder(getActivity());
                alert.setTitle(getResources().getString(R.string.unblock));
                String message = String.format(getResources().getString(R.string.unblock_user_question), user.getName());
                alert.setMessage(message);
                alert.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        unBlockUser(user, var1);
                    }
                });
                alert.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                alert.create();
                alert.show();
            }
        }
    }));
    fetchBlockedUser();
    return view;
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) User(com.cometchat.pro.models.User) DialogInterface(android.content.DialogInterface) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) MaterialToolbar(com.google.android.material.appbar.MaterialToolbar) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

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