From 12caa1e8cda083267cdb733539067a5bf1f1c0f9 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Thu, 2 Jan 2020 18:08:53 +0300 Subject: [PATCH] Update to 5.13.0 (1823) --- TMessagesProj/build.gradle | 2 +- .../jni/tgnet/ConnectionsManager.cpp | 4 +- TMessagesProj/jni/tgnet/Datacenter.cpp | 3 +- .../org/telegram/messenger/BuildVars.java | 2 +- .../org/telegram/messenger/FileLoader.java | 2 +- .../messenger/MessagesController.java | 20 +++- .../telegram/messenger/MessagesStorage.java | 18 ++- .../java/org/telegram/ui/ActionBar/Theme.java | 113 ++++++++++-------- .../ui/Adapters/DialogsSearchAdapter.java | 2 +- .../telegram/ui/Cells/ChatMessageCell.java | 3 + .../ui/Cells/TextSelectionHelper.java | 20 +++- .../ui/Cells/ThemesHorizontalListCell.java | 2 +- .../java/org/telegram/ui/ChatActivity.java | 16 ++- .../org/telegram/ui/Components/EmojiView.java | 2 +- .../java/org/telegram/ui/DialogsActivity.java | 4 +- .../org/telegram/ui/LocationActivity.java | 13 +- .../java/org/telegram/ui/PhotoViewer.java | 2 +- .../java/org/telegram/ui/ThemeActivity.java | 2 +- .../org/telegram/ui/ThemePreviewActivity.java | 44 +++++-- .../telegram/ui/WallpapersListActivity.java | 2 +- 20 files changed, 181 insertions(+), 95 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 2e4448575..34bcca801 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -283,7 +283,7 @@ android { } } - defaultConfig.versionCode = 1821 + defaultConfig.versionCode = 1823 applicationVariants.all { variant -> variant.outputs.all { output -> diff --git a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp index fb5950500..53cf68960 100644 --- a/TMessagesProj/jni/tgnet/ConnectionsManager.cpp +++ b/TMessagesProj/jni/tgnet/ConnectionsManager.cpp @@ -1434,7 +1434,7 @@ void ConnectionsManager::processServerResponse(TLObject *message, int64_t messag int64_t time = (int64_t) (messageId / 4294967296.0 * 1000); int64_t currentTime = getCurrentTimeMillis(); timeDifference = (int32_t) ((time - currentTime) / 1000 - currentPingTime / 2); - lastOutgoingMessageId = messageId > (lastOutgoingMessageId ? messageId : lastOutgoingMessageId); + lastOutgoingMessageId = (messageId > lastOutgoingMessageId ? messageId : lastOutgoingMessageId); } if ((connection->getConnectionType() & ConnectionTypeDownload) == 0 || !datacenter->containsServerSalt(messageSalt, media)) { TL_bad_server_salt *response = (TL_bad_server_salt *) message; @@ -2186,7 +2186,7 @@ void ConnectionsManager::processRequestQueue(uint32_t connectionTypes, uint32_t bool forceThisRequest = (connectionTypes & requestConnectionType) && requestDatacenter->getDatacenterId() == dc; - if (typeInfo == typeid(TL_get_future_salts) || typeInfo == typeid(TL_destroy_session)) { + if (typeInfo == typeid(TL_get_future_salts)) { if (request->messageId != 0) { request->addRespondMessageId(request->messageId); } diff --git a/TMessagesProj/jni/tgnet/Datacenter.cpp b/TMessagesProj/jni/tgnet/Datacenter.cpp index 90bf51cb7..348a2c289 100644 --- a/TMessagesProj/jni/tgnet/Datacenter.cpp +++ b/TMessagesProj/jni/tgnet/Datacenter.cpp @@ -688,7 +688,8 @@ void Datacenter::mergeServerSalts(TL_future_salts *futureSalts, bool media) { std::vector> &salts = media ? mediaServerSalts : serverSalts; int32_t date = ConnectionsManager::getInstance(instanceNum).getCurrentTime(); - std::vector existingSalts(salts.size()); + std::vector existingSalts; + existingSalts.reserve(salts.size()); size_t size = salts.size(); for (uint32_t a = 0; a < size; a++) { existingSalts.push_back(salts[a]->salt); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index e560294d7..c249a4a08 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 = 1821; + public static int BUILD_VERSION = 1823; 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/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java index af2621a6a..5815c8c2c 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java @@ -446,7 +446,7 @@ public class FileLoader extends BaseController { } public boolean isLoadingFile(final String fileName) { - return loadOperationPathsUI.containsKey(fileName); + return fileName != null && loadOperationPathsUI.containsKey(fileName); } public float getBufferedProgressFromPosition(final float position, final String fileName) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 27459b355..84bd934a1 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -4523,7 +4523,10 @@ public class MessagesController extends BaseController implements NotificationCe for (int a = 0; a < allDialogs.size(); a++) { TLRPC.Dialog d = allDialogs.get(a); if (!d.pinned) { - break; + if (d.id != proxyDialogId) { + break; + } + continue; } maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum); } @@ -8196,7 +8199,10 @@ public class MessagesController extends BaseController implements NotificationCe continue; } if (!dialog.pinned) { - break; + if (dialog.id != proxyDialogId) { + break; + } + continue; } getMessagesStorage().setDialogPinned(dialog.id, dialog.pinnedNum); if ((int) dialog.id != 0) { @@ -8250,7 +8256,10 @@ public class MessagesController extends BaseController implements NotificationCe continue; } if (!d.pinned) { - break; + if (d.id != proxyDialogId) { + break; + } + continue; } maxPinnedNum = Math.max(d.pinnedNum, maxPinnedNum); } @@ -8413,7 +8422,10 @@ public class MessagesController extends BaseController implements NotificationCe continue; } if (!dialog.pinned) { - break; + if (dialog.id != proxyDialogId) { + break; + } + continue; } maxPinnedNum = Math.max(dialog.pinnedNum, maxPinnedNum); dialog.pinned = false; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index da4c23deb..94cc69fdc 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -7261,16 +7261,14 @@ public class MessagesStorage extends BaseController { message.attachPath = oldMessage.attachPath; message.ttl = cursor.intValue(2); } - if (!message.out) { - boolean sameMedia = false; //TODO check - if (oldMessage.media instanceof TLRPC.TL_messageMediaPhoto && message.media instanceof TLRPC.TL_messageMediaPhoto && oldMessage.media.photo != null && message.media.photo != null) { - sameMedia = oldMessage.media.photo.id == message.media.photo.id; - } else if (oldMessage.media instanceof TLRPC.TL_messageMediaDocument && message.media instanceof TLRPC.TL_messageMediaDocument && oldMessage.media.document != null && message.media.document != null) { - sameMedia = oldMessage.media.document.id == message.media.document.id; - } - if (!sameMedia) { - addFilesToDelete(oldMessage, filesToDelete, false); - } + boolean sameMedia = false; + if (oldMessage.media instanceof TLRPC.TL_messageMediaPhoto && message.media instanceof TLRPC.TL_messageMediaPhoto && oldMessage.media.photo != null && message.media.photo != null) { + sameMedia = oldMessage.media.photo.id == message.media.photo.id; + } else if (oldMessage.media instanceof TLRPC.TL_messageMediaDocument && message.media instanceof TLRPC.TL_messageMediaDocument && oldMessage.media.document != null && message.media.document != null) { + sameMedia = oldMessage.media.document.id == message.media.document.id; + } + if (!sameMedia) { + addFilesToDelete(oldMessage, filesToDelete, false); } } boolean oldMention = cursor.intValue(3) != 0; 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 611531445..5dcf4bea9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/Theme.java @@ -486,34 +486,7 @@ public class Theme { if (svg) { patternBitmap = SvgHelper.getBitmap(patternPath, AndroidUtilities.dp(360), AndroidUtilities.dp(640), false); } else { - BitmapFactory.Options opts = new BitmapFactory.Options(); - opts.inSampleSize = 1; - opts.inJustDecodeBounds = true; - BitmapFactory.decodeFile(patternPath.getAbsolutePath(), opts); - float photoW = opts.outWidth; - float photoH = opts.outHeight; - float scaleFactor; - int w_filter = AndroidUtilities.dp(360); - int h_filter = AndroidUtilities.dp(640); - if (w_filter >= h_filter && photoW > photoH) { - scaleFactor = Math.max(photoW / w_filter, photoH / h_filter); - } else { - scaleFactor = Math.min(photoW / w_filter, photoH / h_filter); - } - if (scaleFactor < 1.2f) { - scaleFactor = 1; - } - opts.inJustDecodeBounds = false; - if (scaleFactor > 1.0f && (photoW > w_filter || photoH > h_filter)) { - int sample = 1; - do { - sample *= 2; - } while (sample * 2 < scaleFactor); - opts.inSampleSize = sample; - } else { - opts.inSampleSize = (int) scaleFactor; - } - patternBitmap = BitmapFactory.decodeFile(patternPath.getAbsolutePath(), opts); + patternBitmap = loadScreenSizedBitmap(new FileInputStream(patternPath), 0); } } @@ -7180,14 +7153,17 @@ public class Theme { } isCustomTheme = true; } else if (themedWallpaperLink != null) { - File pathToWallpaper = new File(ApplicationLoader.getFilesDirFixed(), Utilities.MD5(themedWallpaperLink) + ".wp"); - Bitmap bitmap = BitmapFactory.decodeFile(pathToWallpaper.getAbsolutePath()); - if (bitmap != null) { - themedWallpaper = wallpaper = new BitmapDrawable(bitmap); - isCustomTheme = true; + try { + File pathToWallpaper = new File(ApplicationLoader.getFilesDirFixed(), Utilities.MD5(themedWallpaperLink) + ".wp"); + Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(pathToWallpaper), 0); + if (bitmap != null) { + themedWallpaper = wallpaper = new BitmapDrawable(bitmap); + isCustomTheme = true; + } + } catch (Exception e) { + FileLog.e(e); } } else if (themedWallpaperFileOffset > 0 && (currentTheme.pathToFile != null || currentTheme.assetName != null)) { - FileInputStream stream = null; try { File file; if (currentTheme.assetName != null) { @@ -7195,23 +7171,13 @@ public class Theme { } else { file = new File(currentTheme.pathToFile); } - stream = new FileInputStream(file); - stream.getChannel().position(themedWallpaperFileOffset); - Bitmap bitmap = BitmapFactory.decodeStream(stream); + Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(file), themedWallpaperFileOffset); if (bitmap != null) { themedWallpaper = wallpaper = new BitmapDrawable(bitmap); isCustomTheme = true; } } catch (Throwable e) { FileLog.e(e); - } finally { - try { - if (stream != null) { - stream.close(); - } - } catch (Exception e) { - FileLog.e(e); - } } } } @@ -7244,11 +7210,14 @@ public class Theme { } } else { File toFile = new File(ApplicationLoader.getFilesDirFixed(), overrideWallpaper.fileName); - long len = toFile.length(); if (toFile.exists()) { - wallpaper = Drawable.createFromPath(toFile.getAbsolutePath()); - isCustomTheme = true; - } else { + Bitmap bitmap = loadScreenSizedBitmap(new FileInputStream(toFile), 0); + if (bitmap != null) { + wallpaper = new BitmapDrawable(bitmap); + isCustomTheme = true; + } + } + if (wallpaper == null) { wallpaper = ApplicationLoader.applicationContext.getResources().getDrawable(R.drawable.background_hd); isCustomTheme = false; } @@ -7273,6 +7242,52 @@ public class Theme { }); } + private static Bitmap loadScreenSizedBitmap(FileInputStream stream, int offset) { + try { + BitmapFactory.Options opts = new BitmapFactory.Options(); + opts.inSampleSize = 1; + opts.inJustDecodeBounds = true; + stream.getChannel().position(offset); + BitmapFactory.decodeStream(stream, null, opts); + float photoW = opts.outWidth; + float photoH = opts.outHeight; + float scaleFactor; + int w_filter = AndroidUtilities.dp(360); + int h_filter = AndroidUtilities.dp(640); + if (w_filter >= h_filter && photoW > photoH) { + scaleFactor = Math.max(photoW / w_filter, photoH / h_filter); + } else { + scaleFactor = Math.min(photoW / w_filter, photoH / h_filter); + } + if (scaleFactor < 1.2f) { + scaleFactor = 1; + } + opts.inJustDecodeBounds = false; + if (scaleFactor > 1.0f && (photoW > w_filter || photoH > h_filter)) { + int sample = 1; + do { + sample *= 2; + } while (sample * 2 < scaleFactor); + opts.inSampleSize = sample; + } else { + opts.inSampleSize = (int) scaleFactor; + } + stream.getChannel().position(offset); + return BitmapFactory.decodeStream(stream, null, opts); + } catch (Exception e) { + FileLog.e(e); + } finally { + try { + if (stream != null) { + stream.close(); + } + } catch (Exception ignore) { + + } + } + return null; + } + public static Drawable getThemedWallpaper(boolean thumb, View ownerView) { Integer backgroundColor = currentColors.get(key_chat_wallpaper); File file = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java index 1a8ec447b..9bd856ab3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DialogsSearchAdapter.java @@ -1049,7 +1049,7 @@ public class DialogsSearchAdapter extends RecyclerListView.SelectionAdapter { @Override public boolean onInterceptTouchEvent(MotionEvent e) { if (getParent() != null && getParent().getParent() != null) { - getParent().getParent().requestDisallowInterceptTouchEvent(true); + getParent().getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1)); } return super.onInterceptTouchEvent(e); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index 141d9ae5d..9a99098c8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -4746,6 +4746,9 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate radialProgress.setIcon(getIconForCurrentState(), false, false); } + if (delegate != null && delegate.getTextSelectionHelper() != null && !messageIdChanged && messageChanged && messageObject != null) { + delegate.getTextSelectionHelper().checkDataChanged(messageObject); + } accessibilityVirtualViewBounds.clear(); } 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 946e31840..253c63b17 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextSelectionHelper.java @@ -1442,14 +1442,17 @@ public abstract class TextSelectionHelper { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ThemesHorizontalListCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ThemesHorizontalListCell.java index c5bb94d08..5651f4b6c 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ThemesHorizontalListCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ThemesHorizontalListCell.java @@ -734,7 +734,7 @@ public class ThemesHorizontalListCell extends RecyclerListView implements Notifi @Override public boolean onInterceptTouchEvent(MotionEvent e) { if (getParent() != null && getParent().getParent() != null) { - getParent().getParent().requestDisallowInterceptTouchEvent(true); + getParent().getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1)); } return super.onInterceptTouchEvent(e); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index fa4c06a89..f64e46e92 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -5001,7 +5001,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not updateTopPanel(false); updatePinnedMessageView(true); - chatScrollHelper = new RecyclerAnimationScrollHelper(chatListView,chatLayoutManager); + chatScrollHelper = new RecyclerAnimationScrollHelper(chatListView, chatLayoutManager); chatScrollHelper.setScrollListener(() -> updateMessagesVisiblePart(false)); chatScrollHelper.setAnimationCallback(chatScrollHelperCallback); @@ -7482,7 +7482,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (viewBottom > height) { viewBottom = viewTop + height; } - messageCell.setVisiblePart(viewTop, viewBottom - viewTop, contentView.getHeightWithKeyboard() - AndroidUtilities.dp(48) - chatListView.getTop()); + messageCell.setVisiblePart(viewTop, viewBottom - viewTop, contentView.getHeightWithKeyboard() - (inPreviewMode ? 0 : AndroidUtilities.dp(48)) - chatListView.getTop()); messageObject = messageCell.getMessageObject(); boolean isVideo; @@ -9465,7 +9465,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } loading = false; - if (chatListView != null) { + if (chatListView != null && chatScrollHelper != null) { if (first || scrollToTopOnResume || forceScrollToTop) { forceScrollToTop = false; if (!postponedScroll) { @@ -9969,6 +9969,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not messages.remove(index); } } + if (removed.hasValidGroupId()) { + MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(removed.getGroupId()); + groupedMessages.messages.remove(removed); + if (newGroups == null) { + newGroups = new LongSparseArray<>(); + } + newGroups.put(groupedMessages.groupId, groupedMessages); + } if (chatAdapter != null) { chatAdapter.notifyDataSetChanged(); } @@ -16032,7 +16040,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (viewBottom > height) { viewBottom = viewTop + height; } - messageCell.setVisiblePart(viewTop, viewBottom - viewTop, contentView.getHeightWithKeyboard() - AndroidUtilities.dp(48) - chatListView.getTop()); + messageCell.setVisiblePart(viewTop, viewBottom - viewTop, contentView.getHeightWithKeyboard() - (inPreviewMode ? 0 : AndroidUtilities.dp(48)) - chatListView.getTop()); return true; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java index cc2feca6d..703f8bf57 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EmojiView.java @@ -1642,7 +1642,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { - getParent().requestDisallowInterceptTouchEvent(true); + getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1)); } return super.onInterceptTouchEvent(ev); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index b3256bac2..f6098ad9e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -2558,7 +2558,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. int lower_id = (int) dialog.id; if (dialog.pinned) { pinnedCount++; - } else { + } else if (!getMessagesController().isProxyDialog(dialog.id, false)) { break; } } @@ -2615,7 +2615,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. } else { pinnedCount++; } - } else { + } else if (!getMessagesController().isProxyDialog(dialog.id, false)) { break; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java index ecc19a516..ae935d535 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java @@ -1026,7 +1026,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter MapsInitializer.initialize(ApplicationLoader.applicationContext); mapView.getMapAsync(map1 -> { googleMap = map1; - if (Theme.getCurrentTheme().isDark() || Theme.isCurrentThemeNight()) { + if (isActiveThemeDark()) { currentMapStyleDark = true; MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night); googleMap.setMapStyle(style); @@ -1154,6 +1154,15 @@ public class LocationActivity extends BaseFragment implements NotificationCenter return fragmentView; } + private boolean isActiveThemeDark() { + Theme.ThemeInfo info = Theme.getActiveTheme(); + if (info.isDark()) { + return true; + } + int color = Theme.getColor(Theme.key_windowBackgroundWhite); + return AndroidUtilities.computePerceivedBrightness(color) < 0.721f; + } + private void updateEmptyView() { if (searching) { if (searchInProgress) { @@ -2052,7 +2061,7 @@ public class LocationActivity extends BaseFragment implements NotificationCenter shadow.invalidate(); if (googleMap != null) { - if (Theme.getCurrentTheme().isDark() || Theme.isCurrentThemeNight()) { + if (isActiveThemeDark()) { if (!currentMapStyleDark) { currentMapStyleDark = true; MapStyleOptions style = MapStyleOptions.loadRawResourceStyle(ApplicationLoader.applicationContext, R.raw.mapstyle_night); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 2bd42e314..06303f76b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -8920,7 +8920,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } } - canvas.drawText(lowQualityDescription, sideSide, cy - AndroidUtilities.dp(20), textPaint); + canvas.drawText(lowQualityDescription, sideSide, cy - AndroidUtilities.dp(16), textPaint); float width = textPaint.measureText(hightQualityDescription); canvas.drawText(hightQualityDescription, getMeasuredWidth() - sideSide - width, cy - AndroidUtilities.dp(16), textPaint); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java index 259f26c46..bd20f7531 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ThemeActivity.java @@ -1532,7 +1532,7 @@ public class ThemeActivity extends BaseFragment implements NotificationCenter.No @Override public boolean onInterceptTouchEvent(MotionEvent e) { if (getParent() != null && getParent().getParent() != null) { - getParent().getParent().requestDisallowInterceptTouchEvent(true); + getParent().getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1)); } return super.onInterceptTouchEvent(e); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ThemePreviewActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ThemePreviewActivity.java index f34901d3e..84753ee33 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ThemePreviewActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ThemePreviewActivity.java @@ -68,6 +68,7 @@ import org.telegram.messenger.MessagesController; import org.telegram.messenger.MessagesStorage; import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.R; +import org.telegram.messenger.SharedConfig; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.tgnet.ConnectionsManager; @@ -865,15 +866,34 @@ public class ThemePreviewActivity extends BaseFragment implements DownloadContro String fileName = isBlurred ? theme.generateWallpaperName(null, false) : originalFileName; File toFile = new File(ApplicationLoader.getFilesDirFixed(), originalFileName); if (currentWallpaper instanceof TLRPC.TL_wallPaper) { - try { - FileOutputStream stream = new FileOutputStream(toFile); - originalBitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); - stream.close(); - done = true; - } catch (Exception e) { - done = false; - FileLog.e(e); + if (originalBitmap != null) { + try { + FileOutputStream stream = new FileOutputStream(toFile); + originalBitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); + stream.close(); + done = true; + } catch (Exception e) { + done = false; + FileLog.e(e); + } + } else { + ImageReceiver imageReceiver = backgroundImage.getImageReceiver(); + if (imageReceiver.hasNotThumb() || imageReceiver.hasStaticThumb()) { + Bitmap bitmap = imageReceiver.getBitmap(); + try { + FileOutputStream stream = new FileOutputStream(toFile); + bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); + stream.close(); + done = true; + } catch (Exception e) { + done = false; + FileLog.e(e); + } + } else { + done = false; + } } + if (!done) { TLRPC.TL_wallPaper wallPaper = (TLRPC.TL_wallPaper) currentWallpaper; File f = FileLoader.getPathToAttach(wallPaper.document, true); @@ -1865,7 +1885,13 @@ public class ThemePreviewActivity extends BaseFragment implements DownloadContro NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper); } if (screenType != SCREEN_TYPE_PREVIEW || accent != null) { - imageFilter = (int) (1080 / AndroidUtilities.density) + "_" + (int) (1920 / AndroidUtilities.density) + "_f"; + if (SharedConfig.getDevicePerfomanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW) { + int w = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y); + int h = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y); + imageFilter = (int) (w / AndroidUtilities.density) + "_" + (int) (h / AndroidUtilities.density) + "_f"; + } else { + imageFilter = (int) (1080 / AndroidUtilities.density) + "_" + (int) (1920 / AndroidUtilities.density) + "_f"; + } maxWallpaperSize = Math.min(1920, Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)); NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersNeedReload); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/WallpapersListActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/WallpapersListActivity.java index b64f00969..8b278402b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/WallpapersListActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/WallpapersListActivity.java @@ -1359,7 +1359,7 @@ public class WallpapersListActivity extends BaseFragment implements Notification @Override public boolean onInterceptTouchEvent(MotionEvent e) { if (getParent() != null && getParent().getParent() != null) { - getParent().getParent().requestDisallowInterceptTouchEvent(true); + getParent().getParent().requestDisallowInterceptTouchEvent(canScrollHorizontally(-1)); } return super.onInterceptTouchEvent(e); }