Search in sources :

Example 1 with GroupMember

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

the class Utils method UserToGroupMember.

/**
 * This method is used to convert user to group member. This method is used when we tries to add
 * user in a group or update group member scope.
 * @param user is object of User
 * @param isScopeUpdate is boolean which help us to check if scope is updated or not.
 * @param newScope is a String which contains newScope. If it is empty then user is added as participant.
 * @return GroupMember
 *
 * @see User
 * @see GroupMember
 */
public static GroupMember UserToGroupMember(User user, boolean isScopeUpdate, String newScope) {
    GroupMember groupMember;
    if (isScopeUpdate)
        groupMember = new GroupMember(user.getUid(), newScope);
    else
        groupMember = new GroupMember(user.getUid(), CometChatConstants.SCOPE_PARTICIPANT);
    groupMember.setAvatar(user.getAvatar());
    groupMember.setName(user.getName());
    groupMember.setStatus(user.getStatus());
    return groupMember;
}
Also used : GroupMember(com.cometchat.pro.models.GroupMember)

Example 2 with GroupMember

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

the class CometChatAdminModeratorList 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_admin_moderator_list, container, false);
    adminList = view.findViewById(R.id.adminList);
    setHasOptionsMenu(true);
    RelativeLayout rlAddMember = view.findViewById(R.id.rl_add_Admin);
    addAs = view.findViewById(R.id.add_as_tv);
    MaterialToolbar toolbar = view.findViewById(R.id.admin_toolbar);
    setToolbar(toolbar);
    CometChatError.init(getContext());
    if (showModerators) {
        toolbar.setTitle(getResources().getString(R.string.moderators));
        addAs.setText(getResources().getString(R.string.assign_as_moderator));
    } else {
        toolbar.setTitle(getResources().getString(R.string.administrators));
        addAs.setText(getResources().getString(R.string.assign_as_admin));
    }
    adapter = new GroupMemberAdapter(getContext(), members, null);
    adminList.setAdapter(adapter);
    if (loggedInUserScope != null && loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN)) {
        rlAddMember.setVisibility(View.VISIBLE);
    }
    if (showModerators) {
        getModeratorList(guid);
    } else {
        getAdminList(guid);
    }
    rlAddMember.setOnClickListener(view1 -> {
        Intent intent = new Intent(getContext(), CometChatGroupMemberListActivity.class);
        intent.putExtra(UIKitConstants.IntentStrings.GUID, guid);
        intent.putExtra(UIKitConstants.IntentStrings.SHOW_MODERATORLIST, showModerators);
        startActivity(intent);
    });
    adminList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), adminList, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            GroupMember groupMember = (GroupMember) var1.getTag(R.string.user);
            if (showModerators) {
                if (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) && !groupMember.getUid().equals(loggedInUser.getUid())) {
                    if (getActivity() != null) {
                        MaterialAlertDialogBuilder alert_dialog = new MaterialAlertDialogBuilder(getActivity());
                        alert_dialog.setTitle(getResources().getString(R.string.remove));
                        alert_dialog.setMessage(String.format(getResources().getString(R.string.remove_as_moderator), groupMember.getName()));
                        alert_dialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {

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

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        });
                        alert_dialog.create();
                        alert_dialog.show();
                    }
                } else {
                    String message;
                    if (groupMember.getUid().equals(loggedInUser.getUid()))
                        message = getResources().getString(R.string.you_cannot_perform_action);
                    else
                        message = getResources().getString(R.string.only_admin_removes_moderator);
                    CometChatSnackBar.show(getContext(), view, message, CometChatSnackBar.WARNING);
                }
            } else {
                if (ownerId != null && loggedInUser.getUid().equals(ownerId) && loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) && !groupMember.getUid().equals(loggedInUser.getUid())) {
                    if (getActivity() != null) {
                        MaterialAlertDialogBuilder alert_dialog = new MaterialAlertDialogBuilder(getActivity());
                        alert_dialog.setTitle(getResources().getString(R.string.remove));
                        alert_dialog.setMessage(String.format(getResources().getString(R.string.remove_as_admin), groupMember.getName()));
                        alert_dialog.setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {

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

                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        });
                        alert_dialog.create();
                        alert_dialog.show();
                    }
                } else {
                    String message;
                    if (groupMember.getUid().equals(loggedInUser.getUid()))
                        message = getResources().getString(R.string.you_cannot_perform_action);
                    else
                        message = getResources().getString(R.string.only_group_owner_removes_admin);
                    CometChatSnackBar.show(getContext(), view, message, CometChatSnackBar.WARNING);
                }
            }
        }
    }));
    return view;
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) GroupMember(com.cometchat.pro.models.GroupMember) DialogInterface(android.content.DialogInterface) GroupMemberAdapter(com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter) Intent(android.content.Intent) 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) RelativeLayout(android.widget.RelativeLayout) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Example 3 with GroupMember

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

