Search in sources :

Example 1 with GroupMemberAdapter

use of com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter 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 2 with GroupMemberAdapter

use of com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatBanMembers 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_ban_member, container, false);
    bannedMemberRv = view.findViewById(R.id.bannedMembers_rv);
    noMemberTv = view.findViewById(R.id.no_member_tv);
    bannedMemberRv.setLayoutManager(new LinearLayoutManager(getContext()));
    groupMemberAdapter = new GroupMemberAdapter(getContext());
    bannedMemberRv.setAdapter(groupMemberAdapter);
    handleArguments();
    CometChatError.init(getContext());
    getBannedMembers();
    bannedMemberRv.addOnItemTouchListener(new RecyclerTouchListener(getContext(), bannedMemberRv, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            GroupMember user = (GroupMember) var1.getTag(R.string.user);
            groupMember = user;
            if (loggedInUserScope != null && (loggedInUserScope.equals(CometChatConstants.SCOPE_ADMIN) || loggedInUserScope.equals(CometChatConstants.SCOPE_MODERATOR))) {
                registerForContextMenu(bannedMemberRv);
                getActivity().openContextMenu(var1);
            }
        }
    }));
    return view;
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) GroupMember(com.cometchat.pro.models.GroupMember) GroupMemberAdapter(com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 GroupMember (com.cometchat.pro.models.GroupMember)2 GroupMemberAdapter (com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter)2 ClickListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)2 RecyclerTouchListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 RelativeLayout (android.widget.RelativeLayout)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 MaterialToolbar (com.google.android.material.appbar.MaterialToolbar)1 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)1