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;
}
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();
}
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();
}
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();
}
Aggregations