Search in sources :

Example 1 with RequestGroupAddMember

use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.

the class FragmentGroupProfile method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    isNeedResume = true;
    // because actionbar not in this view do that and not correct in viewModel
    imvGroupAvatar = binding.toolbarAvatar;
    imvGroupAvatar.setOnClickListener(v -> viewModel.onClickRippleGroupAvatar());
    if (currentRoomAccess != null) {
        checkRoomAccess(currentRoomAccess);
        roomAccessChangeListener = (realmRoomAccess, changeSet) -> checkRoomAccess(realmRoomAccess);
        currentRoomAccess.addChangeListener(roomAccessChangeListener);
    }
    binding.toolbarMore.setOnClickListener(v -> viewModel.onClickRippleMenu());
    binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
    binding.toolbarEdit.setOnClickListener(v -> {
        if (getActivity() != null && currentRoomAccess != null && currentRoomAccess.isCanModifyRoom()) {
            new HelperFragment(getActivity().getSupportFragmentManager(), EditGroupFragment.newInstance(viewModel.roomId)).setReplace(false).load();
        }
    });
    viewModel.groupName.observe(getViewLifecycleOwner(), s -> {
        binding.toolbarTxtNameCollapsed.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameCollapsed.getPaint().getFontMetricsInt()));
        binding.toolbarTxtNameExpanded.setText(EmojiManager.getInstance().replaceEmoji(s, binding.toolbarTxtNameExpanded.getPaint().getFontMetricsInt()));
    });
    viewModel.groupNumber.observe(getViewLifecycleOwner(), s -> binding.toolbarTxtStatusExpanded.setText(String.format("%s %s", s, getString(R.string.member))));
    viewModel.showMoreMenu.observe(getViewLifecycleOwner(), isShow -> {
        if (isShow != null) {
            binding.toolbarMore.setVisibility(isShow ? View.VISIBLE : View.GONE);
        }
    });
    viewModel.goToShearedMediaPage.observe(getViewLifecycleOwner(), model -> {
        if (getActivity() != null && model != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(model)).setReplace(false).load();
        }
    });
    viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), roomId -> {
        if (getActivity() != null && roomId != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowAvatars.newInstance(roomId, FragmentShowAvatars.From.group)).setReplace(false).load();
        }
    });
    viewModel.showMenu.observe(getViewLifecycleOwner(), menuList -> {
        if (getActivity() != null && menuList != null) {
            new TopSheetDialog(getActivity()).setListDataWithResourceId(menuList, -1, position -> {
                if (menuList.get(position) == R.string.clear_history) {
                    new MaterialDialog.Builder(getActivity()).title(R.string.clear_history).content(R.string.clear_history_content).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            getMessageController().clearHistoryMessage(viewModel.roomId);
                        }
                    }).negativeText(R.string.no).show();
                } else if (menuList.get(position) == R.string.group_title_convert_to_public || menuList.get(position) == R.string.group_title_convert_to_private) {
                    viewModel.convertMenuClick();
                }
            }).show();
        }
    });
    viewModel.goToShowMemberPage.observe(getViewLifecycleOwner(), type -> {
        if (getActivity() != null && type != null) {
            FragmentShowMember fragment = FragmentShowMember.newInstance2(this, viewModel.roomId, viewModel.role.toString(), AccountManager.getInstance().getCurrentUser().getId(), type, viewModel.isNeedgetContactlist, true);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        }
    });
    viewModel.showDialogConvertToPublic.observe(getViewLifecycleOwner(), isShow -> {
        if (getActivity() != null && isShow != null && isShow) {
            new MaterialDialog.Builder(getActivity()).title(getString(R.string.group_title_convert_to_public)).content(getString(R.string.group_text_convert_to_public)).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                    setUsername();
                }
            }).negativeText(R.string.no).show();
        }
    });
    viewModel.showDialogConvertToPrivate.observe(getViewLifecycleOwner(), isShow -> {
        if (getActivity() != null && isShow != null && isShow) {
            new MaterialDialog.Builder(getActivity()).title(R.string.group_title_convert_to_private).content(R.string.group_text_convert_to_private).positiveText(R.string.yes).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    viewModel.sendRequestRemoveGroupUsername();
                }
            }).negativeText(R.string.no).show();
        }
    });
    viewModel.showRequestError.observe(getViewLifecycleOwner(), errorMessage -> {
        if (errorMessage != null) {
            HelperError.showSnackMessage(getString(errorMessage), false);
        }
    });
    viewModel.goToShowCustomListPage.observe(getViewLifecycleOwner(), listItem -> {
        if (getActivity() != null && listItem != null) {
            ShowCustomList showCustomListFragment = new ShowCustomList();
            showCustomListFragment.setFields(ProtoGlobal.Room.Type.GROUP, listItem, (result, message, countForShowLastMessage, list) -> {
                for (int i = 0; i < list.size(); i++) {
                    new RequestGroupAddMember().groupAddMember(viewModel.roomId, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(viewModel.roomId, countForShowLastMessage));
                }
            });
            Bundle bundle = new Bundle();
            bundle.putBoolean("DIALOG_SHOWING", true);
            bundle.putLong("COUNT_MESSAGE", 0);
            showCustomListFragment.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), showCustomListFragment).setReplace(false).load();
        }
    });
    viewModel.goBack.observe(getViewLifecycleOwner(), isGoBack -> {
        if (isGoBack != null && isGoBack) {
            popBackStackFragment();
        }
    });
    BetterLinkMovementMethod.linkify(Linkify.ALL, binding.description).setOnLinkClickListener((tv, url) -> {
        return false;
    }).setOnLinkLongClickListener((tv, url) -> {
        if (HelperUrl.isTextLink(url)) {
            G.isLinkClicked = true;
            HelperUrl.openLinkDialog(getActivity(), url);
        }
        return true;
    });
    viewModel.groupDescription.observe(getViewLifecycleOwner(), groupDescription -> {
        if (getActivity() != null && groupDescription != null) {
            binding.description.setText(EmojiManager.getInstance().replaceEmoji(HelperUrl.setUrlLink(getActivity(), groupDescription, true, false, null, true), binding.description.getPaint().getFontMetricsInt()));
        }
    });
    viewModel.goToRoomListPage.observe(getViewLifecycleOwner(), isGo -> {
        if (getActivity() instanceof ActivityMain && isGo != null) {
            Log.wtf(this.getClass().getName(), "goToRoomListPage observe");
            ((ActivityMain) getActivity()).removeAllFragmentFromMain();
        /*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(2);*/
        }
    });
    viewModel.showDialogEditLink.observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).negativeText(R.string.edit).onPositive((dialog1, which) -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
                clipboard.setPrimaryClip(clip);
            }).onNegative((dialog12, which) -> {
                if (viewModel.isPrivate) {
                    viewModel.sendRequestRevokeGroupUsername();
                } else {
                    setUsername();
                }
            }).build();
            dialog.show();
        }
    });
    viewModel.showDialogCopyLink.observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            MaterialDialog dialog = new MaterialDialog.Builder(getActivity()).title(R.string.group_link).positiveText(R.string.array_Copy).customView(createDialogLayout(link), true).widgetColor(new Theme().getPrimaryColor(getContext())).onPositive((dialog1, which) -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("LINK_GROUP", link);
                clipboard.setPrimaryClip(clip);
                Toast.makeText(getActivity(), R.string.copied, Toast.LENGTH_SHORT).show();
            }).build();
            dialog.show();
        }
    });
    viewModel.goToCustomNotificationPage.observe(getViewLifecycleOwner(), roomId -> {
        if (getActivity() != null && roomId != null) {
            FragmentNotification fragmentNotification = new FragmentNotification();
            Bundle bundle = new Bundle();
            bundle.putLong("ID", roomId);
            fragmentNotification.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragmentNotification).setReplace(false).load();
        }
    });
    viewModel.showDialogLeaveGroup.observe(getViewLifecycleOwner(), isShow -> {
        if (isShow != null && isShow) {
            groupLeft();
        }
    });
    if (viewModel.role.equals(GroupChatRole.OWNER)) {
        binding.editGroupPermission.setVisibility(View.VISIBLE);
        binding.editGroupPermission.setOnClickListener(v -> {
            openChatEditRightsFragment(viewModel.getRealmRoom());
        });
    }
    initComponent();
    attachFile = new AttachFile(getActivity());
    G.onGroupAvatarDelete = this;
    initialToolbar();
}
Also used : TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) OnGroupAvatarDelete(net.iGap.observers.interfaces.OnGroupAvatarDelete) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) WindowManager(android.view.WindowManager) AttachFile(net.iGap.module.AttachFile) Theme(net.iGap.module.Theme) OnGroupCheckUsername(net.iGap.observers.interfaces.OnGroupCheckUsername) Selection(android.text.Selection) G(net.iGap.G) GroupChatRole(net.iGap.module.enums.GroupChatRole) RequestGroupUpdateUsername(net.iGap.request.RequestGroupUpdateUsername) Fragment(androidx.fragment.app.Fragment) ActivityGroupProfileBinding(net.iGap.databinding.ActivityGroupProfileBinding) ClipboardManager(android.content.ClipboardManager) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnComplete(net.iGap.observers.interfaces.OnComplete) MEditText(net.iGap.module.MEditText) RealmObjectChangeListener(io.realm.RealmObjectChangeListener) RealmRoom(net.iGap.realm.RealmRoom) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ProtoGroupCheckUsername(net.iGap.proto.ProtoGroupCheckUsername) AlphaAnimation(android.view.animation.AlphaAnimation) CLIPBOARD_SERVICE(android.content.Context.CLIPBOARD_SERVICE) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) EventManager(net.iGap.observers.eventbus.EventManager) NotNull(org.jetbrains.annotations.NotNull) TextWatcher(android.text.TextWatcher) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) Context(android.content.Context) Config(net.iGap.Config) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ActivityMain(net.iGap.activities.ActivityMain) HelperUrl(net.iGap.helper.HelperUrl) TextInputLayout(com.google.android.material.textfield.TextInputLayout) AccountManager(net.iGap.module.accountManager.AccountManager) Linkify(android.text.util.Linkify) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) ClipData(android.content.ClipData) Toast(android.widget.Toast) RequestGroupCheckUsername(net.iGap.request.RequestGroupCheckUsername) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Build(android.os.Build) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) LayoutInflater(android.view.LayoutInflater) FragmentGroupProfileViewModel(net.iGap.viewmodel.FragmentGroupProfileViewModel) DialogAction(com.afollestad.materialdialogs.DialogAction) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) CircleImageView(net.iGap.module.CircleImageView) Gravity(android.view.Gravity) CountDownTimer(android.os.CountDownTimer) TypedValue(android.util.TypedValue) HelperString(net.iGap.helper.HelperString) OnGroupUpdateUsername(net.iGap.observers.interfaces.OnGroupUpdateUsername) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) BetterLinkMovementMethod(me.saket.bettermovementmethod.BetterLinkMovementMethod) DbManager(net.iGap.module.accountManager.DbManager) ClipboardManager(android.content.ClipboardManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Bundle(android.os.Bundle) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) ActivityMain(net.iGap.activities.ActivityMain) DialogAction(com.afollestad.materialdialogs.DialogAction) AttachFile(net.iGap.module.AttachFile) NonNull(androidx.annotation.NonNull) Theme(net.iGap.module.Theme) HelperFragment(net.iGap.helper.HelperFragment) ClipData(android.content.ClipData)

