From cc1dc35742f9ed21587e464cea5233bf201a2b2d Mon Sep 17 00:00:00 2001 From: DrKLO Date: Tue, 31 Dec 2019 22:46:59 +0300 Subject: [PATCH] Update to 5.13.0 (1819) --- TMessagesProj/build.gradle | 2 +- .../jni/tgnet/ConnectionsManager.cpp | 8 ++- .../org/telegram/messenger/BuildVars.java | 2 +- .../org/telegram/messenger/EmojiData.java | 2 +- .../telegram/messenger/MediaController.java | 49 +++++++------ .../org/telegram/messenger/MessageObject.java | 2 +- .../messenger/MessagesController.java | 11 +-- .../telegram/messenger/browser/Browser.java | 2 +- .../video/MediaCodecVideoConvertor.java | 48 +------------ .../org/telegram/ui/ActionBar/ActionBar.java | 3 +- .../java/org/telegram/ui/ActionBar/Theme.java | 10 ++- .../org/telegram/ui/ActionIntroActivity.java | 3 + .../java/org/telegram/ui/ArticleViewer.java | 10 +-- .../ui/Cells/TextSelectionHelper.java | 70 +++++++++++++++---- .../telegram/ui/Components/AlertsCreator.java | 3 + .../ui/Components/Crop/CropAreaView.java | 4 +- .../ui/Components/EditTextBoldCursor.java | 4 +- .../ui/Components/ScrollSlidingTabStrip.java | 8 +++ .../ui/DialogOrContactPickerActivity.java | 8 ++- .../java/org/telegram/ui/DialogsActivity.java | 7 +- .../org/telegram/ui/LocationActivity.java | 22 +++--- .../java/org/telegram/ui/PhotoViewer.java | 3 + .../telegram/ui/ProxySettingsActivity.java | 8 ++- .../java/org/telegram/ui/ThemeActivity.java | 6 +- 24 files changed, 175 insertions(+), 120 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 843769c0a..11ac42293 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -283,7 +283,7 @@ android { } } - defaultConfig.versionCode = 1818 + defaultConfig.versionCode = 1819 applicationVariants.all { variant -> variant.outputs.all { output -> diff --git a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp index 2a3fed418..23ebc1621 100644 --- a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp +++ b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp @@ -1440,10 +1440,11 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag TL_bad_server_salt *response = (TL_bad_server_salt *) message; int64_t resultMid = response->bad_msg_id; if (resultMid != 0) { + bool beginHandshake = false; for (requestsIter iter = runningRequests.begin(); iter != runningRequests.end(); iter++) { Request *request = iter->get(); - if (request->datacenterId == datacenter->datacenterId && typeid(*request->rawRequest) == typeid(TL_auth_bindTempAuthKey) && request->respondsToMessageId(response->bad_msg_id)) { - datacenter->beginHandshake(HandshakeTypeCurrent, false); + if (!beginHandshake && request->datacenterId == datacenter->datacenterId && typeid(*request->rawRequest) == typeid(TL_auth_bindTempAuthKey) && request->respondsToMessageId(response->bad_msg_id)) { + beginHandshake = true; } if ((request->connectionType & ConnectionTypeDownload) == 0) { continue; @@ -1454,6 +1455,9 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag request->failedBySalt = true; } } + if (beginHandshake) { + datacenter->beginHandshake(HandshakeTypeCurrent, false); + } } datacenter->clearServerSalts(media); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index c704e7d68..400df7919 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -19,7 +19,7 @@ public class BuildVars { public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; public static boolean TON_WALLET_STANDALONE = false; - public static int BUILD_VERSION = 1818; + public static int BUILD_VERSION = 1819; public static String BUILD_VERSION_STRING = "5.13.0"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/EmojiData.java b/TMessagesProj/src/main/java/org/telegram/messenger/EmojiData.java index 679508a26..0dc20fc61 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/EmojiData.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/EmojiData.java @@ -24,7 +24,7 @@ public class EmojiData { 0x2197, 0x2198, 0x2199, 0x2196, 0x2195, 0x2194, 0x21AA, 0x21A9, 0x2934, 0x2935, 0x2139, 0x2714, 0x2716, 0x2611, 0x26AA, 0x26AB, 0x25AA, 0x25AB, 0x2B1B, 0x2B1C, 0x25FC, 0x25FB, 0x25FE, 0x25FD, 0x2660, 0x2663, 0x2665, 0x2666, 0x263A, 0x2639, - 0x270C, 0x261D, 0x2764 + 0x270C, 0x261D, 0x2764, 0x2603 }; public static final char[] dataChars = { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index 1850d3e3a..fca0133a8 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -1388,7 +1388,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, countLess = 0; } else if (proximityTouched) { if (playingMessageObject != null && !ApplicationLoader.mainInterfacePaused && (playingMessageObject.isVoice() || playingMessageObject.isRoundVideo())) { - if (!useFrontSpeaker && NotificationsController.audioManager.isWiredHeadsetOn()) { + if (!useFrontSpeaker && !NotificationsController.audioManager.isWiredHeadsetOn()) { if (BuildVars.LOGS_ENABLED) { FileLog.d("start listen by proximity only"); } @@ -3521,7 +3521,9 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, if (!videoConvertQueue.isEmpty()) { MessageObject messageObject = videoConvertQueue.get(0); synchronized (videoConvertSync) { - messageObject.videoEditedInfo.canceled = false; + if (messageObject != null && messageObject.videoEditedInfo != null) { + messageObject.videoEditedInfo.canceled = false; + } } Intent intent = new Intent(ApplicationLoader.applicationContext, VideoEncodingService.class); intent.putExtra("path", messageObject.messageOwner.attachPath); @@ -3675,19 +3677,20 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, private boolean convertVideo(final MessageObject messageObject) { - if (messageObject == null || messageObject.videoEditedInfo == null) { + VideoEditedInfo info = messageObject.videoEditedInfo; + if (messageObject == null || info == null) { return false; } - String videoPath = messageObject.videoEditedInfo.originalPath; - long startTime = messageObject.videoEditedInfo.startTime; - long endTime = messageObject.videoEditedInfo.endTime; - int resultWidth = messageObject.videoEditedInfo.resultWidth; - int resultHeight = messageObject.videoEditedInfo.resultHeight; - int rotationValue = messageObject.videoEditedInfo.rotationValue; - int originalWidth = messageObject.videoEditedInfo.originalWidth; - int originalHeight = messageObject.videoEditedInfo.originalHeight; - int framerate = messageObject.videoEditedInfo.framerate; - int bitrate = messageObject.videoEditedInfo.bitrate; + String videoPath = info.originalPath; + long startTime = info.startTime; + long endTime = info.endTime; + int resultWidth = info.resultWidth; + int resultHeight = info.resultHeight; + int rotationValue = info.rotationValue; + int originalWidth = info.originalWidth; + int originalHeight = info.originalHeight; + int framerate = info.framerate; + int bitrate = info.bitrate; int rotateRender = 0; boolean isSecret = ((int) messageObject.getDialogId()) == 0; final File cacheFile = new File(messageObject.messageOwner.attachPath); @@ -3705,9 +3708,9 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } else if (endTime > 0) { duration = endTime; } else if (startTime > 0) { - duration = messageObject.videoEditedInfo.originalDuration - startTime; + duration = info.originalDuration - startTime; } else { - duration = messageObject.videoEditedInfo.originalDuration; + duration = info.originalDuration; } if (framerate == 0) { @@ -3734,7 +3737,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } boolean needCompress = resultWidth != originalWidth || resultHeight != originalHeight || rotateRender != 0 - || messageObject.videoEditedInfo.roundVideo || Build.VERSION.SDK_INT >= 18 && startTime != -1; + || info.roundVideo || Build.VERSION.SDK_INT >= 18 && startTime != -1; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("videoconvert", Activity.MODE_PRIVATE); @@ -3747,17 +3750,19 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, @Override public boolean checkConversionCanceled() { - return messageObject.videoEditedInfo.canceled; + return info.canceled; } @Override public void didWriteData(long availableSize, float progress) { - if (messageObject.videoEditedInfo.canceled) return; + if (info.canceled) { + return; + } if (availableSize < 0) { availableSize = cacheFile.length(); } - if (!messageObject.videoEditedInfo.needUpdateProgress && lastAvailableSize == availableSize) { + if (!info.needUpdateProgress && lastAvailableSize == availableSize) { return; } @@ -3766,7 +3771,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } }; - messageObject.videoEditedInfo.videoConvertFirstWrite = true; + info.videoConvertFirstWrite = true; MediaCodecVideoConvertor videoConvertor = new MediaCodecVideoConvertor(); boolean error = videoConvertor.convertVideo(videoPath, cacheFile, @@ -3778,10 +3783,10 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, callback); - boolean canceled = messageObject.videoEditedInfo.canceled; + boolean canceled = info.canceled; if (!canceled) { synchronized (videoConvertSync) { - canceled = messageObject.videoEditedInfo.canceled; + canceled = info.canceled; } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java index 6b9caeace..05433959e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessageObject.java @@ -3081,7 +3081,7 @@ public class MessageObject { } } - private static void addUrlsByPattern(boolean isOut, CharSequence charSequence, boolean botCommands, int patternType, int duration) { + public static void addUrlsByPattern(boolean isOut, CharSequence charSequence, boolean botCommands, int patternType, int duration) { try { Matcher matcher; if (patternType == 3 || patternType == 4) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index b43f32683..27459b355 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -841,13 +841,14 @@ public class MessagesController extends BaseController implements NotificationCe TLRPC.TL_account_uploadWallPaper req = new TLRPC.TL_account_uploadWallPaper(); req.file = file; req.mime_type = "image/jpeg"; + Theme.OverrideWallpaperInfo overrideWallpaperInfo = uploadingWallpaperInfo; final TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings(); - settings.blur = uploadingWallpaperInfo.isBlurred; - settings.motion = uploadingWallpaperInfo.isMotion; + settings.blur = overrideWallpaperInfo.isBlurred; + settings.motion = overrideWallpaperInfo.isMotion; req.settings = settings; getConnectionsManager().sendRequest(req, (response, error) -> { TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) response; - File path = new File(ApplicationLoader.getFilesDirFixed(), uploadingWallpaperInfo.originalFileName); + File path = new File(ApplicationLoader.getFilesDirFixed(), overrideWallpaperInfo.originalFileName); if (wallPaper != null) { try { AndroidUtilities.copyFile(path, FileLoader.getPathToAttach(wallPaper.document, true)); @@ -859,8 +860,8 @@ public class MessagesController extends BaseController implements NotificationCe if (uploadingWallpaper != null && wallPaper != null) { wallPaper.settings = settings; wallPaper.flags |= 4; - uploadingWallpaperInfo.slug = wallPaper.slug; - uploadingWallpaperInfo.saveOverrideWallpaper(); + overrideWallpaperInfo.slug = wallPaper.slug; + overrideWallpaperInfo.saveOverrideWallpaper(); ArrayList wallpapers = new ArrayList<>(); wallpapers.add(wallPaper); getMessagesStorage().putWallpapers(wallpapers, 2); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java index 8feed0d8c..2ccd958cf 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java @@ -290,7 +290,7 @@ public class Browser { builder.setToolbarColor(Theme.getColor(Theme.key_actionBarBrowser)); builder.setShowTitle(true); - builder.setActionButton(BitmapFactory.decodeResource(context.getResources(), R.drawable.abc_ic_menu_share_mtrl_alpha), LocaleController.getString("ShareFile", R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, share, 0), false); + builder.setActionButton(BitmapFactory.decodeResource(context.getResources(), R.drawable.abc_ic_menu_share_mtrl_alpha), LocaleController.getString("ShareFile", R.string.ShareFile), PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 0, share, 0), true); CustomTabsIntent intent = builder.build(); intent.setUseNewTask(); intent.launchUrl(context, uri); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/video/MediaCodecVideoConvertor.java b/TMessagesProj/src/main/java/org/telegram/messenger/video/MediaCodecVideoConvertor.java index b1bfd8b80..0e36f6b10 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/video/MediaCodecVideoConvertor.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/video/MediaCodecVideoConvertor.java @@ -177,51 +177,9 @@ public class MediaCodecVideoConvertor { outputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, framerate); outputFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 2); - if (Build.VERSION.SDK_INT >= 23) { - int profile; - int level; - - if (Math.min(resultHeight, resultWidth) >= 1080) { - profile = MediaCodecInfo.CodecProfileLevel.AVCProfileHigh; - level = MediaCodecInfo.CodecProfileLevel.AVCLevel41; - } else if (Math.min(resultHeight, resultWidth) >= 720) { - profile = MediaCodecInfo.CodecProfileLevel.AVCProfileHigh; - level = MediaCodecInfo.CodecProfileLevel.AVCLevel4; - } else if (Math.min(resultHeight, resultWidth) >= 480) { - profile = MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline; - level = MediaCodecInfo.CodecProfileLevel.AVCLevel31; - } else { - profile = MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline; - level = MediaCodecInfo.CodecProfileLevel.AVCLevel3; - } - - MediaCodecInfo.CodecCapabilities capabilities = MediaCodecInfo.CodecCapabilities.createFromProfileLevel(MediaController.VIDEO_MIME_TYPE, profile, level); - - if (capabilities == null && profile == MediaCodecInfo.CodecProfileLevel.AVCProfileHigh) { - profile = MediaCodecInfo.CodecProfileLevel.AVCProfileBaseline; - capabilities = MediaCodecInfo.CodecCapabilities.createFromProfileLevel(MediaController.VIDEO_MIME_TYPE, profile, level); - } - if (capabilities.getEncoderCapabilities() != null) { - outputFormat.setInteger(MediaFormat.KEY_PROFILE, profile); - outputFormat.setInteger(MediaFormat.KEY_LEVEL, level); - - int maxBitrate = capabilities.getVideoCapabilities().getBitrateRange().getUpper(); - if (bitrate > maxBitrate) { - bitrate = maxBitrate; - outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate); - } - - int maxFramerate = capabilities.getVideoCapabilities().getSupportedFrameRates().getUpper(); - if (framerate > maxFramerate) { - framerate = maxFramerate; - outputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, framerate); - } - } - } else { - if (Math.min(resultHeight, resultWidth) <= 480) { - if (bitrate > 921600) bitrate = 921600; - outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate); - } + if (Build.VERSION.SDK_INT < 23 && Math.min(resultHeight, resultWidth) <= 480) { + if (bitrate > 921600) bitrate = 921600; + outputFormat.setInteger(MediaFormat.KEY_BIT_RATE, bitrate); } if (Build.VERSION.SDK_INT < 18) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java index b45e8971a..cb4e71381 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBar.java @@ -30,7 +30,6 @@ import android.widget.FrameLayout; import android.widget.ImageView; import org.telegram.messenger.AndroidUtilities; -import org.telegram.messenger.BuildVars; import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.ui.Components.FireworksEffect; @@ -172,7 +171,7 @@ public class ActionBar extends FrameLayout { snowflakesEffect = new SnowflakesEffect(); titleTextView.invalidate(); invalidate(); - } else if (BuildVars.DEBUG_PRIVATE_VERSION) { + } else { snowflakesEffect = null; fireworksEffect = new FireworksEffect(); titleTextView.invalidate(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java index c909c03e6..635c03e91 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java @@ -3760,7 +3760,7 @@ public class Theme { OverrideWallpaperInfo overrideWallpaper = new OverrideWallpaperInfo(); overrideWallpaper.color = preferences.getInt("selectedColor", 0); overrideWallpaper.slug = preferences.getString("selectedBackgroundSlug", ""); - if (id == -1 && TextUtils.isEmpty(overrideWallpaper.slug)) { + if (id >= -100 && id <= -1 && TextUtils.isEmpty(overrideWallpaper.slug)) { overrideWallpaper.slug = COLOR_BACKGROUND_SLUG; overrideWallpaper.fileName = ""; overrideWallpaper.originalFileName = ""; @@ -4714,7 +4714,7 @@ public class Theme { } public static boolean deleteThemeAccent(ThemeInfo theme, ThemeAccent accent, boolean save) { - if (accent == null) { + if (accent == null || theme == null || theme.themeAccents == null) { return false; } boolean current = accent.id == theme.currentAccentId; @@ -5335,7 +5335,7 @@ public class Theme { boolean changed = false; if (response instanceof TLRPC.TL_theme) { TLRPC.TL_theme theme = (TLRPC.TL_theme) response; - if (theme.settings != null) { + if (accent != null && theme.settings != null) { if (!ThemeInfo.accentEquals(accent, theme.settings)) { File file = accent.getPathToWallpaper(); if (file != null) { @@ -5347,6 +5347,7 @@ public class Theme { NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needSetDayNightTheme, currentTheme, currentNightTheme == currentTheme, null, -1); } PatternsLoader.createLoader(true); + changed = true; } accent.patternMotion = theme.settings.wallpaper != null && theme.settings.wallpaper.settings != null && theme.settings.wallpaper.settings.motion; } else if (theme.document != null && theme.document.id != info.document.id) { @@ -6835,6 +6836,9 @@ public class Theme { Integer color = currentColorsNoAccent.get(key); if (color != null) { ThemeAccent accent = currentTheme.getAccent(false); + if (accent == null) { + return 0; + } float[] hsvTemp1 = getTempHsv(1); float[] hsvTemp2 = getTempHsv(2); Color.colorToHSV(currentTheme.accentBaseColor, hsvTemp1); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionIntroActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionIntroActivity.java index e039e5e94..71292137a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionIntroActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionIntroActivity.java @@ -671,6 +671,9 @@ public class ActionIntroActivity extends BaseFragment implements LocationControl } private void updateColors() { + if (colors == null || imageView == null) { + return; + } colors[0] = 0x333333; colors[1] = Theme.getColor(Theme.key_windowBackgroundWhiteBlackText); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ArticleViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/ArticleViewer.java index 7d9a96eb7..1fa250a36 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ArticleViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ArticleViewer.java @@ -985,6 +985,8 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg layoutManager[0] = layoutManagerToUpdate; pagesStack.remove(pagesStack.size() - 1); currentPage = pagesStack.get(pagesStack.size() - 1); + + titleTextView.setText(currentPage.site_name == null ? "" : currentPage.site_name); } listView[1].setVisibility(GONE); headerView.invalidate(); @@ -1923,7 +1925,7 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg boolean extraSpace = maxWidth >= 0 && innerRichText instanceof TLRPC.TL_textUrl && ((TLRPC.TL_textUrl) innerRichText).webpage_id != 0; if (extraSpace && spannableStringBuilder.length() != 0 && spannableStringBuilder.charAt(spannableStringBuilder.length() - 1) != '\n') { spannableStringBuilder.append(" "); - spannableStringBuilder.setSpan(new TextSelectionHelper.IngnoreCopySpanable(), spannableStringBuilder.length() - 1, spannableStringBuilder.length(), 0); + spannableStringBuilder.setSpan(new TextSelectionHelper.IgnoreCopySpannable(), spannableStringBuilder.length() - 1, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } CharSequence innerText = getText(parentView, parentRichText, innerRichText, parentBlock, maxWidth); @@ -1943,17 +1945,17 @@ public class ArticleViewer implements NotificationCenter.NotificationCenterDeleg span = new TextPaintUrlSpan(getTextPaint(parentRichText, lastRichText, parentBlock), url); } if (startLength != spannableStringBuilder.length()) { - spannableStringBuilder.setSpan(span, startLength, spannableStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + spannableStringBuilder.setSpan(span, startLength, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { if (startLength != spannableStringBuilder.length()) { - spannableStringBuilder.setSpan(new TextPaintSpan(getTextPaint(parentRichText, lastRichText, parentBlock)), startLength, spannableStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + spannableStringBuilder.setSpan(new TextPaintSpan(getTextPaint(parentRichText, lastRichText, parentBlock)), startLength, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } } if (extraSpace && a != count - 1) { spannableStringBuilder.append(" "); - spannableStringBuilder.setSpan(new TextSelectionHelper.IngnoreCopySpanable(), spannableStringBuilder.length() - 1, spannableStringBuilder.length(), 0); + spannableStringBuilder.setSpan(new TextSelectionHelper.IgnoreCopySpannable(), spannableStringBuilder.length() - 1, spannableStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } return spannableStringBuilder; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java index d76af8613..946e31840 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java @@ -70,7 +70,7 @@ public abstract class TextSelectionHelper= layout.getText().length()) { + if (layout == null || offset > layout.getText().length()) { return tmpCoord; } int line = layout.getLineForOffset(offset); @@ -1387,12 +1387,11 @@ public abstract class TextSelectionHelper 0 && line < layout.getLineCount() - 1) { + if (path.lastBottom < layout.getLineBottom(line)) { int lineBottom = layout.getLineBottom(line); int lineTop = layout.getLineTop(line); float lineH = lineBottom - lineTop; - float lineHWithoutSpaсing = (lineBottom - layout.getSpacingAdd()) - lineTop; + float lineHWithoutSpaсing = path.lastBottom - lineTop; canvas.save(); canvas.scale(1f, lineH / lineHWithoutSpaсing, 0, lineTop); canvas.drawPath(path, selectionPaint); @@ -2322,11 +2321,28 @@ public abstract class TextSelectionHelper text.length()) e = text.length(); + stringBuilder.append(text.subSequence(s, e)); + stringBuilder.append('\n'); + } + } else if (startViewPosition == endViewPosition && k == endViewChildPosition) { + CharSequence prefix = prefixTextByPosition.get(i + (k << 16)); + if (prefix != null) { + stringBuilder.append(prefix).append(' '); + } + int e = endViewOffset; + if (e > text.length()) e = text.length(); + stringBuilder.append(text.subSequence(0, e)); stringBuilder.append('\n'); } else if (k == startViewChildPosition) { - stringBuilder.append(text.subSequence(startViewOffset, text.length())); - stringBuilder.append('\n'); + int s = startViewOffset; + if (s < text.length()) { + stringBuilder.append(text.subSequence(s, text.length())); + stringBuilder.append('\n'); + } } else { CharSequence prefix = prefixTextByPosition.get(i + (k << 16)); if (prefix != null) { @@ -2340,14 +2356,21 @@ public abstract class TextSelectionHelper text.length()) e = text.length(); + stringBuilder.append(text.subSequence(s, e)); + stringBuilder.append('\n'); + } } else if (k == endViewChildPosition) { CharSequence prefix = prefixTextByPosition.get(i + (k << 16)); if (prefix != null) { stringBuilder.append(prefix).append(' '); } - stringBuilder.append(text.subSequence(0, endViewOffset)); + int e = endViewOffset; + if (e > text.length()) e = text.length(); + stringBuilder.append(text.subSequence(0, e)); stringBuilder.append('\n'); } else { CharSequence prefix = prefixTextByPosition.get(i + (k << 16)); @@ -2372,8 +2395,8 @@ public abstract class TextSelectionHelper 0) { - IngnoreCopySpanable[] spans = stringBuilder.getSpans(0, stringBuilder.length() - 1, IngnoreCopySpanable.class); - for (IngnoreCopySpanable span : spans) { + IgnoreCopySpannable[] spans = stringBuilder.getSpans(0, stringBuilder.length() - 1, IgnoreCopySpannable.class); + for (IgnoreCopySpannable span : spans) { int end = stringBuilder.getSpanEnd(span); int start = stringBuilder.getSpanStart(span); stringBuilder.delete(start, end); @@ -2484,7 +2507,26 @@ public abstract class TextSelectionHelper lastBottom) { + lastBottom = bottom; + } + } + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java index ba0592840..c752b4470 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java @@ -2827,6 +2827,9 @@ public class AlertsCreator { } private static void processCreate(EditTextBoldCursor editText, AlertDialog alertDialog, BaseFragment fragment) { + if (fragment == null || fragment.getParentActivity() == null) { + return; + } AndroidUtilities.hideKeyboard(editText); Theme.ThemeInfo themeInfo = Theme.createNewTheme(editText.getText().toString()); NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.themeListUpdated); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/Crop/CropAreaView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/Crop/CropAreaView.java index 7809244e4..93c99f43a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/Crop/CropAreaView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/Crop/CropAreaView.java @@ -278,7 +278,9 @@ public class CropAreaView extends View { canvas.drawRect(0, (int) actualRect.top, (int) actualRect.left, (int) actualRect.bottom, dimPaint); canvas.drawRect((int) actualRect.right, (int) actualRect.top, getWidth(), (int) actualRect.bottom, dimPaint); canvas.drawRect(0, (int) actualRect.bottom, getWidth(), getHeight(), dimPaint); - canvas.drawBitmap(circleBitmap, (int) actualRect.left, (int) actualRect.top, null); + if (circleBitmap != null) { + canvas.drawBitmap(circleBitmap, (int) actualRect.left, (int) actualRect.top, null); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextBoldCursor.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextBoldCursor.java index 73e638f33..eb90c93c0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextBoldCursor.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextBoldCursor.java @@ -667,7 +667,9 @@ public class EditTextBoldCursor extends EditText { floatingToolbar = new FloatingToolbar(getContext(), windowView != null ? windowView : attachedToWindow, getActionModeStyle()); floatingActionMode = new FloatingActionMode(getContext(), new ActionModeCallback2Wrapper(callback), this, floatingToolbar); floatingToolbarPreDrawListener = () -> { - floatingActionMode.updateViewLocationInWindow(); + if (floatingActionMode != null) { + floatingActionMode.updateViewLocationInWindow(); + } return true; }; callback.onCreateActionMode(floatingActionMode, floatingActionMode.getMenu()); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ScrollSlidingTabStrip.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ScrollSlidingTabStrip.java index c2e97998a..262ef7a68 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ScrollSlidingTabStrip.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ScrollSlidingTabStrip.java @@ -99,6 +99,9 @@ public class ScrollSlidingTabStrip extends HorizontalScrollView { layoutTransition.setAnimateParentHierarchy(false); layoutTransition.setDuration(250); layoutTransition.addTransitionListener(new LayoutTransition.TransitionListener() { + + private boolean inTransition; + @Override public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { @@ -106,7 +109,12 @@ public class ScrollSlidingTabStrip extends HorizontalScrollView { @Override public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { + if (inTransition) { + return; + } + inTransition = true; tabsContainer.setLayoutTransition(null); + inTransition = false; } }); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogOrContactPickerActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogOrContactPickerActivity.java index 5e9ba8d8d..e4cdf2901 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogOrContactPickerActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogOrContactPickerActivity.java @@ -518,10 +518,14 @@ public class DialogOrContactPickerActivity extends BaseFragment { if (scrollY != 0 && scrollY != actionBarHeight) { if (scrollY < actionBarHeight / 2) { viewPages[0].listView.smoothScrollBy(0, -scrollY); - viewPages[0].listView2.smoothScrollBy(0, -scrollY); + if (viewPages[0].listView2 != null) { + viewPages[0].listView2.smoothScrollBy(0, -scrollY); + } } else { viewPages[0].listView.smoothScrollBy(0, actionBarHeight - scrollY); - viewPages[0].listView2.smoothScrollBy(0, actionBarHeight - scrollY); + if (viewPages[0].listView2 != null) { + viewPages[0].listView2.smoothScrollBy(0, actionBarHeight - scrollY); + } } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index d11bf115e..b3256bac2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -727,6 +727,9 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. int dialogIndex = dialogsAdapter.fixPosition(position); int count = dialogsAdapter.getItemCount(); Runnable finishRunnable = () -> { + if (frozenDialogsList == null) { + return; + } TLRPC.Dialog dialog = frozenDialogsList.remove(dialogIndex); int pinnedNum = dialog.pinnedNum; slidingView = null; @@ -1097,7 +1100,9 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName)); } } - actionBar.setSupportsHolidayImage(true); + if (folderId == 0) { + actionBar.setSupportsHolidayImage(true); + } } actionBar.setTitleActionRunnable(() -> { hideFloatingButton(false); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java index 875b89597..e7ab9bf2c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java @@ -2051,16 +2051,18 @@ public class LocationActivity extends BaseFragment implements NotificationCenter shadowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogBackground), PorterDuff.Mode.MULTIPLY)); shadow.invalidate(); - if (Theme.getCurrentTheme().isDark() || Theme.isCurrentThemeNight()) { - if (!currentMapStyleDark) { - currentMapStyleDark = true; - MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night); - googleMap.setMapStyle(style); - } - } else { - if (currentMapStyleDark) { - currentMapStyleDark = false; - googleMap.setMapStyle(null); + if (googleMap != null) { + if (Theme.getCurrentTheme().isDark() || Theme.isCurrentThemeNight()) { + if (!currentMapStyleDark) { + currentMapStyleDark = true; + MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night); + googleMap.setMapStyle(style); + } + } else { + if (currentMapStyleDark) { + currentMapStyleDark = false; + googleMap.setMapStyle(null); + } } } }; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 9ca2c7a16..7e59553ed 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -6435,6 +6435,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat if (messageObject != null && !messageObject.messageOwner.entities.isEmpty()) { Spannable spannableString = SpannableString.valueOf(caption.toString()); messageObject.addEntitiesToText(spannableString, true, false); + if (messageObject.isVideo()) { + MessageObject.addUrlsByPattern(messageObject.isOutOwner(), spannableString, false, 3, messageObject.getDuration()); + } str = Emoji.replaceEmoji(spannableString, captionTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false); } else { str = Emoji.replaceEmoji(new SpannableStringBuilder(caption), captionTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProxySettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProxySettingsActivity.java index 73b526308..42328c38e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProxySettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProxySettingsActivity.java @@ -569,9 +569,13 @@ public class ProxySettingsActivity extends BaseFragment { private void updatePasteCell() { final ClipData clip = clipboardManager.getPrimaryClip(); - final String clipText; + String clipText; if (clip != null && clip.getItemCount() > 0) { - clipText = clip.getItemAt(0).coerceToText(fragmentView.getContext()).toString(); + try { + clipText = clip.getItemAt(0).coerceToText(fragmentView.getContext()).toString(); + } catch (Exception e) { + clipText = null; + } } else { clipText = null; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java index 1f47e4a95..b25d9b872 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java @@ -895,7 +895,8 @@ public class ThemeActivity extends BaseFragment implements NotificationCenter.No return; } Theme.ThemeInfo themeInfo = Theme.getCurrentTheme(); - if (themeInfo.themeAccents != null && !themeInfo.themeAccents.isEmpty() && themeInfo.getAccent(false).id >= 100) { + Theme.ThemeAccent accent = themeInfo.getAccent(false); + if (themeInfo.themeAccents != null && !themeInfo.themeAccents.isEmpty() && accent != null && accent.id >= 100) { menuItem.showSubItem(share_theme); menuItem.showSubItem(edit_theme); } else { @@ -1583,6 +1584,9 @@ public class ThemeActivity extends BaseFragment implements NotificationCenter.No } }); accentsListView.setOnItemLongClickListener((view12, position) -> { + if (position < 0 || position >= accentsAdapter.themeAccents.size()) { + return false; + } Theme.ThemeAccent accent = accentsAdapter.themeAccents.get(position); if (accent.id >= 100) { AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());