Search in sources :

Example 1 with MEditText

use of net.iGap.module.MEditText in project iGap-Android by KianIranian-STDG.

the class FragmentGroupProfile method createDialogLayout.

private View createDialogLayout(String link) {
    LinearLayout layoutGroupLink = new LinearLayout(getActivity());
    layoutGroupLink.setOrientation(LinearLayout.VERTICAL);
    View viewRevoke = new View(getActivity());
    TextInputLayout inputGroupLink = new TextInputLayout(getActivity());
    MEditText edtLink = new MEditText(getActivity());
    edtLink.setHint(getString(R.string.group_link_hint_revoke));
    edtLink.setTypeface(ResourcesCompat.getFont(edtLink.getContext(), R.font.main_font));
    edtLink.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.dp14));
    edtLink.setText(link);
    edtLink.setTextColor(getResources().getColor(R.color.text_edit_text));
    edtLink.setHintTextColor(getResources().getColor(R.color.hint_edit_text));
    edtLink.setPadding(0, 16, 0, 8);
    edtLink.setEnabled(false);
    edtLink.setSingleLine(true);
    inputGroupLink.addView(edtLink);
    inputGroupLink.addView(viewRevoke);
    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);
    layoutGroupLink.addView(inputGroupLink, layoutParams);
    return layoutGroupLink;
}
Also used : MEditText(net.iGap.module.MEditText) TextInputLayout(com.google.android.material.textfield.TextInputLayout) View(android.view.View) TextView(android.widget.TextView) CircleImageView(net.iGap.module.CircleImageView) LinearLayout(android.widget.LinearLayout)

Example 2 with MEditText

use of net.iGap.module.MEditText 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 MEditText

use of net.iGap.module.MEditText in project iGap-Android by KianIranian-STDG.

the class FragmentGroupProfile method setUsername.