Example 2 with RequestGroupAddMember

use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.

the class FragmentShowMember method goToAddMember.

private void goToAddMember() {
    List<StructContactInfo> userList = Contacts.retrieve(null);
    RealmList<RealmMember> memberList = DbManager.getInstance().doRealmTask(realm -> {
        return RealmMember.getMembers(realm, mRoomID);
    });
    for (int i = 0; i < memberList.size(); i++) {
        for (int j = 0; j < userList.size(); j++) {
            if (userList.get(j).peerId == memberList.get(i).getPeerId()) {
                userList.remove(j);
                break;
            }
        }
    }
    if (getActivity() != null) {
        ShowCustomList showCustomListFragment = new ShowCustomList();
        showCustomListFragment.setFields(roomType, userList, new OnSelectedList() {

            @Override
            public void getSelectedList(boolean result, String message, int countForShowLastMessage, final ArrayList<StructContactInfo> list) {
                if (isGroup) {
                    for (int i = 0; i < list.size(); i++) {
                        new RequestGroupAddMember().groupAddMember(mRoomID, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(mRoomID, countForShowLastMessage));
                    }
                } else {
                    for (int i = 0; i < list.size(); i++) {
                        new RequestChannelAddMember().channelAddMember(mRoomID, list.get(i).peerId);
                    }
                }
            }
        });
        Bundle bundle = new Bundle();
        bundle.putBoolean("DIALOG_SHOWING", true);
        bundle.putLong("COUNT_MESSAGE", 0);
        showCustomListFragment.setArguments(bundle);
        new HelperFragment(getActivity().getSupportFragmentManager(), showCustomListFragment).setReplace(false).load();
    }
}
Also used : StructContactInfo(net.iGap.module.structs.StructContactInfo) Bundle(android.os.Bundle) OnSelectedList(net.iGap.observers.interfaces.OnSelectedList) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) HelperFragment(net.iGap.helper.HelperFragment) RealmMember(net.iGap.realm.RealmMember) RequestChannelAddMember(net.iGap.request.RequestChannelAddMember)