the class CometChatGroupMemberList 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_add_member, container, false);
    rvGroupMemberList = view.findViewById(R.id.rv_user_list);
    etSearch = view.findViewById(R.id.search_bar);
    clearSearch = view.findViewById(R.id.clear_search);
    MaterialToolbar toolbar = view.findViewById(R.id.add_member_toolbar);
    setToolbar(toolbar);
    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) {
            if (charSequence.length() > 0)
                clearSearch.setVisibility(View.VISIBLE);
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    etSearch.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_SEARCH) {
            searchUser(textView.getText().toString());
            clearSearch.setVisibility(View.VISIBLE);
            return true;
        }
        return false;
    });
    clearSearch.setOnClickListener(view1 -> {
        etSearch.setText("");
        clearSearch.setVisibility(View.GONE);
        searchUser(etSearch.getText().toString());
        if (getActivity() != null) {
            InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
            // Hide the soft keyboard
            assert inputMethodManager != null;
            inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
        }
    });
    rvGroupMemberList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                fetchGroupMembers();
            }
        }
    });
    // On click of any group member item in rvUserList, It shows dialog with positive and negative button. On click of positive button it changes scope of group member
    rvGroupMemberList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), rvGroupMemberList, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            GroupMember groupMember = (GroupMember) var1.getTag(R.string.user);
            if (transferOwnerShip) {
                MaterialAlertDialogBuilder alert_dialog = new MaterialAlertDialogBuilder(getActivity());
                alert_dialog.setTitle(getResources().getString(R.string.make_owner));
                alert_dialog.setMessage(String.format(getResources().getString(R.string.make_owner_question), groupMember.getName()));
                alert_dialog.setPositiveButton(getResources().getString(R.string.yes), (dialogInterface, i) -> transferOwner(groupMember));
                alert_dialog.setNegativeButton(getResources().getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
                alert_dialog.create();
                alert_dialog.show();
            } else {
                if (showModerators) {
                    if (getActivity() != null) {
                        MaterialAlertDialogBuilder alert_dialog = new MaterialAlertDialogBuilder(getActivity());
                        alert_dialog.setTitle(getResources().getString(R.string.make_group_moderator));
                        alert_dialog.setMessage(String.format(getResources().getString(R.string.make_moderator_question), groupMember.getName()));
                        alert_dialog.setPositiveButton(getResources().getString(R.string.yes), (dialogInterface, i) -> updateAsModeratorScope(groupMember));
                        alert_dialog.setNegativeButton(getResources().getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
                        alert_dialog.create();
                        alert_dialog.show();
                    }
                } else {
                    if (getActivity() != null) {
                        MaterialAlertDialogBuilder alert_dialog = new MaterialAlertDialogBuilder(getActivity());
                        alert_dialog.setTitle(getResources().getString(R.string.make_group_admin));
                        alert_dialog.setMessage(String.format(getResources().getString(R.string.make_admin_question), groupMember.getName()));
                        alert_dialog.setPositiveButton(getResources().getString(R.string.yes), (dialogInterface, i) -> updateAsAdminScope(groupMember));
                        alert_dialog.setNegativeButton(getResources().getString(R.string.cancel), (dialogInterface, i) -> dialogInterface.dismiss());
                        alert_dialog.create();
                        alert_dialog.show();
                    }
                }
            }
        }
    }));
    fetchGroupMembers();
    return view;
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) GroupMember(com.cometchat.pro.models.GroupMember) InputMethodManager(android.view.inputmethod.InputMethodManager) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) MaterialToolbar(com.google.android.material.appbar.MaterialToolbar) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Example 4 with GroupMember

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

the class GroupMemberAdapter method onBindViewHolder.

/**
 *  This method is used to bind the GroupMemberViewHolder contents with groupMember at given
 *  position. It set name icon, scope with respective GroupMemberViewHolder content.
 *
 * @param groupMemberViewHolder is a object of GroupMemberViewHolder.
 * @param i is a position of item in recyclerView.
 * @see GroupMember
 */
