Search in sources :

Example 1 with CLIPBOARD_SERVICE

use of android.content.Context.CLIPBOARD_SERVICE 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 CLIPBOARD_SERVICE

use of android.content.Context.CLIPBOARD_SERVICE 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 CLIPBOARD_SERVICE

use of android.content.Context.CLIPBOARD_SERVICE in project iGap-Android by KianIranian-STDG.

the class FragmentContactsProfile method onViewCreated.

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    initialToolbar();
    DbManager.getInstance().doRealmTask(realm -> {
        realmRoom = realm.where(RealmRoom.class).equalTo("id", viewModel.roomId).findFirst();
        if (realmRoom != null) {
            roomType = realmRoom.getType();
            action = realmRoom.getActionState();
        }
    });
    G.onSetAction = this;
    if (peerId == AccountManager.getInstance().getCurrentUser().getId()) {
        binding.toolbarTxtStatusExpanded.setText(requireContext().getResources().getString(R.string.chat_with_yourself));
    } else {
        viewModel.lastSeen.observe(getViewLifecycleOwner(), lastSeen -> {
            if (action != null && realmRoom != null)
                binding.toolbarTxtStatusExpanded.setText(action);
            else
                binding.toolbarTxtStatusExpanded.setText(HelperCalander.unicodeManage(lastSeen));
        });
    }
    userAvatarImageView = binding.toolbarAvatar;
    userAvatarImageView.setOnClickListener(v -> viewModel.onImageClick());
    binding.toolbarBack.setOnClickListener(v -> popBackStackFragment());
    binding.toolbarMore.setOnClickListener(v -> viewModel.onMoreButtonClick());
    binding.toolbarCall.setOnClickListener(v -> onCallButtonClick());
    viewModel.copyUserNameToClipBoard.observe(getViewLifecycleOwner(), userName -> {
        if (userName == null)
            return;
        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("LINK_USER", Config.IGAP_LINK_PREFIX + userName);
        clipboard.setPrimaryClip(clip);
        Toast.makeText(getActivity(), getString(R.string.username_copied), Toast.LENGTH_SHORT).show();
    });
    viewModel.getCloudVisibility().observe(getViewLifecycleOwner(), thisMyCloud -> {
        if (thisMyCloud != null) {
            if (thisMyCloud) {
                binding.report.setVisibility(View.GONE);
                binding.block.setVisibility(View.GONE);
                binding.enableNotificationLyt.setVisibility(View.GONE);
                binding.line1.setVisibility(View.GONE);
                binding.customNotification.setVisibility(View.GONE);
            } else {
                binding.report.setVisibility(View.VISIBLE);
                binding.block.setVisibility(View.VISIBLE);
                binding.line1.setVisibility(View.VISIBLE);
                binding.enableNotificationLyt.setVisibility(View.VISIBLE);
                binding.customNotification.setVisibility(View.VISIBLE);
            }
        }
    });
    viewModel.menuVisibility.observe(getViewLifecycleOwner(), visible -> {
        if (visible != null)
            binding.toolbarMore.setVisibility(visible);
    });
    viewModel.videoCallVisibility.observe(getViewLifecycleOwner(), visible -> {
        if (visible != null)
            binding.toolbarCall.setVisibility(visible);
    });
    viewModel.isMuteNotificationChangeListener.observe(getViewLifecycleOwner(), isChecked -> {
        binding.enableNotification.setChecked(isChecked);
        getRoomController().clientMuteRoom(viewModel.roomId, isChecked);
    });
    viewModel.contactName.observe(getViewLifecycleOwner(), name -> {
        if (name != null) {
            binding.toolbarTxtNameCollapsed.setText(EmojiManager.getInstance().replaceEmoji(name, binding.toolbarTxtNameCollapsed.getPaint().getFontMetricsInt()));
            binding.toolbarTxtNameExpanded.setText(EmojiManager.getInstance().replaceEmoji(name, binding.toolbarTxtNameExpanded.getPaint().getFontMetricsInt()));
            binding.toolbarTxtNameExpanded.setSelected(true);
        }
    });
    viewModel.goToChatPage.observe(getViewLifecycleOwner(), userRoomId -> {
        if (getActivity() != null && userRoomId != null) {
            if (G.twoPaneMode) {
                ((ActivityMain) getActivity()).removeAllFragment();
            } else {
                ((ActivityMain) getActivity()).removeAllFragmentFromMain();
            }
            new GoToChatActivity(userRoomId).startActivity(getActivity());
        }
    });
    viewModel.goBack.observe(getViewLifecycleOwner(), isBack -> {
        if (isBack != null && isBack) {
            popBackStackFragment();
        }
    });
    viewModel.goToShearedMediaPage.observe(getViewLifecycleOwner(), data -> {
        if (getActivity() != null && data != null) {
            new HelperFragment(getActivity().getSupportFragmentManager(), FragmentShearedMedia.newInstance(data)).setReplace(false).load();
        }
    });
    if (viewModel.phone != null && (!viewModel.phone.get().equals("0") || viewModel.showNumber.get())) {
        if (viewModel.phone.get().equals("0")) {
            binding.toolbarTxtTelExpanded.setVisibility(View.GONE);
            viewModel.menuVisibility.setValue(View.GONE);
        } else {
            binding.toolbarTxtTelExpanded.setText(viewModel.phone.get());
            binding.toolbarTxtTelExpanded.setOnClickListener(v -> viewModel.onPhoneNumberClick());
        }
    } else {
        binding.toolbarTxtTelExpanded.setVisibility(View.GONE);
    }
    /*binding.toolbarTxtUsernameExpanded.setText(viewModel.username.get());*/
    binding.toolbarFabChat.setOnClickListener(v -> {
        viewModel.onClickGoToChat();
    });
    /*binding.chiFabSetPic.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(G.fabBottom)));
        binding.chiFabSetPic.setColorFilter(Color.WHITE);
        binding.chiFabSetPic.setOnClickListener(new View.OnClickListener() { //fab button
            @Override
            public void onClick(View view) {

                if (enterFrom.equals(ProtoGlobal.Room.Type.GROUP.toString()) || enterFrom.equals("Others")) { // Others is from FragmentMapUsers adapter

final RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo("chatRoom.peer_id", userId).findFirst();

                    if (realmRoom != null) {
                        new HelperFragment().removeAll(true);
                        new GoToChatActivity(realmRoom.getId()).startActivity();
                    } else {
                        G.onChatGetRoom = new OnChatGetRoom() {
                            @Override
                            public void onChatGetRoom(final ProtoGlobal.Room room) {
                                G.handler.post(new Runnable() {
                                    @Override
                                    public void run() {
                                        new HelperFragment().removeAll(true);
                                        new GoToChatActivity(room.getId()).setPeerID(userId).startActivity();
                                        G.onChatGetRoom = null;
                                    }
                                });
                            }

                            @Override
                            public void onChatGetRoomTimeOut() {

                            }

                            @Override
                            public void onChatGetRoomError(int majorCode, int minorCode) {

                            }
                        };

                        new RequestChatGetRoom().chatGetRoom(userId);
                    }


                } else {
                    popBackStackFragment();
                }
            }
        });*/
    /*if (viewModel.showNumber.get()) {
            binding.chiLayoutNickname.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    if (viewModel.contactName.get() == null) {
                        return;
                    }

                    final LinearLayout layoutNickname = new LinearLayout(G.fragmentActivity);
                    layoutNickname.setOrientation(LinearLayout.VERTICAL);

                    String splitNickname[] = viewModel.contactName.get().split(" ");
                    String firsName = "";
                    String lastName = "";
                    StringBuilder stringBuilder = null;
                    if (splitNickname.length > 1) {

                        lastName = splitNickname[splitNickname.length - 1];
                        stringBuilder = new StringBuilder();
                        for (int i = 0; i < splitNickname.length - 1; i++) {

                            stringBuilder.append(splitNickname[i]).append(" ");
                        }
                        firsName = stringBuilder.toString();
                    } else {
                        firsName = splitNickname[0];
                    }
                    final View viewFirstName = new View(G.fragmentActivity);
                    viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));

                    LinearLayout.LayoutParams viewParams = new AppBarLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2);

                    TextInputLayout inputFirstName = new TextInputLayout(G.fragmentActivity);
                    final EmojiEditTextE edtFirstName = new EmojiEditTextE(G.fragmentActivity);
                    edtFirstName.setHint(R.string.first_name);
                    edtFirstName.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                    edtFirstName.setTypeface(G.typeface_IRANSansMobile);
                    edtFirstName.setText(firsName);
                    edtFirstName.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14));
                    edtFirstName.setTextColor(G.context.getResources().getColor(R.color.text_edit_text));
                    edtFirstName.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text));
                    edtFirstName.setPadding(0, 8, 0, 8);
                    edtFirstName.setSingleLine(true);
                    inputFirstName.addView(edtFirstName);
                    inputFirstName.addView(viewFirstName, viewParams);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        edtFirstName.setBackground(G.context.getResources().getDrawable(android.R.color.transparent));
                    }

                    final View viewLastName = new View(G.fragmentActivity);
                    viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));

                    TextInputLayout inputLastName = new TextInputLayout(G.fragmentActivity);
                    final MEditText edtLastName = new MEditText(G.fragmentActivity);
                    edtLastName.setHint(R.string.last_name);
                    edtLastName.setTypeface(G.typeface_IRANSansMobile);
                    edtLastName.setText(lastName);
                    edtLastName.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14));
                    edtLastName.setTextColor(G.context.getResources().getColor(R.color.text_edit_text));
                    edtLastName.setHintTextColor(G.context.getResources().getColor(R.color.hint_edit_text));
                    edtLastName.setPadding(0, 8, 0, 8);
                    edtLastName.setSingleLine(true);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        edtLastName.setBackground(G.context.getResources().getDrawable(android.R.color.transparent));
                    }
                    inputLastName.addView(edtLastName);
                    inputLastName.addView(viewLastName, viewParams);

                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    layoutParams.setMargins(0, 0, 0, 15);
                    LinearLayout.LayoutParams lastNameLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    lastNameLayoutParams.setMargins(0, 15, 0, 10);

                    layoutNickname.addView(inputFirstName, layoutParams);
                    layoutNickname.addView(inputLastName, lastNameLayoutParams);

                    final MaterialDialog dialog = new MaterialDialog.Builder(G.fragmentActivity).title(G.fragmentActivity.getResources().getString(R.string.pu_nikname_profileUser))
                            .positiveText(G.fragmentActivity.getResources().getString(R.string.B_ok))
                            .customView(layoutNickname, true)
                            .widgetColor(Color.parseColor(G.appBarColor))
                            .negativeText(G.fragmentActivity.getResources().getString(R.string.B_cancel))
                            .build();

                    final View positive = dialog.getActionButton(DialogAction.POSITIVE);
                    positive.setEnabled(false);

                    edtFirstName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                        @Override
                        public void onFocusChange(View view, boolean b) {
                            if (b) {
                                viewFirstName.setBackgroundColor(Color.parseColor(G.appBarColor));
                            } else {
                                viewFirstName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
                            }
                        }
                    });

                    edtLastName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                        @Override
                        public void onFocusChange(View view, boolean b) {
                            if (b) {
                                viewLastName.setBackgroundColor(Color.parseColor(G.appBarColor));
                            } else {
                                viewLastName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
                            }
                        }
                    });

                    final String finalFirsName = firsName;
                    edtFirstName.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) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {

                            if (!edtFirstName.getText().toString().equals(finalFirsName)) {
                                positive.setEnabled(true);
                            } else {
                                positive.setEnabled(false);
                            }
                        }
                    });

                    final String finalLastName = lastName;
                    edtLastName.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) {

                        }

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (!edtLastName.getText().toString().equals(finalLastName)) {
                                positive.setEnabled(true);
                            } else {
                                positive.setEnabled(false);
                            }
                        }
                    });

                    positive.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            long po = Long.parseLong(viewModel.phone.get());
                            String firstName = edtFirstName.getText().toString().trim();
                            String lastName = edtLastName.getText().toString().trim();
                            new RequestUserContactsEdit().contactsEdit(userId, po, firstName, lastName);
                            dialog.dismiss();
                        }
                    });

                    dialog.show();
                }
            });
        }*/
    /*binding.chiAppbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                ViewGroup viewGroup = binding.chiRootCircleImage;
                if (verticalOffset < -5) {
                    viewGroup.animate().alpha(0).setDuration(700);
                    viewGroup.setVisibility(View.GONE);
                    binding.chiTxtTitleToolbarDisplayName.setVisibility(View.VISIBLE);
                    binding.chiTxtTitleToolbarDisplayName.animate().alpha(1).setDuration(300);
                    binding.chiTxtTitleToolbarLastSeen.setVisibility(View.VISIBLE);
                    binding.chiTxtTitleToolbarLastSeen.animate().alpha(1).setDuration(300);
                } else {
                    viewGroup.setVisibility(View.VISIBLE);
                    viewGroup.animate().alpha(1).setDuration(700);
                    binding.chiTxtTitleToolbarDisplayName.setVisibility(View.GONE);
                    binding.chiTxtTitleToolbarDisplayName.animate().alpha(0).setDuration(500);
                    binding.chiTxtTitleToolbarLastSeen.setVisibility(View.GONE);
                    binding.chiTxtTitleToolbarLastSeen.animate().alpha(0).setDuration(500);
                }
            }
        });*/
    viewModel.showMenu.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null && aBoolean) {
            showPopUp();
        }
    });
    viewModel.showPhoneNumberDialog.observe(getViewLifecycleOwner(), new Observer<Boolean>() {

        @Override
        public void onChanged(@Nullable Boolean aBoolean) {
            if (aBoolean != null && aBoolean) {
                try {
                    HelperPermission.getContactPermision(G.fragmentActivity, new OnGetPermission() {

                        @Override
                        public void Allow() {
                            showPopupPhoneNumber(/*t.getProfileTell()*/
                            null, viewModel.phone.get());
                        }

                        @Override
                        public void deny() {
                            showDeniedPermissionMessage(G.context.getString(R.string.permission_contact));
                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    /*binding.chiLayoutSharedMedia.setOnClickListener(new View.OnClickListener() {// go to the ActivityMediaChanel
            @Override
            public void onClick(View view) {
                new HelperFragment(FragmentShearedMedia.newInstance(viewModel.shearedId)).setReplace(false).load();
            }
        });*/
    viewModel.showClearChatDialog.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null && aBoolean) {
            showAlertDialog(getString(R.string.clear_this_chat), getString(R.string.clear), getString(R.string.cancel));
        }
    });
    viewModel.goToCustomNotificationPage.observe(getViewLifecycleOwner(), aBoolean -> {
        if (getActivity() != null && aBoolean != null && aBoolean) {
            FragmentNotification fragmentNotification = new FragmentNotification();
            Bundle bundle = new Bundle();
            bundle.putString("PAGE", "CONTACT");
            bundle.putLong("ID", viewModel.roomId);
            fragmentNotification.setArguments(bundle);
            new HelperFragment(getActivity().getSupportFragmentManager(), fragmentNotification).setReplace(false).load();
        }
    });
    viewModel.setAvatar.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null) {
            if (aBoolean) {
                avatarHandler.getAvatar(new ParamWithAvatarType(userAvatarImageView, viewModel.userId).avatarSize(R.dimen.dp100).avatarType(AvatarHandler.AvatarType.USER).showMain());
            } else {
                userAvatarImageView.setImageResource(R.drawable.ic_cloud_space_blue);
            }
        }
    });
    viewModel.showDeleteContactDialog.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null && aBoolean) {
            new MaterialDialog.Builder(G.fragmentActivity).title(R.string.to_delete_contact).content(R.string.delete_text).positiveText(R.string.B_ok).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    viewModel.deleteContact();
                }
            }).negativeText(R.string.B_cancel).show();
        }
    });
    viewModel.showDialogReportContact.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null && aBoolean) {
            openDialogReport();
        }
    });
    viewModel.showDialogStartSecretChat.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean != null && aBoolean) {
            Toast.makeText(getContext(), "secret chat", Toast.LENGTH_LONG).show();
        }
    });
    viewModel.goToShowAvatarPage.observe(getViewLifecycleOwner(), isCurrentUser -> {
        if (getActivity() != null && isCurrentUser != null) {
            Log.wtf(this.getClass().getName(), "goToShowAvatarPage observe");
            FragmentShowAvatars fragment;
            if (isCurrentUser) {
                fragment = FragmentShowAvatars.newInstance(viewModel.userId, FragmentShowAvatars.From.setting);
            } else {
                fragment = FragmentShowAvatars.newInstance(viewModel.userId, FragmentShowAvatars.From.chat);
            }
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
        }
    });
    viewModel.blockDialogListener.observe(getViewLifecycleOwner(), isBlockUser -> {
        if (isBlockUser == null)
            return;
        if (isBlockUser) {
            new MaterialDialog.Builder(getContext()).title(R.string.unblock_the_user).content(R.string.unblock_the_user_text).positiveText(R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    new RequestUserContactsUnblock().userContactsUnblock(viewModel.userId);
                }
            }).negativeText(R.string.cancel).dismissListener(dialog -> checkViewsState()).showListener(dialog -> checkViewsState()).show();
        } else {
            new MaterialDialog.Builder(getContext()).title(R.string.block_the_user).content(R.string.block_the_user_text).positiveText(R.string.ok).onPositive(new MaterialDialog.SingleButtonCallback() {

                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    new RequestUserContactsBlock().userContactsBlock(viewModel.userId);
                }
            }).negativeText(R.string.cancel).dismissListener(dialog -> checkViewsState()).showListener(dialog -> checkViewsState()).show();
        }
    });
    viewModel.editContactListener.observe(getViewLifecycleOwner(), aBoolean -> {
        if (aBoolean == null)
            return;
        FragmentAddContact fragment = FragmentAddContact.newInstance(viewModel.userId, viewModel.phoneNumber, viewModel.firstName, viewModel.lastName, FragmentAddContact.ContactMode.EDIT, (name, family) -> {
            viewModel.contactName.setValue(name + " " + family);
            viewModel.firstName = name;
            viewModel.lastName = family;
            if (getActivity() != null) {
                ((ActivityMain) getActivity()).onUpdateContacts();
            }
        });
        if (getActivity() != null)
            new HelperFragment(getActivity().getSupportFragmentManager(), fragment).setReplace(false).load();
    });
}
Also used : ClipboardManager(android.content.ClipboardManager) ContentProviderOperation(android.content.ContentProviderOperation) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FragmentContactsProfileBinding(net.iGap.databinding.FragmentContactsProfileBinding) G(net.iGap.G) ContactsContract(android.provider.ContactsContract) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) DialogAnimation(net.iGap.module.DialogAnimation) BottomSheetFragment(net.iGap.module.dialog.bottomsheet.BottomSheetFragment) OnSetAction(net.iGap.observers.interfaces.OnSetAction) ClipboardManager(android.content.ClipboardManager) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) ProtoUserReport(net.iGap.proto.ProtoUserReport) HelperFragment(net.iGap.helper.HelperFragment) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) FragmentContactsProfileViewModel(net.iGap.viewmodel.FragmentContactsProfileViewModel) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperCalander(net.iGap.helper.HelperCalander) InputType(android.text.InputType) RealmRoom(net.iGap.realm.RealmRoom) ViewGroup(android.view.ViewGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) HelperPreferences(net.iGap.helper.HelperPreferences) SHP_SETTING(net.iGap.module.SHP_SETTING) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) AlphaAnimation(android.view.animation.AlphaAnimation) CLIPBOARD_SERVICE(android.content.Context.CLIPBOARD_SERVICE) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) Snackbar(com.google.android.material.snackbar.Snackbar) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) Config(net.iGap.Config) StructListOfContact(net.iGap.module.structs.StructListOfContact) RequestUserReport(net.iGap.request.RequestUserReport) ActivityMain(net.iGap.activities.ActivityMain) AccountManager(net.iGap.module.accountManager.AccountManager) Intent(android.content.Intent) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) GoToChatActivity(net.iGap.helper.GoToChatActivity) Toast(android.widget.Toast) RequestUserContactsUnblock(net.iGap.request.RequestUserContactsUnblock) HelperGetAction(net.iGap.helper.HelperGetAction) Cursor(android.database.Cursor) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RequestUserContactImport(net.iGap.request.RequestUserContactImport) LayoutInflater(android.view.LayoutInflater) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) Contacts.showLimitDialog(net.iGap.module.Contacts.showLimitDialog) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) CircleImageView(net.iGap.module.CircleImageView) Observer(androidx.lifecycle.Observer) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RequestUserContactsBlock(net.iGap.request.RequestUserContactsBlock) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) RequestUserContactsBlock(net.iGap.request.RequestUserContactsBlock) Bundle(android.os.Bundle) RequestUserContactsUnblock(net.iGap.request.RequestUserContactsUnblock) IOException(java.io.IOException) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) ActivityMain(net.iGap.activities.ActivityMain) DialogAction(com.afollestad.materialdialogs.DialogAction) GoToChatActivity(net.iGap.helper.GoToChatActivity) RealmRoom(net.iGap.realm.RealmRoom) HelperFragment(net.iGap.helper.HelperFragment) ClipData(android.content.ClipData)

