From 4a43f809b3e201a5cece3c2e4b3df8d04bfefff3 Mon Sep 17 00:00:00 2001 From: xaxtix Date: Thu, 9 Dec 2021 19:28:33 +0300 Subject: [PATCH] Update to 8.3.1 --- TMessagesProj/build.gradle | 4 +- .../config/debug/AndroidManifest.xml | 4 +- .../config/debug/AndroidManifest_SDK23.xml | 2 +- .../config/release/AndroidManifest.xml | 4 +- .../config/release/AndroidManifest_SDK23.xml | 4 +- .../release/AndroidManifest_standalone.xml | 4 +- TMessagesProj/src/main/AndroidManifest.xml | 4 +- .../org/telegram/messenger/BuildVars.java | 12 +- .../java/org/telegram/messenger/FileLog.java | 2 +- .../messenger/FilesMigrationService.java | 315 +++++ .../messenger/MessagesController.java | 23 +- .../telegram/messenger/MessagesStorage.java | 10 +- .../messenger/NotificationCenter.java | 2 + .../telegram/tgnet/ConnectionsManager.java | 2 +- .../main/java/org/telegram/tgnet/TLRPC.java | 40 +- .../ui/ActionBar/ActionBarMenuItem.java | 3 + .../org/telegram/ui/CacheControlActivity.java | 164 +-- .../org/telegram/ui/Cells/ChatActionCell.java | 2 +- .../org/telegram/ui/Cells/SessionCell.java | 18 +- .../java/org/telegram/ui/ChatActivity.java | 1257 +++++++++-------- .../org/telegram/ui/ChatEditTypeActivity.java | 6 +- .../telegram/ui/Components/AlertsCreator.java | 29 +- .../ui/Components/ChatActivityEnterView.java | 6 +- .../ChatAttachAlertDocumentLayout.java | 14 +- .../telegram/ui/Components/MediaActivity.java | 2 +- .../Components/MotionBackgroundDrawable.java | 1 - .../ui/Components/RecyclerListView.java | 19 +- .../ui/Components/StickerImageView.java | 85 ++ .../telegram/ui/DefaultThemesPreviewCell.java | 2 +- .../java/org/telegram/ui/DialogsActivity.java | 16 + .../java/org/telegram/ui/LaunchActivity.java | 4 +- .../java/org/telegram/ui/PhotoViewer.java | 5 +- .../java/org/telegram/ui/ProfileActivity.java | 2 +- .../org/telegram/ui/SessionBottomSheet.java | 4 +- TMessagesProj/src/main/res/values/strings.xml | 5 + 35 files changed, 1206 insertions(+), 870 deletions(-) create mode 100644 TMessagesProj/src/main/java/org/telegram/messenger/FilesMigrationService.java create mode 100644 TMessagesProj/src/main/java/org/telegram/ui/Components/StickerImageView.java diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 9edd68934..05d2525a0 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -299,7 +299,7 @@ android { } } - defaultConfig.versionCode = 2493 + defaultConfig.versionCode = 2495 applicationVariants.all { variant -> variant.outputs.all { output -> @@ -318,7 +318,7 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 30 - versionName "8.3.0" + versionName "8.3.1" vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi'] diff --git a/TMessagesProj/config/debug/AndroidManifest.xml b/TMessagesProj/config/debug/AndroidManifest.xml index c01d13c3b..3938549e9 100644 --- a/TMessagesProj/config/debug/AndroidManifest.xml +++ b/TMessagesProj/config/debug/AndroidManifest.xml @@ -10,12 +10,12 @@ - + - + - + diff --git a/TMessagesProj/config/release/AndroidManifest.xml b/TMessagesProj/config/release/AndroidManifest.xml index 7bb790100..4f2e1456e 100644 --- a/TMessagesProj/config/release/AndroidManifest.xml +++ b/TMessagesProj/config/release/AndroidManifest.xml @@ -10,12 +10,12 @@ - + - + - + @@ -18,7 +18,7 @@ - + - + @@ -18,7 +18,7 @@ - + - + @@ -80,6 +80,7 @@ android:manageSpaceActivity="org.telegram.ui.ExternalActionActivity" android:supportsRtl="false" android:requestLegacyExternalStorage="true" + android:preserveLegacyExternalStorage="true" android:allowAudioPlaybackCapture="true" tools:replace="android:supportsRtl"> @@ -448,6 +449,7 @@ + diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index ae6a40c46..7910f61e9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -19,18 +19,14 @@ public class BuildVars { public static boolean USE_CLOUD_STRINGS = true; public static boolean CHECK_UPDATES = true; public static boolean NO_SCOPED_STORAGE = Build.VERSION.SDK_INT <= 29; - public static int BUILD_VERSION = 2493; - public static String BUILD_VERSION_STRING = "8.3.0"; + public static int BUILD_VERSION = 2495; + public static String BUILD_VERSION_STRING = "8.3.1"; public static int APP_ID = 4; public static String APP_HASH = "014b35b6184100b085b0d0572f9b5103"; public static String APPCENTER_HASH = "a5b5c4f5-51da-dedc-9918-d9766a22ca7c"; - // PUBLIC + public static boolean DEBUG_PRIVATE_VERSION = false; - // public static String APPCENTER_HASH_DEBUG = "f9726602-67c9-48d2-b5d0-4761f1c1a8f3"; - // PRIVATE - //public static boolean DEBUG_PRIVATE_VERSION = true; - //public static String APPCENTER_HASH_DEBUG = DEBUG_PRIVATE_VERSION ? "29d0a6f1-b92f-493a-9fce-445681d767ec" : "f9726602-67c9-48d2-b5d0-4761f1c1a8f3"; - // + public static String SMS_HASH = isStandaloneApp() ? "w0lkcmTZkKh" : (DEBUG_VERSION ? "O2P2z+/jBpJ" : "oLeq9AcOZkT"); public static String PLAYSTORE_APP_URL = "https://play.google.com/store/apps/details?id=org.telegram.messenger"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java index 239cdd71f..4618a54e3 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLog.java @@ -166,7 +166,7 @@ public class FileLog { if (!BuildVars.LOGS_ENABLED) { return; } - if (BuildVars.DEBUG_VERSION && needSent(e)) { + if (BuildVars.DEBUG_VERSION && needSent(e) && logToAppCenter) { AndroidUtilities.appCenterLog(e); } ensureInitied(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FilesMigrationService.java b/TMessagesProj/src/main/java/org/telegram/messenger/FilesMigrationService.java new file mode 100644 index 000000000..9ffa04135 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FilesMigrationService.java @@ -0,0 +1,315 @@ +package org.telegram.messenger; + +import android.Manifest; +import android.app.Activity; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.Service; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Environment; +import android.os.IBinder; +import android.text.TextUtils; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.LinearLayout; +import android.widget.ScrollView; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; +import androidx.core.graphics.ColorUtils; + +import com.google.android.exoplayer2.util.Log; + +import org.telegram.ui.ActionBar.BaseFragment; +import org.telegram.ui.ActionBar.BottomSheet; +import org.telegram.ui.ActionBar.Theme; +import org.telegram.ui.Components.LayoutHelper; +import org.telegram.ui.Components.StickerImageView; +import org.telegram.ui.DialogsActivity; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.stream.Stream; + +@RequiresApi(api = Build.VERSION_CODES.R) +public class FilesMigrationService extends Service { + + public static boolean hasOldFolder; + public static boolean isRunning; + public static FilesMigrationBottomSheet filesMigrationBottomSheet; + private int totalFilesCount; + private int movedFilesCount; + private static boolean wasShown = false; + + @Nullable + @Override + public IBinder onBind(Intent intent) { + return null; + } + + public static void start() { + Intent intent = new Intent(ApplicationLoader.applicationContext, FilesMigrationService.class); + ApplicationLoader.applicationContext.startService(intent); + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + NotificationsController.checkOtherNotificationsChannel(); + Notification notification = new Notification.Builder(this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) + .setContentTitle(getText(R.string.MigratingFiles)) + .setAutoCancel(false) + .setSmallIcon(R.drawable.notification) + .build(); + + isRunning = true; + new Thread() { + @Override + public void run() { + migrateOldFolder(); + AndroidUtilities.runOnUIThread(() -> { + isRunning = false; + stopForeground(true); + stopSelf(); + }); + } + }.start(); + startForeground(301, notification); + + return super.onStartCommand(intent, flags, startId); + } + + public void migrateOldFolder() { + File path = Environment.getExternalStorageDirectory(); + if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(SharedConfig.storageCacheDir)) { + ArrayList dirs = AndroidUtilities.getRootDirs(); + if (dirs != null) { + for (int a = 0, N = dirs.size(); a < N; a++) { + File dir = dirs.get(a); + if (dir.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) { + path = dir; + break; + } + } + } + } + + File newPath = ApplicationLoader.applicationContext.getExternalFilesDir(null); + File telegramPath = new File(newPath, "Telegram"); + File oldPath = new File(path, "Telegram"); + + totalFilesCount = getFilesCount(oldPath); + + long moveStart = System.currentTimeMillis(); + if (oldPath.canRead() && oldPath.canWrite()) { + moveDirectory(oldPath, telegramPath); + } + long dt = System.currentTimeMillis() - moveStart; + + FileLog.d("move time = " + dt); + + SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("systemConfig", Context.MODE_PRIVATE); + sharedPreferences.edit().putBoolean("migration_to_scoped_storage_finished", true).apply(); + } + + private int getFilesCount(File source) { + if (!source.exists()) { + return 0; + } + int count = 0; + File[] fileList = source.listFiles(); + if (fileList != null) { + for (int i = 0; i < fileList.length; i++) { + if (fileList[i].isDirectory()) { + count += getFilesCount(fileList[i]); + } else { + count++; + } + } + } + return count; + } + + private void moveDirectory(File source, File target) { + if (!source.exists() || (!target.exists() && !target.mkdir())) { + return; + } + try (Stream files = Files.list(source.toPath())) { + files.forEach(path -> { + File dest = new File(target, path.getFileName().toString()); + if (Files.isDirectory(path)) { + moveDirectory(path.toFile(), dest); + } else { + try { + Files.move(path, dest.toPath()); + } catch (Exception e) { + FileLog.e(e, false); + try { + path.toFile().delete(); + } catch (Exception e1) { + FileLog.e(e1); + } + } + movedFilesCount++; + updateProgress(); + } + }); + } catch (Exception e) { + FileLog.e(e); + } + try { + source.delete(); + } catch (Exception e) { + FileLog.e(e); + } + } + + long lastUpdateTime; + private void updateProgress() { + long time = System.currentTimeMillis(); + if (time - lastUpdateTime > 20 || movedFilesCount >= totalFilesCount - 1) { + int currentCount = movedFilesCount; + AndroidUtilities.runOnUIThread(() -> { + Notification notification = new Notification.Builder(FilesMigrationService.this, NotificationsController.OTHER_NOTIFICATIONS_CHANNEL) + .setContentTitle(getText(R.string.MigratingFiles)) + .setContentText(String.format("%s/%s", currentCount, totalFilesCount)) + .setSmallIcon(R.drawable.notification) + .setAutoCancel(false) + .setProgress(totalFilesCount, currentCount, false) + .build(); + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.notify(301, notification); + }); + } + } + + public static void checkBottomSheet(BaseFragment fragment) { + SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("systemConfig", Context.MODE_PRIVATE); + if (!Environment.isExternalStorageLegacy() || sharedPreferences.getBoolean("migration_to_scoped_storage_finished", false) || sharedPreferences.getInt("migration_to_scoped_storage_count", 0) >= 5 || wasShown || filesMigrationBottomSheet != null || isRunning) { + return; + } + if (Build.VERSION.SDK_INT >= 30) { + File path = Environment.getExternalStorageDirectory(); + if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) { + ArrayList dirs = AndroidUtilities.getRootDirs(); + if (dirs != null) { + for (int a = 0, N = dirs.size(); a < N; a++) { + File dir = dirs.get(a); + if (dir.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) { + path = dir; + break; + } + } + } + } + File oldDirectory = new File(path, "Telegram"); + hasOldFolder = oldDirectory.exists(); + } + if (hasOldFolder) { + filesMigrationBottomSheet = new FilesMigrationBottomSheet(fragment); + filesMigrationBottomSheet.show(); + wasShown = true; + sharedPreferences.edit().putInt("migration_to_scoped_storage_count", sharedPreferences.getInt("migration_to_scoped_storage_count", 0) + 1).apply(); + } else { + sharedPreferences.edit().putBoolean("migration_to_scoped_storage_finished", true).apply(); + } + } + + public static class FilesMigrationBottomSheet extends BottomSheet { + + BaseFragment fragment; + + @Override + protected boolean canDismissWithSwipe() { + return false; + } + + @Override + protected boolean canDismissWithTouchOutside() { + return false; + } + + public FilesMigrationBottomSheet(BaseFragment fragment) { + super(fragment.getParentActivity(), false); + this.fragment = fragment; + setCanceledOnTouchOutside(false); + Context context = fragment.getParentActivity(); + LinearLayout linearLayout = new LinearLayout(context); + linearLayout.setOrientation(LinearLayout.VERTICAL); + + StickerImageView imageView = new StickerImageView(context, currentAccount); + imageView.setStickerNum(7); + imageView.getImageReceiver().setAutoRepeat(1); + linearLayout.addView(imageView, LayoutHelper.createLinear(144, 144, Gravity.CENTER_HORIZONTAL, 0, 16, 0, 0)); + + TextView title = new TextView(context); + title.setGravity(Gravity.START); + title.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); + title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); + title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + title.setText(LocaleController.getString("MigrateOldFolderTitle", R.string.MigrateOldFolderTitle)); + linearLayout.addView(title, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 21, 30, 21, 0)); + + TextView description = new TextView(context); + description.setGravity(Gravity.START); + description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); + description.setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); + description.setText(AndroidUtilities.replaceTags(LocaleController.getString("MigrateOldFolderDescription", R.string.MigrateOldFolderDescription))); + linearLayout.addView(description, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 21, 15, 21, 16)); + + + TextView buttonTextView = new TextView(context); + buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0); + buttonTextView.setGravity(Gravity.CENTER); + buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); + buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + buttonTextView.setText(LocaleController.getString("MigrateOldFolderButton", R.string.MigrateOldFolderButton)); + + buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText)); + buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_featuredStickers_addButton), ColorUtils.setAlphaComponent(Theme.getColor(Theme.key_windowBackgroundWhite), 120))); + + linearLayout.addView(buttonTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, 0, 16, 15, 16, 16)); + + buttonTextView.setOnClickListener(view -> { + migrateOldFolder(); + }); + + ScrollView scrollView = new ScrollView(context); + scrollView.addView(linearLayout); + setCustomView(scrollView); + } + + public void migrateOldFolder() { + Activity activity = fragment.getParentActivity(); + boolean canWrite = activity.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; + boolean canRead = activity.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; + + if (!canRead || !canWrite) { + ArrayList permissions = new ArrayList<>(); + if (!canRead) { + permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE); + } + if (!canWrite) { + permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } + String[] string = new String[permissions.size()]; + activity.requestPermissions(permissions.toArray(string), 4); + return; + } + start(); + dismiss(); + } + + @Override + public void dismiss() { + super.dismiss(); + filesMigrationBottomSheet = null; + } + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java index 3572033d7..457b38b2d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesController.java @@ -4722,20 +4722,26 @@ public class MessagesController extends BaseController implements NotificationCe }); } - public void deleteUserChannelHistory(TLRPC.Chat chat, TLRPC.User user, int offset) { + public void deleteUserChannelHistory(TLRPC.Chat currentChat, TLRPC.User fromUser, TLRPC.Chat fromChat, int offset) { + long fromId = 0; + if (fromUser != null) { + fromId = fromUser.id; + } else if (fromChat != null){ + fromId = fromChat.id; + } if (offset == 0) { - getMessagesStorage().deleteUserChatHistory(-chat.id, user.id); + getMessagesStorage().deleteUserChatHistory(-currentChat.id, fromId); } TLRPC.TL_channels_deleteParticipantHistory req = new TLRPC.TL_channels_deleteParticipantHistory(); - req.channel = getInputChannel(chat); - req.participant = getInputPeer(user); + req.channel = getInputChannel(currentChat); + req.participant = fromUser != null ? getInputPeer(fromUser) : getInputPeer(fromChat); getConnectionsManager().sendRequest(req, (response, error) -> { if (error == null) { TLRPC.TL_messages_affectedHistory res = (TLRPC.TL_messages_affectedHistory) response; if (res.offset > 0) { - deleteUserChannelHistory(chat, user, res.offset); + deleteUserChannelHistory(currentChat, fromUser, fromChat, res.offset); } - processNewChannelDifferenceParams(res.pts, res.pts_count, chat.id); + processNewChannelDifferenceParams(res.pts, res.pts_count, currentChat.id); } }); } @@ -14810,10 +14816,7 @@ public class MessagesController extends BaseController implements NotificationCe } public void markSponsoredAsRead(long dialog_id, MessageObject object) { - ArrayList messages = getSponsoredMessages(dialog_id); - if (messages != null) { - messages.remove(object); - } + sponsoredMessages.remove(dialog_id); } public void deleteMessagesRange(long dialogId, long channelId, int minDate, int maxDate, boolean forAll, Runnable callback) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java index dc59684e8..80294eb4d 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MessagesStorage.java @@ -292,7 +292,7 @@ public class MessagesStorage extends BaseController { shmCacheFile = new File(filesDir, "cache4.db-shm"); boolean createTable = false; - //cacheFile.delete(); + if (!cacheFile.exists()) { createTable = true; } @@ -452,6 +452,9 @@ public class MessagesStorage extends BaseController { } cursor.dispose(); } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("malformed")) { + throw new RuntimeException("malformed"); + } FileLog.e(e); try { database.executeFast("CREATE TABLE IF NOT EXISTS params(id INTEGER PRIMARY KEY, seq INTEGER, pts INTEGER, date INTEGER, qts INTEGER, lsv INTEGER, sg INTEGER, pbytes BLOB)").stepThis().dispose(); @@ -6015,6 +6018,9 @@ public class MessagesStorage extends BaseController { participant = TLRPC.ChannelParticipant.TLdeserialize(data, data.readInt32(false), false); data.reuse(); } + if (participant != null && participant.user_id == getUserConfig().clientUserId) { + user = getUserConfig().getCurrentUser(); + } if (user != null && participant != null) { if (user.status != null) { user.status.expires = cursor.intValue(1); @@ -8748,7 +8754,7 @@ public class MessagesStorage extends BaseController { try { SQLitePreparedStatement state = database.executeFast("UPDATE messages_v2 SET replies_data = ? WHERE mid = ? AND uid = ?"); TLRPC.MessageReplies currentReplies = null; - SQLiteCursor cursor = database.queryFinalized(String.format("SELECT replies_data FROM messages_v2 WHERE mid = %d AND uid = %d", mid, -chatId)); + SQLiteCursor cursor = database.queryFinalized(String.format(Locale.ENGLISH, "SELECT replies_data FROM messages_v2 WHERE mid = %d AND uid = %d", mid, -chatId)); if (cursor.next()) { NativeByteBuffer data = cursor.byteBufferValue(0); if (data != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java index 54d978597..a9b64e0ea 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/NotificationCenter.java @@ -13,6 +13,8 @@ import androidx.annotation.UiThread; import android.os.SystemClock; import android.util.SparseArray; +import com.google.android.exoplayer2.util.Log; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java index 36d12943d..8a62a2595 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/ConnectionsManager.java @@ -1025,7 +1025,7 @@ public class ConnectionsManager extends BaseController { httpConnectionStream.close(); } } catch (Throwable e) { - FileLog.e(e); + FileLog.e(e, false); } try { if (outbuf != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java index 7e5e3de46..d2d206cc3 100644 --- a/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java +++ b/TMessagesProj/src/main/java/org/telegram/tgnet/TLRPC.java @@ -49905,29 +49905,29 @@ public class TLRPC { } } - public static class TL_channels_reportSpam extends TLObject { - public static int constructor = 0xfe087810; + public static class TL_channels_reportSpam extends TLObject { + public static int constructor = 0xf44a8315; - public InputChannel channel; - public InputUser user_id; - public ArrayList id = new ArrayList<>(); + public InputChannel channel; + public InputPeer participant; + public ArrayList id = new ArrayList<>(); - public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) { - return Bool.TLdeserialize(stream, constructor, exception); - } + public TLObject deserializeResponse(AbstractSerializedData stream, int constructor, boolean exception) { + return Bool.TLdeserialize(stream, constructor, exception); + } - public void serializeToStream(AbstractSerializedData stream) { - stream.writeInt32(constructor); - channel.serializeToStream(stream); - user_id.serializeToStream(stream); - stream.writeInt32(0x1cb5c415); - int count = id.size(); - stream.writeInt32(count); - for (int a = 0; a < count; a++) { - stream.writeInt32(id.get(a)); - } - } - } + public void serializeToStream(AbstractSerializedData stream) { + stream.writeInt32(constructor); + channel.serializeToStream(stream); + participant.serializeToStream(stream); + stream.writeInt32(0x1cb5c415); + int count = id.size(); + stream.writeInt32(count); + for (int a = 0; a < count; a++) { + stream.writeInt32(id.get(a)); + } + } + } public static class TL_channels_getMessages extends TLObject { public static int constructor = 0x93d7b347; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java index e3b25c574..f70624ac3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/ActionBarMenuItem.java @@ -1590,6 +1590,7 @@ public class ActionBarMenuItem extends FrameLayout { if (view != null && view.getVisibility() != GONE) { view.setVisibility(GONE); measurePopup = true; + checkHideMenuItem(); } } @@ -1618,6 +1619,7 @@ public class ActionBarMenuItem extends FrameLayout { popupLayout.getItemAt(a).setVisibility(GONE); } measurePopup = true; + checkHideMenuItem(); } public boolean isSubItemVisible(int id) { @@ -1636,6 +1638,7 @@ public class ActionBarMenuItem extends FrameLayout { if (view != null && view.getVisibility() != VISIBLE) { view.setVisibility(VISIBLE); measurePopup = true; + checkHideMenuItem(); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/CacheControlActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/CacheControlActivity.java index cca5ae1d6..fcb1a3b7e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/CacheControlActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/CacheControlActivity.java @@ -10,13 +10,11 @@ package org.telegram.ui; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; import android.content.SharedPreferences; -import android.net.Uri; +import android.content.pm.PackageManager; import android.os.Build; import android.os.Environment; import android.os.StatFs; -import android.provider.Settings; import android.text.TextUtils; import android.transition.ChangeBounds; import android.transition.Fade; @@ -25,7 +23,6 @@ import android.transition.TransitionSet; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; -import android.widget.CheckBox; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; @@ -35,18 +32,14 @@ import androidx.core.widget.NestedScrollView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.exoplayer2.util.Log; - import org.telegram.SQLite.SQLiteCursor; import org.telegram.SQLite.SQLiteDatabase; import org.telegram.SQLite.SQLitePreparedStatement; import org.telegram.messenger.AndroidUtilities; -import org.telegram.messenger.ApplicationLoader; -import org.telegram.messenger.BuildConfig; -import org.telegram.messenger.BuildVars; import org.telegram.messenger.DialogObject; import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; +import org.telegram.messenger.FilesMigrationService; import org.telegram.messenger.ImageLoader; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MediaDataController; @@ -79,11 +72,7 @@ import org.telegram.ui.Components.StroageUsageView; import org.telegram.ui.Components.UndoView; import java.io.File; -import java.nio.file.CopyOption; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; -import java.util.stream.Stream; public class CacheControlActivity extends BaseFragment { @@ -118,7 +107,6 @@ public class CacheControlActivity extends BaseFragment { private boolean calculating = true; private volatile boolean canceled = false; - private boolean hasOldFolder; private View bottomSheetView; private BottomSheet bottomSheet; @@ -213,24 +201,6 @@ public class CacheControlActivity extends BaseFragment { }); fragmentCreateTime = System.currentTimeMillis(); - - if (Build.VERSION.SDK_INT >= 30) { - File path = Environment.getExternalStorageDirectory(); - if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(SharedConfig.storageCacheDir)) { - ArrayList dirs = AndroidUtilities.getRootDirs(); - if (dirs != null) { - for (int a = 0, N = dirs.size(); a < N; a++) { - File dir = dirs.get(a); - if (dir.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) { - path = dir; - break; - } - } - } - } - File oldDirectory = new File(path, "Telegram"); - hasOldFolder = oldDirectory.exists(); - } updateRows(); return true; } @@ -247,21 +217,18 @@ public class CacheControlActivity extends BaseFragment { cacheInfoRow = rowCount++; databaseRow = rowCount++; databaseInfoRow = rowCount++; -// if (hasOldFolder) { -// migrateOldFolderRow = rowCount++; -// } } private void updateStorageUsageRow() { View view = layoutManager.findViewByPosition(storageUsageRow); if (view instanceof StroageUsageView) { StroageUsageView stroageUsageView = ((StroageUsageView) view); - long currentTime = System.currentTimeMillis(); + long currentTime = System.currentTimeMillis(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && currentTime - fragmentCreateTime > 250) { TransitionSet transition = new TransitionSet(); ChangeBounds changeBounds = new ChangeBounds(); changeBounds.setDuration(250); - changeBounds.excludeTarget(stroageUsageView.legendLayout,true); + changeBounds.excludeTarget(stroageUsageView.legendLayout, true); Fade in = new Fade(Fade.IN); in.setDuration(290); transition @@ -569,111 +536,7 @@ public class CacheControlActivity extends BaseFragment { @RequiresApi(api = Build.VERSION_CODES.R) private void migrateOldFolder() { - boolean isExternalStorageManager = Environment.isExternalStorageManager(); - - if (!BuildVars.NO_SCOPED_STORAGE && !isExternalStorageManager) { - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setTitle(LocaleController.getString("MigrateOldFolder", R.string.MigrateOldFolder)); - builder.setMessage(LocaleController.getString("ManageAllFilesRational2", R.string.ManageAllFilesRational2)); - builder.setPositiveButton(LocaleController.getString("Allow", R.string.Allow), (i1, i2) -> { - Uri uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID); - getParentActivity().startActivity(new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri)); - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (i1, i2) -> { - - }); - builder.show(); - return; - } - - Thread thread = new Thread() { - - int totalFilesCount; - int movedFilesCount; - @Override - public void run() { - super.run(); - File path = Environment.getExternalStorageDirectory(); - if (Build.VERSION.SDK_INT >= 19 && !TextUtils.isEmpty(SharedConfig.storageCacheDir)) { - ArrayList dirs = AndroidUtilities.getRootDirs(); - if (dirs != null) { - for (int a = 0, N = dirs.size(); a < N; a++) { - File dir = dirs.get(a); - if (dir.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) { - path = dir; - break; - } - } - } - } - - File newPath = ApplicationLoader.applicationContext.getExternalFilesDir(null); - File telegramPath = new File(newPath, "Telegram"); - File oldPath = new File(path, "Telegram"); - - totalFilesCount = getFilesCount(oldPath); - - long moveStart = System.currentTimeMillis(); - moveDirectory(oldPath, telegramPath); - long dt = System.currentTimeMillis() - moveStart; - FileLog.d("move time = " + dt); - } - - private int getFilesCount(File source) { - if (!source.exists()) { - return 0; - } - int count = 0; - File[] fileList = source.listFiles(); - for (int i = 0; i < fileList.length; i++) { - if (fileList[i].isDirectory()) { - count += getFilesCount(fileList[i]); - } else { - count++; - } - } - return count; - } - - private void moveDirectory(File source, File target) { - if (!source.exists() || (!target.exists() && !target.mkdir())) { - return; - } - try (Stream files = Files.list(source.toPath())) { - files.forEach(path -> { - File dest = new File(target, path.getFileName().toString()); - if (Files.isDirectory(path)) { - moveDirectory(path.toFile(), dest); - } else { - try { - Files.move(path, dest.toPath()); - } catch (Exception e) { - FileLog.e(e); - try { - path.toFile().delete(); - } catch (Exception e1) { - FileLog.e(e1); - } - } - movedFilesCount++; - updateProgress(); - } - }); - } catch (Exception e) { - FileLog.e(e); - } - try { - source.delete(); - } catch (Exception e) { - FileLog.e(e); - } - } - - private void updateProgress() { - float p = movedFilesCount / (float) totalFilesCount; - } - }; - thread.start(); + FilesMigrationService.checkBottomSheet(this); } private void clearDatabase() { @@ -982,4 +845,21 @@ public class CacheControlActivity extends BaseFragment { arrayList.add(new ThemeDescription(bottomSheetView, 0, null, null, null, null, Theme.key_statisticChartLine_indigo)); return arrayList; } + + @Override + public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) { + if (requestCode == 4) { + boolean allGranted = true; + for (int a = 0; a < grantResults.length; a++) { + if (grantResults[a] != PackageManager.PERMISSION_GRANTED) { + allGranted = false; + break; + } + } + if (allGranted && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && FilesMigrationService.filesMigrationBottomSheet != null) { + FilesMigrationService.filesMigrationBottomSheet.migrateOldFolder(); + } + + } + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java index 51c7bdc67..78dd6fcaf 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatActionCell.java @@ -378,7 +378,7 @@ public class ChatActionCell extends BaseCell implements DownloadController.FileD } else if (url.startsWith("http")) { Browser.openUrl(getContext(), url); } else { - delegate.needOpenUserProfile(Integer.parseInt(url)); + delegate.needOpenUserProfile(Long.parseLong(url)); } } result = true; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/SessionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/SessionCell.java index 61a170e7d..55985d392 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/SessionCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/SessionCell.java @@ -105,6 +105,16 @@ public class SessionCell extends FrameLayout { linearLayout.addView(onlineTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT | Gravity.TOP, 0, 2, 0, 0)); } + int leftMargin; + int rightMargin; + if (LocaleController.isRTL) { + rightMargin = type == 0 ? 72 : 21; + leftMargin = 21; + } else { + leftMargin = type == 0 ? 72 : 21; + rightMargin = 21; + } + detailTextView = new TextView(context); detailTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); detailTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); @@ -113,7 +123,7 @@ public class SessionCell extends FrameLayout { detailTextView.setSingleLine(true); detailTextView.setEllipsize(TextUtils.TruncateAt.END); detailTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP); - addView(detailTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, type == 0 ? 72 : 21, 36, 21, 0)); + addView(detailTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, leftMargin, 36, rightMargin, 0)); detailExTextView = new TextView(context); detailExTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3)); @@ -123,7 +133,7 @@ public class SessionCell extends FrameLayout { detailExTextView.setSingleLine(true); detailExTextView.setEllipsize(TextUtils.TruncateAt.END); detailExTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP); - addView(detailExTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, type == 0 ? 72 : 21, 59, 21, 0)); + addView(detailExTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, leftMargin, 59, rightMargin, 0)); } @Override @@ -136,11 +146,7 @@ public class SessionCell extends FrameLayout { if (object instanceof TLRPC.TL_authorization) { TLRPC.TL_authorization session = (TLRPC.TL_authorization) object; - - imageView.setImageDrawable(createDrawable(session)); - // nameTextView.setText(String.format(Locale.US, "%s %s", session.app_name, session.app_version)); - StringBuilder stringBuilder = new StringBuilder(); if (session.device_model.length() != 0) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 892bc3555..63cddae57 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1794,9 +1794,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not * @return Other same chats index difference */ public int getOtherSameChatsDiff() { + if (parentLayout == null || parentLayout.fragmentsStack == null) { + return 0; + } int cur = parentLayout.fragmentsStack.indexOf(this); - if (cur == -1) + if (cur == -1) { cur = parentLayout.fragmentsStack.size(); + } int i = cur; for (int a = 0; a < parentLayout.fragmentsStack.size(); a++) { BaseFragment fragment = parentLayout.fragmentsStack.get(a); @@ -2344,6 +2348,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not }); } }); + } else { + actionBar.setSubtitle(LocaleController.getString("NoMessagesForThisDay", R.string.NoMessagesForThisDay)); } } }); @@ -2388,7 +2394,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not AndroidUtilities.updateViewVisibilityAnimated(avatarContainer, true, 0.95f, true); if (editTextItem != null && editTextItem.getTag() != null) { if (headerItem != null) { - Log.d("kek", "2"); headerItem.setVisibility(View.GONE); } if (editTextItem != null) { @@ -2405,7 +2410,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } } else if (chatActivityEnterView.hasText() && TextUtils.isEmpty(chatActivityEnterView.getSlowModeTimer()) && (currentChat == null || ChatObject.canSendMessages(currentChat))) { if (headerItem != null) { - Log.d("kek", "3"); headerItem.setVisibility(View.GONE); } if (editTextItem != null) { @@ -2516,7 +2520,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not searchItemVisible = false; } - if (chatMode == 0 && threadMessageId == 0 && !UserObject.isReplyUser(currentUser) && reportType < 0) { + if (chatMode == 0 && threadMessageId == 0 && !UserObject.isReplyUser(currentUser) && reportType < 0 && !inMenuMode) { TLRPC.UserFull userFull = null; if (currentUser != null) { audioCallIconItem = menu.addItem(call, R.drawable.ic_call, themeDelegate); @@ -6972,7 +6976,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (editTextItem.getTag() == null) { editTextItem.setTag(1); editTextItem.setVisibility(View.VISIBLE); - Log.d("kek", "4"); headerItem.setVisibility(View.GONE); attachItem.setVisibility(View.GONE); } @@ -6983,7 +6986,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not editTextItem.setTag(null); editTextItem.setVisibility(View.GONE); if (chatActivityEnterView.hasText() && TextUtils.isEmpty(chatActivityEnterView.getSlowModeTimer())) { - Log.d("kek", "5"); headerItem.setVisibility(View.GONE); attachItem.setVisibility(View.VISIBLE); } else { @@ -7045,7 +7047,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } if (TextUtils.isEmpty(chatActivityEnterView.getSlowModeTimer())) { if (headerItem != null) { - Log.d("kek", "6"); headerItem.setVisibility(View.GONE); } if (attachItem != null) { @@ -14171,14 +14172,25 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not } if (startLoadFromDate != 0) { int dateObjectIndex = -1; + int closeDateObjectIndex = -1; + int closeDateDiff = 0; for (int i = 0; i < messages.size(); i++) { if (messages.get(i).isDateObject && Math.abs(startLoadFromDate - messages.get(i).messageOwner.date) <= 100) { dateObjectIndex = i; break; } + if (messages.get(i).isDateObject) { + int timeDiff = Math.abs(startLoadFromDate - messages.get(i).messageOwner.date); + if (closeDateObjectIndex == -1 || timeDiff < closeDateDiff) { + closeDateDiff = timeDiff; + closeDateObjectIndex = i; + } + } } - if (dateObjectIndex > 0) { + if (dateObjectIndex >= 0) { chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + dateObjectIndex, (int) (AndroidUtilities.dp(4)), false); + } else if (closeDateObjectIndex >= 0) { + chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + closeDateObjectIndex, chatListView.getMeasuredHeight() / 2 - AndroidUtilities.dp(24), false); } } } @@ -21901,7 +21913,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (!actionBar.isSearchFieldVisible()) { AndroidUtilities.updateViewVisibilityAnimated(avatarContainer, false, 0.95f, true); if (headerItem != null) { - Log.d("kek", "1"); headerItem.setVisibility(View.GONE); } if (attachItem != null) { @@ -22964,681 +22975,675 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not view = new ChatMessageCell(mContext, true, themeDelegate); } ChatMessageCell chatMessageCell = (ChatMessageCell) view; - if (!inPreviewMode) { - chatMessageCell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() { + chatMessageCell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() { - @Override - public void didPressHint(ChatMessageCell cell, int type) { - if (type == 0) { - TLRPC.TL_messageMediaPoll media = (TLRPC.TL_messageMediaPoll) cell.getMessageObject().messageOwner.media; - showPollSolution(cell.getMessageObject(), media.results); - } else if (type == 1) { - MessageObject messageObject = cell.getMessageObject(); - if (messageObject.messageOwner.fwd_from == null || TextUtils.isEmpty(messageObject.messageOwner.fwd_from.psa_type)) { - return; - } - CharSequence text = LocaleController.getString("PsaMessageInfo_" + messageObject.messageOwner.fwd_from.psa_type); - if (TextUtils.isEmpty(text)) { - text = LocaleController.getString("PsaMessageInfoDefault", R.string.PsaMessageInfoDefault); - } - SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text); - MessageObject.addLinks(false, stringBuilder); - MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); - if (group != null) { - for (int a = 0, N = group.posArray.size(); a < N; a++) { - MessageObject.GroupedMessagePosition pos = group.posArray.get(a); - if ((pos.flags & MessageObject.POSITION_FLAG_LEFT) != 0) { - MessageObject m = group.messages.get(a); - if (m != messageObject) { - messageObject = m; - int count = chatListView.getChildCount(); - for (int b = 0; b < count; b++) { - View view = chatListView.getChildAt(b); - if (!(view instanceof ChatMessageCell)) { - continue; - } - ChatMessageCell c = (ChatMessageCell) view; - if (messageObject.equals(c.getMessageObject())) { - cell = c; - } + @Override + public void didPressHint(ChatMessageCell cell, int type) { + if (type == 0) { + TLRPC.TL_messageMediaPoll media = (TLRPC.TL_messageMediaPoll) cell.getMessageObject().messageOwner.media; + showPollSolution(cell.getMessageObject(), media.results); + } else if (type == 1) { + MessageObject messageObject = cell.getMessageObject(); + if (messageObject.messageOwner.fwd_from == null || TextUtils.isEmpty(messageObject.messageOwner.fwd_from.psa_type)) { + return; + } + CharSequence text = LocaleController.getString("PsaMessageInfo_" + messageObject.messageOwner.fwd_from.psa_type); + if (TextUtils.isEmpty(text)) { + text = LocaleController.getString("PsaMessageInfoDefault", R.string.PsaMessageInfoDefault); + } + SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text); + MessageObject.addLinks(false, stringBuilder); + MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); + if (group != null) { + for (int a = 0, N = group.posArray.size(); a < N; a++) { + MessageObject.GroupedMessagePosition pos = group.posArray.get(a); + if ((pos.flags & MessageObject.POSITION_FLAG_LEFT) != 0) { + MessageObject m = group.messages.get(a); + if (m != messageObject) { + messageObject = m; + int count = chatListView.getChildCount(); + for (int b = 0; b < count; b++) { + View view = chatListView.getChildAt(b); + if (!(view instanceof ChatMessageCell)) { + continue; + } + ChatMessageCell c = (ChatMessageCell) view; + if (messageObject.equals(c.getMessageObject())) { + cell = c; } } - break; } + break; } } - showInfoHint(messageObject, stringBuilder, 1); } - cell.showHintButton(false, true, type); + showInfoHint(messageObject, stringBuilder, 1); } + cell.showHintButton(false, true, type); + } - @Override - public boolean shouldDrawThreadProgress(ChatMessageCell cell) { - MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); - MessageObject message; - if (group != null && !group.messages.isEmpty()) { - message = group.messages.get(0); + @Override + public boolean shouldDrawThreadProgress(ChatMessageCell cell) { + MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); + MessageObject message; + if (group != null && !group.messages.isEmpty()) { + message = group.messages.get(0); + } else { + message = cell.getMessageObject(); + } + if (message == null) { + return false; + } + return message.getId() == commentLoadingMessageId; + } + + @Override + public void didPressSideButton(ChatMessageCell cell) { + if (getParentActivity() == null) { + return; + } + if (chatActivityEnterView != null) { + chatActivityEnterView.closeKeyboard(); + } + MessageObject messageObject = cell.getMessageObject(); + if (chatMode == MODE_PINNED) { + chatActivityDelegate.openReplyMessage(messageObject.getId()); + finishFragment(); + } else if ((UserObject.isReplyUser(currentUser) || UserObject.isUserSelf(currentUser)) && messageObject.messageOwner.fwd_from.saved_from_peer != null) { + if (UserObject.isReplyUser(currentUser) && messageObject.messageOwner.reply_to != null && messageObject.messageOwner.reply_to.reply_to_top_id != 0) { + openDiscussionMessageChat(messageObject.messageOwner.reply_to.reply_to_peer_id.channel_id, null, messageObject.messageOwner.reply_to.reply_to_top_id, 0, -1, messageObject.messageOwner.fwd_from.saved_from_msg_id, messageObject); } else { - message = cell.getMessageObject(); + openOriginalReplyChat(messageObject); } - if (message == null) { - return false; + } else { + ArrayList arrayList = null; + if (messageObject.getGroupId() != 0) { + MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId()); + if (groupedMessages != null) { + arrayList = groupedMessages.messages; + } } - return message.getId() == commentLoadingMessageId; - } + if (arrayList == null) { + arrayList = new ArrayList<>(); + arrayList.add(messageObject); + } + showDialog(new ShareAlert(mContext, ChatActivity.this, arrayList, null, null, ChatObject.isChannel(currentChat), null, null, false, false, themeDelegate) { + @Override + public void dismissInternal() { + super.dismissInternal(); + AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid); + if (chatActivityEnterView.getVisibility() == View.VISIBLE) { + fragmentView.requestLayout(); + } + } - @Override - public void didPressSideButton(ChatMessageCell cell) { + @Override + protected void onSend(LongSparseArray dids, int count) { + if (dids.size() == 1) { + undoView.showWithAction(dids.valueAt(0).id, UndoView.ACTION_FWD_MESSAGES, count); + } else { + undoView.showWithAction(0, UndoView.ACTION_FWD_MESSAGES, count, dids.size(), null, null); + } + } + }); + AndroidUtilities.setAdjustResizeToNothing(getParentActivity(), classGuid); + fragmentView.requestLayout(); + } + } + + @Override + public boolean needPlayMessage(MessageObject messageObject) { + if (messageObject.isVoice() || messageObject.isRoundVideo()) { + boolean result = MediaController.getInstance().playMessage(messageObject); + MediaController.getInstance().setVoiceMessagesPlaylist(result ? createVoiceMessagesPlaylist(messageObject, false) : null, false); + return result; + } else if (messageObject.isMusic()) { + return MediaController.getInstance().setPlaylist(messages, messageObject, mergeDialogId); + } + return false; + } + + @Override + public void videoTimerReached() { + showNoSoundHint(); + } + + @Override + public void didPressTime(ChatMessageCell cell) { + undoView.showWithAction(dialog_id, UndoView.ACTION_IMPORT_INFO, null); + } + + @Override + public void didPressChannelAvatar(ChatMessageCell cell, TLRPC.Chat chat, int postId, float touchX, float touchY) { + if (chat == null) { + return; + } + if (actionBar.isActionModeShowed() || reportType >= 0) { + processRowSelect(cell, true, touchX, touchY); + return; + } + openChat(cell, chat, postId); + } + + @Override + public void didPressHiddenForward(ChatMessageCell cell) { + if (cell.getMessageObject().isImportedForward()) { + didPressTime(cell); + return; + } + showForwardHint(cell); + } + + @Override + public void didPressOther(ChatMessageCell cell, float otherX, float otherY) { + MessageObject messageObject = cell.getMessageObject(); + if (messageObject.type == 16) { + if (currentUser != null) { + VoIPHelper.startCall(currentUser, messageObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), getAccountInstance()); + } + } else { + createMenu(cell, true, false, otherX, otherY, messageObject.isMusic()); + } + } + + @Override + public void didPressUserAvatar(ChatMessageCell cell, TLRPC.User user, float touchX, float touchY) { + if (actionBar.isActionModeShowed() || reportType >= 0) { + processRowSelect(cell, true, touchX, touchY); + return; + } + openProfile(user); + } + + @Override + public boolean didLongPressUserAvatar(ChatMessageCell cell, TLRPC.User user, float touchX, float touchY) { + if (isAvatarPreviewerEnabled()) { + final boolean enableMention = currentChat != null && (bottomOverlayChat == null || bottomOverlayChat.getVisibility() != View.VISIBLE) && (bottomOverlay == null || bottomOverlay.getVisibility() != View.VISIBLE); + final AvatarPreviewer.MenuItem[] menuItems = new AvatarPreviewer.MenuItem[2 + (enableMention ? 1 : 0)]; + menuItems[0] = AvatarPreviewer.MenuItem.OPEN_PROFILE; + menuItems[1] = AvatarPreviewer.MenuItem.SEND_MESSAGE; + if (enableMention) { + menuItems[2] = AvatarPreviewer.MenuItem.MENTION; + } + final TLRPC.UserFull userFull = getMessagesController().getUserFull(user.id); + final AvatarPreviewer.Data data; + if (userFull != null) { + data = AvatarPreviewer.Data.of(userFull, menuItems); + } else { + data = AvatarPreviewer.Data.of(user, classGuid, menuItems); + } + if (AvatarPreviewer.canPreview(data)) { + AvatarPreviewer.getInstance().show((ViewGroup) fragmentView, data, item -> { + switch (item) { + case SEND_MESSAGE: + openDialog(cell, user); + break; + case OPEN_PROFILE: + openProfile(user); + break; + case MENTION: + appendMention(user); + break; + } + }); + return true; + } + } + return false; + } + + private void appendMention(TLRPC.User user) { + if (chatActivityEnterView != null) { + final SpannableStringBuilder sb = new SpannableStringBuilder(); + final CharSequence text = chatActivityEnterView.getFieldText(); + if (text != null) { + sb.append(text); + } + if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { + sb.append(' '); + } + if (user.username != null) { + sb.append("@").append(user.username).append(" "); + } else { + String name = UserObject.getFirstName(user, false); + Spannable spannable = new SpannableString(name + " "); + spannable.setSpan(new URLSpanUserMention("" + user.id, 3), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + sb.append(spannable); + } + chatActivityEnterView.setFieldText(sb); + AndroidUtilities.runOnUIThread(() -> chatActivityEnterView.openKeyboard(), 200); + } + } + + @Override + public boolean didLongPressChannelAvatar(ChatMessageCell cell, TLRPC.Chat chat, int postId, float touchX, float touchY) { + if (isAvatarPreviewerEnabled()) { + AvatarPreviewer.MenuItem[] menuItems = {AvatarPreviewer.MenuItem.OPEN_PROFILE}; + if (currentChat == null || currentChat.id != chat.id || isThreadChat()) { + menuItems = Arrays.copyOf(menuItems, 2); + menuItems[1] = chat.broadcast ? AvatarPreviewer.MenuItem.OPEN_CHANNEL : AvatarPreviewer.MenuItem.OPEN_GROUP; + } + final TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id); + final AvatarPreviewer.Data data; + if (chatFull != null) { + data = AvatarPreviewer.Data.of(chat, chatFull, menuItems); + } else { + data = AvatarPreviewer.Data.of(chat, classGuid, menuItems); + } + if (AvatarPreviewer.canPreview(data)) { + AvatarPreviewer.getInstance().show((ViewGroup) fragmentView, data, item -> { + switch (item) { + case OPEN_PROFILE: + openProfile(chat); + break; + case OPEN_GROUP: + case OPEN_CHANNEL: + openChat(cell, chat, 0); + break; + } + }); + return true; + } + } + return false; + } + + private void openProfile(TLRPC.User user) { + if (user != null && user.id != getUserConfig().getClientUserId()) { + Bundle args = new Bundle(); + args.putLong("user_id", user.id); + ProfileActivity fragment = new ProfileActivity(args); + fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == user.id ? 1 : 0); + AndroidUtilities.setAdjustResizeToNothing(getParentActivity(), classGuid); + presentFragment(fragment); + } + } + + private void openProfile(TLRPC.Chat chat) { + if (chat != null) { + Bundle args = new Bundle(); + args.putLong("chat_id", chat.id); + presentFragment(new ProfileActivity(args)); + } + } + + private void openDialog(ChatMessageCell cell, TLRPC.User user) { + if (user != null) { + Bundle args = new Bundle(); + args.putLong("user_id", user.id); + if (getMessagesController().checkCanOpenChat(args, ChatActivity.this, cell.getMessageObject())) { + presentFragment(new ChatActivity(args)); + } + } + } + + private void openChat(ChatMessageCell cell, TLRPC.Chat chat, int postId) { + if (currentChat != null && chat.id == currentChat.id) { + scrollToMessageId(postId, cell.getMessageObject().getId(), true, 0, true, 0); + } else if (currentChat == null || chat.id != currentChat.id || isThreadChat()) { + Bundle args = new Bundle(); + args.putLong("chat_id", chat.id); + if (postId != 0) { + args.putInt("message_id", postId); + } + if (getMessagesController().checkCanOpenChat(args, ChatActivity.this, cell.getMessageObject())) { + presentFragment(new ChatActivity(args)); + } + } + } + + private boolean isAvatarPreviewerEnabled() { + return UserObject.isUserSelf(currentUser) || (currentChat != null && (!ChatObject.isChannel(currentChat) || currentChat.megagroup)); + } + + @Override + public void didPressBotButton(ChatMessageCell cell, TLRPC.KeyboardButton button) { + if (getParentActivity() == null || bottomOverlayChat.getVisibility() == View.VISIBLE && + !(button instanceof TLRPC.TL_keyboardButtonSwitchInline) && !(button instanceof TLRPC.TL_keyboardButtonCallback) && + !(button instanceof TLRPC.TL_keyboardButtonGame) && !(button instanceof TLRPC.TL_keyboardButtonUrl) && + !(button instanceof TLRPC.TL_keyboardButtonBuy) && !(button instanceof TLRPC.TL_keyboardButtonUrlAuth)) { + return; + } + chatActivityEnterView.didPressedBotButton(button, cell.getMessageObject(), cell.getMessageObject()); + } + + @Override + public void didPressReaction(ChatMessageCell cell, TLRPC.TL_reactionCount reaction) { + getSendMessagesHelper().sendReaction(cell.getMessageObject(), reaction.reaction, ChatActivity.this); + } + + @Override + public void didPressVoteButtons(ChatMessageCell cell, ArrayList buttons, int showCount, int x, int y) { + if (showCount >= 0 || buttons.isEmpty()) { if (getParentActivity() == null) { return; } - if (chatActivityEnterView != null) { - chatActivityEnterView.closeKeyboard(); - } - MessageObject messageObject = cell.getMessageObject(); - if (chatMode == MODE_PINNED) { - chatActivityDelegate.openReplyMessage(messageObject.getId()); - finishFragment(); - } else if ((UserObject.isReplyUser(currentUser) || UserObject.isUserSelf(currentUser)) && messageObject.messageOwner.fwd_from.saved_from_peer != null) { - if (UserObject.isReplyUser(currentUser) && messageObject.messageOwner.reply_to != null && messageObject.messageOwner.reply_to.reply_to_top_id != 0) { - openDiscussionMessageChat(messageObject.messageOwner.reply_to.reply_to_peer_id.channel_id, null, messageObject.messageOwner.reply_to.reply_to_top_id, 0, -1, messageObject.messageOwner.fwd_from.saved_from_msg_id, messageObject); - } else { - openOriginalReplyChat(messageObject); - } - } else { - ArrayList arrayList = null; - if (messageObject.getGroupId() != 0) { - MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId()); - if (groupedMessages != null) { - arrayList = groupedMessages.messages; - } - } - if (arrayList == null) { - arrayList = new ArrayList<>(); - arrayList.add(messageObject); - } - showDialog(new ShareAlert(mContext, ChatActivity.this, arrayList, null, null, ChatObject.isChannel(currentChat), null, null, false, false, themeDelegate) { - @Override - public void dismissInternal() { - super.dismissInternal(); - AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid); - if (chatActivityEnterView.getVisibility() == View.VISIBLE) { - fragmentView.requestLayout(); - } - } - - @Override - protected void onSend(LongSparseArray dids, int count) { - if (dids.size() == 1) { - undoView.showWithAction(dids.valueAt(0).id, UndoView.ACTION_FWD_MESSAGES, count); - } else { - undoView.showWithAction(0, UndoView.ACTION_FWD_MESSAGES, count, dids.size(), null, null); - } - } - }); - AndroidUtilities.setAdjustResizeToNothing(getParentActivity(), classGuid); - fragmentView.requestLayout(); - } - } - - @Override - public boolean needPlayMessage(MessageObject messageObject) { - if (messageObject.isVoice() || messageObject.isRoundVideo()) { - boolean result = MediaController.getInstance().playMessage(messageObject); - MediaController.getInstance().setVoiceMessagesPlaylist(result ? createVoiceMessagesPlaylist(messageObject, false) : null, false); - return result; - } else if (messageObject.isMusic()) { - return MediaController.getInstance().setPlaylist(messages, messageObject, mergeDialogId); - } - return false; - } - - @Override - public void videoTimerReached() { - showNoSoundHint(); - } - - @Override - public void didPressTime(ChatMessageCell cell) { - undoView.showWithAction(dialog_id, UndoView.ACTION_IMPORT_INFO, null); - } - - @Override - public void didPressChannelAvatar(ChatMessageCell cell, TLRPC.Chat chat, int postId, float touchX, float touchY) { - if (chat == null) { - return; - } - if (actionBar.isActionModeShowed() || reportType >= 0) { - processRowSelect(cell, true, touchX, touchY); - return; - } - openChat(cell, chat, postId); - } - - @Override - public void didPressHiddenForward(ChatMessageCell cell) { - if (cell.getMessageObject().isImportedForward()) { - didPressTime(cell); - return; - } - showForwardHint(cell); - } - - @Override - public void didPressOther(ChatMessageCell cell, float otherX, float otherY) { - MessageObject messageObject = cell.getMessageObject(); - if (messageObject.type == 16) { - if (currentUser != null) { - VoIPHelper.startCall(currentUser, messageObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), getAccountInstance()); - } - } else { - createMenu(cell, true, false, otherX, otherY, messageObject.isMusic()); - } - } - - @Override - public void didPressUserAvatar(ChatMessageCell cell, TLRPC.User user, float touchX, float touchY) { - if (actionBar.isActionModeShowed() || reportType >= 0) { - processRowSelect(cell, true, touchX, touchY); - return; - } - openProfile(user); - } - - @Override - public boolean didLongPressUserAvatar(ChatMessageCell cell, TLRPC.User user, float touchX, float touchY) { - if (isAvatarPreviewerEnabled()) { - final boolean enableMention = currentChat != null && (bottomOverlayChat == null || bottomOverlayChat.getVisibility() != View.VISIBLE) && (bottomOverlay == null || bottomOverlay.getVisibility() != View.VISIBLE); - final AvatarPreviewer.MenuItem[] menuItems = new AvatarPreviewer.MenuItem[2 + (enableMention ? 1 : 0)]; - menuItems[0] = AvatarPreviewer.MenuItem.OPEN_PROFILE; - menuItems[1] = AvatarPreviewer.MenuItem.SEND_MESSAGE; - if (enableMention) { - menuItems[2] = AvatarPreviewer.MenuItem.MENTION; - } - final TLRPC.UserFull userFull = getMessagesController().getUserFull(user.id); - final AvatarPreviewer.Data data; - if (userFull != null) { - data = AvatarPreviewer.Data.of(userFull, menuItems); - } else { - data = AvatarPreviewer.Data.of(user, classGuid, menuItems); - } - if (AvatarPreviewer.canPreview(data)) { - AvatarPreviewer.getInstance().show((ViewGroup) fragmentView, data, item -> { - switch (item) { - case SEND_MESSAGE: - openDialog(cell, user); - break; - case OPEN_PROFILE: - openProfile(user); - break; - case MENTION: - appendMention(user); - break; - } - }); - return true; - } - } - return false; - } - - private void appendMention(TLRPC.User user) { - if (chatActivityEnterView != null) { - final SpannableStringBuilder sb = new SpannableStringBuilder(); - final CharSequence text = chatActivityEnterView.getFieldText(); - if (text != null) { - sb.append(text); - } - if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') { - sb.append(' '); - } - if (user.username != null) { - sb.append("@").append(user.username).append(" "); - } else { - String name = UserObject.getFirstName(user, false); - Spannable spannable = new SpannableString(name + " "); - spannable.setSpan(new URLSpanUserMention("" + user.id, 3), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - sb.append(spannable); - } - chatActivityEnterView.setFieldText(sb); - AndroidUtilities.runOnUIThread(() -> chatActivityEnterView.openKeyboard(), 200); - } - } - - @Override - public boolean didLongPressChannelAvatar(ChatMessageCell cell, TLRPC.Chat chat, int postId, float touchX, float touchY) { - if (isAvatarPreviewerEnabled()) { - AvatarPreviewer.MenuItem[] menuItems = {AvatarPreviewer.MenuItem.OPEN_PROFILE}; - if (currentChat == null || currentChat.id != chat.id || isThreadChat()) { - menuItems = Arrays.copyOf(menuItems, 2); - menuItems[1] = chat.broadcast ? AvatarPreviewer.MenuItem.OPEN_CHANNEL : AvatarPreviewer.MenuItem.OPEN_GROUP; - } - final TLRPC.ChatFull chatFull = getMessagesController().getChatFull(chat.id); - final AvatarPreviewer.Data data; - if (chatFull != null) { - data = AvatarPreviewer.Data.of(chat, chatFull, menuItems); - } else { - data = AvatarPreviewer.Data.of(chat, classGuid, menuItems); - } - if (AvatarPreviewer.canPreview(data)) { - AvatarPreviewer.getInstance().show((ViewGroup) fragmentView, data, item -> { - switch (item) { - case OPEN_PROFILE: - openProfile(chat); - break; - case OPEN_GROUP: - case OPEN_CHANNEL: - openChat(cell, chat, 0); - break; - } - }); - return true; - } - } - return false; - } - - private void openProfile(TLRPC.User user) { - if (user != null && user.id != getUserConfig().getClientUserId()) { - Bundle args = new Bundle(); - args.putLong("user_id", user.id); - ProfileActivity fragment = new ProfileActivity(args); - fragment.setPlayProfileAnimation(currentUser != null && currentUser.id == user.id ? 1 : 0); - AndroidUtilities.setAdjustResizeToNothing(getParentActivity(), classGuid); - presentFragment(fragment); - } - } - - private void openProfile(TLRPC.Chat chat) { - if (chat != null) { - Bundle args = new Bundle(); - args.putLong("chat_id", chat.id); - presentFragment(new ProfileActivity(args)); - } - } - - private void openDialog(ChatMessageCell cell, TLRPC.User user) { - if (user != null) { - Bundle args = new Bundle(); - args.putLong("user_id", user.id); - if (getMessagesController().checkCanOpenChat(args, ChatActivity.this, cell.getMessageObject())) { - presentFragment(new ChatActivity(args)); - } - } - } - - private void openChat(ChatMessageCell cell, TLRPC.Chat chat, int postId) { - if (currentChat != null && chat.id == currentChat.id) { - scrollToMessageId(postId, cell.getMessageObject().getId(), true, 0, true, 0); - } else if (currentChat == null || chat.id != currentChat.id || isThreadChat()) { - Bundle args = new Bundle(); - args.putLong("chat_id", chat.id); - if (postId != 0) { - args.putInt("message_id", postId); - } - if (getMessagesController().checkCanOpenChat(args, ChatActivity.this, cell.getMessageObject())) { - presentFragment(new ChatActivity(args)); - } - } - } - - private boolean isAvatarPreviewerEnabled() { - return UserObject.isUserSelf(currentUser) || (currentChat != null && (!ChatObject.isChannel(currentChat) || currentChat.megagroup)); - } - - @Override - public void didPressBotButton(ChatMessageCell cell, TLRPC.KeyboardButton button) { - if (getParentActivity() == null || bottomOverlayChat.getVisibility() == View.VISIBLE && - !(button instanceof TLRPC.TL_keyboardButtonSwitchInline) && !(button instanceof TLRPC.TL_keyboardButtonCallback) && - !(button instanceof TLRPC.TL_keyboardButtonGame) && !(button instanceof TLRPC.TL_keyboardButtonUrl) && - !(button instanceof TLRPC.TL_keyboardButtonBuy) && !(button instanceof TLRPC.TL_keyboardButtonUrlAuth)) { - return; - } - chatActivityEnterView.didPressedBotButton(button, cell.getMessageObject(), cell.getMessageObject()); - } - - @Override - public void didPressReaction(ChatMessageCell cell, TLRPC.TL_reactionCount reaction) { - getSendMessagesHelper().sendReaction(cell.getMessageObject(), reaction.reaction, ChatActivity.this); - } - - @Override - public void didPressVoteButtons(ChatMessageCell cell, ArrayList buttons, int showCount, int x, int y) { - if (showCount >= 0 || buttons.isEmpty()) { - if (getParentActivity() == null) { + if (pollHintView == null) { + pollHintView = new HintView(getParentActivity(), HintView.TYPE_POLL_VOTE, themeDelegate); + pollHintView.setAlpha(0.0f); + pollHintView.setVisibility(View.INVISIBLE); + int index = contentView.indexOfChild(chatActivityEnterView); + if (index == -1) { return; } - if (pollHintView == null) { - pollHintView = new HintView(getParentActivity(), HintView.TYPE_POLL_VOTE, themeDelegate); - pollHintView.setAlpha(0.0f); - pollHintView.setVisibility(View.INVISIBLE); - int index = contentView.indexOfChild(chatActivityEnterView); - if (index == -1) { - return; - } - contentView.addView(pollHintView, index + 1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0)); - } - if (buttons.isEmpty() && showCount < 0) { - ArrayList pollButtons = cell.getPollButtons(); - float lastDiff = 0; - for (int a = 0, N = pollButtons.size(); a < N; a++) { - ChatMessageCell.PollButton button = pollButtons.get(a); - lastDiff = cell.getY() + button.y - AndroidUtilities.dp(4) - chatListViewPaddingTop; - pollHintX = button.x + AndroidUtilities.dp(13.3f); - pollHintY = button.y - AndroidUtilities.dp(6) + y; - if (lastDiff > 0) { - lastDiff = 0; - x = pollHintX; - y = pollHintY; - break; - } - } - if (lastDiff != 0) { - chatListView.smoothScrollBy(0, (int) lastDiff); - pollHintCell = cell; - return; + contentView.addView(pollHintView, index + 1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0)); + } + if (buttons.isEmpty() && showCount < 0) { + ArrayList pollButtons = cell.getPollButtons(); + float lastDiff = 0; + for (int a = 0, N = pollButtons.size(); a < N; a++) { + ChatMessageCell.PollButton button = pollButtons.get(a); + lastDiff = cell.getY() + button.y - AndroidUtilities.dp(4) - chatListViewPaddingTop; + pollHintX = button.x + AndroidUtilities.dp(13.3f); + pollHintY = button.y - AndroidUtilities.dp(6) + y; + if (lastDiff > 0) { + lastDiff = 0; + x = pollHintX; + y = pollHintY; + break; } } - pollHintView.showForMessageCell(cell, showCount, x, y, true); - } else { - getSendMessagesHelper().sendVote(cell.getMessageObject(), buttons, null); + if (lastDiff != 0) { + chatListView.smoothScrollBy(0, (int) lastDiff); + pollHintCell = cell; + return; + } } + pollHintView.showForMessageCell(cell, showCount, x, y, true); + } else { + getSendMessagesHelper().sendVote(cell.getMessageObject(), buttons, null); } + } - @Override - public void didPressCancelSendButton(ChatMessageCell cell) { - MessageObject message = cell.getMessageObject(); - if (message.messageOwner.send_state != 0) { - getSendMessagesHelper().cancelSendingMessage(message); - } + @Override + public void didPressCancelSendButton(ChatMessageCell cell) { + MessageObject message = cell.getMessageObject(); + if (message.messageOwner.send_state != 0) { + getSendMessagesHelper().cancelSendingMessage(message); } + } - @Override - public void didLongPress(ChatMessageCell cell, float x, float y) { + @Override + public void didLongPress(ChatMessageCell cell, float x, float y) { + createMenu(cell, false, false, x, y); + startMultiselect(chatListView.getChildAdapterPosition(cell)); + } + + @Override + public boolean canPerformActions() { + return actionBar != null && !actionBar.isActionModeShowed() && reportType < 0 || inPreviewMode; + } + + @Override + public void didPressUrl(ChatMessageCell cell, final CharacterStyle url, boolean longPress) { + didPressMessageUrl(url, longPress, cell.getMessageObject(), cell); + } + + @Override + public void needOpenWebView(MessageObject message, String url, String title, String description, String originalUrl, int w, int h) { + try { + EmbedBottomSheet.show(getParentActivity(), message, photoViewerProvider, title, description, originalUrl, url, w, h, isKeyboardVisible()); + } catch (Throwable e) { + FileLog.e(e); + } + } + + @Override + public void didPressReplyMessage(ChatMessageCell cell, int id) { + if (UserObject.isReplyUser(currentUser)) { + didPressSideButton(cell); + return; + } + MessageObject messageObject = cell.getMessageObject(); + if (chatMode == MODE_PINNED || chatMode == MODE_SCHEDULED) { + chatActivityDelegate.openReplyMessage(id); + finishFragment(); + } else { + scrollToMessageId(id, messageObject.getId(), true, messageObject.getDialogId() == mergeDialogId ? 1 : 0, true, 0); + } + } + + @Override + public void didPressViaBot(ChatMessageCell cell, String username) { + if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() == View.VISIBLE || bottomOverlay != null && bottomOverlay.getVisibility() == View.VISIBLE) { + return; + } + if (chatActivityEnterView != null && username != null && username.length() > 0) { + chatActivityEnterView.setFieldText("@" + username + " "); + chatActivityEnterView.openKeyboard(); + } + } + + @Override + public void didStartVideoStream(MessageObject message) { + if (message.isVideo()) { + sendSecretMessageRead(message, true); + } + } + + @Override + public void needReloadPolls() { + invalidateMessagesVisiblePart(); + } + + @Override + public void didPressImage(ChatMessageCell cell, float x, float y) { + MessageObject message = cell.getMessageObject(); + if (message.isSendError()) { createMenu(cell, false, false, x, y); - startMultiselect(chatListView.getChildAdapterPosition(cell)); + return; + } else if (message.isSending()) { + return; } - - @Override - public boolean canPerformActions() { - return actionBar != null && !actionBar.isActionModeShowed() && reportType < 0; - } - - @Override - public void didPressUrl(ChatMessageCell cell, final CharacterStyle url, boolean longPress) { - didPressMessageUrl(url, longPress, cell.getMessageObject(), cell); - } - - @Override - public void needOpenWebView(MessageObject message, String url, String title, String description, String originalUrl, int w, int h) { + if (message.isDice()) { + undoView.showWithAction(0, chatActivityEnterView.getVisibility() == View.VISIBLE && bottomOverlay.getVisibility() != View.VISIBLE ? UndoView.ACTION_DICE_INFO : UndoView.ACTION_DICE_NO_SEND_INFO, message.getDiceEmoji(), null, () -> getSendMessagesHelper().sendMessage(message.getDiceEmoji(), dialog_id, replyingMessageObject, getThreadMessage(), null, false, null, null, null, true, 0, null)); + } else if (message.isAnimatedEmoji()) { + restartSticker(cell); + emojiAnimationsOverlay.onTapItem(cell, ChatActivity.this); + chatListView.cancelClickRunnables(false); + } else if (message.needDrawBluredPreview()) { + Runnable action = sendSecretMessageRead(message, false); + cell.invalidate(); + SecretMediaViewer.getInstance().setParentActivity(getParentActivity()); + SecretMediaViewer.getInstance().openMedia(message, photoViewerProvider, action); + } else if (message.getInputStickerSet() != null) { + StickersAlert alert = new StickersAlert(getParentActivity(), ChatActivity.this, message.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE && (currentChat == null || ChatObject.canSendStickers(currentChat)) ? chatActivityEnterView : null, themeDelegate); + alert.setCalcMandatoryInsets(isKeyboardVisible()); + showDialog(alert); + } else if (message.isVideo() || message.type == 1 || message.type == 0 && !message.isWebpageDocument() || message.isGif()) { + openPhotoViewerForMessage(cell, message); + } else if (message.type == 3) { + sendSecretMessageRead(message, true); try { - EmbedBottomSheet.show(getParentActivity(), message, photoViewerProvider, title, description, originalUrl, url, w, h, isKeyboardVisible()); - } catch (Throwable e) { + File f = null; + if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { + f = new File(message.messageOwner.attachPath); + } + if (f == null || !f.exists()) { + f = FileLoader.getPathToMessage(message.messageOwner); + } + Intent intent = new Intent(Intent.ACTION_VIEW); + if (Build.VERSION.SDK_INT >= 24) { + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setDataAndType(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "video/mp4"); + } else { + intent.setDataAndType(Uri.fromFile(f), "video/mp4"); + } + getParentActivity().startActivityForResult(intent, 500); + } catch (Exception e) { FileLog.e(e); + alertUserOpenError(message); } - } - - @Override - public void didPressReplyMessage(ChatMessageCell cell, int id) { - if (UserObject.isReplyUser(currentUser)) { - didPressSideButton(cell); + } else if (message.type == 4) { + if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) { return; } - MessageObject messageObject = cell.getMessageObject(); - if (chatMode == MODE_PINNED || chatMode == MODE_SCHEDULED) { - chatActivityDelegate.openReplyMessage(id); - finishFragment(); + if (message.isLiveLocation()) { + LocationActivity fragment = new LocationActivity(currentChat == null || ChatObject.canSendMessages(currentChat) || currentChat.megagroup ? 2 : LocationActivity.LOCATION_TYPE_LIVE_VIEW); + fragment.setDelegate(ChatActivity.this); + fragment.setMessageObject(message); + presentFragment(fragment); } else { - scrollToMessageId(id, messageObject.getId(), true, messageObject.getDialogId() == mergeDialogId ? 1 : 0, true, 0); + LocationActivity fragment = new LocationActivity(currentEncryptedChat == null ? 3 : 0); + fragment.setDelegate(ChatActivity.this); + fragment.setMessageObject(message); + presentFragment(fragment); } - } - - @Override - public void didPressViaBot(ChatMessageCell cell, String username) { - if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() == View.VISIBLE || bottomOverlay != null && bottomOverlay.getVisibility() == View.VISIBLE) { - return; + } else if (message.type == 9 || message.type == 0) { + if (message.getDocumentName().toLowerCase().endsWith("attheme")) { + File locFile = null; + if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { + File f = new File(message.messageOwner.attachPath); + if (f.exists()) { + locFile = f; + } + } + if (locFile == null) { + File f = FileLoader.getPathToMessage(message.messageOwner); + if (f.exists()) { + locFile = f; + } + } + Theme.ThemeInfo themeInfo = Theme.applyThemeFile(locFile, message.getDocumentName(), null, true); + if (themeInfo != null) { + presentFragment(new ThemePreviewActivity(themeInfo)); + return; + } else { + scrollToPositionOnRecreate = -1; + } } - if (chatActivityEnterView != null && username != null && username.length() > 0) { - chatActivityEnterView.setFieldText("@" + username + " "); - chatActivityEnterView.openKeyboard(); + boolean handled = false; + if (message.canPreviewDocument()) { + PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate); + PhotoViewer.getInstance().openPhoto(message, ChatActivity.this, message.type != 0 ? dialog_id : 0, message.type != 0 ? mergeDialogId : 0, photoViewerProvider); + handled = true; } - } - - @Override - public void didStartVideoStream(MessageObject message) { - if (message.isVideo()) { - sendSecretMessageRead(message, true); - } - } - - @Override - public void needReloadPolls() { - invalidateMessagesVisiblePart(); - } - - @Override - public void didPressImage(ChatMessageCell cell, float x, float y) { - MessageObject message = cell.getMessageObject(); - if (message.isSendError()) { - createMenu(cell, false, false, x, y); - return; - } else if (message.isSending()) { - return; - } - if (message.isDice()) { - undoView.showWithAction(0, chatActivityEnterView.getVisibility() == View.VISIBLE && bottomOverlay.getVisibility() != View.VISIBLE ? UndoView.ACTION_DICE_INFO : UndoView.ACTION_DICE_NO_SEND_INFO, message.getDiceEmoji(), null, () -> getSendMessagesHelper().sendMessage(message.getDiceEmoji(), dialog_id, replyingMessageObject, getThreadMessage(), null, false, null, null, null, true, 0, null)); - } else if (message.isAnimatedEmoji()) { - restartSticker(cell); - emojiAnimationsOverlay.onTapItem(cell, ChatActivity.this); - chatListView.cancelClickRunnables(false); - } else if (message.needDrawBluredPreview()) { - Runnable action = sendSecretMessageRead(message, false); - cell.invalidate(); - SecretMediaViewer.getInstance().setParentActivity(getParentActivity()); - SecretMediaViewer.getInstance().openMedia(message, photoViewerProvider, action); - } else if (message.getInputStickerSet() != null) { - StickersAlert alert = new StickersAlert(getParentActivity(), ChatActivity.this, message.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE && (currentChat == null || ChatObject.canSendStickers(currentChat)) ? chatActivityEnterView : null, themeDelegate); - alert.setCalcMandatoryInsets(isKeyboardVisible()); - showDialog(alert); - } else if (message.isVideo() || message.type == 1 || message.type == 0 && !message.isWebpageDocument() || message.isGif()) { - openPhotoViewerForMessage(cell, message); - } else if (message.type == 3) { - sendSecretMessageRead(message, true); + if (!handled) { try { - File f = null; - if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { - f = new File(message.messageOwner.attachPath); - } - if (f == null || !f.exists()) { - f = FileLoader.getPathToMessage(message.messageOwner); - } - Intent intent = new Intent(Intent.ACTION_VIEW); - if (Build.VERSION.SDK_INT >= 24) { - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setDataAndType(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "video/mp4"); - } else { - intent.setDataAndType(Uri.fromFile(f), "video/mp4"); - } - getParentActivity().startActivityForResult(intent, 500); + AndroidUtilities.openForView(message, getParentActivity(), themeDelegate); } catch (Exception e) { FileLog.e(e); alertUserOpenError(message); } - } else if (message.type == 4) { - if (!AndroidUtilities.isGoogleMapsInstalled(ChatActivity.this)) { - return; - } - if (message.isLiveLocation()) { - LocationActivity fragment = new LocationActivity(currentChat == null || ChatObject.canSendMessages(currentChat) || currentChat.megagroup ? 2 : LocationActivity.LOCATION_TYPE_LIVE_VIEW); - fragment.setDelegate(ChatActivity.this); - fragment.setMessageObject(message); - presentFragment(fragment); + } + } + } + + @Override + public void didPressInstantButton(ChatMessageCell cell, int type) { + MessageObject messageObject = cell.getMessageObject(); + if (type == 8) { + PollVotesAlert.showForPoll(ChatActivity.this, messageObject); + } else if (type == 0) { + if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.webpage != null && messageObject.messageOwner.media.webpage.cached_page != null) { + ArticleViewer.getInstance().setParentActivity(getParentActivity(), ChatActivity.this); + ArticleViewer.getInstance().open(messageObject); + } + } else if (type == 5) { + long uid = messageObject.messageOwner.media.user_id; + TLRPC.User user = null; + if (uid != 0) { + user = MessagesController.getInstance(currentAccount).getUser(uid); + } + openVCard(user, messageObject.messageOwner.media.vcard, messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name); + } else { + if (messageObject.isSponsored()) { + Bundle args = new Bundle(); + long peerId = MessageObject.getPeerId(messageObject.messageOwner.from_id); + if (peerId < 0) { + args.putLong("chat_id", -peerId); } else { - LocationActivity fragment = new LocationActivity(currentEncryptedChat == null ? 3 : 0); - fragment.setDelegate(ChatActivity.this); - fragment.setMessageObject(message); - presentFragment(fragment); + args.putLong("user_id", peerId); } - } else if (message.type == 9 || message.type == 0) { - if (message.getDocumentName().toLowerCase().endsWith("attheme")) { - File locFile = null; - if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { - File f = new File(message.messageOwner.attachPath); - if (f.exists()) { - locFile = f; - } - } - if (locFile == null) { - File f = FileLoader.getPathToMessage(message.messageOwner); - if (f.exists()) { - locFile = f; - } - } - Theme.ThemeInfo themeInfo = Theme.applyThemeFile(locFile, message.getDocumentName(), null, true); - if (themeInfo != null) { - presentFragment(new ThemePreviewActivity(themeInfo)); - return; - } else { - scrollToPositionOnRecreate = -1; - } + if (messageObject.sponsoredChannelPost != 0) { + args.putInt("message_id", messageObject.sponsoredChannelPost); } - boolean handled = false; - if (message.canPreviewDocument()) { - PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate); - PhotoViewer.getInstance().openPhoto(message, ChatActivity.this, message.type != 0 ? dialog_id : 0, message.type != 0 ? mergeDialogId : 0, photoViewerProvider); - handled = true; + if (messageObject.botStartParam != null) { + args.putString("inline_query", messageObject.botStartParam); } - if (!handled) { - try { - AndroidUtilities.openForView(message, getParentActivity(), themeDelegate); - } catch (Exception e) { - FileLog.e(e); - alertUserOpenError(message); - } + if (getMessagesController().checkCanOpenChat(args, ChatActivity.this)) { + presentFragment(new ChatActivity(args)); + } + } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.webpage != null) { + if (!openLinkInternally(messageObject.messageOwner.media.webpage.url, messageObject.getId())) { + Browser.openUrl(getParentActivity(), messageObject.messageOwner.media.webpage.url); } } } + } - @Override - public void didPressInstantButton(ChatMessageCell cell, int type) { - MessageObject messageObject = cell.getMessageObject(); - if (type == 8) { - PollVotesAlert.showForPoll(ChatActivity.this, messageObject); - } else if (type == 0) { - if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.webpage != null && messageObject.messageOwner.media.webpage.cached_page != null) { - ArticleViewer.getInstance().setParentActivity(getParentActivity(), ChatActivity.this); - ArticleViewer.getInstance().open(messageObject); - } - } else if (type == 5) { - long uid = messageObject.messageOwner.media.user_id; - TLRPC.User user = null; - if (uid != 0) { - user = MessagesController.getInstance(currentAccount).getUser(uid); - } - openVCard(user, messageObject.messageOwner.media.vcard, messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name); - } else { - if (messageObject.isSponsored()) { - Bundle args = new Bundle(); - long peerId = MessageObject.getPeerId(messageObject.messageOwner.from_id); - if (peerId < 0) { - args.putLong("chat_id", -peerId); - } else { - args.putLong("user_id", peerId); - } - if (messageObject.sponsoredChannelPost != 0) { - args.putInt("message_id", messageObject.sponsoredChannelPost); - } - if (messageObject.botStartParam != null) { - args.putString("inline_query", messageObject.botStartParam); - } - if (getMessagesController().checkCanOpenChat(args, ChatActivity.this)) { - presentFragment(new ChatActivity(args)); - } - } else if (messageObject.messageOwner.media != null && messageObject.messageOwner.media.webpage != null) { - if (!openLinkInternally(messageObject.messageOwner.media.webpage.url, messageObject.getId())) { - Browser.openUrl(getParentActivity(), messageObject.messageOwner.media.webpage.url); - } - } - } + @Override + public void didPressCommentButton(ChatMessageCell cell) { + MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); + MessageObject message; + if (group != null && !group.messages.isEmpty()) { + message = group.messages.get(0); + } else { + message = cell.getMessageObject(); } - - @Override - public void didPressCommentButton(ChatMessageCell cell) { - MessageObject.GroupedMessages group = cell.getCurrentMessagesGroup(); - MessageObject message; - if (group != null && !group.messages.isEmpty()) { - message = group.messages.get(0); - } else { - message = cell.getMessageObject(); - } - int maxReadId; - long linkedChatId; - if (message.messageOwner.replies != null) { - maxReadId = message.messageOwner.replies.read_max_id; - linkedChatId = message.messageOwner.replies.channel_id; - } else { - maxReadId = -1; - linkedChatId = 0; - } - openDiscussionMessageChat(currentChat.id, message, message.getId(), linkedChatId, maxReadId, 0, null); + int maxReadId; + long linkedChatId; + if (message.messageOwner.replies != null) { + maxReadId = message.messageOwner.replies.read_max_id; + linkedChatId = message.messageOwner.replies.channel_id; + } else { + maxReadId = -1; + linkedChatId = 0; } + openDiscussionMessageChat(currentChat.id, message, message.getId(), linkedChatId, maxReadId, 0, null); + } - @Override - public String getAdminRank(long uid) { - if (ChatObject.isChannel(currentChat) && currentChat.megagroup) { - return getMessagesController().getAdminRank(currentChat.id, uid); - } - return null; + @Override + public String getAdminRank(long uid) { + if (ChatObject.isChannel(currentChat) && currentChat.megagroup) { + return getMessagesController().getAdminRank(currentChat.id, uid); } + return null; + } - @Override - public boolean shouldRepeatSticker(MessageObject message) { - return !alreadyPlayedStickers.containsKey(message); + @Override + public boolean shouldRepeatSticker(MessageObject message) { + return !alreadyPlayedStickers.containsKey(message); + } + + @Override + public void setShouldNotRepeatSticker(MessageObject message) { + alreadyPlayedStickers.put(message, true); + } + + @Override + public TextSelectionHelper.ChatListTextSelectionHelper getTextSelectionHelper() { + return textSelectionHelper; + } + + @Override + public boolean hasSelectedMessages() { + return selectedMessagesIds[0].size() + selectedMessagesIds[1].size() > 0; + } + + @Override + public void onDiceFinished() { + if (fireworksOverlay.isStarted()) { + return; } + fireworksOverlay.start(); + fireworksOverlay.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); + } - @Override - public void setShouldNotRepeatSticker(MessageObject message) { - alreadyPlayedStickers.put(message, true); - } + @Override + public PinchToZoomHelper getPinchToZoomHelper() { + return pinchToZoomHelper; + } - @Override - public TextSelectionHelper.ChatListTextSelectionHelper getTextSelectionHelper() { - return textSelectionHelper; - } + @Override + public boolean keyboardIsOpened() { + return contentView.getKeyboardHeight() + chatEmojiViewPadding >= AndroidUtilities.dp(20); + } - @Override - public boolean hasSelectedMessages() { - return selectedMessagesIds[0].size() + selectedMessagesIds[1].size() > 0; - } - - @Override - public void onDiceFinished() { - if (fireworksOverlay.isStarted()) { - return; - } - fireworksOverlay.start(); - fireworksOverlay.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING); - } - - @Override - public PinchToZoomHelper getPinchToZoomHelper() { - return pinchToZoomHelper; - } - - @Override - public boolean keyboardIsOpened() { - return contentView.getKeyboardHeight() + chatEmojiViewPadding >= AndroidUtilities.dp(20); - } - - public boolean isLandscape() { - return contentView.getMeasuredWidth() > contentView.getMeasuredHeight(); - } - }); - } else { - chatMessageCell.setDelegate(new ChatMessageCell.ChatMessageCellDelegate() { - - }); - } + public boolean isLandscape() { + return contentView.getMeasuredWidth() > contentView.getMeasuredHeight(); + } + }); if (currentEncryptedChat == null) { chatMessageCell.setAllowAssistant(true); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatEditTypeActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatEditTypeActivity.java index bb5ae288c..91f3afe1d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatEditTypeActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatEditTypeActivity.java @@ -142,7 +142,7 @@ public class ChatEditTypeActivity extends BaseFragment implements NotificationCe } isPrivate = !isForcePublic && TextUtils.isEmpty(currentChat.username); isChannel = ChatObject.isChannel(currentChat) && !currentChat.megagroup; - isSaveRestricted = isPrivate && currentChat.noforwards; + isSaveRestricted = currentChat.noforwards; if (isForcePublic && TextUtils.isEmpty(currentChat.username) || isPrivate && currentChat.creator) { TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername(); req.username = "1"; @@ -470,7 +470,7 @@ public class ChatEditTypeActivity extends BaseFragment implements NotificationCe } private void processDone() { - if (isPrivate && currentChat.noforwards != isSaveRestricted) { + if (currentChat.noforwards != isSaveRestricted) { getMessagesController().toggleChatNoForwards(chatId, currentChat.noforwards = isSaveRestricted); } if (trySetUsername()) { @@ -616,7 +616,7 @@ public class ChatEditTypeActivity extends BaseFragment implements NotificationCe } publicContainer.setVisibility(isPrivate ? View.GONE : View.VISIBLE); privateContainer.setVisibility(isPrivate ? View.VISIBLE : View.GONE); - saveContainer.setVisibility(isPrivate ? View.VISIBLE : View.GONE); + saveContainer.setVisibility(View.VISIBLE); manageLinksTextView.setVisibility(View.VISIBLE); manageLinksInfoCell.setVisibility(View.VISIBLE); linkContainer.setPadding(0, 0, 0, isPrivate ? 0 : AndroidUtilities.dp(7)); 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 c1c4edc23..facb40b26 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/AlertsCreator.java @@ -4130,6 +4130,7 @@ public class AlertsCreator { final boolean[] checks = new boolean[3]; final boolean[] deleteForAll = new boolean[1]; TLRPC.User actionUser = null; + TLRPC.Chat actionChat = null; boolean canRevokeInbox = user != null && MessagesController.getInstance(currentAccount).canRevokePmInbox; int revokeTimeLimit; if (user != null) { @@ -4148,7 +4149,13 @@ public class AlertsCreator { selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) { - actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id); + if (selectedMessage.messageOwner.from_id.user_id != 0) { + actionUser = MessagesController.getInstance(currentAccount).getUser(selectedMessage.messageOwner.from_id.user_id); + } else if (selectedMessage.messageOwner.from_id.channel_id != 0) { + actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.channel_id); + } else if (selectedMessage.messageOwner.from_id.chat_id != 0) { + actionChat = MessagesController.getInstance(currentAccount).getChat(selectedMessage.messageOwner.from_id.chat_id); + } } boolean hasOutgoing = !selectedMessage.isSendError() && selectedMessage.getDialogId() == mergeDialogId && (selectedMessage.messageOwner.action == null || selectedMessage.messageOwner.action instanceof TLRPC.TL_messageActionEmpty) && selectedMessage.isOut() && (currentDate - selectedMessage.messageOwner.date) <= revokeTimeLimit; if (hasOutgoing) { @@ -4188,8 +4195,8 @@ public class AlertsCreator { actionUser = MessagesController.getInstance(currentAccount).getUser(from_id); } } - if (actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) { - if (loadParticipant == 1 && !chat.creator) { + if ((actionUser != null && actionUser.id != UserConfig.getInstance(currentAccount).getClientUserId()) || (actionChat != null && !ChatObject.hasAdminRights(actionChat))) { + if (loadParticipant == 1 && !chat.creator && actionUser != null) { final AlertDialog[] progressDialog = new AlertDialog[]{new AlertDialog(activity, 3)}; TLRPC.TL_channels_getParticipant req = new TLRPC.TL_channels_getParticipant(); @@ -4224,6 +4231,7 @@ public class AlertsCreator { } FrameLayout frameLayout = new FrameLayout(activity); int num = 0; + String name = actionUser != null ? ContactsController.formatName(actionUser.first_name, actionUser.last_name) : actionChat.title; for (int a = 0; a < 3; a++) { if ((loadParticipant == 2 || !canBan) && a == 0) { continue; @@ -4236,7 +4244,7 @@ public class AlertsCreator { } else if (a == 1) { cell.setText(LocaleController.getString("DeleteReportSpam", R.string.DeleteReportSpam), "", false, false); } else { - cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, ContactsController.formatName(actionUser.first_name, actionUser.last_name)), "", false, false); + cell.setText(LocaleController.formatString("DeleteAllFrom", R.string.DeleteAllFrom, name), "", false, false); } cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0); frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 48 * num, 0, 0)); @@ -4335,6 +4343,7 @@ public class AlertsCreator { } } final TLRPC.User userFinal = actionUser; + final TLRPC.Chat chatFinal = actionChat; builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> { ArrayList ids = null; if (selectedMessage != null) { @@ -4386,21 +4395,25 @@ public class AlertsCreator { selectedMessages[a].clear(); } } - if (userFinal != null) { + if (userFinal != null || chatFinal != null) { if (checks[0]) { - MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatInfo); + MessagesController.getInstance(currentAccount).deleteParticipantFromChat(chat.id, userFinal, chatFinal, chatInfo, false, false); } if (checks[1]) { TLRPC.TL_channels_reportSpam req = new TLRPC.TL_channels_reportSpam(); req.channel = MessagesController.getInputChannel(chat); - req.user_id = MessagesController.getInstance(currentAccount).getInputUser(userFinal); + if (userFinal != null) { + req.participant = MessagesController.getInputPeer(userFinal); + } else { + req.participant = MessagesController.getInputPeer(chatFinal); + } req.id = ids; ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> { }); } if (checks[2]) { - MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, 0); + MessagesController.getInstance(currentAccount).deleteUserChannelHistory(chat, userFinal, chatFinal, 0); } } if (onDelete != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 82eccf8c0..b2d2b9c5d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -4659,7 +4659,6 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe messageEditText.setAlpha(1f); messageEditText.setTranslationX(0); messageEditText.requestFocus(); - updateSendAsButton(); } }); @@ -6816,7 +6815,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe } } boolean wasVisible = senderSelectView.getVisibility() == View.VISIBLE; - boolean isVisible = delegate.getSendAsPeers() != null && defPeer != null && delegate.getSendAsPeers().peers.size() > 1 && !isEditingMessage() && !isRecordingAudioVideo() && (recordedAudioPanel == null || recordedAudioPanel.getVisibility() == View.GONE); + boolean isVisible = delegate.getSendAsPeers() != null && defPeer != null && delegate.getSendAsPeers().peers.size() > 1 && !isEditingMessage() && !isRecordingAudioVideo(); int pad = AndroidUtilities.dp(2); MarginLayoutParams params = (MarginLayoutParams) senderSelectView.getLayoutParams(); float sA = isVisible ? 0 : 1; @@ -6832,8 +6831,7 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe } if (parentFragment.getOtherSameChatsDiff() == 0 && parentFragment.fragmentOpened) { - ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(220); - anim.setInterpolator(CubicBezierInterpolator.DEFAULT); + ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(150); anim.addUpdateListener(animation -> { float val = (float) animation.getAnimatedValue(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertDocumentLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertDocumentLayout.java index 6c6f4bdcf..2dcd18693 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertDocumentLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatAttachAlertDocumentLayout.java @@ -336,13 +336,13 @@ public class ChatAttachAlertDocumentLayout extends ChatAttachAlert.AttachAlertLa ListItem item = (ListItem) object; File file = item.file; boolean isExternalStorageManager = false; -// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { -// isExternalStorageManager = Environment.isExternalStorageManager(); -// } - if (!BuildVars.NO_SCOPED_STORAGE && (item.icon == R.drawable.files_storage || item.icon == R.drawable.files_internal)) { - //if (SharedConfig.dontAskManageStorage) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + isExternalStorageManager = Environment.isExternalStorageManager(); + } + if (!BuildVars.NO_SCOPED_STORAGE && (item.icon == R.drawable.files_storage || item.icon == R.drawable.files_internal) && !isExternalStorageManager) { + if (SharedConfig.dontAskManageStorage) { delegate.startDocumentSelectActivity(); - /*} else { + } else { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTopImage(R.drawable.doc_big, Theme.getColor(Theme.key_dialogTopBackground)); builder.setMessage(AndroidUtilities.replaceTags(LocaleController.getString("ManageAllFilesRational", R.string.ManageAllFilesRational))); @@ -368,7 +368,7 @@ public class ChatAttachAlertDocumentLayout extends ChatAttachAlert.AttachAlertLa delegate.startDocumentSelectActivity(); }); builder.show(); - }*/ + } } else if (file == null) { if (item.icon == R.drawable.files_gallery) { HashMap selectedPhotos = new HashMap<>(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/MediaActivity.java index 2968b7cf8..ad3a88d81 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/MediaActivity.java @@ -104,7 +104,7 @@ public class MediaActivity extends BaseFragment implements SharedMediaLayout.Sha @Override public boolean dispatchTouchEvent(MotionEvent ev) { - if (sharedMediaLayout != null && sharedMediaLayout.isInFastScroll() && sharedMediaLayout.getY() == 0) { + if (sharedMediaLayout != null && sharedMediaLayout.isInFastScroll()) { return sharedMediaLayout.dispatchFastScrollEvent(ev); } if (sharedMediaLayout != null && sharedMediaLayout.checkPinchToZoom(ev)) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/MotionBackgroundDrawable.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/MotionBackgroundDrawable.java index 03da6b631..ef3687770 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/MotionBackgroundDrawable.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/MotionBackgroundDrawable.java @@ -440,7 +440,6 @@ public class MotionBackgroundDrawable extends Drawable { legacyBitmap2 = null; } try { - legacyBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); legacyCanvas = new Canvas(legacyBitmap); invalidateLegacy = true; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java index 359095900..276a3ce14 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/RecyclerListView.java @@ -385,6 +385,7 @@ public class RecyclerListView extends RecyclerView { float touchSlop; Drawable fastScrollShadowDrawable; Drawable fastScrollBackgroundDrawable; + boolean isRtl; Runnable hideFloatingDateRunnable = new Runnable() { @Override @@ -404,7 +405,9 @@ public class RecyclerListView extends RecyclerView { this.type = type; if (type == LETTER_TYPE) { letterPaint.setTextSize(AndroidUtilities.dp(45)); + isRtl = LocaleController.isRTL; } else { + isRtl = false; letterPaint.setTextSize(AndroidUtilities.dp(13)); letterPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); paint2.setColor(Theme.getColor(Theme.key_windowBackgroundWhite)); @@ -415,7 +418,7 @@ public class RecyclerListView extends RecyclerView { radii[a] = AndroidUtilities.dp(44); } - scrollX = LocaleController.isRTL ? AndroidUtilities.dp(10) : AndroidUtilities.dp((type == LETTER_TYPE ? 132 : 240) - 15); + scrollX = isRtl ? AndroidUtilities.dp(10) : AndroidUtilities.dp((type == LETTER_TYPE ? 132 : 240) - 15); updateColors(); setFocusableInTouchMode(true); ViewConfiguration vc = ViewConfiguration.get(context); @@ -453,11 +456,11 @@ public class RecyclerListView extends RecyclerView { float x = event.getX(); startY = lastY = event.getY(); float currentY = (float) Math.ceil((getMeasuredHeight() - AndroidUtilities.dp(24 + 30)) * progress) + AndroidUtilities.dp(12); - if (LocaleController.isRTL && x > AndroidUtilities.dp(25) || !LocaleController.isRTL && x < AndroidUtilities.dp(107) || lastY < currentY || lastY > currentY + AndroidUtilities.dp(30)) { + if (isRtl && x > AndroidUtilities.dp(25) || !isRtl && x < AndroidUtilities.dp(107) || lastY < currentY || lastY > currentY + AndroidUtilities.dp(30)) { return false; } if (type == DATE_TYPE && !floatingDateVisible) { - if (LocaleController.isRTL && x > AndroidUtilities.dp(25) || !LocaleController.isRTL && x < (getMeasuredWidth() - AndroidUtilities.dp(25)) || lastY < currentY || lastY > currentY + AndroidUtilities.dp(30)) { + if (isRtl && x > AndroidUtilities.dp(25) || !isRtl && x < (getMeasuredWidth() - AndroidUtilities.dp(25)) || lastY < currentY || lastY > currentY + AndroidUtilities.dp(30)) { return false; } } @@ -552,7 +555,7 @@ public class RecyclerListView extends RecyclerView { if (letterLayout.getLineCount() > 0) { float lWidth = letterLayout.getLineWidth(0); float lleft = letterLayout.getLineLeft(0); - if (LocaleController.isRTL) { + if (isRtl) { textX = AndroidUtilities.dp(10) + (AndroidUtilities.dp(88) - letterLayout.getLineWidth(0)) / 2 - letterLayout.getLineLeft(0); } else { textX = (AndroidUtilities.dp(88) - letterLayout.getLineWidth(0)) / 2 - letterLayout.getLineLeft(0); @@ -625,8 +628,8 @@ public class RecyclerListView extends RecyclerView { raduisBottom = AndroidUtilities.dp(44); raduisTop = AndroidUtilities.dp(4) + (1.0f - diff / AndroidUtilities.dp(29)) * AndroidUtilities.dp(40); } - if (LocaleController.isRTL && (radii[0] != raduisTop || radii[6] != raduisBottom) || !LocaleController.isRTL && (radii[2] != raduisTop || radii[4] != raduisBottom)) { - if (LocaleController.isRTL) { + if (isRtl && (radii[0] != raduisTop || radii[6] != raduisBottom) || !isRtl && (radii[2] != raduisTop || radii[4] != raduisBottom)) { + if (isRtl) { radii[0] = radii[1] = raduisTop; radii[6] = radii[7] = raduisBottom; } else { @@ -634,7 +637,7 @@ public class RecyclerListView extends RecyclerView { radii[4] = radii[5] = raduisBottom; } path.reset(); - rect.set(LocaleController.isRTL ? AndroidUtilities.dp(10) : 0, 0, AndroidUtilities.dp(LocaleController.isRTL ? 98 : 88), AndroidUtilities.dp(88)); + rect.set(isRtl ? AndroidUtilities.dp(10) : 0, 0, AndroidUtilities.dp(isRtl ? 98 : 88), AndroidUtilities.dp(88)); path.addRoundRect(rect, radii, Path.Direction.CW); path.close(); } @@ -1225,7 +1228,7 @@ public class RecyclerListView extends RecyclerView { if (fastScroll != null) { selfOnLayout = true; t += getPaddingTop(); - if (LocaleController.isRTL) { + if (fastScroll.isRtl) { fastScroll.layout(0, t, fastScroll.getMeasuredWidth(), t + fastScroll.getMeasuredHeight()); } else { int x = getMeasuredWidth() - fastScroll.getMeasuredWidth(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/StickerImageView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/StickerImageView.java new file mode 100644 index 000000000..557a0a283 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/StickerImageView.java @@ -0,0 +1,85 @@ +package org.telegram.ui.Components; + +import android.content.Context; + +import org.telegram.messenger.AndroidUtilities; +import org.telegram.messenger.DocumentObject; +import org.telegram.messenger.ImageLocation; +import org.telegram.messenger.MediaDataController; +import org.telegram.messenger.NotificationCenter; +import org.telegram.messenger.SvgHelper; +import org.telegram.tgnet.TLRPC; +import org.telegram.ui.ActionBar.Theme; + +public class StickerImageView extends BackupImageView implements NotificationCenter.NotificationCenterDelegate { + + int currentAccount; + int stickerNum; + String stickerPackName = AndroidUtilities.STICKERS_PLACEHOLDER_PACK_NAME; + + public StickerImageView(Context context, int currentAccount) { + super(context); + this.currentAccount = currentAccount; + } + + public void setStickerNum(int stickerNum) { + this.stickerNum = stickerNum; + } + + public void setStickerPackName(String stickerPackName) { + this.stickerPackName = stickerPackName; + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + setSticker(); + NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.diceStickersDidLoad); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.diceStickersDidLoad); + } + + @Override + public void didReceivedNotification(int id, int account, Object... args) { + if (id == NotificationCenter.diceStickersDidLoad) { + String name = (String) args[0]; + if (stickerPackName.equals(name)) { + setSticker(); + } + } + } + + private void setSticker() { + String imageFilter = null; + TLRPC.Document document = null; + TLRPC.TL_messages_stickerSet set = null; + + set = MediaDataController.getInstance(currentAccount).getStickerSetByName(stickerPackName); + if (set == null) { + set = MediaDataController.getInstance(currentAccount).getStickerSetByEmojiOrName(stickerPackName); + } + if (set != null && set.documents.size() > stickerNum) { + document = set.documents.get(stickerNum); + } + imageFilter = "130_130"; + + SvgHelper.SvgDrawable svgThumb = null; + if (document != null) { + svgThumb = DocumentObject.getSvgThumb(document.thumbs, Theme.key_emptyListPlaceholder, 0.2f); + } + if (svgThumb != null) { + svgThumb.overrideWidthAndHeight(512, 512); + } + + if (document != null) { + ImageLocation imageLocation = ImageLocation.getForDocument(document); + setImage(imageLocation, imageFilter, "tgs", svgThumb, set); + } else { + MediaDataController.getInstance(currentAccount).loadStickersByEmojiOrName(stickerPackName, false, set == null); + } + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DefaultThemesPreviewCell.java b/TMessagesProj/src/main/java/org/telegram/ui/DefaultThemesPreviewCell.java index bcd39b86c..aa21d8c18 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DefaultThemesPreviewCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DefaultThemesPreviewCell.java @@ -248,7 +248,7 @@ public class DefaultThemesPreviewCell extends LinearLayout { if (!Theme.isCurrentThemeDay()) { darkThemeDrawable.setCurrentFrame(darkThemeDrawable.getFramesCount() - 1); - dayNightCell.setTextAndIcon(LocaleController.getString("SettingsSwitchToDaytMode", R.string.SettingsSwitchToDayMode), darkThemeDrawable, true); + dayNightCell.setTextAndIcon(LocaleController.getString("SettingsSwitchToDayMode", R.string.SettingsSwitchToDayMode), darkThemeDrawable, true); } else { dayNightCell.setTextAndIcon(LocaleController.getString("SettingsSwitchToNightMode", R.string.SettingsSwitchToNightMode), darkThemeDrawable, true); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index e6edaac55..46b75aef3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -88,6 +88,7 @@ import org.telegram.messenger.ContactsController; import org.telegram.messenger.DialogObject; import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; +import org.telegram.messenger.FilesMigrationService; import org.telegram.messenger.ImageLoader; import org.telegram.messenger.ImageLocation; import org.telegram.messenger.LocaleController; @@ -3534,6 +3535,9 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. showSearch(false, false); } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + FilesMigrationService.checkBottomSheet(this); + } updateMenuButton(false); return fragmentView; } @@ -6347,6 +6351,18 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter. askingForPermissions = false; showFiltersHint(); } + } else if (requestCode == 4) { + boolean allGranted = true; + for (int a = 0; a < grantResults.length; a++) { + if (grantResults[a] != PackageManager.PERMISSION_GRANTED) { + allGranted = false; + break; + } + } + if (allGranted && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && FilesMigrationService.filesMigrationBottomSheet != null) { + FilesMigrationService.filesMigrationBottomSheet.migrateOldFolder(); + } + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index cdd061243..c16f0e178 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -1942,12 +1942,12 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa String msgID = data.getQueryParameter("message_id"); if (userID != null) { try { - push_user_id = Integer.parseInt(userID); + push_user_id = Long.parseLong(userID); } catch (NumberFormatException ignore) { } } else if (chatID != null) { try { - push_chat_id = Integer.parseInt(chatID); + push_chat_id = Long.parseLong(chatID); } catch (NumberFormatException ignore) { } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 12bf8a79a..dbe89a353 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -9648,7 +9648,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat isEvent = object != null && object.isEvent; sharedMediaType = MediaDataController.MEDIA_PHOTOVIDEO; allMediaItem.setText(LocaleController.getString("ShowAllMedia", R.string.ShowAllMedia)); - menuItem.setVisibility(View.VISIBLE); setItemVisible(sendItem, false, false); setItemVisible(pipItem, false, true); cameraItem.setVisibility(View.GONE); @@ -9894,7 +9893,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat cameraItem.setVisibility(View.VISIBLE); cameraItem.setTag(1); } - menuItem.setVisibility(View.GONE); imagesArrLocals.addAll(photos); Object obj = imagesArrLocals.get(index); boolean allowCaption; @@ -10553,7 +10551,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat } actionBar.setTitle(LocaleController.getString("AttachGif", R.string.AttachGif)); } else { - menuItem.setVisibility(View.VISIBLE); if (size == 1) { if (isVideo) { actionBar.setTitle(LocaleController.getString("AttachVideo", R.string.AttachVideo)); @@ -12350,7 +12347,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat disableShowCheck = false; object.imageReceiver.setVisible(false, true); }; - if (parentChatActivity != null) { + if (parentChatActivity != null && parentChatActivity.getFragmentView() != null) { parentChatActivity.getUndoView().hide(false, 1); parentChatActivity.getFragmentView().invalidate(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index e90bfb4d7..ed8767e32 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -3886,7 +3886,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter. participant.inviter_id = participant.channelParticipant.inviter_id; participant.user_id = MessageObject.getPeerId(participant.channelParticipant.peer); participant.date = participant.channelParticipant.date; - if (participant.user_id != 0 && participantsMap.indexOfKey(participant.user_id) < 0) { + if (participantsMap.indexOfKey(participant.user_id) < 0) { if (chatInfo.participants == null) { chatInfo.participants = new TLRPC.TL_chatParticipants(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SessionBottomSheet.java b/TMessagesProj/src/main/java/org/telegram/ui/SessionBottomSheet.java index 5b2f8352f..5b0a6936f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SessionBottomSheet.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SessionBottomSheet.java @@ -378,15 +378,17 @@ public class SessionBottomSheet extends BottomSheet { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); - addView(linearLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 64, 4, 0, 4)); + addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 64, 4, 0, 4)); valueText = new TextView(context); valueText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); + valueText.setGravity(Gravity.LEFT); valueText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); linearLayout.addView(valueText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 0, 0, 0, 0)); descriptionText = new TextView(context); descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); + descriptionText.setGravity(Gravity.LEFT); descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText)); linearLayout.addView(descriptionText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 0, 4, 0, 0)); setPadding(0, AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4)); diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 75d2058b4..6cdb64478 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -4889,4 +4889,9 @@ You received this message because you requested to join **%1$s** on %2$s un1 sent this message: Get code on this phone + Migration + Move Files Now + Migrate Files to Scoped Storage + Due to a change made by **Google**, we need to move the files you downloaded using **Telegram** to a new folder.\n\nThis may take a few moments. You can continue using the app while the files are moved. + Migrating files