Example 3 with RequestGroupAddMember

use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.

the class FragmentNewGroup method addMembersToGroup.

private void addMembersToGroup() {
    G.onGroupAddMember = new OnGroupAddMember() {

        @Override
        public void onGroupAddMember(Long roomId, Long UserId) {
            countAddMemberResponse++;
            countMember++;
            if (countAddMemberResponse == countAddMemberRequest) {
                addMember(roomId, ProtoGlobal.Room.Type.GROUP);
            }
        }

        @Override
        public void onError(int majorCode, int minorCode) {
            countAddMemberResponse++;
            if (countAddMemberResponse == countAddMemberRequest) {
                addMember(createdRoomId, ProtoGlobal.Room.Type.GROUP);
            }
        }
    };
    /**
     * request add member for group
     */
    // countAddMemberRequest = ContactGroupFragment.selectedContacts.size() ;
    ArrayList<Long> list = getSelectedList();
    if (list.size() > 0) {
        for (long peerId : list) {
            new RequestGroupAddMember().groupAddMember(createdRoomId, peerId, 0);
        }
    } else {
        if (getActivity() instanceof ActivityMain && isAdded()) {
            Log.wtf(this.getClass().getName(), "addMembersToGroup is done");
            /* if (FragmentNewGroup.onRemoveFragmentNewGroup != null)
                    FragmentNewGroup.onRemoveFragmentNewGroup.onRemove();*/
            G.refreshRealmUi();
            /*popBackStackFragment();
                popBackStackFragment();
                removeFromBaseFragment(FragmentNewGroup.this);*/
            ((ActivityMain) getActivity()).removeAllFragmentFromMain();
            new GoToChatActivity(createdRoomId).startActivity(getActivity());
        }
    }
}
Also used : ActivityMain(net.iGap.activities.ActivityMain) OnGroupAddMember(net.iGap.observers.interfaces.OnGroupAddMember) GoToChatActivity(net.iGap.helper.GoToChatActivity) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember)