// TODO: change this and create custom dialog and handle request in it and ...
// TODO: because no time be this and this code is not correct and should be change it
public void setUsername() {
    final LinearLayout layoutUserName = new LinearLayout(getContext());
    layoutUserName.setOrientation(LinearLayout.VERTICAL);
    final View viewUserName = new View(getContext());
    LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    final TextInputLayout inputUserName = new TextInputLayout(getContext());
    final MEditText edtUserName = new MEditText(getContext());
    edtUserName.setHint(getString(R.string.group_title_set_username));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        edtUserName.setTextDirection(View.TEXT_DIRECTION_LTR);
    }
    edtUserName.setTypeface(ResourcesCompat.getFont(edtUserName.getContext(), R.font.main_font));
    edtUserName.setTextSize(TypedValue.COMPLEX_UNIT_PX, getContext().getResources().getDimension(R.dimen.dp14));
    // TODO: fixed this and this will set viewModel
    if (viewModel.isPopup) {
        edtUserName.setText(Config.IGAP_LINK_PREFIX);
    } else {
        edtUserName.setText(Config.IGAP_LINK_PREFIX + viewModel.linkUsername);
    }
    edtUserName.setTextColor(getContext().getResources().getColor(R.color.text_edit_text));
    edtUserName.setHintTextColor(getContext().getResources().getColor(R.color.hint_edit_text));
    edtUserName.setPadding(0, 8, 0, 8);
    edtUserName.setSingleLine(true);
    inputUserName.addView(edtUserName);
    inputUserName.addView(viewUserName, viewParams);
    viewUserName.setBackgroundColor(getContext().getResources().getColor(R.color.line_edit_text));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        edtUserName.setBackground(getContext().getResources().getDrawable(android.R.color.transparent));
    }
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutUserName.addView(inputUserName, layoutParams);
    ProgressBar progressBar = new ProgressBar(getContext());
    LinearLayout.LayoutParams progParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    progParams.gravity = Gravity.CENTER;
    progressBar.setLayoutParams(progParams);
    progressBar.setIndeterminate(true);
    progressBar.setVisibility(View.GONE);
    layoutUserName.addView(progressBar);
    final MaterialDialog dialog = new MaterialDialog.Builder(getContext()).title(R.string.st_username).positiveText(R.string.save).customView(layoutUserName, true).widgetColor(new Theme().getAccentColor(getContext())).negativeText(R.string.B_cancel).build();
    final View positive = dialog.getActionButton(DialogAction.POSITIVE);
    positive.setEnabled(false);
    edtUserName.setSelection((edtUserName.getText().toString().length()));
    G.handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            edtUserName.requestFocus();
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (inputMethodManager != null) {
                inputMethodManager.showSoftInput(edtUserName, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    }, 100);
    edtUserName.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 (!editable.toString().startsWith(Config.IGAP_LINK_PREFIX)) {
                edtUserName.setText(Config.IGAP_LINK_PREFIX);
                Selection.setSelection(edtUserName.getText(), edtUserName.getText().length());
            } else {
                Selection.setSelection(edtUserName.getText(), edtUserName.getText().length());
            }
            if (HelperString.regexCheckUsername(editable.toString().replace(Config.IGAP_LINK_PREFIX, ""))) {
                if (getRequestManager().isUserLogin()) {
                    String userName = edtUserName.getText().toString().replace(Config.IGAP_LINK_PREFIX, "");
                    new RequestGroupCheckUsername().GroupCheckUsername(viewModel.roomId, userName, new OnGroupCheckUsername() {

                        @Override
                        public void onGroupCheckUsername(final ProtoGroupCheckUsername.GroupCheckUsernameResponse.Status status) {
                            G.handler.post(new Runnable() {

                                @Override
                                public void run() {
                                    if (status == ProtoGroupCheckUsername.GroupCheckUsernameResponse.Status.AVAILABLE) {
                                        positive.setEnabled(true);
                                        inputUserName.setErrorEnabled(true);
                                        inputUserName.setError("");
                                    } else if (status == ProtoGroupCheckUsername.GroupCheckUsernameResponse.Status.INVALID) {
                                        positive.setEnabled(false);
                                        inputUserName.setErrorEnabled(true);
                                        inputUserName.setError(getString(R.string.INVALID));
                                    } else if (status == ProtoGroupCheckUsername.GroupCheckUsernameResponse.Status.TAKEN) {
                                        positive.setEnabled(false);
                                        inputUserName.setErrorEnabled(true);
                                        inputUserName.setError(getString(R.string.TAKEN));
                                    } else if (status == ProtoGroupCheckUsername.GroupCheckUsernameResponse.Status.OCCUPYING_LIMIT_EXCEEDED) {
                                        positive.setEnabled(false);
                                        inputUserName.setErrorEnabled(true);
                                        inputUserName.setError("" + getString(R.string.OCCUPYING_LIMIT_EXCEEDED));
                                    }
                                }
                            });
                        }

                        @Override
                        public void onError(int majorCode, int minorCode) {
                            if (majorCode == 5) {
                                positive.setEnabled(false);
                                inputUserName.setErrorEnabled(true);
                                inputUserName.setError(getString(R.string.network_error));
                            } else {
                                positive.setEnabled(false);
                                inputUserName.setErrorEnabled(true);
                                inputUserName.setError(getString(R.string.server_error));
                            }
                        }
                    });
                } else {
                    positive.setEnabled(false);
                    inputUserName.setErrorEnabled(true);
                    inputUserName.setError(getString(R.string.network_error));
                }
            } else {
                positive.setEnabled(false);
                inputUserName.setErrorEnabled(true);
                inputUserName.setError(getString(R.string.INVALID));
            }
        }
    });
    positive.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            hideKeyboard();
            String userName = edtUserName.getText().toString().replace(Config.IGAP_LINK_PREFIX, "");
            if (getRequestManager().isUserLogin()) {
                progressBar.setVisibility(View.VISIBLE);
                positive.setEnabled(false);
                new RequestGroupUpdateUsername().groupUpdateUsername(viewModel.roomId, userName, new OnGroupUpdateUsername() {

                    @Override
                    public void onGroupUpdateUsername(final long roomId, final String username) {
                        G.handler.post(new Runnable() {

                            @Override
                            public void run() {
                                positive.setEnabled(true);
                                progressBar.setVisibility(View.GONE);
                                viewModel.isPrivate = false;
                                dialog.dismiss();
                                viewModel.linkUsername = username;
                                viewModel.setTextGroupLik();
                            }
                        });
                    }

                    @Override
                    public void onError(final int majorCode, int minorCode, final int time) {
                        G.handler.post(new Runnable() {

                            @Override
                            public void run() {
                                positive.setEnabled(true);
                                progressBar.setVisibility(View.GONE);
                                switch(majorCode) {
                                    case 5:
                                        HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
                                    case 368:
                                        if (dialog.isShowing())
                                            dialog.dismiss();
                                        dialogWaitTime(R.string.GROUP_UPDATE_USERNAME_UPDATE_LOCK, time, majorCode);
                                        break;
                                }
                            }
                        });
                    }
                });
            } else {
                progressBar.setVisibility(View.GONE);
                HelperError.showSnackMessage(getString(R.string.wallet_error_server), false);
            }
        }
    });
    edtUserName.setOnFocusChangeListener((view, b) -> {
        if (b) {
            viewUserName.setBackgroundColor(new Theme().getAccentColor(getContext()));
        } else {
            viewUserName.setBackgroundColor(getContext().getResources().getColor(R.color.line_edit_text));
        }
    });
    // check each word with server
    dialog.setOnDismissListener(dialog1 -> hideKeyboard());
    dialog.show();
}
Also used : RequestGroupUpdateUsername(net.iGap.request.RequestGroupUpdateUsername) InputMethodManager(android.view.inputmethod.InputMethodManager) HelperString(net.iGap.helper.HelperString) OnGroupUpdateUsername(net.iGap.observers.interfaces.OnGroupUpdateUsername) ProtoGroupCheckUsername(net.iGap.proto.ProtoGroupCheckUsername) OnGroupCheckUsername(net.iGap.observers.interfaces.OnGroupCheckUsername) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(com.google.android.material.textfield.TextInputLayout) ProgressBar(android.widget.ProgressBar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MEditText(net.iGap.module.MEditText) View(android.view.View) TextView(android.widget.TextView) CircleImageView(net.iGap.module.CircleImageView) RequestGroupCheckUsername(net.iGap.request.RequestGroupCheckUsername) Theme(net.iGap.module.Theme) LinearLayout(android.widget.LinearLayout)

Example 4 with MEditText

use of net.iGap.module.MEditText in project iGap-Android by KianIranian-STDG.

the class EditChannelFragment method setUsername.

private void setUsername(String username) {
    final LinearLayout layoutUserName = new LinearLayout(getContext());
    layoutUserName.setOrientation(LinearLayout.VERTICAL);
    final View viewUserName = new View(getContext());
    LinearLayout.LayoutParams viewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    final TextInputLayout inputUserName = new TextInputLayout(G.fragmentActivity);
    final MEditText edtUserName = new MEditText(getContext());
    edtUserName.setHint(G.fragmentActivity.getResources().getString(R.string.channel_title_channel_set_username));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        edtUserName.setTextDirection(View.TEXT_DIRECTION_LTR);
    }
    edtUserName.setTypeface(ResourcesCompat.getFont(edtUserName.getContext(), R.font.main_font));
    edtUserName.setTextSize(TypedValue.COMPLEX_UNIT_PX, G.context.getResources().getDimension(R.dimen.dp14));
    /*if (isPopup) {*/
    edtUserName.setText(Config.IGAP_LINK_PREFIX + username);
    /*} else {
            edtUserName.setText(Config.IGAP_LINK_PREFIX + linkUsername);
        }*/
    edtUserName.setTextColor(getResources().getColor(R.color.text_edit_text));
    edtUserName.setHintTextColor(getResources().getColor(R.color.hint_edit_text));
    edtUserName.setPadding(0, 8, 0, 8);
    edtUserName.setSingleLine(true);
    inputUserName.addView(edtUserName);
    inputUserName.addView(viewUserName, viewParams);
    viewUserName.setBackgroundColor(getResources().getColor(R.color.line_edit_text));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        edtUserName.setBackground(getResources().getDrawable(android.R.color.transparent));
    }
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutUserName.addView(inputUserName, layoutParams);
    final MaterialDialog dialog = new MaterialDialog.Builder(getContext()).title(R.string.st_username).positiveText(R.string.save).customView(layoutUserName, true).widgetColor(new Theme().getPrimaryColor(getContext())).negativeText(R.string.B_cancel).build();
    final View positive = dialog.getActionButton(DialogAction.POSITIVE);
    positive.setEnabled(false);
    G.onChannelCheckUsername = new OnChannelCheckUsername() {

        @Override
        public void onChannelCheckUsername(final ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status status) {
            G.handler.post(new Runnable() {

                @Override
                public void run() {
                    if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.AVAILABLE) {
                        positive.setEnabled(true);
                        inputUserName.setErrorEnabled(true);
                        inputUserName.setError("");
                    } else if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.INVALID) {
                        positive.setEnabled(false);
                        inputUserName.setErrorEnabled(true);
                        inputUserName.setError("" + G.fragmentActivity.getResources().getString(R.string.INVALID));
                    } else if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.TAKEN) {
                        positive.setEnabled(false);
                        inputUserName.setErrorEnabled(true);
                        inputUserName.setError("" + G.fragmentActivity.getResources().getString(R.string.TAKEN));
                    } else if (status == ProtoChannelCheckUsername.ChannelCheckUsernameResponse.Status.OCCUPYING_LIMIT_EXCEEDED) {
                        positive.setEnabled(false);
                        inputUserName.setErrorEnabled(true);
                        inputUserName.setError("" + G.fragmentActivity.getResources().getString(R.string.OCCUPYING_LIMIT_EXCEEDED));
                    }
                }
            });
        }

        @Override
        public void onError(int majorCode, int minorCode) {
        }

        @Override
        public void onTimeOut() {
        }
    };
    edtUserName.setSelection((edtUserName.getText().toString().length()));
    G.handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            edtUserName.requestFocus();
            InputMethodManager inputMethodManager = (InputMethodManager) G.context.getSystemService(Context.INPUT_METHOD_SERVICE);
            if (inputMethodManager != null) {
                inputMethodManager.showSoftInput(edtUserName, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    }, 100);
    edtUserName.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 (!editable.toString().startsWith(Config.IGAP_LINK_PREFIX)) {
                edtUserName.setText(Config.IGAP_LINK_PREFIX);
                Selection.setSelection(edtUserName.getText(), edtUserName.getText().length());
            } else {
                Selection.setSelection(edtUserName.getText(), edtUserName.getText().length());
            }
            if (HelperString.regexCheckUsername(editable.toString().replace(Config.IGAP_LINK_PREFIX, ""))) {
                String userName = edtUserName.getText().toString().replace(Config.IGAP_LINK_PREFIX, "");
                new RequestChannelCheckUsername().channelCheckUsername(viewModel.roomId, userName);
            } else {
                positive.setEnabled(false);
                inputUserName.setErrorEnabled(true);
                inputUserName.setError("" + G.fragmentActivity.getResources().getString(R.string.INVALID));
            }
        }
    });
    G.onChannelUpdateUsername = new OnChannelUpdateUsername() {

        @Override
        public void onChannelUpdateUsername(final long roomId, final String username) {
            G.handler.post(() -> {
                viewModel.setPrivate(false, username);
                dialog.dismiss();
                viewModel.linkUsername = username;
            /*setTextChannelLik();*/
            });
        }

        @Override
        public void onError(final int majorCode, int minorCode, final int time) {
            switch(majorCode) {
                case 457:
                    G.handler.post(() -> {
                        if (dialog.isShowing())
                            dialog.dismiss();
                        dialogWaitTime(R.string.limit_for_set_username, time, majorCode);
                    });
                    break;
            }
        }

        @Override
        public void onTimeOut() {
        }
    };
    positive.setOnClickListener(view -> {
        String userName = edtUserName.getText().toString().replace(Config.IGAP_LINK_PREFIX, "");
        new RequestChannelUpdateUsername().channelUpdateUsername(viewModel.roomId, userName);
    });
    edtUserName.setOnFocusChangeListener((view, b) -> {
        if (b) {
            viewUserName.setBackgroundColor(new Theme().getAccentColor(getContext()));
        } else {
            viewUserName.setBackgroundColor(G.context.getResources().getColor(R.color.line_edit_text));
        }
    });
    // check each word with server
    dialog.setOnDismissListener(dialog1 -> AndroidUtils.closeKeyboard(binding.getRoot()));
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) OnChannelCheckUsername(net.iGap.observers.interfaces.OnChannelCheckUsername) RequestChannelCheckUsername(net.iGap.request.RequestChannelCheckUsername) MEditText(net.iGap.module.MEditText) InputMethodManager(android.view.inputmethod.InputMethodManager) HelperString(net.iGap.helper.HelperString) View(android.view.View) TextView(android.widget.TextView) RequestChannelUpdateUsername(net.iGap.request.RequestChannelUpdateUsername) OnChannelUpdateUsername(net.iGap.observers.interfaces.OnChannelUpdateUsername) Theme(net.iGap.module.Theme) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(com.google.android.material.textfield.TextInputLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)4 LinearLayout (android.widget.LinearLayout)4 TextView (android.widget.TextView)4 TextInputLayout (com.google.android.material.textfield.TextInputLayout)4 MEditText (net.iGap.module.MEditText)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)3 CircleImageView (net.iGap.module.CircleImageView)3 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 HelperString (net.iGap.helper.HelperString)2 Theme (net.iGap.module.Theme)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 CLIPBOARD_SERVICE (android.content.Context.CLIPBOARD_SERVICE)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Linkify (android.text.util.Linkify)1 TypedValue (android.util.TypedValue)1 LayoutInflater (android.view.LayoutInflater)1