@Override
public void onBindViewHolder(@NonNull GroupMemberViewHolder groupMemberViewHolder, int i) {
    GroupMember groupMember = groupMemberList.get(i);
    groupMemberViewHolder.userListRowBinding.avUser.setBackgroundColor(context.getResources().getColor(R.color.colorPrimary));
    groupMemberViewHolder.userListRowBinding.getRoot().setTag(R.string.user, groupMember);
    if (groupMember.getUid().equals(CometChat.getLoggedInUser().getUid())) {
        groupMemberViewHolder.userListRowBinding.txtUserName.setText(R.string.you);
    } else
        groupMemberViewHolder.userListRowBinding.txtUserName.setText(groupMember.getName());
    if (groupOwnerId != null && groupMember.getUid().equals(groupOwnerId) && groupMember.getScope().equals(CometChatConstants.SCOPE_ADMIN)) {
        groupMemberViewHolder.userListRowBinding.txtUserScope.setText(R.string.owner);
    } else if (groupMember.getScope().equals(CometChatConstants.SCOPE_ADMIN)) {
        groupMemberViewHolder.userListRowBinding.txtUserScope.setText(R.string.admin);
    } else if (groupMember.getScope().equals(CometChatConstants.SCOPE_MODERATOR)) {
        groupMemberViewHolder.userListRowBinding.txtUserScope.setText(R.string.moderator);
    } else {
        groupMemberViewHolder.userListRowBinding.txtUserScope.setText(R.string.participant);
    }
    groupMemberViewHolder.userListRowBinding.txtUserName.setTypeface(fontUtils.getTypeFace(FontUtils.robotoMedium));
    if (groupMember.getAvatar() == null || groupMember.getAvatar().isEmpty())
        groupMemberViewHolder.userListRowBinding.avUser.setInitials(groupMember.getName());
    else
        groupMemberViewHolder.userListRowBinding.avUser.setAvatar(groupMember.getAvatar());
    if (groupMember.getStatus().equalsIgnoreCase(CometChatConstants.USER_STATUS_ONLINE))
        groupMemberViewHolder.userListRowBinding.statusIndicator.setVisibility(View.VISIBLE);
    groupMemberViewHolder.userListRowBinding.statusIndicator.setUserStatus(groupMember.getStatus());
    if (Utils.isDarkMode(context)) {
        groupMemberViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.textColorWhite));
        groupMemberViewHolder.userListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.grey));
        groupMemberViewHolder.userListRowBinding.txtUserScope.setTextColor(context.getResources().getColor(R.color.textColorWhite));
    } else {
        groupMemberViewHolder.userListRowBinding.txtUserName.setTextColor(context.getResources().getColor(R.color.primaryTextColor));
        groupMemberViewHolder.userListRowBinding.tvSeprator.setBackgroundColor(context.getResources().getColor(R.color.light_grey));
        groupMemberViewHolder.userListRowBinding.txtUserScope.setTextColor(context.getResources().getColor(R.color.secondaryTextColor));
    }
    if (i == getItemCount() - 1)
        groupMemberViewHolder.userListRowBinding.tvSeprator.setVisibility(View.GONE);
}
Also used : GroupMember(com.cometchat.pro.models.GroupMember)

Example 5 with GroupMember

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

the class CometChatMessageList method getMember.

/**
 * This method is used to get Group Members and display names of group member.
 *
 * @see GroupMember
 * @see GroupMembersRequest
 */
private void getMember() {
    GroupMembersRequest groupMembersRequest = new GroupMembersRequest.GroupMembersRequestBuilder(Id).setLimit(30).build();
    groupMembersRequest.fetchNext(new CometChat.CallbackListener<List<GroupMember>>() {

        @Override
        public void onSuccess(List<GroupMember> list) {
            String[] s = new String[0];
            if (list != null && list.size() != 0) {
                s = new String[list.size()];
                for (int j = 0; j < list.size(); j++) {
                    s[j] = list.get(j).getName();
                }
            }
            setSubTitle(s);
        }

        @Override
        public void onError(CometChatException e) {
            Log.d(TAG, "Group Member list fetching failed with exception: " + e.getMessage());
            Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : CometChatException(com.cometchat.pro.exceptions.CometChatException) GroupMember(com.cometchat.pro.models.GroupMember) GroupMembersRequest(com.cometchat.pro.core.GroupMembersRequest) CometChat(com.cometchat.pro.core.CometChat) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

GroupMember (com.cometchat.pro.models.GroupMember)10 View (android.view.View)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 ClickListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)4 RecyclerTouchListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener)4 TextView (android.widget.TextView)3 CometChat (com.cometchat.pro.core.CometChat)3 CometChatException (com.cometchat.pro.exceptions.CometChatException)3 ArrayList (java.util.ArrayList)3 ImageView (android.widget.ImageView)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 GroupMembersRequest (com.cometchat.pro.core.GroupMembersRequest)2 GroupMemberAdapter (com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter)2 MaterialToolbar (com.google.android.material.appbar.MaterialToolbar)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 List (java.util.List)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 ColorStateList (android.content.res.ColorStateList)1