mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-12 15:30:34 +01:00
Merge 8.2.3 (2466)
This commit is contained in:
commit
23e1b288b7
@ -38,6 +38,7 @@ import android.graphics.Typeface;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
@ -100,6 +101,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.android.internal.telephony.ITelephony;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
|
||||
import org.telegram.PhoneFormat.PhoneFormat;
|
||||
import org.telegram.messenger.browser.Browser;
|
||||
@ -2300,11 +2302,11 @@ public class AndroidUtilities {
|
||||
return;
|
||||
}
|
||||
File f = new File(fromPath);
|
||||
Uri contentUri = Uri.fromFile(f);
|
||||
addMediaToGallery(contentUri);
|
||||
addMediaToGallery(f);
|
||||
}
|
||||
|
||||
public static void addMediaToGallery(Uri uri) {
|
||||
public static void addMediaToGallery(File file) {
|
||||
Uri uri = Uri.fromFile(file);
|
||||
if (uri == null) {
|
||||
return;
|
||||
}
|
||||
@ -2318,8 +2320,8 @@ public class AndroidUtilities {
|
||||
}
|
||||
|
||||
private static File getAlbumDir(boolean secretChat) {
|
||||
if (secretChat || !BuildVars.NO_SCOPED_STORAGE || (Build.VERSION.SDK_INT >= 23 && ApplicationLoader.applicationContext.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
|
||||
return FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE);
|
||||
if (secretChat || !BuildVars.NO_SCOPED_STORAGE ||(Build.VERSION.SDK_INT >= 23 && ApplicationLoader.applicationContext.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)) {
|
||||
return FileLoader.getDirectory(FileLoader.MEDIA_DIR_IMAGE);
|
||||
}
|
||||
File storageDir = null;
|
||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
@ -2432,17 +2434,25 @@ public class AndroidUtilities {
|
||||
|
||||
public static File generatePicturePath(boolean secretChat, String ext) {
|
||||
try {
|
||||
File storageDir = getAlbumDir(secretChat);
|
||||
Date date = new Date();
|
||||
date.setTime(System.currentTimeMillis() + Utilities.random.nextInt(1000) + 1);
|
||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(date);
|
||||
return new File(storageDir, "IMG_" + timeStamp + "." + (TextUtils.isEmpty(ext) ? "jpg" : ext));
|
||||
File storageDir = ApplicationLoader.applicationContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
|
||||
return new File(storageDir, generateFileName(0, ext));
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String generateFileName(int type, String ext) {
|
||||
Date date = new Date();
|
||||
date.setTime(System.currentTimeMillis() + Utilities.random.nextInt(1000) + 1);
|
||||
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss_SSS", Locale.US).format(date);
|
||||
if (type == 0) {
|
||||
return "IMG_" + timeStamp + "." + (TextUtils.isEmpty(ext) ? "jpg" : ext);
|
||||
} else {
|
||||
return "VID_" + timeStamp + ".mp4";
|
||||
}
|
||||
}
|
||||
|
||||
public static CharSequence generateSearchName(String name, String name2, String q) {
|
||||
if (name == null && name2 == null || TextUtils.isEmpty(q)) {
|
||||
return "";
|
||||
@ -2733,7 +2743,10 @@ public class AndroidUtilities {
|
||||
}
|
||||
|
||||
public static boolean copyFile(InputStream sourceFile, File destFile) throws IOException {
|
||||
OutputStream out = new FileOutputStream(destFile);
|
||||
return copyFile(sourceFile, new FileOutputStream(destFile));
|
||||
}
|
||||
|
||||
public static boolean copyFile(InputStream sourceFile, OutputStream out) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int len;
|
||||
while ((len = sourceFile.read(buf)) > 0) {
|
||||
|
@ -16,6 +16,7 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.DownloadManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -81,8 +82,10 @@ import org.telegram.ui.PhotoViewer;
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -1997,6 +2000,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
}
|
||||
return audioPlayer.getDuration();
|
||||
}
|
||||
|
||||
public MessageObject getPlayingMessageObject() {
|
||||
return playingMessageObject;
|
||||
}
|
||||
@ -2522,7 +2526,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
final MessageObject currentMessage = playingMessageObject;
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
if (audioPlayer != null && playingMessageObject != null && !isPaused) {
|
||||
if (isSamePlayingMessage(currentMessage )) {
|
||||
if (isSamePlayingMessage(currentMessage)) {
|
||||
seekToProgress(playingMessageObject, p);
|
||||
}
|
||||
audioPlayer.play();
|
||||
@ -3823,7 +3827,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
}
|
||||
if (!cancelled) {
|
||||
if (isMusic) {
|
||||
AndroidUtilities.addMediaToGallery(Uri.fromFile(destFile));
|
||||
AndroidUtilities.addMediaToGallery(destFile);
|
||||
} else {
|
||||
DownloadManager downloadManager = (DownloadManager) ApplicationLoader.applicationContext.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
String mimeType = mime;
|
||||
@ -3900,7 +3904,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
}
|
||||
|
||||
public static void saveFile(String fullPath, Context context, final int type, final String name, final String mime, final Runnable onSaved) {
|
||||
if (fullPath == null) {
|
||||
if (fullPath == null || context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3919,6 +3923,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
final File sourceFile = file;
|
||||
final boolean[] cancelled = new boolean[]{false};
|
||||
if (sourceFile.exists()) {
|
||||
|
||||
AlertDialog progressDialog = null;
|
||||
final boolean[] finished = new boolean[1];
|
||||
if (context != null && type != 0) {
|
||||
@ -3943,99 +3948,152 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
File destFile;
|
||||
if (type == 0) {
|
||||
destFile = AndroidUtilities.generatePicturePath(false, FileLoader.getFileExtension(sourceFile));
|
||||
} else if (type == 1) {
|
||||
destFile = AndroidUtilities.generateVideoPath();
|
||||
} else {
|
||||
File dir;
|
||||
if (type == 2) {
|
||||
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
} else {
|
||||
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
|
||||
}
|
||||
dir.mkdir();
|
||||
destFile = new File(dir, name);
|
||||
if (destFile.exists()) {
|
||||
int idx = name.lastIndexOf('.');
|
||||
for (int a = 0; a < 10; a++) {
|
||||
String newName;
|
||||
if (idx != -1) {
|
||||
newName = name.substring(0, idx) + "(" + (a + 1) + ")" + name.substring(idx);
|
||||
} else {
|
||||
newName = name + "(" + (a + 1) + ")";
|
||||
boolean result = true;
|
||||
if (Build.VERSION.SDK_INT >= 29) {
|
||||
try {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(sourceFile.getAbsolutePath());
|
||||
String mimeType = null;
|
||||
if (extension != null) {
|
||||
mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
}
|
||||
Uri uriToInsert = null;
|
||||
if (type == 0) {
|
||||
uriToInsert = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
File dirDest = new File(Environment.DIRECTORY_PICTURES, "Telegram");
|
||||
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, dirDest + File.separator);
|
||||
}
|
||||
destFile = new File(dir, newName);
|
||||
if (!destFile.exists()) {
|
||||
contentValues.put(MediaStore.Images.Media.DISPLAY_NAME, AndroidUtilities.generateFileName(0, extension));
|
||||
contentValues.put(MediaStore.Images.Media.MIME_TYPE, mimeType);
|
||||
} else if (type == 1) {
|
||||
File dirDest = new File(Environment.DIRECTORY_MOVIES, "Telegram");
|
||||
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, dirDest + File.separator);
|
||||
uriToInsert = MediaStore.Video.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||
contentValues.put(MediaStore.Video.Media.DISPLAY_NAME, AndroidUtilities.generateFileName(1, extension));
|
||||
} else if (type == 2) {
|
||||
File dirDest = new File(Environment.DIRECTORY_DOWNLOADS, "Telegram");
|
||||
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, dirDest + File.separator);
|
||||
uriToInsert = MediaStore.Downloads.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||
contentValues.put(MediaStore.Downloads.DISPLAY_NAME, sourceFile.getName());
|
||||
} else {
|
||||
File dirDest = new File(Environment.DIRECTORY_MUSIC, "Telegram");
|
||||
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, dirDest + File.separator);
|
||||
uriToInsert = MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY);
|
||||
contentValues.put(MediaStore.Audio.Media.DISPLAY_NAME, sourceFile.getName());
|
||||
}
|
||||
|
||||
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
|
||||
|
||||
Uri dstUri = context.getContentResolver().insert(uriToInsert, contentValues);
|
||||
if (dstUri != null) {
|
||||
FileInputStream fileInputStream = new FileInputStream(sourceFile);
|
||||
OutputStream outputStream = context.getContentResolver().openOutputStream(dstUri);
|
||||
AndroidUtilities.copyFile(fileInputStream, outputStream);
|
||||
fileInputStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
result = false;
|
||||
}
|
||||
} else {
|
||||
File destFile;
|
||||
if (type == 0) {
|
||||
destFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Telegram");
|
||||
destFile.mkdirs();
|
||||
destFile = new File(destFile, AndroidUtilities.generateFileName(0, FileLoader.getFileExtension(sourceFile)));
|
||||
} else if (type == 1) {
|
||||
destFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "Telegram");
|
||||
destFile.mkdirs();
|
||||
destFile = new File(destFile, AndroidUtilities.generateFileName(1, FileLoader.getFileExtension(sourceFile)));
|
||||
} else {
|
||||
File dir;
|
||||
if (type == 2) {
|
||||
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
||||
} else {
|
||||
dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
|
||||
}
|
||||
dir = new File(dir, "Telegram");
|
||||
dir.mkdirs();
|
||||
destFile = new File(dir, name);
|
||||
if (destFile.exists()) {
|
||||
int idx = name.lastIndexOf('.');
|
||||
for (int a = 0; a < 10; a++) {
|
||||
String newName;
|
||||
if (idx != -1) {
|
||||
newName = name.substring(0, idx) + "(" + (a + 1) + ")" + name.substring(idx);
|
||||
} else {
|
||||
newName = name + "(" + (a + 1) + ")";
|
||||
}
|
||||
destFile = new File(dir, newName);
|
||||
if (!destFile.exists()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
long lastProgress = System.currentTimeMillis() - 500;
|
||||
try (FileInputStream inputStream = new FileInputStream(sourceFile); FileChannel source = inputStream.getChannel(); FileChannel destination = new FileOutputStream(destFile).getChannel()) {
|
||||
long size = source.size();
|
||||
try {
|
||||
@SuppressLint("DiscouragedPrivateApi") Method getInt = FileDescriptor.class.getDeclaredMethod("getInt$");
|
||||
int fdint = (Integer) getInt.invoke(inputStream.getFD());
|
||||
if (AndroidUtilities.isInternalUri(fdint)) {
|
||||
if (finalProgress != null) {
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
finalProgress.dismiss();
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
for (long a = 0; a < size; a += 4096) {
|
||||
if (cancelled[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!destFile.exists()) {
|
||||
destFile.createNewFile();
|
||||
}
|
||||
boolean result = true;
|
||||
long lastProgress = System.currentTimeMillis() - 500;
|
||||
try (FileInputStream inputStream = new FileInputStream(sourceFile); FileChannel source = inputStream.getChannel(); FileChannel destination = new FileOutputStream(destFile).getChannel()) {
|
||||
long size = source.size();
|
||||
try {
|
||||
@SuppressLint("DiscouragedPrivateApi") Method getInt = FileDescriptor.class.getDeclaredMethod("getInt$");
|
||||
int fdint = (Integer) getInt.invoke(inputStream.getFD());
|
||||
if (AndroidUtilities.isInternalUri(fdint)) {
|
||||
destination.transferFrom(source, a, Math.min(4096, size - a));
|
||||
if (finalProgress != null) {
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
finalProgress.dismiss();
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
if (lastProgress <= System.currentTimeMillis() - 500) {
|
||||
lastProgress = System.currentTimeMillis();
|
||||
final int progress = (int) ((float) a / (float) size * 100);
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
finalProgress.setProgress(progress);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
result = false;
|
||||
}
|
||||
for (long a = 0; a < size; a += 4096) {
|
||||
if (cancelled[0]) {
|
||||
break;
|
||||
}
|
||||
destination.transferFrom(source, a, Math.min(4096, size - a));
|
||||
if (finalProgress != null) {
|
||||
if (lastProgress <= System.currentTimeMillis() - 500) {
|
||||
lastProgress = System.currentTimeMillis();
|
||||
final int progress = (int) ((float) a / (float) size * 100);
|
||||
AndroidUtilities.runOnUIThread(() -> {
|
||||
try {
|
||||
finalProgress.setProgress(progress);
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (cancelled[0]) {
|
||||
destFile.delete();
|
||||
result = false;
|
||||
}
|
||||
if (result) {
|
||||
if (type == 2) {
|
||||
DownloadManager downloadManager = (DownloadManager) ApplicationLoader.applicationContext.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
downloadManager.addCompletedDownload(destFile.getName(), destFile.getName(), false, mime, destFile.getAbsolutePath(), destFile.length(), true);
|
||||
} else {
|
||||
AndroidUtilities.addMediaToGallery(destFile.getAbsoluteFile());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
result = false;
|
||||
}
|
||||
if (cancelled[0]) {
|
||||
destFile.delete();
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (type == 2) {
|
||||
DownloadManager downloadManager = (DownloadManager) ApplicationLoader.applicationContext.getSystemService(Context.DOWNLOAD_SERVICE);
|
||||
downloadManager.addCompletedDownload(destFile.getName(), destFile.getName(), false, mime, destFile.getAbsolutePath(), destFile.length(), true);
|
||||
} else {
|
||||
AndroidUtilities.addMediaToGallery(Uri.fromFile(destFile));
|
||||
}
|
||||
if (onSaved != null) {
|
||||
AndroidUtilities.runOnUIThread(onSaved);
|
||||
}
|
||||
if (result && onSaved != null) {
|
||||
AndroidUtilities.runOnUIThread(onSaved);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FileLog.e(e);
|
||||
|
@ -6019,6 +6019,7 @@ public class MessageObject {
|
||||
attachPathExists = f.exists();
|
||||
}
|
||||
if (!attachPathExists) {
|
||||
|
||||
File file = FileLoader.getPathToMessage(messageOwner);
|
||||
if (type == 3 && needDrawBluredPreview()) {
|
||||
mediaExists = new File(file.getAbsolutePath() + ".enc").exists();
|
||||
|
@ -14920,6 +14920,13 @@ public class MessagesController extends BaseController implements NotificationCe
|
||||
.apply();
|
||||
}
|
||||
|
||||
public void markSponsoredAsRead(long dialog_id, MessageObject object) {
|
||||
ArrayList<MessageObject> messages = getSponsoredMessages(dialog_id);
|
||||
if (messages != null) {
|
||||
messages.remove(object);
|
||||
}
|
||||
}
|
||||
|
||||
public interface MessagesLoadedCallback {
|
||||
void onMessagesLoaded(boolean fromCache);
|
||||
|
||||
|
@ -5890,7 +5890,11 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
|
||||
|
||||
if (messageObject.isSponsored()) {
|
||||
drawInstantView = true;
|
||||
drawInstantViewType = 1;
|
||||
if (messageObject.sponsoredChannelPost != 0) {
|
||||
drawInstantViewType = 12;
|
||||
} else {
|
||||
drawInstantViewType = 1;
|
||||
}
|
||||
long id = MessageObject.getPeerId(messageObject.messageOwner.from_id);
|
||||
if (id > 0) {
|
||||
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(id);
|
||||
@ -6927,7 +6931,9 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
|
||||
if (drawInstantView && instantViewLayout == null) {
|
||||
String str;
|
||||
instantWidth = AndroidUtilities.dp(12 + 9 + 12);
|
||||
if (drawInstantViewType == 1) {
|
||||
if (drawInstantViewType == 12) {
|
||||
str = LocaleController.getString("OpenChannelPost", R.string.OpenChannelPost);
|
||||
} else if (drawInstantViewType == 1) {
|
||||
str = LocaleController.getString("OpenChannel", R.string.OpenChannel);
|
||||
} else if (drawInstantViewType == 10) {
|
||||
str = LocaleController.getString("OpenBot", R.string.OpenBot);
|
||||
@ -6968,7 +6974,7 @@ public class ChatMessageCell extends BaseCell implements SeekBar.SeekBarDelegate
|
||||
if (currentMessageObject.type == 12) {
|
||||
totalHeight += AndroidUtilities.dp(14);
|
||||
}
|
||||
if (hasNewLineForTime) {
|
||||
if (currentMessageObject.isSponsored() && hasNewLineForTime) {
|
||||
totalHeight += AndroidUtilities.dp(16);
|
||||
}
|
||||
if (instantViewLayout != null && instantViewLayout.getLineCount() > 0) {
|
||||
|
@ -6177,7 +6177,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
} else if (returnToMessageId > 0) {
|
||||
scrollToMessageId(returnToMessageId, 0, true, returnToLoadIndex, true, 0);
|
||||
} else {
|
||||
scrollToLastMessage();
|
||||
scrollToLastMessage(false);
|
||||
if (!pinnedMessageIds.isEmpty()) {
|
||||
forceScrollToFirst = true;
|
||||
forceNextPinnedMessageId = pinnedMessageIds.get(0);
|
||||
@ -9800,7 +9800,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
} else {
|
||||
SendMessagesHelper.getInstance(currentAccount).sendMessage(getUserConfig().getCurrentUser(), dialog_id, messageObject, getThreadMessage(), null, null, true, 0);
|
||||
if (chatMode == 0) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
hideFieldPanel(false);
|
||||
}
|
||||
@ -11483,9 +11483,18 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
}
|
||||
|
||||
private void moveScrollToLastMessage() {
|
||||
private void moveScrollToLastMessage(boolean skipSponsored) {
|
||||
if (chatListView != null && !messages.isEmpty() && !pinchToZoomHelper.isInOverlayMode()) {
|
||||
chatLayoutManager.scrollToPositionWithOffset(0, 0);
|
||||
int position = 0;
|
||||
if (skipSponsored) {
|
||||
while (position < messages.size()) {
|
||||
if (!messages.get(position).isSponsored()) {
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}
|
||||
chatLayoutManager.scrollToPositionWithOffset(position, 0);
|
||||
chatListView.stopScroll();
|
||||
}
|
||||
}
|
||||
@ -11558,7 +11567,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
}
|
||||
|
||||
private void scrollToLastMessage() {
|
||||
private void scrollToLastMessage(boolean skipSponsored) {
|
||||
if (chatListView.isFastScrollAnimationRunning()) {
|
||||
return;
|
||||
}
|
||||
@ -11575,7 +11584,16 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
} else {
|
||||
chatAdapter.updateRowsSafe();
|
||||
chatScrollHelperCallback.scrollTo = null;
|
||||
chatScrollHelper.scrollToPosition(0, 0, true, true);
|
||||
int position = 0;
|
||||
if (skipSponsored) {
|
||||
while (position < messages.size()) {
|
||||
if (!messages.get(position).isSponsored()) {
|
||||
break;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
}
|
||||
chatScrollHelper.scrollToPosition(position, 0, true, true);
|
||||
}
|
||||
} else {
|
||||
if (progressDialog != null) {
|
||||
@ -14458,7 +14476,8 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
scrollToMessagePosition = -10000;
|
||||
scrollToMessage = null;
|
||||
} else {
|
||||
moveScrollToLastMessage();
|
||||
addSponsoredMessages(!isFirstLoading);
|
||||
moveScrollToLastMessage(true);
|
||||
}
|
||||
if (loaded_mentions_count != 0) {
|
||||
showMentionDownButton(true, true);
|
||||
@ -15145,7 +15164,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
if (chatLayoutManager != null) {
|
||||
if (mediaUpdated && chatLayoutManager.findFirstVisibleItemPosition() == 0) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
}
|
||||
getNotificationsController().playOutChatSound();
|
||||
@ -16933,7 +16952,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
needAnimateToMessage = obj;
|
||||
}
|
||||
if (obj.isOut() && obj.wasJustSent) {
|
||||
scrollToLastMessage();
|
||||
scrollToLastMessage(true);
|
||||
return;
|
||||
}
|
||||
if (obj.type < 0 || messagesDict[0].indexOfKey(messageId) >= 0) {
|
||||
@ -17166,7 +17185,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
maxDate[0] = Math.max(maxDate[0], obj.messageOwner.date);
|
||||
messagesDict[0].put(messageId, obj);
|
||||
ArrayList<MessageObject> dayArray = messagesByDays.get(obj.dateKey);
|
||||
ArrayList<MessageObject> dayArray;
|
||||
if (isAd && !messages.isEmpty()) {
|
||||
dayArray = messagesByDays.get(messages.get(0).dateKey);
|
||||
} else {
|
||||
dayArray = messagesByDays.get(obj.dateKey);
|
||||
}
|
||||
if (placeToPaste > messages.size()) {
|
||||
placeToPaste = messages.size();
|
||||
}
|
||||
@ -17317,7 +17341,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
scrollToTopOnResume = true;
|
||||
} else {
|
||||
forceScrollToTop = true;
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -17348,7 +17372,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
chatListItemAnimator.setShouldAnimateEnterFromBottom(needMoveScrollToLastMessage);
|
||||
}
|
||||
if (needMoveScrollToLastMessage) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
} else {
|
||||
int index = messages.indexOf(messageObject);
|
||||
if (chatLayoutManager != null && index > 0 && (chatLayoutManager.findViewByPosition(chatAdapter.messagesStartRow + index) != null || chatLayoutManager.findViewByPosition(chatAdapter.messagesStartRow + index - 1) != null)) {
|
||||
@ -19541,7 +19565,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + messages.indexOf(scrollToMessage), yOffset, bottom);
|
||||
}
|
||||
} else {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
scrollToTopUnReadOnResume = false;
|
||||
scrollToTopOnResume = false;
|
||||
@ -19658,8 +19682,15 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
int messageId = 0;
|
||||
int offset = 0;
|
||||
if (chatLayoutManager != null) {
|
||||
boolean sponsoredMessageFound = false;
|
||||
for (int i = 0; i < chatListView.getChildCount(); i++) {
|
||||
if (chatListView.getChildAt(i) instanceof ChatMessageCell && ((ChatMessageCell) chatListView.getChildAt(i)).getMessageObject().isSponsored()) {
|
||||
sponsoredMessageFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int position = chatLayoutManager.findFirstVisibleItemPosition();
|
||||
if (position != 0) {
|
||||
if (position != 0 && !sponsoredMessageFound) {
|
||||
RecyclerListView.Holder holder = (RecyclerListView.Holder) chatListView.findViewHolderForAdapterPosition(position);
|
||||
if (holder != null) {
|
||||
int mid = 0;
|
||||
@ -21586,13 +21617,13 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
}
|
||||
if (success && chatMode == 0) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
} else {
|
||||
if (getSendMessagesHelper().retrySendMessage(selectedObject, false)) {
|
||||
updateVisibleRows();
|
||||
if (chatMode == 0) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -22612,7 +22643,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
}
|
||||
} else {
|
||||
fragment.finishFragment();
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
showFieldPanelForForward(true, fmessages);
|
||||
if (AndroidUtilities.isTablet()) {
|
||||
hideActionMode();
|
||||
@ -22902,7 +22933,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
public void didSelectLocation(TLRPC.MessageMedia location, int locationType, boolean notify, int scheduleDate) {
|
||||
getSendMessagesHelper().sendMessage(location, dialog_id, replyingMessageObject, getThreadMessage(), null, null, notify, scheduleDate);
|
||||
if (chatMode == 0) {
|
||||
moveScrollToLastMessage();
|
||||
moveScrollToLastMessage(false);
|
||||
}
|
||||
if (locationType == LocationActivity.LOCATION_TYPE_SEND || locationType == LocationActivity.LOCATION_TYPE_SEND_WITH_LIVE) {
|
||||
afterMessageSend();
|
||||
@ -23811,6 +23842,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
getConnectionsManager().sendRequest(req, (response, error) -> {
|
||||
|
||||
});
|
||||
getMessagesController().markSponsoredAsRead(dialog_id, object);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -334,6 +334,10 @@ public class ChatAttachAlertDocumentLayout extends ChatAttachAlert.AttachAlertLa
|
||||
if (object instanceof ListItem) {
|
||||
ListItem item = (ListItem) object;
|
||||
File file = item.file;
|
||||
boolean isExternalStorageManager = false;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||
isExternalStorageManager = Environment.isExternalStorageManager();
|
||||
}
|
||||
if (file == null) {
|
||||
if (item.icon == R.drawable.files_gallery) {
|
||||
HashMap<Object, Object> selectedPhotos = new HashMap<>();
|
||||
@ -377,7 +381,7 @@ public class ChatAttachAlertDocumentLayout extends ChatAttachAlert.AttachAlertLa
|
||||
if (delegate != null) {
|
||||
delegate.startMusicSelectActivity();
|
||||
}
|
||||
} else if (!BuildVars.NO_SCOPED_STORAGE && item.icon == R.drawable.files_storage) {
|
||||
} else if (!BuildVars.NO_SCOPED_STORAGE && item.icon == R.drawable.files_storage && !isExternalStorageManager) {
|
||||
delegate.startDocumentSelectActivity();
|
||||
} else {
|
||||
int top = getTopForScroll();
|
||||
@ -950,7 +954,11 @@ public class ChatAttachAlertDocumentLayout extends ChatAttachAlert.AttachAlertLa
|
||||
items.clear();
|
||||
|
||||
HashSet<String> paths = new HashSet<>();
|
||||
if (!BuildVars.NO_SCOPED_STORAGE) {
|
||||
boolean isExternalStorageManager = false;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
|
||||
isExternalStorageManager = Environment.isExternalStorageManager();
|
||||
}
|
||||
if (!BuildVars.NO_SCOPED_STORAGE && !isExternalStorageManager) {
|
||||
ListItem ext = new ListItem();
|
||||
ext.title = LocaleController.getString("InternalStorage", R.string.InternalStorage);
|
||||
ext.icon = R.drawable.files_storage;
|
||||
|
@ -10034,7 +10034,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
|
||||
MessageObject openingObject = imagesArr.get(index);
|
||||
if (!openingObject.scheduled && (parentChatActivity == null || !parentChatActivity.isThreadChat())) {
|
||||
opennedFromMedia = true;
|
||||
startOffset = object.starOffset;
|
||||
if (object != null) {
|
||||
startOffset = object.starOffset;
|
||||
}
|
||||
menuItem.showSubItem(gallery_menu_showinchat);
|
||||
if (openingObject.canForwardMessage()) {
|
||||
setItemVisible(sendNoQuoteItem, true, false);
|
||||
|
@ -4810,4 +4810,5 @@
|
||||
<string name="UserAcceptedToGroupAction">un1 was accepted into the group</string>
|
||||
<string name="UserAcceptedToGroupPush">%1$s was accepted into the group</string>
|
||||
<string name="UserAcceptedToGroupPushWithGroup">%2$s|%1$s was accepted into the group</string>
|
||||
<string name="OpenChannelPost">VIEW POST</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user