Example 4 with RequestGroupAddMember

use of net.iGap.request.RequestGroupAddMember in project iGap-Android by KianIranian-STDG.

the class ContactGroupFragment method onRightIconClickListener.

@Override
public void onRightIconClickListener(View view) {
    fixChipsLayoutShowingState();
    if (typeCreate.equals("CHANNEL")) {
        G.onChannelAddMember = new OnChannelAddMember() {

            @Override
            public void onChannelAddMember(Long RoomId, Long UserId, ProtoGlobal.ChannelRoom.Role role) {
                G.runOnUiThread(() -> {
                    progressDialog.dismiss();
                    countAddMemberResponse++;
                    addMember(RoomId, ProtoGlobal.Room.Type.CHANNEL);
                    countMember++;
                    if (countAddMemberResponse == countAddMemberRequest) {
                        addMember(RoomId, ProtoGlobal.Room.Type.CHANNEL);
                    }
                });
            }

            @Override
            public void onError(int majorCode, int minorCode) {
                G.runOnUiThread(() -> {
                    progressDialog.dismiss();
                    countAddMemberResponse++;
                    if (countAddMemberResponse == countAddMemberRequest) {
                        addMember(roomId, ProtoGlobal.Room.Type.CHANNEL);
                    }
                    HelperError.showSnackMessage(requireContext().getResources().getString(R.string.error), false);
                });
            }

            @Override
            public void onTimeOut() {
                G.runOnUiThread(() -> {
                    progressDialog.dismiss();
                    HelperError.showSnackMessage(requireContext().getResources().getString(R.string.time_out), false);
                });
            }
        };
        ArrayList<Long> list = getSelectedList();
        if (list.size() > 0) {
            for (long peerId : list) {
                new RequestChannelAddMember().channelAddMember(roomId, peerId);
                progressDialog.show();
                progressDialog.setCancelable(false);
            }
        } else {
            if (isAdded()) {
                if (getActivity() instanceof ActivityMain) {
                    ((ActivityMain) getActivity()).removeAllFragmentFromMain();
                    new GoToChatActivity(ContactGroupFragment.this.roomId).startActivity(getActivity());
                }
            }
        }
    } else if (typeCreate.equals("GROUP")) {
        if (roomId == -127) {
            if (getActivity() != null) {
                FragmentNewGroup fragment = FragmentNewGroup.newInstance();
                Bundle bundle_ = new Bundle();
                bundle_.putString("TYPE", "NewGroup");
                fragment.setArguments(bundle_);
                new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load(true);
                return;
            }
        }
        G.onGroupAddMember = new OnGroupAddMember() {

            @Override
            public void onGroupAddMember(Long roomId, Long UserId) {
                countAddMemberResponse++;
                countMember++;
                if (countAddMemberResponse == countAddMemberRequest) {
                    addMember(roomId, ProtoGlobal.Room.Type.GROUP);
                }
            }

            @Override
            public void onError(int majorCode, int minorCode) {
                countAddMemberResponse++;
                if (countAddMemberResponse == countAddMemberRequest) {
                    addMember(roomId, ProtoGlobal.Room.Type.GROUP);
                }
            }
        };
        /**
         * request add member for group
         */
        ArrayList<Long> list = getSelectedList();
        if (list.size() > 0) {
            for (long peerId : list) {
                new RequestGroupAddMember().groupAddMember(roomId, peerId, 0);
            }
        } else {
            if (getActivity() != null && isAdded()) {
                removeFromBaseFragment(ContactGroupFragment.this);
                new GoToChatActivity(ContactGroupFragment.this.roomId).startActivity(getActivity());
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) ActivityMain(net.iGap.activities.ActivityMain) OnChannelAddMember(net.iGap.observers.interfaces.OnChannelAddMember) GoToChatActivity(net.iGap.helper.GoToChatActivity) OnGroupAddMember(net.iGap.observers.interfaces.OnGroupAddMember) HelperFragment(net.iGap.helper.HelperFragment) RequestChannelAddMember(net.iGap.request.RequestChannelAddMember)

Aggregations

Bundle (android.os.Bundle)3 ActivityMain (net.iGap.activities.ActivityMain)3 RequestGroupAddMember (net.iGap.request.RequestGroupAddMember)3 GoToChatActivity (net.iGap.helper.GoToChatActivity)2 HelperFragment (net.iGap.helper.HelperFragment)2 OnGroupAddMember (net.iGap.observers.interfaces.OnGroupAddMember)2 RequestChannelAddMember (net.iGap.request.RequestChannelAddMember)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 CLIPBOARD_SERVICE (android.content.Context.CLIPBOARD_SERVICE)1 Build (android.os.Build)1 CountDownTimer (android.os.CountDownTimer)1 Editable (android.text.Editable)1 Selection (android.text.Selection)1 TextWatcher (android.text.TextWatcher)1 Linkify (android.text.util.Linkify)1 Log (android.util.Log)1 TypedValue (android.util.TypedValue)1 Gravity (android.view.Gravity)1