use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemeActivity method didReceivedNotification.
@Override
public void didReceivedNotification(int id, int account, Object... args) {
if (id == NotificationCenter.locationPermissionGranted) {
updateSunTime(null, true);
} else if (id == NotificationCenter.didSetNewWallpapper || id == NotificationCenter.emojiLoaded) {
if (listView != null) {
listView.invalidateViews();
}
updateMenuItem();
} else if (id == NotificationCenter.themeAccentListUpdated) {
if (listAdapter != null && themeAccentListRow != -1) {
listAdapter.notifyItemChanged(themeAccentListRow, new Object());
}
} else if (id == NotificationCenter.themeListUpdated) {
updateRows(true);
} else if (id == NotificationCenter.themeUploadedToServer) {
Theme.ThemeInfo themeInfo = (Theme.ThemeInfo) args[0];
Theme.ThemeAccent accent = (Theme.ThemeAccent) args[1];
if (themeInfo == sharingTheme && accent == sharingAccent) {
String link = "https://" + getMessagesController().linkPrefix + "/addtheme/" + (accent != null ? accent.info.slug : themeInfo.info.slug);
showDialog(new ShareAlert(getParentActivity(), null, link, false, link, false));
if (sharingProgressDialog != null) {
sharingProgressDialog.dismiss();
}
}
} else if (id == NotificationCenter.themeUploadError) {
Theme.ThemeInfo themeInfo = (Theme.ThemeInfo) args[0];
Theme.ThemeAccent accent = (Theme.ThemeAccent) args[1];
if (themeInfo == sharingTheme && accent == sharingAccent && sharingProgressDialog == null) {
sharingProgressDialog.dismiss();
}
} else if (id == NotificationCenter.needShareTheme) {
if (getParentActivity() == null || isPaused) {
return;
}
sharingTheme = (Theme.ThemeInfo) args[0];
sharingAccent = (Theme.ThemeAccent) args[1];
sharingProgressDialog = new AlertDialog(getParentActivity(), 3);
sharingProgressDialog.setCanCacnel(true);
showDialog(sharingProgressDialog, dialog -> {
sharingProgressDialog = null;
sharingTheme = null;
sharingAccent = null;
});
} else if (id == NotificationCenter.needSetDayNightTheme) {
updateMenuItem();
checkCurrentDayNight();
} else if (id == NotificationCenter.emojiPreviewThemesChanged) {
if (themeListRow2 >= 0) {
listAdapter.notifyItemChanged(themeListRow2);
}
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaController method saveFile.
public static void saveFile(String fullPath, Context context, final int type, final String name, final String mime, final Runnable onSaved) {
if (fullPath == null || context == null) {
return;
}
File file = null;
if (!TextUtils.isEmpty(fullPath)) {
file = new File(fullPath);
if (!file.exists() || AndroidUtilities.isInternalUri(Uri.fromFile(file))) {
file = null;
}
}
if (file == null) {
return;
}
final File sourceFile = file;
final boolean[] cancelled = new boolean[] { false };
if (sourceFile.exists()) {
AlertDialog progressDialog = null;
final boolean[] finished = new boolean[1];
if (context != null && type != 0) {
try {
final AlertDialog dialog = new AlertDialog(context, 2);
dialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(true);
dialog.setOnCancelListener(d -> cancelled[0] = true);
AndroidUtilities.runOnUIThread(() -> {
if (!finished[0]) {
dialog.show();
}
}, 250);
progressDialog = dialog;
} catch (Exception e) {
FileLog.e(e);
}
}
final AlertDialog finalProgress = progressDialog;
new Thread(() -> {
try {
boolean result = true;
if (Build.VERSION.SDK_INT >= 29) {
result = saveFileInternal(type, sourceFile, null);
} else {
File destFile;
if (type == 0) {
destFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Telegram");
destFile.mkdirs();
destFile = new File(destFile, AndroidUtilities.generateFileName(0, FileLoader.getFileExtension(sourceFile)));
} else if (type == 1) {
destFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "Telegram");
destFile.mkdirs();
destFile = new File(destFile, AndroidUtilities.generateFileName(1, FileLoader.getFileExtension(sourceFile)));
} else {
File dir;
if (type == 2) {
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
} else {
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
}
dir = new File(dir, "Telegram");
dir.mkdirs();
destFile = new File(dir, name);
if (destFile.exists()) {
int idx = name.lastIndexOf('.');
for (int a = 0; a < 10; a++) {
String newName;
if (idx != -1) {
newName = name.substring(0, idx) + "(" + (a + 1) + ")" + name.substring(idx);
} else {
newName = name + "(" + (a + 1) + ")";
}
destFile = new File(dir, newName);
if (!destFile.exists()) {
break;
}
}
}
}
if (!destFile.exists()) {
destFile.createNewFile();
}
long lastProgress = System.currentTimeMillis() - 500;
try (FileInputStream inputStream = new FileInputStream(sourceFile);
FileChannel source = inputStream.getChannel();
FileChannel destination = new FileOutputStream(destFile).getChannel()) {
long size = source.size();
try {
@SuppressLint("DiscouragedPrivateApi") Method getInt = FileDescriptor.class.getDeclaredMethod("getInt$");
int fdint = (Integer) getInt.invoke(inputStream.getFD());
if (AndroidUtilities.isInternalUri(fdint)) {
if (finalProgress != null) {
AndroidUtilities.runOnUIThread(() -> {
try {
finalProgress.dismiss();
} catch (Exception e) {
FileLog.e(e);
}
});
}
return;
}
} catch (Throwable e) {
FileLog.e(e);
}
for (long a = 0; a < size; a += 4096) {
if (cancelled[0]) {
break;
}
destination.transferFrom(source, a, Math.min(4096, size - a));
if (finalProgress != null) {
if (lastProgress <= System.currentTimeMillis() - 500) {
lastProgress = System.currentTimeMillis();
final int progress = (int) ((float) a / (float) size * 100);
AndroidUtilities.runOnUIThread(() -> {
try {
finalProgress.setProgress(progress);
} catch (Exception e) {
FileLog.e(e);
}
});
}
}
}
} catch (Exception e) {
FileLog.e(e);
result = false;
}
if (cancelled[0]) {
destFile.delete();
result = false;
}
if (result) {
if (type == 2) {
DownloadManager downloadManager = (DownloadManager) ApplicationLoader.applicationContext.getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.addCompletedDownload(destFile.getName(), destFile.getName(), false, mime, destFile.getAbsolutePath(), destFile.length(), true);
} else {
AndroidUtilities.addMediaToGallery(destFile.getAbsoluteFile());
}
}
}
if (result && onSaved != null) {
AndroidUtilities.runOnUIThread(onSaved);
}
} catch (Exception e) {
FileLog.e(e);
}
if (finalProgress != null) {
AndroidUtilities.runOnUIThread(() -> {
try {
if (finalProgress.isShowing()) {
finalProgress.dismiss();
} else {
finished[0] = true;
}
} catch (Exception e) {
FileLog.e(e);
}
});
}
}).start();
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickersAlert method showNameEnterAlert.
private void showNameEnterAlert() {
Context context = getContext();
int[] state = new int[] { 0 };
FrameLayout fieldLayout = new FrameLayout(context);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(LocaleController.getString("ImportStickersEnterName", R.string.ImportStickersEnterName));
builder.setPositiveButton(LocaleController.getString("Next", R.string.Next), (dialog, which) -> {
});
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
linearLayout.addView(fieldLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
TextView message = new TextView(context);
TextView textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
textView.setTextColor(getThemedColor(Theme.key_dialogTextHint));
textView.setMaxLines(1);
textView.setLines(1);
textView.setText("t.me/addstickers/");
textView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
textView.setGravity(Gravity.LEFT | Gravity.TOP);
textView.setSingleLine(true);
textView.setVisibility(View.INVISIBLE);
textView.setImeOptions(EditorInfo.IME_ACTION_DONE);
textView.setPadding(0, AndroidUtilities.dp(4), 0, 0);
fieldLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.LEFT));
EditTextBoldCursor editText = new EditTextBoldCursor(context);
editText.setBackgroundDrawable(Theme.createEditTextDrawable(context, true));
editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
editText.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
editText.setMaxLines(1);
editText.setLines(1);
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
editText.setGravity(Gravity.LEFT | Gravity.TOP);
editText.setSingleLine(true);
editText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
editText.setCursorColor(getThemedColor(Theme.key_windowBackgroundWhiteBlackText));
editText.setCursorSize(AndroidUtilities.dp(20));
editText.setCursorWidth(1.5f);
editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (state[0] != 2) {
return;
}
checkUrlAvailable(message, editText.getText().toString(), false);
}
@Override
public void afterTextChanged(Editable s) {
}
});
fieldLayout.addView(editText, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT));
editText.setOnEditorActionListener((view, i, keyEvent) -> {
if (i == EditorInfo.IME_ACTION_NEXT) {
builder.create().getButton(AlertDialog.BUTTON_POSITIVE).callOnClick();
return true;
}
return false;
});
editText.setSelection(editText.length());
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (dialog, which) -> AndroidUtilities.hideKeyboard(editText));
message.setText(AndroidUtilities.replaceTags(LocaleController.getString("ImportStickersEnterNameInfo", R.string.ImportStickersEnterNameInfo)));
message.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23), AndroidUtilities.dp(6));
message.setTextColor(getThemedColor(Theme.key_dialogTextGray2));
linearLayout.addView(message, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
editText.requestFocus();
AndroidUtilities.showKeyboard(editText);
}));
alertDialog.show();
editText.requestFocus();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
if (state[0] == 1) {
return;
}
if (state[0] == 0) {
state[0] = 1;
TLRPC.TL_stickers_suggestShortName req = new TLRPC.TL_stickers_suggestShortName();
req.title = setTitle = editText.getText().toString();
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
boolean set = false;
if (response instanceof TLRPC.TL_stickers_suggestedShortName) {
TLRPC.TL_stickers_suggestedShortName res = (TLRPC.TL_stickers_suggestedShortName) response;
if (res.short_name != null) {
editText.setText(res.short_name);
editText.setSelection(0, editText.length());
checkUrlAvailable(message, editText.getText().toString(), true);
set = true;
}
}
textView.setVisibility(View.VISIBLE);
editText.setPadding(textView.getMeasuredWidth(), AndroidUtilities.dp(4), 0, 0);
if (!set) {
editText.setText("");
}
state[0] = 2;
}));
} else if (state[0] == 2) {
state[0] = 3;
if (!lastNameAvailable) {
AndroidUtilities.shakeView(editText, 2, 0);
editText.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
AndroidUtilities.hideKeyboard(editText);
SendMessagesHelper.getInstance(currentAccount).prepareImportStickers(setTitle, lastCheckName, importingSoftware, importingStickersPaths, (param) -> {
ImportingAlert importingAlert = new ImportingAlert(getContext(), lastCheckName, null, resourcesProvider);
importingAlert.show();
});
builder.getDismissRunnable().run();
dismiss();
}
});
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method didPressMessageUrl.
private void didPressMessageUrl(CharacterStyle url, boolean longPress, MessageObject messageObject, ChatMessageCell cell) {
if (url == null || getParentActivity() == null) {
return;
}
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
if (url instanceof URLSpanMono) {
if (!noforwards) {
((URLSpanMono) url).copyToClipboard();
getUndoView().showWithAction(0, UndoView.ACTION_TEXT_COPIED, null);
}
} else if (url instanceof URLSpanUserMention) {
TLRPC.User user = getMessagesController().getUser(Utilities.parseLong(((URLSpanUserMention) url).getURL()));
if (user != null) {
MessagesController.openChatOrProfileWith(user, null, ChatActivity.this, 0, false);
}
} else if (url instanceof URLSpanNoUnderline) {
String str = ((URLSpanNoUnderline) url).getURL();
if (messageObject != null && str.startsWith("/")) {
if (URLSpanBotCommand.enabled) {
chatActivityEnterView.setCommand(messageObject, str, longPress, currentChat != null && currentChat.megagroup);
if (!longPress && chatActivityEnterView.getFieldText() == null) {
hideFieldPanel(false);
}
}
} else if (messageObject != null && str.startsWith("video") && !longPress) {
int seekTime = Utilities.parseInt(str);
TLRPC.WebPage webPage;
if (messageObject.isYouTubeVideo()) {
webPage = messageObject.messageOwner.media.webpage;
} else if (messageObject.replyMessageObject != null && messageObject.replyMessageObject.isYouTubeVideo()) {
webPage = messageObject.replyMessageObject.messageOwner.media.webpage;
messageObject = messageObject.replyMessageObject;
} else {
webPage = null;
}
if (webPage != null) {
EmbedBottomSheet.show(getParentActivity(), messageObject, photoViewerProvider, webPage.site_name, webPage.title, webPage.url, webPage.embed_url, webPage.embed_width, webPage.embed_height, seekTime, isKeyboardVisible());
} else {
if (!messageObject.isVideo() && messageObject.replyMessageObject != null) {
MessageObject obj = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
cell = null;
if (obj == null) {
messageObject = messageObject.replyMessageObject;
} else {
messageObject = obj;
}
}
messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
openPhotoViewerForMessage(cell, messageObject);
}
} else if (messageObject != null && str.startsWith("audio")) {
int seekTime = Utilities.parseInt(str);
if (!messageObject.isMusic() && messageObject.replyMessageObject != null) {
messageObject = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
}
float progress = seekTime / (float) messageObject.getDuration();
MediaController mediaController = getMediaController();
if (mediaController.isPlayingMessage(messageObject)) {
messageObject.audioProgress = progress;
mediaController.seekToProgress(messageObject, progress);
if (mediaController.isMessagePaused()) {
mediaController.playMessage(messageObject);
}
} else {
messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
mediaController.playMessage(messageObject);
}
} else if (str.startsWith("card:")) {
String number = str.substring(5);
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
TLRPC.TL_payments_getBankCardData req = new TLRPC.TL_payments_getBankCardData();
req.number = number;
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
if (response instanceof TLRPC.TL_payments_bankCardData) {
if (getParentActivity() == null) {
return;
}
TLRPC.TL_payments_bankCardData data = (TLRPC.TL_payments_bankCardData) response;
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
ArrayList<CharSequence> arrayList = new ArrayList<>();
for (int a = 0, N = data.open_urls.size(); a < N; a++) {
arrayList.add(data.open_urls.get(a).name);
}
arrayList.add(LocaleController.getString("CopyCardNumber", R.string.CopyCardNumber));
builder.setTitle(data.title);
builder.setItems(arrayList.toArray(new CharSequence[0]), (dialog, which) -> {
if (which < data.open_urls.size()) {
Browser.openUrl(getParentActivity(), data.open_urls.get(which).url, inlineReturn == 0, false);
} else {
AndroidUtilities.addToClipboard(number);
Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("CardNumberCopied", R.string.CardNumberCopied), Toast.LENGTH_SHORT).show();
}
});
showDialog(builder.create());
}
}), null, null, 0, getMessagesController().webFileDatacenterId, ConnectionsManager.ConnectionTypeGeneric, true);
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
} else {
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
int timestamp = -1;
if (str.startsWith("video?")) {
timestamp = Utilities.parseInt(str);
}
if (timestamp >= 0) {
builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
} else {
builder.setTitle(str);
}
final int finalTimestamp = timestamp;
ChatMessageCell finalCell = cell;
MessageObject finalMessageObject = messageObject;
builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
if (which == 0) {
if (str.startsWith("video?")) {
didPressMessageUrl(url, false, finalMessageObject, finalCell);
} else {
openClickableLink(str);
}
} else if (which == 1) {
if (str.startsWith("video?") && finalMessageObject != null && !finalMessageObject.scheduled) {
MessageObject messageObject1 = finalMessageObject;
boolean isMedia = finalMessageObject.isVideo() || finalMessageObject.isRoundVideo() || finalMessageObject.isVoice() || finalMessageObject.isMusic();
if (!isMedia && finalMessageObject.replyMessageObject != null) {
messageObject1 = finalMessageObject.replyMessageObject;
}
long dialogId = messageObject1.getDialogId();
int messageId = messageObject1.getId();
String link = null;
if (messageObject1.messageOwner.fwd_from != null) {
if (messageObject1.messageOwner.fwd_from.saved_from_peer != null) {
dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.saved_from_peer);
messageId = messageObject1.messageOwner.fwd_from.saved_from_msg_id;
} else if (messageObject1.messageOwner.fwd_from.from_id != null) {
dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.from_id);
messageId = messageObject1.messageOwner.fwd_from.channel_post;
}
}
if (DialogObject.isChatDialog(dialogId)) {
TLRPC.Chat currentChat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
if (currentChat != null && currentChat.username != null) {
link = "https://t.me/" + currentChat.username + "/" + messageId + "?t=" + finalTimestamp;
}
} else {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(dialogId);
if (user != null && user.username != null) {
link = "https://t.me/" + user.username + "/" + messageId + "?t=" + finalTimestamp;
}
}
if (link == null) {
return;
}
AndroidUtilities.addToClipboard(link);
} else {
AndroidUtilities.addToClipboard(str);
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
}
});
showDialog(builder.create());
} else {
openClickableLink(str);
}
}
} else {
final String urlFinal = ((URLSpan) url).getURL();
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
builder.setTitle(urlFinal);
builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
if (which == 0) {
processExternalUrl(1, urlFinal, false);
} else if (which == 1) {
String url1 = urlFinal;
boolean tel = false;
boolean mail = false;
if (url1.startsWith("mailto:")) {
url1 = url1.substring(7);
mail = true;
} else if (url1.startsWith("tel:")) {
url1 = url1.substring(4);
tel = true;
}
AndroidUtilities.addToClipboard(url1);
if (mail) {
undoView.showWithAction(0, UndoView.ACTION_EMAIL_COPIED, null);
} else if (tel) {
undoView.showWithAction(0, UndoView.ACTION_PHONE_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
}
});
showDialog(builder.create());
} else {
boolean forceAlert = url instanceof URLSpanReplacement;
if (url instanceof URLSpanReplacement && (urlFinal == null || !urlFinal.startsWith("mailto:")) || AndroidUtilities.shouldShowUrlInAlert(urlFinal)) {
if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
return;
}
forceAlert = true;
} else {
if (messageObject != null && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage != null && messageObject.messageOwner.media.webpage.cached_page != null) {
String lowerUrl = urlFinal.toLowerCase();
String lowerUrl2 = messageObject.messageOwner.media.webpage.url.toLowerCase();
if ((lowerUrl.contains("telegram.org/blog") || Browser.isTelegraphUrl(lowerUrl, false) || lowerUrl.contains("t.me/iv")) && (lowerUrl.contains(lowerUrl2) || lowerUrl2.contains(lowerUrl))) {
ArticleViewer.getInstance().setParentActivity(getParentActivity(), ChatActivity.this);
ArticleViewer.getInstance().open(messageObject);
return;
}
}
if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
return;
}
}
if (Browser.urlMustNotHaveConfirmation(urlFinal)) {
forceAlert = false;
}
processExternalUrl(2, urlFinal, forceAlert);
}
}
}
use of org.telegram.ui.ActionBar.AlertDialog in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method scrollToMessageId.
public void scrollToMessageId(int id, int fromMessageId, boolean select, int loadIndex, boolean forceScroll, int forcePinnedMessageId) {
if (id == 0 || NotificationCenter.getInstance(currentAccount).isAnimationInProgress() || getParentActivity() == null) {
if (NotificationCenter.getInstance(currentAccount).isAnimationInProgress()) {
nextScrollToMessageId = id;
nextScrollFromMessageId = fromMessageId;
nextScrollSelect = select;
nextScrollLoadIndex = loadIndex;
nextScrollForce = forceScroll;
nextScrollForcePinnedMessageId = forcePinnedMessageId;
NotificationCenter.getInstance(currentAccount).doOnIdle(() -> {
if (nextScrollToMessageId != 0) {
scrollToMessageId(nextScrollToMessageId, nextScrollFromMessageId, nextScrollSelect, nextScrollLoadIndex, nextScrollForce, nextScrollForcePinnedMessageId);
nextScrollToMessageId = 0;
}
});
}
return;
}
forceNextPinnedMessageId = Math.abs(forcePinnedMessageId);
forceScrollToFirst = forcePinnedMessageId > 0;
wasManualScroll = true;
MessageObject object = messagesDict[loadIndex].get(id);
boolean query = false;
int scrollDirection = RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UNSET;
int scrollFromIndex = 0;
if (fromMessageId != 0) {
boolean scrollDown = fromMessageId < id;
if (isSecretChat()) {
scrollDown = !scrollDown;
}
scrollDirection = scrollDown ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
} else if (messages.size() > 0) {
if (isThreadChat() && id == threadMessageId) {
scrollDirection = RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
} else {
int end = chatLayoutManager.findLastVisibleItemPosition();
for (int i = chatLayoutManager.findFirstVisibleItemPosition(); i <= end; i++) {
if (i >= chatAdapter.messagesStartRow && i <= chatAdapter.messagesEndRow) {
MessageObject messageObject = messages.get(i - chatAdapter.messagesStartRow);
if (messageObject.getId() == 0) {
continue;
}
scrollFromIndex = i - chatAdapter.messagesStartRow;
boolean scrollDown = messageObject.getId() < id;
if (isSecretChat()) {
scrollDown = !scrollDown;
}
scrollDirection = scrollDown ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
break;
}
}
}
}
chatScrollHelper.setScrollDirection(scrollDirection);
if (object != null) {
MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(object.getGroupId());
if (object.getGroupId() != 0 && groupedMessages != null) {
MessageObject primary = groupedMessages.findPrimaryMessageObject();
if (primary != null) {
object = primary;
}
}
int index = messages.indexOf(object);
if (index != -1) {
if (scrollFromIndex > 0) {
scrollDirection = scrollFromIndex > index ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
chatScrollHelper.setScrollDirection(scrollDirection);
}
removeSelectedMessageHighlight();
if (select) {
highlightMessageId = id;
}
chatAdapter.updateRowsSafe();
int position = chatAdapter.messagesStartRow + messages.indexOf(object);
updateVisibleRows();
boolean found = false;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
found = true;
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
found = true;
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
}
if (found) {
int yOffset = getScrollOffsetForMessage(object);
int scrollY = (int) (view.getTop() - chatListViewPaddingTop - yOffset);
int maxScrollOffset = chatListView.computeVerticalScrollRange() - chatListView.computeVerticalScrollOffset() - chatListView.computeVerticalScrollExtent();
if (maxScrollOffset < 0)
maxScrollOffset = 0;
if (scrollY > maxScrollOffset) {
scrollY = maxScrollOffset;
}
if (scrollY != 0) {
scrollByTouch = false;
chatListView.smoothScrollBy(0, scrollY);
chatListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
}
break;
}
}
if (!found) {
int yOffset = getScrollOffsetForMessage(object);
chatScrollHelperCallback.scrollTo = object;
chatScrollHelperCallback.lastBottom = false;
chatScrollHelperCallback.lastItemOffset = yOffset;
chatScrollHelperCallback.lastPadding = (int) chatListViewPaddingTop;
chatScrollHelper.setScrollDirection(scrollDirection);
chatScrollHelper.scrollToPosition(position, yOffset, false, true);
canShowPagedownButton = true;
updatePagedownButtonVisibility(true);
}
} else {
query = true;
}
} else {
query = true;
}
if (query) {
if (isThreadChat() && id == threadMessageId) {
scrollToThreadMessage = true;
id = 1;
}
if (progressDialog != null) {
progressDialog.dismiss();
}
showPinnedProgress(forceNextPinnedMessageId != 0);
progressDialog = new AlertDialog(getParentActivity(), 3, themeDelegate);
progressDialog.setOnShowListener(dialogInterface -> showPinnedProgress(false));
progressDialog.setOnCancelListener(postponedScrollCancelListener);
progressDialog.showDelayed(400);
waitingForLoad.clear();
removeSelectedMessageHighlight();
scrollToMessagePosition = -10000;
startLoadFromMessageId = id;
showScrollToMessageError = !forceScroll;
if (id == createUnreadMessageAfterId) {
createUnreadMessageAfterIdLoading = true;
}
postponedScrollIsCanceled = false;
waitingForLoad.add(lastLoadIndex);
postponedScrollToLastMessageQueryIndex = lastLoadIndex;
postponedScrollMinMessageId = minMessageId[0];
postponedScrollMessageId = id;
getMessagesController().loadMessages(loadIndex == 0 ? dialog_id : mergeDialogId, 0, false, isThreadChat() || AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, 0, true, 0, classGuid, 3, 0, chatMode, threadMessageId, replyMaxReadId, lastLoadIndex++);
} else {
View child = chatListView.getChildAt(0);
if (child != null && child.getTop() <= 0) {
showFloatingDateView(false);
}
}
returnToMessageId = fromMessageId;
returnToLoadIndex = loadIndex;
needSelectFromMessageId = select;
}
Aggregations