use of org.telegram.ui.Components.JoinGroupAlert in project Telegram-FOSS by Telegram-FOSS-Team.
the class DialogsActivity method onItemClick.
private void onItemClick(View view, int position, RecyclerListView.Adapter adapter) {
if (getParentActivity() == null) {
return;
}
long dialogId = 0;
int message_id = 0;
boolean isGlobalSearch = false;
int folderId = 0;
int filterId = 0;
if (adapter instanceof DialogsAdapter) {
DialogsAdapter dialogsAdapter = (DialogsAdapter) adapter;
int dialogsType = dialogsAdapter.getDialogsType();
if (dialogsType == 7 || dialogsType == 8) {
MessagesController.DialogFilter dialogFilter = getMessagesController().selectedDialogFilter[dialogsType == 7 ? 0 : 1];
filterId = dialogFilter.id;
}
TLObject object = dialogsAdapter.getItem(position);
if (object instanceof TLRPC.User) {
dialogId = ((TLRPC.User) object).id;
} else if (object instanceof TLRPC.Dialog) {
TLRPC.Dialog dialog = (TLRPC.Dialog) object;
folderId = dialog.folder_id;
if (dialog instanceof TLRPC.TL_dialogFolder) {
if (actionBar.isActionModeShowed(null)) {
return;
}
TLRPC.TL_dialogFolder dialogFolder = (TLRPC.TL_dialogFolder) dialog;
Bundle args = new Bundle();
args.putInt("folderId", dialogFolder.folder.id);
presentFragment(new DialogsActivity(args));
return;
}
dialogId = dialog.id;
if (actionBar.isActionModeShowed(null)) {
showOrUpdateActionMode(dialogId, view);
return;
}
} else if (object instanceof TLRPC.TL_recentMeUrlChat) {
dialogId = -((TLRPC.TL_recentMeUrlChat) object).chat_id;
} else if (object instanceof TLRPC.TL_recentMeUrlUser) {
dialogId = ((TLRPC.TL_recentMeUrlUser) object).user_id;
} else if (object instanceof TLRPC.TL_recentMeUrlChatInvite) {
TLRPC.TL_recentMeUrlChatInvite chatInvite = (TLRPC.TL_recentMeUrlChatInvite) object;
TLRPC.ChatInvite invite = chatInvite.chat_invite;
if (invite.chat == null && (!invite.channel || invite.megagroup) || invite.chat != null && (!ChatObject.isChannel(invite.chat) || invite.chat.megagroup)) {
String hash = chatInvite.url;
int index = hash.indexOf('/');
if (index > 0) {
hash = hash.substring(index + 1);
}
showDialog(new JoinGroupAlert(getParentActivity(), invite, hash, DialogsActivity.this));
return;
} else {
if (invite.chat != null) {
dialogId = -invite.chat.id;
} else {
return;
}
}
} else if (object instanceof TLRPC.TL_recentMeUrlStickerSet) {
TLRPC.StickerSet stickerSet = ((TLRPC.TL_recentMeUrlStickerSet) object).set.set;
TLRPC.TL_inputStickerSetID set = new TLRPC.TL_inputStickerSetID();
set.id = stickerSet.id;
set.access_hash = stickerSet.access_hash;
showDialog(new StickersAlert(getParentActivity(), DialogsActivity.this, set, null, null));
return;
} else if (object instanceof TLRPC.TL_recentMeUrlUnknown) {
return;
} else {
return;
}
} else if (adapter == searchViewPager.dialogsSearchAdapter) {
Object obj = searchViewPager.dialogsSearchAdapter.getItem(position);
isGlobalSearch = searchViewPager.dialogsSearchAdapter.isGlobalSearch(position);
if (obj instanceof TLRPC.User) {
dialogId = ((TLRPC.User) obj).id;
if (!onlySelect) {
searchDialogId = dialogId;
searchObject = (TLRPC.User) obj;
}
} else if (obj instanceof TLRPC.Chat) {
dialogId = -((TLRPC.Chat) obj).id;
if (!onlySelect) {
searchDialogId = dialogId;
searchObject = (TLRPC.Chat) obj;
}
} else if (obj instanceof TLRPC.EncryptedChat) {
dialogId = DialogObject.makeEncryptedDialogId(((TLRPC.EncryptedChat) obj).id);
if (!onlySelect) {
searchDialogId = dialogId;
searchObject = (TLRPC.EncryptedChat) obj;
}
} else if (obj instanceof MessageObject) {
MessageObject messageObject = (MessageObject) obj;
dialogId = messageObject.getDialogId();
message_id = messageObject.getId();
searchViewPager.dialogsSearchAdapter.addHashtagsFromMessage(searchViewPager.dialogsSearchAdapter.getLastSearchString());
} else if (obj instanceof String) {
String str = (String) obj;
if (searchViewPager.dialogsSearchAdapter.isHashtagSearch()) {
actionBar.openSearchField(str, false);
} else if (!str.equals("section")) {
NewContactActivity activity = new NewContactActivity();
activity.setInitialPhoneNumber(str, true);
presentFragment(activity);
}
}
if (dialogId != 0 && actionBar.isActionModeShowed()) {
if (actionBar.isActionModeShowed(ACTION_MODE_SEARCH_DIALOGS_TAG) && message_id == 0 && !isGlobalSearch) {
showOrUpdateActionMode(dialogId, view);
}
return;
}
}
if (dialogId == 0) {
return;
}
if (onlySelect) {
if (!validateSlowModeDialog(dialogId)) {
return;
}
if (!selectedDialogs.isEmpty() || (initialDialogsType == 3 && selectAlertString != null)) {
boolean checked = addOrRemoveSelectedDialog(dialogId, view);
if (adapter == searchViewPager.dialogsSearchAdapter) {
actionBar.closeSearchField();
findAndUpdateCheckBox(dialogId, checked);
}
updateSelectedCount();
} else {
didSelectResult(dialogId, true, false);
}
} else {
Bundle args = new Bundle();
if (DialogObject.isEncryptedDialog(dialogId)) {
args.putInt("enc_id", DialogObject.getEncryptedChatId(dialogId));
} else if (DialogObject.isUserDialog(dialogId)) {
args.putLong("user_id", dialogId);
} else {
long did = dialogId;
if (message_id != 0) {
TLRPC.Chat chat = getMessagesController().getChat(-did);
if (chat != null && chat.migrated_to != null) {
args.putLong("migrated_to", did);
did = -chat.migrated_to.channel_id;
}
}
args.putLong("chat_id", -did);
}
if (message_id != 0) {
args.putInt("message_id", message_id);
} else if (!isGlobalSearch) {
closeSearch();
} else {
if (searchObject != null) {
searchViewPager.dialogsSearchAdapter.putRecentSearch(searchDialogId, searchObject);
searchObject = null;
}
}
args.putInt("dialog_folder_id", folderId);
args.putInt("dialog_filter_id", filterId);
if (AndroidUtilities.isTablet()) {
if (openedDialogId == dialogId && adapter != searchViewPager.dialogsSearchAdapter) {
return;
}
if (viewPages != null) {
for (int a = 0; a < viewPages.length; a++) {
viewPages[a].dialogsAdapter.setOpenedDialogId(openedDialogId = dialogId);
}
}
updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
}
if (searchViewPager.actionModeShowing()) {
searchViewPager.hideActionMode();
}
if (searchString != null) {
if (getMessagesController().checkCanOpenChat(args, DialogsActivity.this)) {
getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
presentFragment(new ChatActivity(args));
}
} else {
if (getMessagesController().checkCanOpenChat(args, DialogsActivity.this)) {
ChatActivity chatActivity = new ChatActivity(args);
if (adapter instanceof DialogsAdapter && DialogObject.isUserDialog(dialogId) && (getMessagesController().dialogs_dict.get(dialogId) == null)) {
TLRPC.Document sticker = getMediaDataController().getGreetingsSticker();
if (sticker != null) {
chatActivity.setPreloadedSticker(sticker, true);
}
}
presentFragment(chatActivity);
}
}
}
}
use of org.telegram.ui.Components.JoinGroupAlert in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method runLinkRequest.
private void runLinkRequest(final int intentAccount, final String username, final String group, final String sticker, final String botUser, final String botChat, final String message, final boolean hasUrl, final Integer messageId, final Long channelId, final Integer threadId, final Integer commentId, final String game, final HashMap<String, String> auth, final String lang, final String unsupportedUrl, final String code, final String loginToken, final TLRPC.TL_wallPaper wallPaper, final String theme, final String voicechat, final String livestream, final int state, final int videoTimestamp) {
if (state == 0 && UserConfig.getActivatedAccountsCount() >= 2 && auth != null) {
AlertsCreator.createAccountSelectDialog(this, account -> {
if (account != intentAccount) {
switchToAccount(account, true);
}
runLinkRequest(account, username, group, sticker, botUser, botChat, message, hasUrl, messageId, channelId, threadId, commentId, game, auth, lang, unsupportedUrl, code, loginToken, wallPaper, theme, voicechat, livestream, 1, videoTimestamp);
}).show();
return;
} else if (code != null) {
if (NotificationCenter.getGlobalInstance().hasObservers(NotificationCenter.didReceiveSmsCode)) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, code);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("OtherLoginCode", R.string.OtherLoginCode, code)));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
}
return;
} else if (loginToken != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("AuthAnotherClient", R.string.AuthAnotherClient));
builder.setMessage(LocaleController.getString("AuthAnotherClientUrl", R.string.AuthAnotherClientUrl));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
return;
}
final AlertDialog progressDialog = new AlertDialog(this, 3);
final int[] requestId = new int[] { 0 };
Runnable cancelRunnable = null;
if (username != null) {
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
req.username = username;
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (!LaunchActivity.this.isFinishing()) {
boolean hideProgressDialog = true;
final TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
if (error == null && actionBarLayout != null && (game == null && voicechat == null || game != null && !res.users.isEmpty() || voicechat != null && !res.chats.isEmpty() || livestream != null && !res.chats.isEmpty())) {
MessagesController.getInstance(intentAccount).putUsers(res.users, false);
MessagesController.getInstance(intentAccount).putChats(res.chats, false);
MessagesStorage.getInstance(intentAccount).putUsersAndChats(res.users, res.chats, false, true);
if (messageId != null && (commentId != null || threadId != null) && !res.chats.isEmpty()) {
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, res.chats.get(0));
if (requestId[0] != 0) {
hideProgressDialog = false;
}
} else if (game != null) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putBoolean("cantSendToChannels", true);
args.putInt("dialogsType", 1);
args.putString("selectAlertString", LocaleController.getString("SendGameToText", R.string.SendGameToText));
args.putString("selectAlertStringGroup", LocaleController.getString("SendGameToGroupText", R.string.SendGameToGroupText));
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment1, dids, message1, param) -> {
long did = dids.get(0);
TLRPC.TL_inputMediaGame inputMediaGame = new TLRPC.TL_inputMediaGame();
inputMediaGame.id = new TLRPC.TL_inputGameShortName();
inputMediaGame.id.short_name = game;
inputMediaGame.id.bot_id = MessagesController.getInstance(intentAccount).getInputUser(res.users.get(0));
SendMessagesHelper.getInstance(intentAccount).sendGame(MessagesController.getInstance(intentAccount).getInputPeer(did), inputMediaGame, 0, 0);
Bundle args1 = new Bundle();
args1.putBoolean("scrollToTopOnResume", true);
if (DialogObject.isEncryptedDialog(did)) {
args1.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args1.putLong("user_id", did);
} else {
args1.putLong("chat_id", -did);
}
if (MessagesController.getInstance(intentAccount).checkCanOpenChat(args1, fragment1)) {
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
actionBarLayout.presentFragment(new ChatActivity(args1), true, false, true, false);
}
});
boolean removeLast;
if (AndroidUtilities.isTablet()) {
removeLast = layersActionBarLayout.fragmentsStack.size() > 0 && layersActionBarLayout.fragmentsStack.get(layersActionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
} else {
removeLast = actionBarLayout.fragmentsStack.size() > 1 && actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1) instanceof DialogsActivity;
}
actionBarLayout.presentFragment(fragment, removeLast, true, true, false);
if (SecretMediaViewer.hasInstance() && SecretMediaViewer.getInstance().isVisible()) {
SecretMediaViewer.getInstance().closePhoto(false, false);
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().closePhoto(false, true);
} else if (ArticleViewer.hasInstance() && ArticleViewer.getInstance().isVisible()) {
ArticleViewer.getInstance().close(false, true);
}
if (GroupCallActivity.groupCallInstance != null) {
GroupCallActivity.groupCallInstance.dismiss();
}
drawerLayoutContainer.setAllowOpenDrawer(false, false);
if (AndroidUtilities.isTablet()) {
actionBarLayout.showLastFragment();
rightActionBarLayout.showLastFragment();
} else {
drawerLayoutContainer.setAllowOpenDrawer(true, false);
}
} else if (botChat != null) {
final TLRPC.User user = !res.users.isEmpty() ? res.users.get(0) : null;
if (user == null || user.bot && user.bot_nochats) {
try {
if (!mainFragmentsStack.isEmpty()) {
BulletinFactory.of(mainFragmentsStack.get(mainFragmentsStack.size() - 1)).createErrorBulletin(LocaleController.getString("BotCantJoinGroups", R.string.BotCantJoinGroups)).show();
}
} catch (Exception e) {
FileLog.e(e);
}
return;
}
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 2);
args.putString("addToGroupAlertString", LocaleController.formatString("AddToTheGroupAlertText", R.string.AddToTheGroupAlertText, UserObject.getUserName(user), "%1$s"));
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment12, dids, message1, param) -> {
long did = dids.get(0);
Bundle args12 = new Bundle();
args12.putBoolean("scrollToTopOnResume", true);
args12.putLong("chat_id", -did);
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args12, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
MessagesController.getInstance(intentAccount).addUserToChat(-did, user, 0, botChat, null, null);
actionBarLayout.presentFragment(new ChatActivity(args12), true, false, true, false);
}
});
presentFragment(fragment);
} else {
long dialog_id;
boolean isBot = false;
Bundle args = new Bundle();
if (!res.chats.isEmpty()) {
args.putLong("chat_id", res.chats.get(0).id);
dialog_id = -res.chats.get(0).id;
} else {
args.putLong("user_id", res.users.get(0).id);
dialog_id = res.users.get(0).id;
}
if (botUser != null && res.users.size() > 0 && res.users.get(0).bot) {
args.putString("botUser", botUser);
isBot = true;
}
if (messageId != null) {
args.putInt("message_id", messageId);
}
if (voicechat != null) {
args.putString("voicechat", voicechat);
}
if (livestream != null) {
args.putString("livestream", livestream);
}
if (videoTimestamp >= 0) {
args.putInt("video_timestamp", videoTimestamp);
}
BaseFragment lastFragment = !mainFragmentsStack.isEmpty() && voicechat == null ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null;
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
if (isBot && lastFragment instanceof ChatActivity && ((ChatActivity) lastFragment).getDialogId() == dialog_id) {
((ChatActivity) lastFragment).setBotUser(botUser);
} else {
MessagesController.getInstance(intentAccount).ensureMessagesLoaded(dialog_id, messageId == null ? 0 : messageId, new MessagesController.MessagesLoadedCallback() {
@Override
public void onMessagesLoaded(boolean fromCache) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (!LaunchActivity.this.isFinishing()) {
ChatActivity fragment = new ChatActivity(args);
actionBarLayout.presentFragment(fragment);
}
}
@Override
public void onError() {
if (!LaunchActivity.this.isFinishing()) {
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
AlertsCreator.showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
}
});
hideProgressDialog = false;
}
}
}
} else {
try {
if (!mainFragmentsStack.isEmpty()) {
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (error != null && error.text != null && error.text.startsWith("FLOOD_WAIT")) {
BulletinFactory.of(fragment).createErrorBulletin(LocaleController.getString("FloodWait", R.string.FloodWait)).show();
} else {
BulletinFactory.of(fragment).createErrorBulletin(LocaleController.getString("NoUsernameFound", R.string.NoUsernameFound)).show();
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (hideProgressDialog) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
}
}
}, ConnectionsManager.RequestFlagFailOnServerErrors));
} else if (group != null) {
if (state == 0) {
final TLRPC.TL_messages_checkChatInvite req = new TLRPC.TL_messages_checkChatInvite();
req.hash = group;
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (!LaunchActivity.this.isFinishing()) {
boolean hideProgressDialog = true;
if (error == null && actionBarLayout != null) {
TLRPC.ChatInvite invite = (TLRPC.ChatInvite) response;
if (invite.chat != null && (!ChatObject.isLeftFromChat(invite.chat) || !invite.chat.kicked && (!TextUtils.isEmpty(invite.chat.username) || invite instanceof TLRPC.TL_chatInvitePeek || invite.chat.has_geo))) {
MessagesController.getInstance(intentAccount).putChat(invite.chat, false);
ArrayList<TLRPC.Chat> chats = new ArrayList<>();
chats.add(invite.chat);
MessagesStorage.getInstance(intentAccount).putUsersAndChats(null, chats, false, true);
Bundle args = new Bundle();
args.putLong("chat_id", invite.chat.id);
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
boolean[] canceled = new boolean[1];
progressDialog.setOnCancelListener(dialog -> canceled[0] = true);
MessagesController.getInstance(intentAccount).ensureMessagesLoaded(-invite.chat.id, 0, new MessagesController.MessagesLoadedCallback() {
@Override
public void onMessagesLoaded(boolean fromCache) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (canceled[0]) {
return;
}
ChatActivity fragment = new ChatActivity(args);
if (invite instanceof TLRPC.TL_chatInvitePeek) {
fragment.setChatInvite(invite);
}
actionBarLayout.presentFragment(fragment);
}
@Override
public void onError() {
if (!LaunchActivity.this.isFinishing()) {
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
AlertsCreator.showSimpleAlert(fragment, LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
}
});
hideProgressDialog = false;
}
} else {
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
fragment.showDialog(new JoinGroupAlert(LaunchActivity.this, invite, group, fragment));
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (error.text.startsWith("FLOOD_WAIT")) {
builder.setMessage(LocaleController.getString("FloodWait", R.string.FloodWait));
} else if (error.text.startsWith("INVITE_HASH_EXPIRED")) {
builder.setTitle(LocaleController.getString("ExpiredLink", R.string.ExpiredLink));
builder.setMessage(LocaleController.getString("InviteExpired", R.string.InviteExpired));
} else {
builder.setMessage(LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
}
try {
if (hideProgressDialog) {
progressDialog.dismiss();
}
} catch (Exception e) {
FileLog.e(e);
}
}
}), ConnectionsManager.RequestFlagFailOnServerErrors);
} else if (state == 1) {
TLRPC.TL_messages_importChatInvite req = new TLRPC.TL_messages_importChatInvite();
req.hash = group;
ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> {
if (error == null) {
TLRPC.Updates updates = (TLRPC.Updates) response;
MessagesController.getInstance(intentAccount).processUpdates(updates, false);
}
AndroidUtilities.runOnUIThread(() -> {
if (!LaunchActivity.this.isFinishing()) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (error == null) {
if (actionBarLayout != null) {
TLRPC.Updates updates = (TLRPC.Updates) response;
if (!updates.chats.isEmpty()) {
TLRPC.Chat chat = updates.chats.get(0);
chat.left = false;
chat.kicked = false;
MessagesController.getInstance(intentAccount).putUsers(updates.users, false);
MessagesController.getInstance(intentAccount).putChats(updates.chats, false);
Bundle args = new Bundle();
args.putLong("chat_id", chat.id);
if (mainFragmentsStack.isEmpty() || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, mainFragmentsStack.get(mainFragmentsStack.size() - 1))) {
ChatActivity fragment = new ChatActivity(args);
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
actionBarLayout.presentFragment(fragment, false, true, true, false);
}
}
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (error.text.startsWith("FLOOD_WAIT")) {
builder.setMessage(LocaleController.getString("FloodWait", R.string.FloodWait));
} else if (error.text.equals("USERS_TOO_MUCH")) {
builder.setMessage(LocaleController.getString("JoinToGroupErrorFull", R.string.JoinToGroupErrorFull));
} else {
builder.setMessage(LocaleController.getString("JoinToGroupErrorNotExist", R.string.JoinToGroupErrorNotExist));
}
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
showAlertDialog(builder);
}
}
});
}, ConnectionsManager.RequestFlagFailOnServerErrors);
}
} else if (sticker != null) {
if (!mainFragmentsStack.isEmpty()) {
TLRPC.TL_inputStickerSetShortName stickerset = new TLRPC.TL_inputStickerSetShortName();
stickerset.short_name = sticker;
BaseFragment fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
StickersAlert alert;
if (fragment instanceof ChatActivity) {
ChatActivity chatActivity = (ChatActivity) fragment;
alert = new StickersAlert(LaunchActivity.this, fragment, stickerset, null, chatActivity.getChatActivityEnterViewForStickers(), chatActivity.getResourceProvider());
alert.setCalcMandatoryInsets(chatActivity.isKeyboardVisible());
} else {
alert = new StickersAlert(LaunchActivity.this, fragment, stickerset, null, null);
}
fragment.showDialog(alert);
}
return;
} else if (message != null) {
Bundle args = new Bundle();
args.putBoolean("onlySelect", true);
args.putInt("dialogsType", 3);
DialogsActivity fragment = new DialogsActivity(args);
fragment.setDelegate((fragment13, dids, m, param) -> {
long did = dids.get(0);
Bundle args13 = new Bundle();
args13.putBoolean("scrollToTopOnResume", true);
args13.putBoolean("hasUrl", hasUrl);
if (DialogObject.isEncryptedDialog(did)) {
args13.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args13.putLong("user_id", did);
} else {
args13.putLong("chat_id", -did);
}
if (MessagesController.getInstance(intentAccount).checkCanOpenChat(args13, fragment13)) {
NotificationCenter.getInstance(intentAccount).postNotificationName(NotificationCenter.closeChats);
MediaDataController.getInstance(intentAccount).saveDraft(did, 0, message, null, null, false);
actionBarLayout.presentFragment(new ChatActivity(args13), true, false, true, false);
}
});
presentFragment(fragment, false, true);
} else if (auth != null) {
final int bot_id = Utilities.parseInt(auth.get("bot_id"));
if (bot_id == 0) {
return;
}
final String payload = auth.get("payload");
final String nonce = auth.get("nonce");
final String callbackUrl = auth.get("callback_url");
final TLRPC.TL_account_getAuthorizationForm req = new TLRPC.TL_account_getAuthorizationForm();
req.bot_id = bot_id;
req.scope = auth.get("scope");
req.public_key = auth.get("public_key");
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req, (response, error) -> {
final TLRPC.TL_account_authorizationForm authorizationForm = (TLRPC.TL_account_authorizationForm) response;
if (authorizationForm != null) {
TLRPC.TL_account_getPassword req2 = new TLRPC.TL_account_getPassword();
requestId[0] = ConnectionsManager.getInstance(intentAccount).sendRequest(req2, (response1, error1) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response1 != null) {
TLRPC.TL_account_password accountPassword = (TLRPC.TL_account_password) response1;
MessagesController.getInstance(intentAccount).putUsers(authorizationForm.users, false);
presentFragment(new PassportActivity(PassportActivity.TYPE_PASSWORD, req.bot_id, req.scope, req.public_key, payload, nonce, callbackUrl, authorizationForm, accountPassword));
}
}));
} else {
AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
if ("APP_VERSION_OUTDATED".equals(error.text)) {
AlertsCreator.showUpdateAppAlert(LaunchActivity.this, LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
} else {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
}
} catch (Exception e) {
FileLog.e(e);
}
});
}
});
} else if (unsupportedUrl != null) {
TLRPC.TL_help_getDeepLinkInfo req = new TLRPC.TL_help_getDeepLinkInfo();
req.path = unsupportedUrl;
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response instanceof TLRPC.TL_help_deepLinkInfo) {
TLRPC.TL_help_deepLinkInfo res = (TLRPC.TL_help_deepLinkInfo) response;
AlertsCreator.showUpdateAppAlert(LaunchActivity.this, res.message, res.update_app);
}
}));
} else if (lang != null) {
TLRPC.TL_langpack_getLanguage req = new TLRPC.TL_langpack_getLanguage();
req.lang_code = lang;
req.lang_pack = "android";
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response instanceof TLRPC.TL_langPackLanguage) {
TLRPC.TL_langPackLanguage res = (TLRPC.TL_langPackLanguage) response;
showAlertDialog(AlertsCreator.createLanguageAlert(LaunchActivity.this, res));
} else if (error != null) {
if ("LANG_CODE_NOT_SUPPORTED".equals(error.text)) {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LanguageUnsupportedError", R.string.LanguageUnsupportedError)));
} else {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
}
}
}));
} else if (wallPaper != null) {
boolean ok = false;
if (TextUtils.isEmpty(wallPaper.slug)) {
try {
WallpapersListActivity.ColorWallpaper colorWallpaper;
if (wallPaper.settings.third_background_color != 0) {
colorWallpaper = new WallpapersListActivity.ColorWallpaper(Theme.COLOR_BACKGROUND_SLUG, wallPaper.settings.background_color, wallPaper.settings.second_background_color, wallPaper.settings.third_background_color, wallPaper.settings.fourth_background_color);
} else {
colorWallpaper = new WallpapersListActivity.ColorWallpaper(Theme.COLOR_BACKGROUND_SLUG, wallPaper.settings.background_color, wallPaper.settings.second_background_color, AndroidUtilities.getWallpaperRotation(wallPaper.settings.rotation, false));
}
ThemePreviewActivity wallpaperActivity = new ThemePreviewActivity(colorWallpaper, null, true, false);
AndroidUtilities.runOnUIThread(() -> presentFragment(wallpaperActivity));
ok = true;
} catch (Exception e) {
FileLog.e(e);
}
}
if (!ok) {
TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
inputWallPaperSlug.slug = wallPaper.slug;
req.wallpaper = inputWallPaperSlug;
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (response instanceof TLRPC.TL_wallPaper) {
TLRPC.TL_wallPaper res = (TLRPC.TL_wallPaper) response;
Object object;
if (res.pattern) {
WallpapersListActivity.ColorWallpaper colorWallpaper = new WallpapersListActivity.ColorWallpaper(res.slug, wallPaper.settings.background_color, wallPaper.settings.second_background_color, wallPaper.settings.third_background_color, wallPaper.settings.fourth_background_color, AndroidUtilities.getWallpaperRotation(wallPaper.settings.rotation, false), wallPaper.settings.intensity / 100.0f, wallPaper.settings.motion, null);
colorWallpaper.pattern = res;
object = colorWallpaper;
} else {
object = res;
}
ThemePreviewActivity wallpaperActivity = new ThemePreviewActivity(object, null, true, false);
wallpaperActivity.setInitialModes(wallPaper.settings.blur, wallPaper.settings.motion);
presentFragment(wallpaperActivity);
} else {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred) + "\n" + error.text));
}
}));
}
} else if (theme != null) {
cancelRunnable = () -> {
loadingThemeFileName = null;
loadingThemeWallpaperName = null;
loadingThemeWallpaper = null;
loadingThemeInfo = null;
loadingThemeProgressDialog = null;
loadingTheme = null;
};
TLRPC.TL_account_getTheme req = new TLRPC.TL_account_getTheme();
req.format = "android";
TLRPC.TL_inputThemeSlug inputThemeSlug = new TLRPC.TL_inputThemeSlug();
inputThemeSlug.slug = theme;
req.theme = inputThemeSlug;
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
int notFound = 2;
if (response instanceof TLRPC.TL_theme) {
TLRPC.TL_theme t = (TLRPC.TL_theme) response;
TLRPC.ThemeSettings settings = null;
if (t.settings.size() > 0) {
settings = t.settings.get(0);
}
if (settings != null) {
String key = Theme.getBaseThemeKey(settings);
Theme.ThemeInfo info = Theme.getTheme(key);
if (info != null) {
TLRPC.TL_wallPaper object;
if (settings.wallpaper instanceof TLRPC.TL_wallPaper) {
object = (TLRPC.TL_wallPaper) settings.wallpaper;
File path = FileLoader.getPathToAttach(object.document, true);
if (!path.exists()) {
loadingThemeProgressDialog = progressDialog;
loadingThemeAccent = true;
loadingThemeInfo = info;
loadingTheme = t;
loadingThemeWallpaper = object;
loadingThemeWallpaperName = FileLoader.getAttachFileName(object.document);
FileLoader.getInstance(currentAccount).loadFile(object.document, object, 1, 1);
return;
}
} else {
object = null;
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
notFound = 0;
openThemeAccentPreview(t, object, info);
} else {
notFound = 1;
}
} else if (t.document != null) {
loadingThemeAccent = false;
loadingTheme = t;
loadingThemeFileName = FileLoader.getAttachFileName(loadingTheme.document);
loadingThemeProgressDialog = progressDialog;
FileLoader.getInstance(currentAccount).loadFile(loadingTheme.document, t, 1, 1);
notFound = 0;
} else {
notFound = 1;
}
} else if (error != null && "THEME_FORMAT_INVALID".equals(error.text)) {
notFound = 1;
}
if (notFound != 0) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
if (notFound == 1) {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("Theme", R.string.Theme), LocaleController.getString("ThemeNotSupported", R.string.ThemeNotSupported)));
} else {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("Theme", R.string.Theme), LocaleController.getString("ThemeNotFound", R.string.ThemeNotFound)));
}
}
}));
} else if (channelId != null && messageId != null) {
if (threadId != null) {
TLRPC.Chat chat = MessagesController.getInstance(intentAccount).getChat(channelId);
if (chat != null) {
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, chat);
} else {
TLRPC.TL_channels_getChannels req = new TLRPC.TL_channels_getChannels();
TLRPC.TL_inputChannel inputChannel = new TLRPC.TL_inputChannel();
inputChannel.channel_id = channelId;
req.id.add(inputChannel);
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
boolean notFound = true;
if (response instanceof TLRPC.TL_messages_chats) {
TLRPC.TL_messages_chats res = (TLRPC.TL_messages_chats) response;
if (!res.chats.isEmpty()) {
notFound = false;
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
requestId[0] = runCommentRequest(intentAccount, progressDialog, messageId, commentId, threadId, res.chats.get(0));
}
}
if (notFound) {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LinkNotFound", R.string.LinkNotFound)));
}
}));
}
} else {
Bundle args = new Bundle();
args.putLong("chat_id", channelId);
args.putInt("message_id", messageId);
BaseFragment lastFragment = !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null;
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
AndroidUtilities.runOnUIThread(() -> {
if (!actionBarLayout.presentFragment(new ChatActivity(args))) {
TLRPC.TL_channels_getChannels req = new TLRPC.TL_channels_getChannels();
TLRPC.TL_inputChannel inputChannel = new TLRPC.TL_inputChannel();
inputChannel.channel_id = channelId;
req.id.add(inputChannel);
requestId[0] = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
boolean notFound = true;
if (response instanceof TLRPC.TL_messages_chats) {
TLRPC.TL_messages_chats res = (TLRPC.TL_messages_chats) response;
if (!res.chats.isEmpty()) {
notFound = false;
MessagesController.getInstance(currentAccount).putChats(res.chats, false);
TLRPC.Chat chat = res.chats.get(0);
if (lastFragment == null || MessagesController.getInstance(intentAccount).checkCanOpenChat(args, lastFragment)) {
actionBarLayout.presentFragment(new ChatActivity(args));
}
}
}
if (notFound) {
showAlertDialog(AlertsCreator.createSimpleAlert(LaunchActivity.this, LocaleController.getString("LinkNotFound", R.string.LinkNotFound)));
}
}));
}
});
}
}
}
if (requestId[0] != 0) {
final Runnable cancelRunnableFinal = cancelRunnable;
progressDialog.setOnCancelListener(dialog -> {
ConnectionsManager.getInstance(intentAccount).cancelRequest(requestId[0], true);
if (cancelRunnableFinal != null) {
cancelRunnableFinal.run();
}
});
try {
progressDialog.showDelayed(300);
} catch (Exception ignore) {
}
}
}
Aggregations