Search in sources :

Example 1 with RealmRoomAccess

use of net.iGap.realm.RealmRoomAccess 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 RealmRoomAccess

use of net.iGap.realm.RealmRoomAccess in project iGap-Android by KianIranian-STDG.

the class FragmentChannelProfile method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (currentRoomAccess != null) {
        checkRoomAccess(currentRoomAccess);
        roomAccessChangeListener = (realmRoomAccess, changeSet) -> checkRoomAccess(realmRoomAccess);
        currentRoomAccess.addChangeListener(roomAccessChangeListener);
    }
    imvChannelAvatar = binding.toolbarAvatar;
    imvChannelAvatar.setOnClickListener(v -> viewModel.onClickCircleImage());
    binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
    binding.toolbarMore.setOnClickListener(v -> showPopUp());
    binding.toolbarEdit.setOnClickListener(v -> {
        if (getActivity() != null && viewModel.checkIsEditableAndReturnState()) {
            new HelperFragment(getActivity().getSupportFragmentManager(), EditChannelFragment.newInstance(viewModel.roomId)).setReplace(false).load();
        }
    });
    viewModel.channelName.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.channelSecondsTitle.observe(getViewLifecycleOwner(), s -> binding.toolbarTxtStatusExpanded.setText(s));
    viewModel.menuPopupVisibility.observe(getViewLifecycleOwner(), integer -> {
        if (integer != null) {
            binding.toolbarMore.setVisibility(integer);
        }
    });
    viewModel.channelDescription.observe(getViewLifecycleOwner(), description -> {
        if (getActivity() != null && description != null) {
            binding.description.setText(HelperUrl.setUrlLink(getActivity(), description, true, false, null, true));
        }
    });
    viewModel.goBack.observe(getViewLifecycleOwner(), goBack -> {
        if (goBack != null && goBack) {
            popBackStackFragment();
        }
    });
    viewModel.muteNotifListener.observe(getViewLifecycleOwner(), isMute -> {
        getRoomController().clientMuteRoom(viewModel.roomId, isMute);
        binding.enableNotification.setChecked(isMute);
    });
    viewModel.goToRoomListPage.observe(getViewLifecycleOwner(), isGo -> {
        if (getActivity() instanceof ActivityMain && isGo != null && isGo) {
            ((ActivityMain) getActivity()).removeAllFragmentFromMain();
        /*new HelperFragment(getActivity().getSupportFragmentManager()).popBackStack(2);*/
        }
    });
    viewModel.goToShowMemberList.observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowMember.newInstance2(this, data.getRoomId(), data.getRole(), data.getUserId(), data.getSelectedRole(), data.isNeedGetMemberList(), false)).setReplace(false).load();
        }
    });
    viewModel.showDialogCopyLink.observe(getViewLifecycleOwner(), link -> {
        if (getActivity() != null && link != null) {
            LinearLayout layoutChannelLink = new LinearLayout(getActivity());
            layoutChannelLink.setOrientation(LinearLayout.VERTICAL);
            View viewRevoke = new View(getActivity());
            LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
            TextInputLayout inputChannelLink = new TextInputLayout(getActivity());
            MEditText edtLink = new MEditText(getActivity());
            edtLink.setHint(R.string.channel_public_hint_revoke);
            edtLink.setTypeface(ResourcesCompat.getFont(edtLink.getContext(), R.font.main_font));
            edtLink.setText(link);
            edtLink.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.dp14));
            edtLink.setTextColor(new Theme().getTitleTextColor(getActivity()));
            edtLink.setHintTextColor(getResources().getColor(R.color.hint_edit_text));
            edtLink.setPadding(0, 8, 0, 8);
            edtLink.setEnabled(false);
            edtLink.setSingleLine(true);
            inputChannelLink.addView(edtLink);
            inputChannelLink.addView(viewRevoke, viewParams);
            TextView txtLink = new AppCompatTextView(getActivity());
            txtLink.setText(link);
            txtLink.setTextColor(new Theme().getTitleTextColor(getActivity()));
            viewRevoke.setBackgroundColor(getResources().getColor(R.color.line_edit_text));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                edtLink.setBackground(getResources().getDrawable(android.R.color.transparent));
            }
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutChannelLink.addView(inputChannelLink, layoutParams);
            layoutChannelLink.addView(txtLink, layoutParams);
            if (getActivity() != null) {
                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();
            }
        }
    });
    viewModel.goToSharedMediaPage.observe(getViewLifecycleOwner(), typeModel -> {
        if (getActivity() != null && typeModel != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(typeModel)).setReplace(false).load();
        }
    });
    viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), roomId -> {
        if (getActivity() != null && roomId != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShowAvatars.newInstance(roomId, FragmentShowAvatars.From.channel)).setReplace(false).load();
        }
    });
    viewModel.showDialogLeaveChannel.observe(getViewLifecycleOwner(), isShow -> showDialogLeaveChannel());
    viewModel.goToChatRoom.observe(getViewLifecycleOwner(), isGo -> {
        if (getActivity() != null && isGo != null && isGo) {
            ((ActivityMain) getActivity()).removeAllFragmentFromMain();
        }
    });
    viewModel.showErrorMessage.observe(getViewLifecycleOwner(), errorMessageResId -> {
        if (errorMessageResId != null) {
            HelperError.showSnackMessage(getString(errorMessageResId), false);
        }
    });
    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;
    });
    // binding.description.setMovementMethod(LinkMovementMethod.getInstance());
    AppUtils.setProgresColler(binding.loading);
    FragmentShowAvatars.onComplete = (result, messageOne, MessageTow) -> {
        long mAvatarId = 0;
        if (messageOne != null && !messageOne.equals("")) {
            mAvatarId = Long.parseLong(messageOne);
        }
        avatarHandler.avatarDelete(new ParamWithAvatarType(imvChannelAvatar, viewModel.roomId).avatarType(AvatarHandler.AvatarType.ROOM), mAvatarId);
    };
    setAvatar();
    initialToolbar();
}
Also used : ClipboardManager(android.content.ClipboardManager) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) NonNull(androidx.annotation.NonNull) ViewModel(androidx.lifecycle.ViewModel) Theme(net.iGap.module.Theme) G(net.iGap.G) ClipboardManager(android.content.ClipboardManager) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) HelperError(net.iGap.helper.HelperError) HelperFragment(net.iGap.helper.HelperFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) MEditText(net.iGap.module.MEditText) RealmObjectChangeListener(io.realm.RealmObjectChangeListener) RequestChannelKickAdmin(net.iGap.request.RequestChannelKickAdmin) ViewGroup(android.view.ViewGroup) FragmentChannelProfileViewModel(net.iGap.viewmodel.FragmentChannelProfileViewModel) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) 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) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) 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) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) Toast(android.widget.Toast) ActivityProfileChannelBinding(net.iGap.databinding.ActivityProfileChannelBinding) Build(android.os.Build) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) RequestChannelKickModerator(net.iGap.request.RequestChannelKickModerator) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) CircleImageView(net.iGap.module.CircleImageView) OnChannelAvatarDelete(net.iGap.observers.interfaces.OnChannelAvatarDelete) TypedValue(android.util.TypedValue) R(net.iGap.R) BetterLinkMovementMethod(me.saket.bettermovementmethod.BetterLinkMovementMethod) DbManager(net.iGap.module.accountManager.DbManager) RequestChannelKickMember(net.iGap.request.RequestChannelKickMember) MEditText(net.iGap.module.MEditText) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) View(android.view.View) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) CircleImageView(net.iGap.module.CircleImageView) ActivityMain(net.iGap.activities.ActivityMain) Theme(net.iGap.module.Theme) TextView(android.widget.TextView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) HelperFragment(net.iGap.helper.HelperFragment) TextInputLayout(com.google.android.material.textfield.TextInputLayout) ClipData(android.content.ClipData) LinearLayout(android.widget.LinearLayout)

