Search in sources :

Example 1 with ClickListener

use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener 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 ClickListener

use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener 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 3 with ClickListener

use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatCalls method setItemClickListener.

/**
 *  This method helps to get Click events of CometChatCallList
 *
 * @param onItemClickListener object of the OnItemClickListener
 */
public void setItemClickListener(OnItemClickListener<Call> onItemClickListener) {
    this.addOnItemTouchListener(new RecyclerTouchListener(context, this, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            Call call = (Call) var1.getTag(R.string.call);
            var1.findViewById(R.id.user_detail_vw).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null)
                        onItemClickListener.OnItemClick(call, var2);
                    else
                        throw new NullPointerException("OnItemClickListener<Call> is null");
                }
            });
        }

        @Override
        public void onLongClick(View var1, int var2) {
            Call call = (Call) var1.getTag(R.string.call);
            if (onItemClickListener != null)
                onItemClickListener.OnItemLongClick(call, var2);
            else
                throw new NullPointerException("OnItemClickListener<Call> is null");
        }
    }));
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) Call(com.cometchat.pro.core.Call) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) OnItemClickListener(com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Example 4 with ClickListener

use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatCalls method setItemCallClickListener.

/**
 *  This method helps to get Click events of CometChatCallList
 *
 * @param onItemClickListener object of the OnItemClickListener
 */
public void setItemCallClickListener(OnItemClickListener<Call> onItemClickListener) {
    this.addOnItemTouchListener(new RecyclerTouchListener(context, this, new ClickListener() {

        @Override
        public void onClick(View var1, int var2) {
            String uid;
            String type;
            Call call = (Call) var1.getTag(R.string.call);
            if (call.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_USER)) {
                if (((User) call.getCallInitiator()).getUid().equals(CometChat.getLoggedInUser().getUid())) {
                    uid = ((User) call.getCallReceiver()).getUid();
                } else {
                    uid = ((User) call.getCallInitiator()).getUid();
                }
                type = CometChatConstants.RECEIVER_TYPE_USER;
            } else {
                uid = ((Group) call.getCallReceiver()).getGuid();
                type = CometChatConstants.RECEIVER_TYPE_GROUP;
            }
            var1.findViewById(R.id.call_iv).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Call callObj = new Call(uid, type, CometChatConstants.CALL_TYPE_AUDIO);
                    if (onItemClickListener != null)
                        onItemClickListener.OnItemClick(callObj, var2);
                    else
                        throw new NullPointerException("OnItemClickListener<Call> is null");
                }
            });
        }

        @Override
        public void onLongClick(View var1, int var2) {
        }
    }));
}
Also used : RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) Call(com.cometchat.pro.core.Call) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) OnItemClickListener(com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Example 5 with ClickListener

use of com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener in project android-java-chat-push-notification-app by cometchat-pro.

the class CometChatAddMembers method init.

public void init(View view) {
    // Inflate the layout
    setHasOptionsMenu(true);
    rvUserList = view.findViewById(R.id.rv_user_list);
    etSearch = view.findViewById(R.id.search_bar);
    toolbar = view.findViewById(R.id.add_member_toolbar);
    CometChatError.init(getContext());
    setToolbar(toolbar);
    checkDarkMode();
    clearSearch = view.findViewById(R.id.clear_search);
    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(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
            if (inputMethodManager != null)
                inputMethodManager.hideSoftInputFromWindow(etSearch.getWindowToken(), 0);
        }
    });
    rvUserList.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            if (!recyclerView.canScrollVertically(1)) {
                fetchUsers();
            }
        }
    });
    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) {
                Intent intent = new Intent(getActivity(), 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.TYPE, CometChatConstants.RECEIVER_TYPE_GROUP);
                intent.putExtra(UIKitConstants.IntentStrings.GUID, guid);
                intent.putExtra(UIKitConstants.IntentStrings.IS_ADD_MEMBER, true);
                intent.putExtra(UIKitConstants.IntentStrings.GROUP_NAME, groupName);
                getActivity().finish();
                startActivity(intent);
            }
        }

        @Override
        public void onLongClick(View var1, int var2) {
        }
    }));
}
Also used : EditText(android.widget.EditText) RecyclerTouchListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener) User(com.cometchat.pro.models.User) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ClickListener(com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)

Aggregations

View (android.view.View)9 RecyclerView (androidx.recyclerview.widget.RecyclerView)9 ClickListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.ClickListener)9 RecyclerTouchListener (com.cometchat.pro.uikit.ui_resources.utils.recycler_touch.RecyclerTouchListener)9 TextView (android.widget.TextView)5 GroupMember (com.cometchat.pro.models.GroupMember)4 ImageView (android.widget.ImageView)3 MaterialToolbar (com.google.android.material.appbar.MaterialToolbar)3 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 Call (com.cometchat.pro.core.Call)2 User (com.cometchat.pro.models.User)2 GroupMemberAdapter (com.cometchat.pro.uikit.ui_components.groups.group_members.GroupMemberAdapter)2 OnItemClickListener (com.cometchat.pro.uikit.ui_resources.utils.item_clickListener.OnItemClickListener)2 KeyEvent (android.view.KeyEvent)1