use of org.telegram.ui.ActionBar.AlertDialog 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) {
}
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method didSelectDialogs.
@Override
public void didSelectDialogs(DialogsActivity dialogsFragment, ArrayList<Long> dids, CharSequence message, boolean param) {
final int account = dialogsFragment != null ? dialogsFragment.getCurrentAccount() : currentAccount;
if (exportingChatUri != null) {
Uri uri = exportingChatUri;
ArrayList<Uri> documentsUris = documentsUrisArray != null ? new ArrayList<>(documentsUrisArray) : null;
final AlertDialog progressDialog = new AlertDialog(this, 3);
SendMessagesHelper.getInstance(account).prepareImportHistory(dids.get(0), exportingChatUri, documentsUrisArray, (result) -> {
if (result != 0) {
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance(account).postNotificationName(NotificationCenter.closeChats);
}
if (DialogObject.isUserDialog(result)) {
args.putLong("user_id", result);
} else {
args.putLong("chat_id", -result);
}
ChatActivity fragment = new ChatActivity(args);
fragment.setOpenImport();
actionBarLayout.presentFragment(fragment, dialogsFragment != null || param, dialogsFragment == null, true, false);
} else {
documentsUrisArray = documentsUris;
if (documentsUrisArray == null) {
documentsUrisArray = new ArrayList<>();
}
documentsUrisArray.add(0, uri);
openDialogsToSend(true);
}
try {
progressDialog.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
});
try {
progressDialog.showDelayed(300);
} catch (Exception ignore) {
}
} else {
boolean notify = dialogsFragment == null || dialogsFragment.notify;
final ChatActivity fragment;
if (dids.size() <= 1) {
final long did = dids.get(0);
Bundle args = new Bundle();
args.putBoolean("scrollToTopOnResume", true);
if (!AndroidUtilities.isTablet()) {
NotificationCenter.getInstance(account).postNotificationName(NotificationCenter.closeChats);
}
if (DialogObject.isEncryptedDialog(did)) {
args.putInt("enc_id", DialogObject.getEncryptedChatId(did));
} else if (DialogObject.isUserDialog(did)) {
args.putLong("user_id", did);
} else {
args.putLong("chat_id", -did);
}
if (!MessagesController.getInstance(account).checkCanOpenChat(args, dialogsFragment)) {
return;
}
fragment = new ChatActivity(args);
} else {
fragment = null;
}
int attachesCount = 0;
if (contactsToSend != null) {
attachesCount += contactsToSend.size();
}
if (videoPath != null) {
attachesCount++;
}
if (photoPathsArray != null) {
attachesCount += photoPathsArray.size();
}
if (documentsPathsArray != null) {
attachesCount += documentsPathsArray.size();
}
if (documentsUrisArray != null) {
attachesCount += documentsUrisArray.size();
}
if (videoPath == null && photoPathsArray == null && documentsPathsArray == null && documentsUrisArray == null && sendingText != null) {
attachesCount++;
}
for (int i = 0; i < dids.size(); i++) {
final long did = dids.get(i);
if (AlertsCreator.checkSlowMode(this, currentAccount, did, attachesCount > 1)) {
return;
}
}
if (contactsToSend != null && contactsToSend.size() == 1 && !mainFragmentsStack.isEmpty()) {
PhonebookShareAlert alert = new PhonebookShareAlert(mainFragmentsStack.get(mainFragmentsStack.size() - 1), null, null, contactsToSendUri, null, null, null);
alert.setDelegate((user, notify2, scheduleDate) -> {
if (fragment != null) {
actionBarLayout.presentFragment(fragment, true, false, true, false);
}
for (int i = 0; i < dids.size(); i++) {
SendMessagesHelper.getInstance(account).sendMessage(user, dids.get(i), null, null, null, null, notify2, scheduleDate);
}
});
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(alert);
} else {
String captionToSend = null;
for (int i = 0; i < dids.size(); i++) {
final long did = dids.get(i);
AccountInstance accountInstance = AccountInstance.getInstance(UserConfig.selectedAccount);
boolean photosEditorOpened = false;
if (fragment != null) {
boolean withoutAnimation = dialogsFragment == null || (videoPath != null || (photoPathsArray != null && photoPathsArray.size() > 0));
actionBarLayout.presentFragment(fragment, dialogsFragment != null, withoutAnimation, true, false);
if (videoPath != null) {
fragment.openVideoEditor(videoPath, sendingText);
sendingText = null;
} else if (photoPathsArray != null && photoPathsArray.size() > 0) {
photosEditorOpened = fragment.openPhotosEditor(photoPathsArray, message == null || message.length() == 0 ? sendingText : message);
if (photosEditorOpened) {
sendingText = null;
}
}
} else {
if (videoPath != null) {
if (sendingText != null && sendingText.length() <= 1024) {
captionToSend = sendingText;
sendingText = null;
}
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(videoPath);
SendMessagesHelper.prepareSendingDocuments(accountInstance, arrayList, arrayList, null, captionToSend, null, did, null, null, null, null, notify, 0);
}
}
if (photoPathsArray != null && !photosEditorOpened) {
if (sendingText != null && sendingText.length() <= 1024 && photoPathsArray.size() == 1) {
photoPathsArray.get(0).caption = sendingText;
sendingText = null;
}
SendMessagesHelper.prepareSendingMedia(accountInstance, photoPathsArray, did, null, null, null, false, false, null, notify, 0);
}
if (documentsPathsArray != null || documentsUrisArray != null) {
if (sendingText != null && sendingText.length() <= 1024 && ((documentsPathsArray != null ? documentsPathsArray.size() : 0) + (documentsUrisArray != null ? documentsUrisArray.size() : 0)) == 1) {
captionToSend = sendingText;
sendingText = null;
}
SendMessagesHelper.prepareSendingDocuments(accountInstance, documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, captionToSend, documentsMimeType, did, null, null, null, null, notify, 0);
}
if (sendingLocation != null) {
SendMessagesHelper.prepareSendingLocation(accountInstance, sendingLocation, did);
sendingText = null;
}
if (sendingText != null) {
SendMessagesHelper.prepareSendingText(accountInstance, sendingText, did, true, 0);
}
if (contactsToSend != null && !contactsToSend.isEmpty()) {
for (int a = 0; a < contactsToSend.size(); a++) {
TLRPC.User user = contactsToSend.get(a);
SendMessagesHelper.getInstance(account).sendMessage(user, did, null, null, null, null, notify, 0);
}
}
if (!TextUtils.isEmpty(message)) {
SendMessagesHelper.prepareSendingText(accountInstance, message.toString(), did, notify, 0);
}
}
}
if (dialogsFragment != null && fragment == null) {
dialogsFragment.finishFragment();
}
}
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
contactsToSend = null;
contactsToSendUri = null;
exportingChatUri = null;
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method didReceivedNotification.
@Override
@SuppressWarnings("unchecked")
public void didReceivedNotification(int id, final int account, Object... args) {
if (id == NotificationCenter.appDidLogout) {
switchToAvailableAccountOrLogout();
} else if (id == NotificationCenter.closeOtherAppActivities) {
if (args[0] != this) {
onFinish();
finish();
}
} else if (id == NotificationCenter.didUpdateConnectionState) {
int state = ConnectionsManager.getInstance(account).getConnectionState();
if (currentConnectionState != state) {
if (BuildVars.LOGS_ENABLED) {
FileLog.d("switch to state " + state);
}
currentConnectionState = state;
updateCurrentConnectionState(account);
}
} else if (id == NotificationCenter.mainUserInfoChanged) {
drawerLayoutAdapter.notifyDataSetChanged();
} else if (id == NotificationCenter.needShowAlert) {
final Integer reason = (Integer) args[0];
if (reason == 6 || reason == 3 && proxyErrorDialog != null) {
return;
} else if (reason == 4) {
showTosActivity(account, (TLRPC.TL_help_termsOfService) args[1]);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
if (reason != 2 && reason != 3) {
builder.setNegativeButton(LocaleController.getString("MoreInfo", R.string.MoreInfo), (dialogInterface, i) -> {
if (!mainFragmentsStack.isEmpty()) {
MessagesController.getInstance(account).openByUserName("spambot", mainFragmentsStack.get(mainFragmentsStack.size() - 1), 1);
}
});
}
if (reason == 5) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam3", R.string.NobodyLikesSpam3));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 0) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam1", R.string.NobodyLikesSpam1));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 1) {
builder.setMessage(LocaleController.getString("NobodyLikesSpam2", R.string.NobodyLikesSpam2));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
} else if (reason == 2) {
builder.setMessage((String) args[1]);
String type = (String) args[2];
if (type.startsWith("AUTH_KEY_DROP_")) {
builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setNegativeButton(LocaleController.getString("LogOut", R.string.LogOut), (dialog, which) -> MessagesController.getInstance(currentAccount).performLogout(2));
} else {
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
}
} else if (reason == 3) {
builder.setTitle(LocaleController.getString("Proxy", R.string.Proxy));
builder.setMessage(LocaleController.getString("UseProxyTelegramError", R.string.UseProxyTelegramError));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
proxyErrorDialog = showAlertDialog(builder);
return;
}
if (!mainFragmentsStack.isEmpty()) {
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
}
} else if (id == NotificationCenter.wasUnableToFindCurrentLocation) {
final HashMap<String, MessageObject> waitingForLocation = (HashMap<String, MessageObject>) args[0];
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setNegativeButton(LocaleController.getString("ShareYouLocationUnableManually", R.string.ShareYouLocationUnableManually), (dialogInterface, i) -> {
if (mainFragmentsStack.isEmpty()) {
return;
}
BaseFragment lastFragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (!AndroidUtilities.isGoogleMapsInstalled(lastFragment)) {
return;
}
LocationActivity fragment = new LocationActivity(0);
fragment.setDelegate((location, live, notify, scheduleDate) -> {
for (HashMap.Entry<String, MessageObject> entry : waitingForLocation.entrySet()) {
MessageObject messageObject = entry.getValue();
SendMessagesHelper.getInstance(account).sendMessage(location, messageObject.getDialogId(), messageObject, null, null, null, notify, scheduleDate);
}
});
presentFragment(fragment);
});
builder.setMessage(LocaleController.getString("ShareYouLocationUnable", R.string.ShareYouLocationUnable));
if (!mainFragmentsStack.isEmpty()) {
mainFragmentsStack.get(mainFragmentsStack.size() - 1).showDialog(builder.create());
}
} else if (id == NotificationCenter.didSetNewWallpapper) {
if (sideMenu != null) {
View child = sideMenu.getChildAt(0);
if (child != null) {
child.invalidate();
}
}
if (backgroundTablet != null) {
backgroundTablet.setBackgroundImage(Theme.getCachedWallpaper(), Theme.isWallpaperMotion());
}
} else if (id == NotificationCenter.didSetPasscode) {
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
} else if (!AndroidUtilities.hasFlagSecureFragment()) {
try {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
FileLog.e(e);
}
}
} else if (id == NotificationCenter.reloadInterface) {
boolean last = mainFragmentsStack.size() > 1 && mainFragmentsStack.get(mainFragmentsStack.size() - 1) instanceof ProfileActivity;
if (last) {
ProfileActivity profileActivity = (ProfileActivity) mainFragmentsStack.get(mainFragmentsStack.size() - 1);
if (!profileActivity.isSettings()) {
last = false;
}
}
rebuildAllFragments(last);
} else if (id == NotificationCenter.suggestedLangpack) {
showLanguageAlert(false);
} else if (id == NotificationCenter.openArticle) {
if (mainFragmentsStack.isEmpty()) {
return;
}
ArticleViewer.getInstance().setParentActivity(this, mainFragmentsStack.get(mainFragmentsStack.size() - 1));
ArticleViewer.getInstance().open((TLRPC.TL_webPage) args[0], (String) args[1]);
} else if (id == NotificationCenter.hasNewContactsToImport) {
if (actionBarLayout == null || actionBarLayout.fragmentsStack.isEmpty()) {
return;
}
final int type = (Integer) args[0];
final HashMap<String, ContactsController.Contact> contactHashMap = (HashMap<String, ContactsController.Contact>) args[1];
final boolean first = (Boolean) args[2];
final boolean schedule = (Boolean) args[3];
BaseFragment fragment = actionBarLayout.fragmentsStack.get(actionBarLayout.fragmentsStack.size() - 1);
AlertDialog.Builder builder = new AlertDialog.Builder(LaunchActivity.this);
builder.setTitle(LocaleController.getString("UpdateContactsTitle", R.string.UpdateContactsTitle));
builder.setMessage(LocaleController.getString("UpdateContactsMessage", R.string.UpdateContactsMessage));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, false));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
builder.setOnBackButtonListener((dialogInterface, i) -> ContactsController.getInstance(account).syncPhoneBookByAlert(contactHashMap, first, schedule, true));
AlertDialog dialog = builder.create();
fragment.showDialog(dialog);
dialog.setCanceledOnTouchOutside(false);
} else if (id == NotificationCenter.didSetNewTheme) {
Boolean nightTheme = (Boolean) args[0];
if (!nightTheme) {
if (sideMenu != null) {
sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
sideMenu.setGlowColor(Theme.getColor(Theme.key_chats_menuBackground));
sideMenu.setListSelectorColor(Theme.getColor(Theme.key_listSelector));
sideMenu.getAdapter().notifyDataSetChanged();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
setTaskDescription(new ActivityManager.TaskDescription(null, null, Theme.getColor(Theme.key_actionBarDefault) | 0xff000000));
} catch (Exception ignore) {
}
}
}
drawerLayoutContainer.setBehindKeyboardColor(Theme.getColor(Theme.key_windowBackgroundWhite));
boolean checkNavigationBarColor = true;
if (args.length > 1) {
checkNavigationBarColor = (boolean) args[1];
}
checkSystemBarColors(true, checkNavigationBarColor);
} else if (id == NotificationCenter.needSetDayNightTheme) {
boolean instant = false;
if (Build.VERSION.SDK_INT >= 21 && args[2] != null) {
if (themeSwitchImageView.getVisibility() == View.VISIBLE) {
return;
}
try {
int[] pos = (int[]) args[2];
boolean toDark = (Boolean) args[4];
RLottieImageView darkThemeView = (RLottieImageView) args[5];
int w = drawerLayoutContainer.getMeasuredWidth();
int h = drawerLayoutContainer.getMeasuredHeight();
if (!toDark) {
darkThemeView.setVisibility(View.INVISIBLE);
}
Bitmap bitmap = Bitmap.createBitmap(drawerLayoutContainer.getMeasuredWidth(), drawerLayoutContainer.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
HashMap<View, Integer> viewLayerTypes = new HashMap<>();
invalidateCachedViews(drawerLayoutContainer);
drawerLayoutContainer.draw(canvas);
frameLayout.removeView(themeSwitchImageView);
if (toDark) {
frameLayout.addView(themeSwitchImageView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
themeSwitchSunView.setVisibility(View.GONE);
} else {
frameLayout.addView(themeSwitchImageView, 1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
themeSwitchSunView.setTranslationX(pos[0] - AndroidUtilities.dp(14));
themeSwitchSunView.setTranslationY(pos[1] - AndroidUtilities.dp(14));
themeSwitchSunView.setVisibility(View.VISIBLE);
themeSwitchSunView.invalidate();
}
themeSwitchImageView.setImageBitmap(bitmap);
themeSwitchImageView.setVisibility(View.VISIBLE);
themeSwitchSunDrawable = darkThemeView.getAnimatedDrawable();
float finalRadius = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + (h - pos[1]) * (h - pos[1])), Math.sqrt(pos[0] * pos[0] + (h - pos[1]) * (h - pos[1])));
float finalRadius2 = (float) Math.max(Math.sqrt((w - pos[0]) * (w - pos[0]) + pos[1] * pos[1]), Math.sqrt(pos[0] * pos[0] + pos[1] * pos[1]));
finalRadius = Math.max(finalRadius, finalRadius2);
Animator anim = ViewAnimationUtils.createCircularReveal(toDark ? drawerLayoutContainer : themeSwitchImageView, pos[0], pos[1], toDark ? 0 : finalRadius, toDark ? finalRadius : 0);
anim.setDuration(400);
anim.setInterpolator(Easings.easeInOutQuad);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
themeSwitchImageView.setImageDrawable(null);
themeSwitchImageView.setVisibility(View.GONE);
themeSwitchSunView.setVisibility(View.GONE);
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeAccentListUpdated);
if (!toDark) {
darkThemeView.setVisibility(View.VISIBLE);
}
DrawerProfileCell.switchingTheme = false;
}
});
anim.start();
instant = true;
} catch (Throwable e) {
FileLog.e(e);
try {
themeSwitchImageView.setImageDrawable(null);
frameLayout.removeView(themeSwitchImageView);
DrawerProfileCell.switchingTheme = false;
} catch (Exception e2) {
FileLog.e(e2);
}
}
} else {
DrawerProfileCell.switchingTheme = false;
}
Theme.ThemeInfo theme = (Theme.ThemeInfo) args[0];
boolean nigthTheme = (Boolean) args[1];
int accentId = (Integer) args[3];
actionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
if (AndroidUtilities.isTablet()) {
layersActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
rightActionBarLayout.animateThemedValues(theme, accentId, nigthTheme, instant);
}
} else if (id == NotificationCenter.notificationsCountUpdated) {
if (sideMenu != null) {
Integer accountNum = (Integer) args[0];
int count = sideMenu.getChildCount();
for (int a = 0; a < count; a++) {
View child = sideMenu.getChildAt(a);
if (child instanceof DrawerUserCell) {
if (((DrawerUserCell) child).getAccountNumber() == accountNum) {
child.invalidate();
break;
}
}
}
}
} else if (id == NotificationCenter.fileLoaded) {
String path = (String) args[0];
if (SharedConfig.isAppUpdateAvailable()) {
String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (name.equals(path)) {
updateAppUpdateViews(true);
}
}
if (loadingThemeFileName != null) {
if (loadingThemeFileName.equals(path)) {
loadingThemeFileName = null;
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
Theme.ThemeInfo themeInfo = Theme.fillThemeValues(locFile, loadingTheme.title, loadingTheme);
if (themeInfo != null) {
if (themeInfo.pathToWallpaper != null) {
File file = new File(themeInfo.pathToWallpaper);
if (!file.exists()) {
TLRPC.TL_account_getWallPaper req = new TLRPC.TL_account_getWallPaper();
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
inputWallPaperSlug.slug = themeInfo.slug;
req.wallpaper = inputWallPaperSlug;
ConnectionsManager.getInstance(themeInfo.account).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (response instanceof TLRPC.TL_wallPaper) {
TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response;
loadingThemeInfo = themeInfo;
loadingThemeWallpaperName = FileLoader.getAttachFileName(wallPaper.document);
loadingThemeWallpaper = wallPaper;
FileLoader.getInstance(themeInfo.account).loadFile(wallPaper.document, wallPaper, 1, 1);
} else {
onThemeLoadFinish();
}
}));
return;
}
}
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
if (finalThemeInfo != null) {
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
}
}
onThemeLoadFinish();
}
} else if (loadingThemeWallpaperName != null) {
if (loadingThemeWallpaperName.equals(path)) {
loadingThemeWallpaperName = null;
File file = (File) args[1];
if (loadingThemeAccent) {
openThemeAccentPreview(loadingTheme, loadingThemeWallpaper, loadingThemeInfo);
onThemeLoadFinish();
} else {
Theme.ThemeInfo info = loadingThemeInfo;
Utilities.globalQueue.postRunnable(() -> {
info.createBackground(file, info.pathToWallpaper);
AndroidUtilities.runOnUIThread(() -> {
if (loadingTheme == null) {
return;
}
File locFile = new File(ApplicationLoader.getFilesDirFixed(), "remote" + loadingTheme.id + ".attheme");
Theme.ThemeInfo finalThemeInfo = Theme.applyThemeFile(locFile, loadingTheme.title, loadingTheme, true);
if (finalThemeInfo != null) {
presentFragment(new ThemePreviewActivity(finalThemeInfo, true, ThemePreviewActivity.SCREEN_TYPE_PREVIEW, false, false));
}
onThemeLoadFinish();
});
});
}
}
}
} else if (id == NotificationCenter.fileLoadFailed) {
String path = (String) args[0];
if (path.equals(loadingThemeFileName) || path.equals(loadingThemeWallpaperName)) {
onThemeLoadFinish();
}
if (SharedConfig.isAppUpdateAvailable()) {
String name = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (name.equals(path)) {
updateAppUpdateViews(true);
}
}
} else if (id == NotificationCenter.screenStateChanged) {
if (ApplicationLoader.mainInterfacePaused) {
return;
}
if (ApplicationLoader.isScreenOn) {
onPasscodeResume();
} else {
onPasscodePause();
}
} else if (id == NotificationCenter.needCheckSystemBarColors) {
checkSystemBarColors();
} else if (id == NotificationCenter.historyImportProgressChanged) {
if (args.length > 1 && !mainFragmentsStack.isEmpty()) {
AlertsCreator.processError(currentAccount, (TLRPC.TL_error) args[2], mainFragmentsStack.get(mainFragmentsStack.size() - 1), (TLObject) args[1]);
}
} else if (id == NotificationCenter.stickersImportComplete) {
MediaDataController.getInstance(account).toggleStickerSet(this, (TLObject) args[0], 2, !mainFragmentsStack.isEmpty() ? mainFragmentsStack.get(mainFragmentsStack.size() - 1) : null, false, true);
} else if (id == NotificationCenter.newSuggestionsAvailable) {
sideMenu.invalidateViews();
} else if (id == NotificationCenter.showBulletin) {
if (!mainFragmentsStack.isEmpty()) {
int type = (int) args[0];
FrameLayout container = null;
BaseFragment fragment = null;
if (GroupCallActivity.groupCallUiVisible && GroupCallActivity.groupCallInstance != null) {
container = GroupCallActivity.groupCallInstance.getContainer();
}
if (container == null) {
fragment = mainFragmentsStack.get(mainFragmentsStack.size() - 1);
}
if (type == Bulletin.TYPE_NAME_CHANGED) {
long peerId = (long) args[1];
String text = peerId > 0 ? LocaleController.getString("YourNameChanged", R.string.YourNameChanged) : LocaleController.getString("CannelTitleChanged", R.string.ChannelTitleChanged);
(container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
} else if (type == Bulletin.TYPE_BIO_CHANGED) {
long peerId = (long) args[1];
String text = peerId > 0 ? LocaleController.getString("YourBioChanged", R.string.YourBioChanged) : LocaleController.getString("CannelDescriptionChanged", R.string.ChannelDescriptionChanged);
(container != null ? BulletinFactory.of(container, null) : BulletinFactory.of(fragment)).createErrorBulletin(text).show();
} else if (type == Bulletin.TYPE_STICKER) {
TLRPC.Document sticker = (TLRPC.Document) args[1];
StickerSetBulletinLayout layout = new StickerSetBulletinLayout(this, null, (int) args[2], sticker, null);
if (fragment != null) {
Bulletin.make(fragment, layout, Bulletin.DURATION_SHORT).show();
} else {
Bulletin.make(container, layout, Bulletin.DURATION_SHORT).show();
}
} else if (type == Bulletin.TYPE_ERROR) {
if (fragment != null) {
BulletinFactory.of(fragment).createErrorBulletin((String) args[1]).show();
} else {
BulletinFactory.of(container, null).createErrorBulletin((String) args[1]).show();
}
}
}
} else if (id == NotificationCenter.groupCallUpdated) {
checkWasMutedByAdmin(false);
} else if (id == NotificationCenter.fileLoadProgressChanged) {
if (updateTextView != null && SharedConfig.isAppUpdateAvailable()) {
String location = (String) args[0];
String fileName = FileLoader.getAttachFileName(SharedConfig.pendingAppUpdate.document);
if (fileName != null && fileName.equals(location)) {
Long loadedSize = (Long) args[1];
Long totalSize = (Long) args[2];
float loadProgress = loadedSize / (float) totalSize;
updateLayoutIcon.setProgress(loadProgress, true);
updateTextView.setText(LocaleController.formatString("AppUpdateDownloading", R.string.AppUpdateDownloading, (int) (loadProgress * 100)));
}
}
} else if (id == NotificationCenter.appUpdateAvailable) {
updateAppUpdateViews(mainFragmentsStack.size() == 1);
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupCallActivity method processSelectedOption.
private void processSelectedOption(TLRPC.TL_groupCallParticipant participant, long peerId, int option) {
VoIPService voIPService = VoIPService.getSharedInstance();
if (voIPService == null) {
return;
}
TLObject object;
if (peerId > 0) {
object = accountInstance.getMessagesController().getUser(peerId);
} else {
object = accountInstance.getMessagesController().getChat(-peerId);
}
if (option == 0 || option == 2 || option == 3) {
if (option == 0) {
if (VoIPService.getSharedInstance() == null) {
return;
}
VoIPService.getSharedInstance().editCallMember(object, true, null, null, null, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED, object, null, null, null);
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setDialogButtonColorKey(Theme.key_voipgroup_listeningText);
TextView messageTextView = new TextView(getContext());
messageTextView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
FrameLayout frameLayout = new FrameLayout(getContext());
builder.setView(frameLayout);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
BackupImageView imageView = new BackupImageView(getContext());
imageView.setRoundRadius(AndroidUtilities.dp(20));
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
avatarDrawable.setInfo(object);
String name;
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
imageView.setForUserOrChat(user, avatarDrawable);
name = UserObject.getFirstName(user);
} else {
TLRPC.Chat chat = (TLRPC.Chat) object;
imageView.setForUserOrChat(chat, avatarDrawable);
name = chat.title;
}
TextView textView = new TextView(getContext());
textView.setTextColor(Theme.getColor(Theme.key_voipgroup_actionBarItems));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
if (option == 2) {
textView.setText(LocaleController.getString("VoipGroupRemoveMemberAlertTitle2", R.string.VoipGroupRemoveMemberAlertTitle2));
if (ChatObject.isChannelOrGiga(currentChat)) {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipChannelRemoveMemberAlertText2", R.string.VoipChannelRemoveMemberAlertText2, name, currentChat.title)));
} else {
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupRemoveMemberAlertText2", R.string.VoipGroupRemoveMemberAlertText2, name, currentChat.title)));
}
} else {
textView.setText(LocaleController.getString("VoipGroupAddMemberTitle", R.string.VoipGroupAddMemberTitle));
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("VoipGroupAddMemberText", R.string.VoipGroupAddMemberText, name, currentChat.title)));
}
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
if (option == 2) {
builder.setPositiveButton(LocaleController.getString("VoipGroupUserRemove", R.string.VoipGroupUserRemove), (dialogInterface, i) -> {
if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, user, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, user, null, null, null);
} else {
TLRPC.Chat chat = (TLRPC.Chat) object;
accountInstance.getMessagesController().deleteParticipantFromChat(currentChat.id, null, chat, null, false, false);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_REMOVED, chat, null, null, null);
}
});
} else if (object instanceof TLRPC.User) {
TLRPC.User user = (TLRPC.User) object;
builder.setPositiveButton(LocaleController.getString("VoipGroupAdd", R.string.VoipGroupAdd), (dialogInterface, i) -> {
BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
accountInstance.getMessagesController().addUserToChat(currentChat.id, user, 0, null, fragment, () -> inviteUserToCall(peerId, false));
});
}
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
AlertDialog dialog = builder.create();
dialog.setBackgroundColor(Theme.getColor(Theme.key_voipgroup_dialogBackground));
dialog.show();
if (option == 2) {
TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_voipgroup_leaveCallMenu));
}
}
} else if (option == 6) {
parentActivity.switchToAccount(currentAccount, true);
Bundle args = new Bundle();
if (peerId > 0) {
args.putLong("user_id", peerId);
} else {
args.putLong("chat_id", -peerId);
}
parentActivity.presentFragment(new ChatActivity(args));
dismiss();
} else if (option == 8) {
parentActivity.switchToAccount(currentAccount, true);
BaseFragment fragment = parentActivity.getActionBarLayout().fragmentsStack.get(parentActivity.getActionBarLayout().fragmentsStack.size() - 1);
if (fragment instanceof ChatActivity) {
if (((ChatActivity) fragment).getDialogId() == peerId) {
dismiss();
return;
}
}
Bundle args = new Bundle();
if (peerId > 0) {
args.putLong("user_id", peerId);
} else {
args.putLong("chat_id", -peerId);
}
parentActivity.presentFragment(new ChatActivity(args));
dismiss();
} else if (option == 7) {
voIPService.editCallMember(object, true, null, null, false, null);
updateMuteButton(MUTE_BUTTON_STATE_MUTED_BY_ADMIN, true);
} else if (option == 9) {
if (currentAvatarUpdater != null && currentAvatarUpdater.isUploadingImage()) {
return;
}
currentAvatarUpdater = new ImageUpdater(true);
currentAvatarUpdater.setOpenWithFrontfaceCamera(true);
currentAvatarUpdater.setForceDarkTheme(true);
currentAvatarUpdater.setSearchAvailable(true, true);
currentAvatarUpdater.setShowingFromDialog(true);
currentAvatarUpdater.parentFragment = parentActivity.getActionBarLayout().getLastFragment();
currentAvatarUpdater.setDelegate(avatarUpdaterDelegate = new AvatarUpdaterDelegate(peerId));
TLRPC.User user = accountInstance.getUserConfig().getCurrentUser();
currentAvatarUpdater.openMenu(user.photo != null && user.photo.photo_big != null && !(user.photo instanceof TLRPC.TL_userProfilePhotoEmpty), () -> accountInstance.getMessagesController().deleteUserPhoto(null), dialog -> {
});
} else if (option == 10) {
AlertsCreator.createChangeBioAlert(participant.about, peerId, getContext(), currentAccount);
} else if (option == 11) {
AlertsCreator.createChangeNameAlert(peerId, getContext(), currentAccount);
} else {
if (option == 5) {
voIPService.editCallMember(object, true, null, null, null, null);
getUndoView().showWithAction(0, UndoView.ACTION_VOIP_MUTED_FOR_YOU, object);
voIPService.setParticipantVolume(participant, 0);
} else {
if ((participant.flags & 128) != 0 && participant.volume == 0) {
participant.volume = 10000;
participant.volume_by_admin = false;
voIPService.editCallMember(object, false, null, participant.volume, null, null);
} else {
voIPService.editCallMember(object, false, null, null, null, null);
}
voIPService.setParticipantVolume(participant, ChatObject.getParticipantVolume(participant));
getUndoView().showWithAction(0, option == 1 ? UndoView.ACTION_VOIP_UNMUTED : UndoView.ACTION_VOIP_UNMUTED_FOR_YOU, object, null, null, null);
}
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class FilterCreateActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
ActionBarMenu menu = actionBar.createMenu();
if (creatingNew) {
actionBar.setTitle(LocaleController.getString("FilterNew", R.string.FilterNew));
} else {
TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(AndroidUtilities.dp(20));
actionBar.setTitle(Emoji.replaceEmoji(filter.name, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false));
}
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
if (checkDiscard()) {
finishFragment();
}
} else if (id == done_button) {
processDone();
}
}
});
doneItem = menu.addItem(done_button, LocaleController.getString("Save", R.string.Save).toUpperCase());
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
listView = new RecyclerListView(context) {
@Override
public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
return false;
}
};
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
listView.setVerticalScrollBarEnabled(false);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(adapter = new ListAdapter(context));
listView.setOnItemClickListener((view, position) -> {
if (getParentActivity() == null) {
return;
}
if (position == includeShowMoreRow) {
includeExpanded = true;
updateRows();
} else if (position == excludeShowMoreRow) {
excludeExpanded = true;
updateRows();
} else if (position == includeAddRow || position == excludeAddRow) {
ArrayList<Long> arrayList = position == excludeAddRow ? newNeverShow : newAlwaysShow;
FilterUsersActivity fragment = new FilterUsersActivity(position == includeAddRow, arrayList, newFilterFlags);
fragment.setDelegate((ids, flags) -> {
newFilterFlags = flags;
if (position == excludeAddRow) {
newNeverShow = ids;
for (int a = 0; a < newNeverShow.size(); a++) {
Long id = newNeverShow.get(a);
newAlwaysShow.remove(id);
newPinned.delete(id);
}
} else {
newAlwaysShow = ids;
for (int a = 0; a < newAlwaysShow.size(); a++) {
newNeverShow.remove(newAlwaysShow.get(a));
}
ArrayList<Long> toRemove = new ArrayList<>();
for (int a = 0, N = newPinned.size(); a < N; a++) {
Long did = newPinned.keyAt(a);
if (DialogObject.isEncryptedDialog(did)) {
continue;
}
if (newAlwaysShow.contains(did)) {
continue;
}
toRemove.add(did);
}
for (int a = 0, N = toRemove.size(); a < N; a++) {
newPinned.delete(toRemove.get(a));
}
}
fillFilterName();
checkDoneButton(false);
updateRows();
});
presentFragment(fragment);
} else if (position == removeRow) {
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setTitle(LocaleController.getString("FilterDelete", R.string.FilterDelete));
builder.setMessage(LocaleController.getString("FilterDeleteAlert", R.string.FilterDeleteAlert));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog, which) -> {
AlertDialog progressDialog = null;
if (getParentActivity() != null) {
progressDialog = new AlertDialog(getParentActivity(), 3);
progressDialog.setCanCacnel(false);
progressDialog.show();
}
final AlertDialog progressDialogFinal = progressDialog;
TLRPC.TL_messages_updateDialogFilter req = new TLRPC.TL_messages_updateDialogFilter();
req.id = filter.id;
getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
if (progressDialogFinal != null) {
progressDialogFinal.dismiss();
}
} catch (Exception e) {
FileLog.e(e);
}
getMessagesController().removeFilter(filter);
getMessagesStorage().deleteDialogFilter(filter);
finishFragment();
}));
});
AlertDialog alertDialog = builder.create();
showDialog(alertDialog);
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
if (button != null) {
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
}
} else if (position == nameRow) {
PollEditTextCell cell = (PollEditTextCell) view;
cell.getTextView().requestFocus();
AndroidUtilities.showKeyboard(cell.getTextView());
} else if (view instanceof UserCell) {
UserCell cell = (UserCell) view;
showRemoveAlert(position, cell.getName(), cell.getCurrentObject(), position < includeSectionRow);
}
});
listView.setOnItemLongClickListener((view, position) -> {
if (view instanceof UserCell) {
UserCell cell = (UserCell) view;
showRemoveAlert(position, cell.getName(), cell.getCurrentObject(), position < includeSectionRow);
return true;
}
return false;
});
checkDoneButton(false);
return fragmentView;
}
Aggregations