Example 4 with CLIPBOARD_SERVICE

use of android.content.Context.CLIPBOARD_SERVICE in project iGap-Android by KianIranian-STDG.

the class FragmentContactsProfile method showPopupPhoneNumber.

/**
 * ************************************ methods ************************************
 */
private void showPopupPhoneNumber(View v, String number) {
    try {
        boolean isExist = false;
        Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
        String[] mPhoneNumberProjection = { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.DISPLAY_NAME };
        Cursor cur = context.getContentResolver().query(lookupUri, mPhoneNumberProjection, null, null, null);
        try {
            if (cur != null) {
                isExist = cur.moveToFirst();
            }
        } finally {
            if (cur != null)
                cur.close();
        }
        if (isExist) {
            new MaterialDialog.Builder(G.fragmentActivity).title(R.string.phone_number).items(R.array.phone_number2).itemsCallback((dialog, view, which, text) -> {
                switch(which) {
                    case 0:
                        String call = "+" + Long.parseLong(viewModel.phone.get());
                        try {
                            Intent callIntent = new Intent(Intent.ACTION_DIAL);
                            callIntent.setData(Uri.parse("tel:" + Uri.encode(call.trim())));
                            callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(callIntent);
                        } catch (Exception ex) {
                            ex.getStackTrace();
                        }
                        break;
                    case 1:
                        String copy;
                        copy = viewModel.phone.get();
                        ClipboardManager clipboard = (ClipboardManager) G.fragmentActivity.getSystemService(CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("PHONE_NUMBER", copy);
                        clipboard.setPrimaryClip(clip);
                        break;
                }
            }).show();
        } else {
            new MaterialDialog.Builder(G.fragmentActivity).title(R.string.phone_number).items(R.array.phone_number).itemsCallback(new MaterialDialog.ListCallback() {

                @Override
                public void onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                    switch(which) {
                        case 0:
                            String name = viewModel.contactName.getValue();
                            String phone = "+" + viewModel.phone.get();
                            ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
                            ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null).build());
                            // ------------------------------------------------------ Names
                            ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name).build());
                            // ------------------------------------------------------ Mobile Number
                            ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0).withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone).withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE).build());
                            try {
                                G.context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
                                addContactToServer();
                                Toast.makeText(G.context, R.string.save_ok, Toast.LENGTH_SHORT).show();
                            } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(G.context, G.fragmentActivity.getResources().getString(R.string.exception) + e.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                            break;
                        case 1:
                            String call = "+" + Long.parseLong(viewModel.phone.get());
                            try {
                                Intent callIntent = new Intent(Intent.ACTION_DIAL);
                                callIntent.setData(Uri.parse("tel:" + Uri.encode(call.trim())));
                                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(callIntent);
                            } catch (Exception ex) {
                                ex.getStackTrace();
                            }
                            break;
                        case 2:
                            ClipboardManager clipboard = (ClipboardManager) G.fragmentActivity.getSystemService(CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("PHONE_NUMBER", viewModel.phone.get());
                            clipboard.setPrimaryClip(clip);
                            break;
                    }
                }
            }).show();
        }
    } catch (SecurityException e) {
        e.printStackTrace();
    }
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FragmentContactsProfileBinding(net.iGap.databinding.FragmentContactsProfileBinding) G(net.iGap.G) ContactsContract(android.provider.ContactsContract) HelperPermission(net.iGap.helper.HelperPermission) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) DialogAnimation(net.iGap.module.DialogAnimation) BottomSheetFragment(net.iGap.module.dialog.bottomsheet.BottomSheetFragment) OnSetAction(net.iGap.observers.interfaces.OnSetAction) ClipboardManager(android.content.ClipboardManager) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) ProtoUserReport(net.iGap.proto.ProtoUserReport) HelperFragment(net.iGap.helper.HelperFragment) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) FragmentContactsProfileViewModel(net.iGap.viewmodel.FragmentContactsProfileViewModel) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperCalander(net.iGap.helper.HelperCalander) InputType(android.text.InputType) RealmRoom(net.iGap.realm.RealmRoom) ViewGroup(android.view.ViewGroup) List(java.util.List) Nullable(androidx.annotation.Nullable) HelperPreferences(net.iGap.helper.HelperPreferences) SHP_SETTING(net.iGap.module.SHP_SETTING) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) AlphaAnimation(android.view.animation.AlphaAnimation) CLIPBOARD_SERVICE(android.content.Context.CLIPBOARD_SERVICE) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) Snackbar(com.google.android.material.snackbar.Snackbar) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) Config(net.iGap.Config) StructListOfContact(net.iGap.module.structs.StructListOfContact) RequestUserReport(net.iGap.request.RequestUserReport) ActivityMain(net.iGap.activities.ActivityMain) AccountManager(net.iGap.module.accountManager.AccountManager) Intent(android.content.Intent) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) GoToChatActivity(net.iGap.helper.GoToChatActivity) Toast(android.widget.Toast) RequestUserContactsUnblock(net.iGap.request.RequestUserContactsUnblock) HelperGetAction(net.iGap.helper.HelperGetAction) Cursor(android.database.Cursor) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RequestUserContactImport(net.iGap.request.RequestUserContactImport) LayoutInflater(android.view.LayoutInflater) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) Contacts.showLimitDialog(net.iGap.module.Contacts.showLimitDialog) TopSheetDialog(net.iGap.module.dialog.topsheet.TopSheetDialog) CircleImageView(net.iGap.module.CircleImageView) Observer(androidx.lifecycle.Observer) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RequestUserContactsBlock(net.iGap.request.RequestUserContactsBlock) ClipboardManager(android.content.ClipboardManager) ContentProviderOperation(android.content.ContentProviderOperation) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Cursor(android.database.Cursor) Uri(android.net.Uri) View(android.view.View) CircleImageView(net.iGap.module.CircleImageView) IOException(java.io.IOException) ClipData(android.content.ClipData)

Aggregations

ClipData (android.content.ClipData)4 ClipboardManager (android.content.ClipboardManager)4 CLIPBOARD_SERVICE (android.content.Context.CLIPBOARD_SERVICE)4 Bundle (android.os.Bundle)4 LayoutInflater (android.view.LayoutInflater)4 View (android.view.View)4 ViewGroup (android.view.ViewGroup)4 AlphaAnimation (android.view.animation.AlphaAnimation)4 Toast (android.widget.Toast)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 DataBindingUtil (androidx.databinding.DataBindingUtil)4 ViewModelProviders (androidx.lifecycle.ViewModelProviders)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 G (net.iGap.G)4 R (net.iGap.R)4 ActivityMain (net.iGap.activities.ActivityMain)4 HelperFragment (net.iGap.helper.HelperFragment)4 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)4 Log (android.util.Log)3