Example 3 with RealmRoomAccess

use of net.iGap.realm.RealmRoomAccess in project iGap-Android by KianIranian-STDG.

the class FragmentShowMember method initComponent.

private void initComponent(View view) {
    mHelperToolbar = HelperToolbar.create().setContext(getContext()).setLifecycleOwner(getViewLifecycleOwner()).setLeftIcon(R.string.icon_back).setLogoShown(true).setSearchBoxShown(true).setListener(this);
    LinearLayout layoutToolbar = view.findViewById(R.id.fcm_layout_toolbar);
    layoutToolbar.addView(mHelperToolbar.getView());
    mBtnAdd = view.findViewById(R.id.fcm_lbl_add);
    realmRoom = DbManager.getInstance().doRealmTask(realm -> {
        return realm.where(RealmRoom.class).equalTo("id", mRoomID).findFirst();
    });
    if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
        if (isGroup) {
            mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.member));
            mBtnAdd.setText(context.getResources().getString(R.string.add_new_member));
        } else {
            mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.subscriber));
            mBtnAdd.setText(context.getResources().getString(R.string.add_new_subscriber));
        }
        if (!isShowAddButton) {
            mBtnAdd.setVisibility(View.GONE);
            view.findViewById(R.id.fcm_splitter_add).setVisibility(View.GONE);
        }
        mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewMember() ? View.VISIBLE : View.GONE);
    } else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
        mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_admin));
        mBtnAdd.setText(context.getResources().getString(R.string.add_admin));
        mBtnAdd.setVisibility(realmRoomAccess != null && realmRoomAccess.isCanAddNewAdmin() ? View.VISIBLE : View.GONE);
        if (realmRoom != null) {
            if (realmRoom.getGroupRoom() != null && realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER) {
                mBtnAdd.setVisibility(View.VISIBLE);
            }
            if (realmRoom.getChannelRoom() != null && realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER) {
                mBtnAdd.setVisibility(View.VISIBLE);
            }
        }
    } else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
        mHelperToolbar.setDefaultTitle(context.getResources().getString(R.string.list_modereator));
        mBtnAdd.setText(context.getResources().getString(R.string.add_modereator));
        mBtnAdd.setVisibility(View.GONE);
        if (realmRoom != null) {
            if (realmRoom.getGroupRoom() != null && (realmRoom.getGroupRoom().getRole() == GroupChatRole.OWNER || realmRoom.getGroupRoom().getRole() == GroupChatRole.ADMIN)) {
                mBtnAdd.setVisibility(View.VISIBLE);
            }
            if (realmRoom.getChannelRoom() != null && (realmRoom.getChannelRoom().getRole() == ChannelChatRole.OWNER || realmRoom.getChannelRoom().getRole() == ChannelChatRole.ADMIN)) {
                mBtnAdd.setVisibility(View.VISIBLE);
            }
        }
    }
    mBtnAdd.setOnClickListener(v -> {
        if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString()) || selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
            openFragmentForAdd(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString(), selectedRole);
        } else if (selectedRole.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
            goToAddMember();
        }
    });
    final EditText edtSearch = mHelperToolbar.getEditTextSearch();
    edtSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(final Editable s) {
            RealmResults<RealmMember> searchMember = DbManager.getInstance().doRealmTask(realm -> {
                return RealmMember.filterMember(realm, mRoomID, s.toString(), getUnselectRow(), selectedRole);
            });
            mAdapter = new MemberAdapter(searchMember, roomType, mMainRole, userID);
            mRecyclerView.setAdapter(mAdapter);
        }
    });
    mRecyclerView = view.findViewById(R.id.fcm_recycler_view_show_member);
    mRecyclerView.setItemViewCacheSize(100);
    mRecyclerView.setItemAnimator(null);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(G.fragmentActivity));
    final PreCachingLayoutManager preCachingLayoutManager = new PreCachingLayoutManager(G.fragmentActivity, DeviceUtils.getScreenHeight(G.fragmentActivity));
    mRecyclerView.setLayoutManager(preCachingLayoutManager);
    progressBar = view.findViewById(R.id.fcg_prgWaiting);
    AppUtils.setProgresColler(progressBar);
    // TextView txtNumberOfMember = (TextView) view.findViewById(R.id.fcg_txt_member);
    // if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.MODERATOR.toString())) {
    // txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_modereator));
    // } else if (selectedRole.toString().equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ADMIN.toString())) {
    // txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(R.string.list_admin));
    // } else {
    // txtNumberOfMember.setText(G.fragmentActivity.getResources().getString(member));
    // }
    scrollListener = new EndlessRecyclerViewScrollListener(preCachingLayoutManager) {

        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            // Triggered only when new data needs to be appended to the list
            // Add whatever code is needed to append new items to the bottom of the list
            loadMoreMember();
        }
    };
    mRecyclerView.addOnScrollListener(scrollListener);
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) AppUtils(net.iGap.module.AppUtils) ToolbarListener(net.iGap.observers.interfaces.ToolbarListener) ProgressBar(android.widget.ProgressBar) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Theme(net.iGap.module.Theme) G(net.iGap.G) RequestGroupGetMemberList(net.iGap.request.RequestGroupGetMemberList) GroupChatRole(net.iGap.module.enums.GroupChatRole) RealmChannelRoom(net.iGap.realm.RealmChannelRoom) Handler(android.os.Handler) Looper(android.os.Looper) Fragment(androidx.fragment.app.Fragment) View(android.view.View) OnGroupKickMember(net.iGap.observers.interfaces.OnGroupKickMember) HelperError(net.iGap.helper.HelperError) RecyclerView(androidx.recyclerview.widget.RecyclerView) HelperFragment(net.iGap.helper.HelperFragment) RequestGroupAddMember(net.iGap.request.RequestGroupAddMember) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) RealmMember(net.iGap.realm.RealmMember) AsyncTask(android.os.AsyncTask) OnComplete(net.iGap.observers.interfaces.OnComplete) RealmRoom(net.iGap.realm.RealmRoom) RealmGroupRoom(net.iGap.realm.RealmGroupRoom) ViewGroup(android.view.ViewGroup) CHANNEL(net.iGap.proto.ProtoGlobal.Room.Type.CHANNEL) OnGroupGetMemberList(net.iGap.observers.interfaces.OnGroupGetMemberList) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) RealmRecyclerViewAdapter(io.realm.RealmRecyclerViewAdapter) RequestChannelAddMember(net.iGap.request.RequestChannelAddMember) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextCell(net.iGap.adapter.items.cells.TextCell) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ProtoGroupGetMemberList(net.iGap.proto.ProtoGroupGetMemberList) NotNull(org.jetbrains.annotations.NotNull) EndlessRecyclerViewScrollListener(net.iGap.module.EndlessRecyclerViewScrollListener) TextWatcher(android.text.TextWatcher) HelperToolbar(net.iGap.helper.HelperToolbar) Context(android.content.Context) RequestChannelGetMemberList(net.iGap.request.RequestChannelGetMemberList) RealmList(io.realm.RealmList) AccountManager(net.iGap.module.accountManager.AccountManager) StructContactInfo(net.iGap.module.structs.StructContactInfo) Dialog(android.app.Dialog) Editable(android.text.Editable) DeviceUtils(net.iGap.module.DeviceUtils) ArrayList(java.util.ArrayList) ProtoChannelGetMemberList(net.iGap.proto.ProtoChannelGetMemberList) LayoutCreator(net.iGap.helper.LayoutCreator) Contacts(net.iGap.module.Contacts) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RequestUserInfo(net.iGap.request.RequestUserInfo) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) OnSelectedList(net.iGap.observers.interfaces.OnSelectedList) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) LayoutInflater(android.view.LayoutInflater) RealmResults(io.realm.RealmResults) CircleImageView(net.iGap.module.CircleImageView) PreCachingLayoutManager(net.iGap.module.PreCachingLayoutManager) Gravity(android.view.Gravity) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) ChannelChatRole(net.iGap.module.enums.ChannelChatRole) OnChannelGetMemberList(net.iGap.observers.interfaces.OnChannelGetMemberList) GROUP(net.iGap.proto.ProtoGlobal.Room.Type.GROUP) DbManager(net.iGap.module.accountManager.DbManager) RequestGroupKickMember(net.iGap.request.RequestGroupKickMember) EditText(android.widget.EditText) RequestChannelKickMember(net.iGap.request.RequestChannelKickMember) EditText(android.widget.EditText) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) PreCachingLayoutManager(net.iGap.module.PreCachingLayoutManager) EndlessRecyclerViewScrollListener(net.iGap.module.EndlessRecyclerViewScrollListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(androidx.recyclerview.widget.RecyclerView) RealmRoom(net.iGap.realm.RealmRoom) LinearLayout(android.widget.LinearLayout) RealmResults(io.realm.RealmResults)

Aggregations

Bundle (android.os.Bundle)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 Nullable (androidx.annotation.Nullable)3 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 G (net.iGap.G)3 R (net.iGap.R)3 HelperError (net.iGap.helper.HelperError)3 HelperFragment (net.iGap.helper.HelperFragment)3 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)3 ParamWithAvatarType (net.iGap.helper.avatar.ParamWithAvatarType)3 AppUtils (net.iGap.module.AppUtils)3 CircleImageView (net.iGap.module.CircleImageView)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2 CLIPBOARD_SERVICE (android.content.Context.CLIPBOARD_SERVICE)2 Build (android.os.Build)2