Java Code Examples for org.telegram.tgnet.TLRPC#TL_channels_checkUsername
The following examples show how to use
org.telegram.tgnet.TLRPC#TL_channels_checkUsername .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChannelCreateActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public ChannelCreateActivity(Bundle args) { super(args); currentStep = args.getInt("step", 0); if (currentStep == 0) { avatarDrawable = new AvatarDrawable(); imageUpdater = new ImageUpdater(); TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"))); } else { if (currentStep == 1) { canCreatePublic = args.getBoolean("canCreatePublic", true); isPrivate = !canCreatePublic; if (!canCreatePublic) { loadAdminedChannels(); } } chatId = args.getInt("chat_id", 0); } }
Example 2
Source File: ChannelCreateActivity.java From Telegram with GNU General Public License v2.0 | 6 votes |
public ChannelCreateActivity(Bundle args) { super(args); currentStep = args.getInt("step", 0); if (currentStep == 0) { avatarDrawable = new AvatarDrawable(); imageUpdater = new ImageUpdater(); TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"))); } else { if (currentStep == 1) { canCreatePublic = args.getBoolean("canCreatePublic", true); isPrivate = !canCreatePublic; if (!canCreatePublic) { loadAdminedChannels(); } } chatId = args.getInt("chat_id", 0); } }
Example 3
Source File: ChannelCreateActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public ChannelCreateActivity(Bundle args) { super(args); currentStep = args.getInt("step", 0); if (currentStep == 0) { avatarDrawable = new AvatarDrawable(); imageUpdater = new ImageUpdater(); TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"); } }); } }); } else { if (currentStep == 1) { canCreatePublic = args.getBoolean("canCreatePublic", true); isPrivate = !canCreatePublic; if (!canCreatePublic) { loadAdminedChannels(); } } chatId = args.getInt("chat_id", 0); } }
Example 4
Source File: ChannelCreateActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public ChannelCreateActivity(Bundle args) { super(args); currentStep = args.getInt("step", 0); if (currentStep == 0) { avatarDrawable = new AvatarDrawable(); imageUpdater = new ImageUpdater(); TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"); } }); } }); } else { if (currentStep == 1) { canCreatePublic = args.getBoolean("canCreatePublic", true); isPrivate = !canCreatePublic; if (!canCreatePublic) { loadAdminedChannels(); } } chatId = args.getInt("chat_id", 0); } }
Example 5
Source File: ChatEditTypeActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
@Override public boolean onFragmentCreate() { currentChat = getMessagesController().getChat(chatId); if (currentChat == null) { currentChat = getMessagesStorage().getChatSync(chatId); if (currentChat != null) { getMessagesController().putChat(currentChat, true); } else { return false; } if (info == null) { info = getMessagesStorage().loadChatInfo(chatId, new CountDownLatch(1), false, false); if (info == null) { return false; } } } isPrivate = !isForcePublic && TextUtils.isEmpty(currentChat.username); isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup; if (isForcePublic && TextUtils.isEmpty(currentChat.username) || isPrivate && currentChat.creator) { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"); if (!canCreatePublic) { loadAdminedChannels(); } })); } getNotificationCenter().addObserver(this, NotificationCenter.chatInfoDidLoad); return super.onFragmentCreate(); }
Example 6
Source File: ChatEditTypeActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean onFragmentCreate() { currentChat = getMessagesController().getChat(chatId); if (currentChat == null) { currentChat = getMessagesStorage().getChatSync(chatId); if (currentChat != null) { getMessagesController().putChat(currentChat, true); } else { return false; } if (info == null) { info = getMessagesStorage().loadChatInfo(chatId, new CountDownLatch(1), false, false); if (info == null) { return false; } } } isPrivate = !isForcePublic && TextUtils.isEmpty(currentChat.username); isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup; if (isForcePublic && TextUtils.isEmpty(currentChat.username) || isPrivate && currentChat.creator) { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; req.channel = new TLRPC.TL_inputChannelEmpty(); getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { canCreatePublic = error == null || !error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH"); if (!canCreatePublic) { loadAdminedChannels(); } })); } getNotificationCenter().addObserver(this, NotificationCenter.chatInfoDidLoad); return super.onFragmentCreate(); }
Example 7
Source File: ChannelEditInfoActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { if (currentChat.megagroup) { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { if (currentChat.megagroup) { checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 8
Source File: ChannelCreateActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = new Runnable() { @Override public void run() { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors); } }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 9
Source File: ChannelEditInfoActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { if (currentChat.megagroup) { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { if (currentChat.megagroup) { checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); } return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 10
Source File: ChannelCreateActivity.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = new Runnable() { @Override public void run() { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() { @Override public void run(final TLObject response, final TLRPC.TL_error error) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } } }); } }, ConnectionsManager.RequestFlagFailOnServerErrors); } }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 11
Source File: ChatEditTypeActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } typeInfoCell.setBackgroundDrawable(checkTextView.getVisibility() == View.VISIBLE ? null : Theme.getThemedDrawable(typeInfoCell.getContext(), R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { getConnectionsManager().cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { if (isChannel) { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } } } if (name == null || name.length() < 5) { if (isChannel) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteGrayText8); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = getMessagesController().getInputChannel(chatId); checkReqId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteGreenText); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 12
Source File: ChannelCreateActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 13
Source File: ChatEditTypeActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } typeInfoCell.setBackgroundDrawable(checkTextView.getVisibility() == View.VISIBLE ? null : Theme.getThemedDrawable(typeInfoCell.getContext(), R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow)); if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { getConnectionsManager().cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { if (isChannel) { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } } } if (name == null || name.length() < 5) { if (isChannel) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); } else { checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteGrayText8); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = getMessagesController().getInputChannel(chatId); checkReqId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTextColor(Theme.key_windowBackgroundWhiteGreenText); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTextColor(Theme.key_windowBackgroundWhiteRedText4); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }
Example 14
Source File: ChannelCreateActivity.java From Telegram with GNU General Public License v2.0 | 4 votes |
private boolean checkUserName(final String name) { if (name != null && name.length() > 0) { checkTextView.setVisibility(View.VISIBLE); } else { checkTextView.setVisibility(View.GONE); } if (checkRunnable != null) { AndroidUtilities.cancelRunOnUIThread(checkRunnable); checkRunnable = null; lastCheckName = null; if (checkReqId != 0) { ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true); } } lastNameAvailable = false; if (name != null) { if (name.startsWith("_") || name.endsWith("_")) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } for (int a = 0; a < name.length(); a++) { char ch = name.charAt(a); if (a == 0 && ch >= '0' && ch <= '9') { checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) { checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } } } if (name == null || name.length() < 5) { checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } if (name.length() > 32) { checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong)); checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); return false; } checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8)); lastCheckName = name; checkRunnable = () -> { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = name; req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId); checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> { checkReqId = 0; if (lastCheckName != null && lastCheckName.equals(name)) { if (error == null && response instanceof TLRPC.TL_boolTrue) { checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name)); checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText)); lastNameAvailable = true; } else { if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) { canCreatePublic = false; loadAdminedChannels(); } else { checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse)); } checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4); checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4)); lastNameAvailable = false; } } }), ConnectionsManager.RequestFlagFailOnServerErrors); }; AndroidUtilities.runOnUIThread(checkRunnable, 300); return true; }