diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle
index 88d655bf..ca670400 100644
--- a/TMessagesProj/build.gradle
+++ b/TMessagesProj/build.gradle
@@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
- versionCode 332
+ versionCode 335
versionName "1.9.0"
}
}
diff --git a/TMessagesProj/src/main/AndroidManifest.xml b/TMessagesProj/src/main/AndroidManifest.xml
index d8ee6d5e..f7bfaaa0 100644
--- a/TMessagesProj/src/main/AndroidManifest.xml
+++ b/TMessagesProj/src/main/AndroidManifest.xml
@@ -138,6 +138,7 @@
+
diff --git a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java
index cc8a2439..9f943129 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java
@@ -41,8 +41,8 @@ public class AndroidUtilities {
public static int statusBarHeight = 0;
public static float density = 1;
public static Point displaySize = new Point();
+ public static Integer photoSize = null;
private static Boolean isTablet = null;
- private static Boolean isSmallTablet = null;
public static int[] arrColors = {0xffee4928, 0xff41a903, 0xffe09602, 0xff0f94ed, 0xff8f3bf7, 0xfffc4380, 0xff00a1c4, 0xffeb7002};
public static int[] arrUsersAvatars = {
@@ -277,11 +277,8 @@ public class AndroidUtilities {
}
public static boolean isSmallTablet() {
- if (isSmallTablet == null) {
- float minSide = Math.min(displaySize.x, displaySize.y) / density;
- isSmallTablet = minSide <= 700;
- }
- return isSmallTablet;
+ float minSide = Math.min(displaySize.x, displaySize.y) / density;
+ return minSide <= 700;
}
public static int getMinTabletSide() {
@@ -354,4 +351,15 @@ public class AndroidUtilities {
public static int getBroadcastAvatarForId(int id) {
return arrBroadcastAvatars[getColorIndex(-Math.abs(id))];
}
+
+ public static int getPhotoSize() {
+ if (photoSize == null) {
+ if (Build.VERSION.SDK_INT >= 16) {
+ photoSize = 1280;
+ } else {
+ photoSize = 800;
+ }
+ }
+ return photoSize;
+ }
}
diff --git a/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java b/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java
index 22cc116a..d1e2b1b9 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java
@@ -64,6 +64,8 @@ public class ImageLoader {
private int lastImageNum = 0;
private long lastProgressUpdateTime = 0;
+ private File telegramPath = null;
+
private class HttpTask extends AsyncTask {
private CacheImage cacheImage = null;
@@ -548,6 +550,13 @@ public class ImageLoader {
AndroidUtilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
+ if (location != null) {
+ if (telegramPath != null && finalFile != null && finalFile.exists() && location.endsWith(".mp4") || location.endsWith(".jpg")) {
+ if (finalFile.toString().startsWith(telegramPath.toString())) {
+ Utilities.addMediaToGallery(finalFile.toString());
+ }
+ }
+ }
ImageLoader.this.fileDidLoaded(location, finalFile, tempFile);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.FileDidLoaded, location);
}
@@ -555,12 +564,12 @@ public class ImageLoader {
}
@Override
- public void fileDidFailedLoad(final String location, final boolean canceled) {
+ public void fileDidFailedLoad(final String location, final int state) {
AndroidUtilities.RunOnUIThread(new Runnable() {
@Override
public void run() {
ImageLoader.this.fileDidFailedLoad(location);
- NotificationCenter.getInstance().postNotificationName(NotificationCenter.FileDidFailedLoad, location, canceled);
+ NotificationCenter.getInstance().postNotificationName(NotificationCenter.FileDidFailedLoad, location, state);
}
});
}
@@ -597,14 +606,14 @@ public class ImageLoader {
try {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- File telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
+ telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
telegramPath.mkdirs();
if (telegramPath.isDirectory()) {
try {
- File imagePath = new File(telegramPath, "Images");
+ File imagePath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Images");
imagePath.mkdir();
if (imagePath.isDirectory()) {
- new File(imagePath, ".nomedia").createNewFile();
+ //new File(imagePath, ".nomedia").delete();
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
}
} catch (Exception e) {
@@ -612,10 +621,10 @@ public class ImageLoader {
}
try {
- File videoPath = new File(telegramPath, "Video");
+ File videoPath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Video");
videoPath.mkdir();
if (videoPath.isDirectory()) {
- new File(videoPath, ".nomedia").createNewFile();
+ //new File(videoPath, ".nomedia").delete();
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
}
} catch (Exception e) {
@@ -623,7 +632,7 @@ public class ImageLoader {
}
try {
- File audioPath = new File(telegramPath, "Audio");
+ File audioPath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Audio");
audioPath.mkdir();
if (audioPath.isDirectory()) {
new File(audioPath, ".nomedia").createNewFile();
@@ -634,7 +643,7 @@ public class ImageLoader {
}
try {
- File documentPath = new File(telegramPath, "Documents");
+ File documentPath = new File(telegramPath, LocaleController.getString("AppName", R.string.AppName) + " Documents");
documentPath.mkdir();
if (documentPath.isDirectory()) {
new File(documentPath, ".nomedia").createNewFile();
@@ -1041,22 +1050,7 @@ public class ImageLoader {
return b;
}
- public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
- if (bitmap == null) {
- return null;
- }
- float photoW = bitmap.getWidth();
- float photoH = bitmap.getHeight();
- if (photoW == 0 || photoH == 0) {
- return null;
- }
- float scaleFactor = Math.max(photoW / maxWidth, photoH / maxHeight);
- int w = (int)(photoW / scaleFactor);
- int h = (int)(photoH / scaleFactor);
- if (h == 0 || w == 0) {
- return null;
- }
-
+ private static TLRPC.PhotoSize scaleAndSaveImageInternal(Bitmap bitmap, int w, int h, float photoW, float photoH, float scaleFactor, int quality, boolean cache) throws Exception {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true);
TLRPC.TL_fileLocation location = new TLRPC.TL_fileLocation();
@@ -1073,25 +1067,54 @@ public class ImageLoader {
size.location = location;
size.w = (int)(photoW / scaleFactor);
size.h = (int)(photoH / scaleFactor);
- try {
- if (!cache) {
- String fileName = location.volume_id + "_" + location.local_id + ".jpg";
- final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
- FileOutputStream stream = new FileOutputStream(cacheFile);
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
- size.size = (int)stream.getChannel().size();
- } else {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
- size.bytes = stream.toByteArray();
- size.size = size.bytes.length;
- }
- if (scaledBitmap != bitmap) {
- scaledBitmap.recycle();
- }
- return size;
- } catch (Throwable e) {
+
+ if (!cache) {
+ String fileName = location.volume_id + "_" + location.local_id + ".jpg";
+ final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
+ FileOutputStream stream = new FileOutputStream(cacheFile);
+ scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
+ size.size = (int)stream.getChannel().size();
+ } else {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
+ size.bytes = stream.toByteArray();
+ size.size = size.bytes.length;
+ }
+ if (scaledBitmap != bitmap) {
+ scaledBitmap.recycle();
+ }
+
+ return size;
+ }
+
+ public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, float maxHeight, int quality, boolean cache) {
+ if (bitmap == null) {
return null;
}
+ float photoW = bitmap.getWidth();
+ float photoH = bitmap.getHeight();
+ if (photoW == 0 || photoH == 0) {
+ return null;
+ }
+ float scaleFactor = Math.max(photoW / maxWidth, photoH / maxHeight);
+ int w = (int)(photoW / scaleFactor);
+ int h = (int)(photoH / scaleFactor);
+ if (h == 0 || w == 0) {
+ return null;
+ }
+
+ try {
+ return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache);
+ } catch (Throwable e) {
+ FileLog.e("tmessages", e);
+ ImageLoader.getInstance().clearMemory();
+ System.gc();
+ try {
+ return scaleAndSaveImageInternal(bitmap, w, h, photoW, photoH, scaleFactor, quality, cache);
+ } catch (Throwable e2) {
+ FileLog.e("tmessages", e2);
+ return null;
+ }
+ }
}
}
diff --git a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java
index ac698b96..3202d64a 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java
@@ -148,6 +148,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private final static int PROCESSOR_TYPE_OTHER = 0;
private final static int PROCESSOR_TYPE_QCOM = 1;
private final static int PROCESSOR_TYPE_INTEL = 2;
+ private final static int PROCESSOR_TYPE_MTK = 3;
+ private final static int PROCESSOR_TYPE_SEC = 4;
+ private final static int PROCESSOR_TYPE_TI = 5;
private final Object videoConvertSync = new Object();
private ArrayList videoConvertQueue = new ArrayList();
@@ -490,6 +493,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
documentDownloadQueue.clear();
videoDownloadQueue.clear();
downloadQueueKeys.clear();
+ videoConvertQueue.clear();
+ cancelVideoConvert(null);
}
protected int getAutodownloadMask() {
@@ -615,9 +620,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.Video) {
- FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
+ FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.Document) {
- FileLoader.getInstance().loadFile((TLRPC.Document)downloadObject.object);
+ FileLoader.getInstance().loadFile((TLRPC.Document)downloadObject.object, false);
} else {
added = false;
}
@@ -644,12 +649,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
- private void checkDownloadFinished(String fileName, boolean canceled) {
+ private void checkDownloadFinished(String fileName, int state) {
DownloadObject downloadObject = downloadQueueKeys.get(fileName);
if (downloadObject != null) {
downloadQueueKeys.remove(fileName);
- if (!canceled) {
- MessagesStorage.getInstance().removeFromDownloadQueue(downloadObject.id, downloadObject.type);
+ if (state == 0 || state == 2) {
+ MessagesStorage.getInstance().removeFromDownloadQueue(downloadObject.id, downloadObject.type, state != 0);
}
if (downloadObject.type == AUTODOWNLOAD_MASK_PHOTO) {
photoDownloadQueue.remove(downloadObject);
@@ -907,7 +912,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
listenerInProgress = false;
processLaterArrays();
- checkDownloadFinished(fileName, (Boolean)args[1]);
+ checkDownloadFinished(fileName, (Integer)args[1]);
} else if (id == NotificationCenter.FileDidLoaded) {
listenerInProgress = true;
String fileName = (String)args[0];
@@ -923,7 +928,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
listenerInProgress = false;
processLaterArrays();
- checkDownloadFinished(fileName, false);
+ checkDownloadFinished(fileName, 0);
} else if (id == NotificationCenter.FileLoadProgressChanged) {
listenerInProgress = true;
String fileName = (String)args[0];
@@ -939,7 +944,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
listenerInProgress = false;
processLaterArrays();
} else if (id == NotificationCenter.FileUploadProgressChanged) {
- String location = (String)args[0];
listenerInProgress = true;
String fileName = (String)args[0];
ArrayList> arrayList = loadingFileObservers.get(fileName);
@@ -1523,8 +1527,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
});
}
- public static void saveFile(String path, String fullPath, Context context, final int type, final String name) {
- if (path == null && fullPath == null) {
+ public static void saveFile(String fullPath, Context context, final int type, final String name) {
+ if (fullPath == null) {
return;
}
@@ -1535,8 +1539,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
file = null;
}
}
+
if (file == null) {
- file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), path);
+ return;
}
final File sourceFile = file;
@@ -1868,19 +1873,31 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
public void cancelVideoConvert(MessageObject messageObject) {
- if (!videoConvertQueue.isEmpty()) {
- if (videoConvertQueue.get(0) == messageObject) {
- synchronized (videoConvertSync) {
- cancelCurrentVideoConversion = true;
- }
+ if (messageObject == null) {
+ synchronized (videoConvertSync) {
+ cancelCurrentVideoConversion = true;
+ }
+ } else {
+ if (!videoConvertQueue.isEmpty()) {
+ if (videoConvertQueue.get(0) == messageObject) {
+ synchronized (videoConvertSync) {
+ cancelCurrentVideoConversion = true;
+ }
+ }
+ videoConvertQueue.remove(messageObject);
}
- videoConvertQueue.remove(messageObject);
}
}
private void startVideoConvertFromQueue() {
if (!videoConvertQueue.isEmpty()) {
+ synchronized (videoConvertSync) {
+ cancelCurrentVideoConversion = false;
+ }
MessageObject messageObject = videoConvertQueue.get(0);
+ Intent intent = new Intent(ApplicationLoader.applicationContext, VideoEncodingService.class);
+ intent.putExtra("path", messageObject.messageOwner.attachPath);
+ ApplicationLoader.applicationContext.startService(intent);
VideoConvertRunnable.runConversion(messageObject);
}
}
@@ -1897,7 +1914,11 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
for (String type : types) {
if (type.equalsIgnoreCase(mimeType)) {
lastCodecInfo = codecInfo;
- FileLog.e("tmessages", "available codec = " + codecInfo.getName());
+ if (!lastCodecInfo.getName().equals("OMX.SEC.avc.enc")) {
+ return lastCodecInfo;
+ } else if (lastCodecInfo.getName().equals("OMX.SEC.AVC.Encoder")) {
+ return lastCodecInfo;
+ }
}
}
}
@@ -1919,13 +1940,17 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
private static int selectColorFormat(MediaCodecInfo codecInfo, String mimeType) {
MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(mimeType);
+ int lastColorFormat = 0;
for (int i = 0; i < capabilities.colorFormats.length; i++) {
int colorFormat = capabilities.colorFormats[i];
if (isRecognizedFormat(colorFormat)) {
- return colorFormat;
+ lastColorFormat = colorFormat;
+ if (!(codecInfo.getName().equals("OMX.SEC.AVC.Encoder") && colorFormat == 19)) {
+ return colorFormat;
+ }
}
}
- return 0;
+ return lastColorFormat;
}
@TargetApi(16)
@@ -1963,7 +1988,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.FileNewChunkAvailable, messageObject, file.toString(), finalSize);
}
- if (finalSize != 0) {
+ if (error || finalSize != 0) {
synchronized (videoConvertSync) {
cancelCurrentVideoConversion = false;
}
@@ -2090,8 +2115,17 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
int originalWidth = messageObject.messageOwner.videoEditedInfo.originalWidth;
int originalHeight = messageObject.messageOwner.videoEditedInfo.originalHeight;
int bitrate = messageObject.messageOwner.videoEditedInfo.bitrate;
+ int rotateRender = 0;
File cacheFile = new File(messageObject.messageOwner.attachPath);
+ if (Build.VERSION.SDK_INT < 18 && resultHeight > resultWidth && resultWidth != originalWidth && resultHeight != originalHeight) {
+ int temp = resultHeight;
+ resultHeight = resultWidth;
+ resultWidth = temp;
+ rotationValue = 90;
+ rotateRender = 270;
+ }
+
File inputFile = new File(videoPath);
if (!inputFile.canRead()) {
return false;
@@ -2112,7 +2146,6 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
Mp4Movie movie = new Mp4Movie();
movie.setCacheFile(cacheFile);
movie.setRotation(rotationValue);
- resultHeight = 352;
movie.setSize(resultWidth, resultHeight);
mediaMuxer = new MP4Builder().createMovie(movie);
extractor = new MediaExtractor();
@@ -2142,18 +2175,29 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (Build.VERSION.SDK_INT < 18) {
MediaCodecInfo codecInfo = selectCodec(MIME_TYPE);
colorFormat = selectColorFormat(codecInfo, MIME_TYPE);
+ if (colorFormat == 0) {
+ throw new RuntimeException("no supported color format");
+ }
String manufacturer = Build.MANUFACTURER.toLowerCase();
- if (codecInfo.getName().contains("OMX.qcom.")) {
+ String codecName = codecInfo.getName();
+ if (codecName.contains("OMX.qcom.")) {
processorType = PROCESSOR_TYPE_QCOM;
if (Build.VERSION.SDK_INT == 16) {
if (manufacturer.equals("lge") || manufacturer.equals("nokia")) {
swapUV = 1;
}
}
- } else if (codecInfo.getName().contains("OMX.Intel.")) {
+ } else if (codecName.contains("OMX.Intel.")) {
processorType = PROCESSOR_TYPE_INTEL;
+ } else if (codecName.equals("OMX.MTK.VIDEO.ENCODER.AVC")) {
+ processorType = PROCESSOR_TYPE_MTK;
+ } else if (codecName.equals("OMX.SEC.AVC.Encoder")) {
+ processorType = PROCESSOR_TYPE_SEC;
+ swapUV = 1;
+ } else if (codecName.equals("OMX.TI.DUCATI1.VIDEO.H264E")) {
+ processorType = PROCESSOR_TYPE_TI;
}
- FileLog.e("tmessages", "codec = " + codecInfo.getName() + " manufacturer = " + manufacturer);
+ FileLog.e("tmessages", "codec = " + codecInfo.getName() + " manufacturer = " + manufacturer + "device = " + Build.MODEL);
} else {
colorFormat = MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface;
}
@@ -2174,8 +2218,12 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
padding = uvoffset - (resultWidth * resultHeight);
bufferSize += padding;
}
- } else if (processorType == PROCESSOR_TYPE_INTEL) {
-
+ } else if (processorType == PROCESSOR_TYPE_TI) {
+ //resultHeightAligned = 368;
+ //bufferSize = resultWidth * resultHeightAligned * 3 / 2;
+ //resultHeightAligned += (16 - (resultHeight % 16));
+ //padding = resultWidth * (resultHeightAligned - resultHeight);
+ //bufferSize += padding * 5 / 4;
}
extractor.selectTrack(videoIndex);
@@ -2192,8 +2240,8 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
outputFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 25);
outputFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 10);
if (Build.VERSION.SDK_INT < 18) {
- outputFormat.setInteger("stride", resultWidth);
- outputFormat.setInteger("slice-height", resultHeightAligned);
+ outputFormat.setInteger("stride", resultWidth + 32);
+ outputFormat.setInteger("slice-height", resultHeight);
}
encoder = MediaCodec.createEncoderByType(MIME_TYPE);
@@ -2208,7 +2256,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (Build.VERSION.SDK_INT >= 18) {
outputSurface = new OutputSurface();
} else {
- outputSurface = new OutputSurface(resultWidth, resultHeight);
+ outputSurface = new OutputSurface(resultWidth, resultHeight, rotateRender);
}
decoder.configure(inputFormat, outputSurface.getSurface(), null, 0);
decoder.start();
@@ -2326,6 +2374,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} else if (decoderStatus == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
MediaFormat newFormat = decoder.getOutputFormat();
+ FileLog.e("tmessages", "newFormat = " + newFormat);
} else if (decoderStatus < 0) {
throw new RuntimeException("unexpected result from decoder.dequeueOutputBuffer: " + decoderStatus);
} else {
@@ -2399,6 +2448,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
} catch (Exception e) {
FileLog.e("tmessages", e);
+ error = true;
}
extractor.unselectTrack(videoIndex);
@@ -2430,7 +2480,9 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
videoStartTime = videoTime;
}
}
- readAndWriteTrack(messageObject, extractor, mediaMuxer, info, videoStartTime, endTime, cacheFile, true);
+ if (!error) {
+ readAndWriteTrack(messageObject, extractor, mediaMuxer, info, videoStartTime, endTime, cacheFile, true);
+ }
} catch (Exception e) {
error = true;
FileLog.e("tmessages", e);
diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java
index 67f56dcd..76869f6f 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java
@@ -417,7 +417,7 @@ public class MessageObject {
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
ArrayList sizes = messageOwner.media.photo.sizes;
if (sizes.size() > 0) {
- TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, 800, 800);
+ TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
if (sizeFull != null) {
return FileLoader.getAttachFileName(sizeFull);
}
diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
index ee849f55..1860c1d3 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java
@@ -1645,37 +1645,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
});
}
- public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri) {
- long time = System.currentTimeMillis();
- Bitmap bitmap = ImageLoader.loadBitmap(path, imageUri, 800, 800);
- ArrayList sizes = new ArrayList();
- TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, true);
- if (size != null) {
- size.type = "s";
- sizes.add(size);
- }
- size = ImageLoader.scaleAndSaveImage(bitmap, 800, 800, 80, false);
- if (size != null) {
- size.type = "x";
- sizes.add(size);
- }
- if (bitmap != null) {
- bitmap.recycle();
- }
- if (sizes.isEmpty()) {
- return null;
- } else {
- UserConfig.saveConfig(false);
- TLRPC.TL_photo photo = new TLRPC.TL_photo();
- photo.user_id = UserConfig.getClientUserId();
- photo.date = ConnectionsManager.getInstance().getCurrentTime();
- photo.sizes = sizes;
- photo.caption = "";
- photo.geo = new TLRPC.TL_geoPointEmpty();
- return photo;
- }
- }
-
public void markDialogAsRead(final long dialog_id, final int max_id, final int max_positive_id, final int offset, final int max_date, final boolean was, final boolean popup) {
int lower_part = (int)dialog_id;
int high_id = (int)(dialog_id >> 32);
diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
index 17e2008e..07b0e37d 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java
@@ -2384,12 +2384,24 @@ public class MessagesStorage {
}
}
- public void removeFromDownloadQueue(final long id, final int type) {
+ public void removeFromDownloadQueue(final long id, final int type, final boolean move) {
storageQueue.postRunnable(new Runnable() {
@Override
public void run() {
try {
- database.executeFast(String.format(Locale.US, "DELETE FROM download_queue WHERE uid = %d AND type = %d", id, type)).stepThis().dispose();
+ if (move) {
+ int minDate = -1;
+ SQLiteCursor cursor = database.queryFinalized(String.format(Locale.US, "SELECT min(date) FROM download_queue WHERE type = %d", type));
+ if (cursor.next()) {
+ minDate = cursor.intValue(0);
+ }
+ cursor.dispose();
+ if (minDate != -1) {
+ database.executeFast(String.format(Locale.US, "UPDATE download_queue SET date = %d WHERE uid = %d AND type = %d", minDate - 1, id, type)).stepThis().dispose();
+ }
+ } else {
+ database.executeFast(String.format(Locale.US, "DELETE FROM download_queue WHERE uid = %d AND type = %d", id, type)).stepThis().dispose();
+ }
} catch (Exception e) {
FileLog.e("tmessages", e);
}
@@ -2588,7 +2600,7 @@ public class MessagesStorage {
}
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) {
- TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.media.photo.sizes, 800, 800);
+ TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.media.photo.sizes, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize());
if (photoSize != null) {
id = message.media.photo.id;
type = MediaController.AUTODOWNLOAD_MASK_PHOTO;
diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java
index 32003f2d..87298e13 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java
@@ -40,6 +40,7 @@ public class NotificationCenter {
public static final int blockedUsersDidLoaded = 28;
public static final int openedChatChanged = 29;
public static final int hideEmojiKeyboard = 30;
+ public static final int stopEncodingService = 31;
public static final int wallpapersDidLoaded = 171;
public static final int closeOtherAppActivities = 702;
diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java
index 10e7c3b6..cc3327a4 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java
@@ -393,7 +393,8 @@ public class NotificationsController {
String lastMessageFull = null;
if (pushMessages.size() == 1) {
String message = lastMessageFull = getStringForMessage(pushMessages.get(0), false);
- lastMessage = getStringForMessage(pushMessages.get(0), true);
+ //lastMessage = getStringForMessage(pushMessages.get(0), true);
+ lastMessage = lastMessageFull;
if (message == null) {
return;
}
@@ -418,7 +419,8 @@ public class NotificationsController {
}
if (i == 0) {
lastMessageFull = message;
- lastMessage = getStringForMessage(pushMessages.get(i), true);
+ //lastMessage = getStringForMessage(pushMessages.get(i), true);
+ lastMessage = lastMessageFull;
}
if (pushDialogs.size() == 1) {
if (replace) {
@@ -444,6 +446,9 @@ public class NotificationsController {
if (!notifyDisabled) {
if (ApplicationLoader.mainInterfacePaused || inAppPreview) {
+ if (lastMessage.length() > 100) {
+ lastMessage = lastMessage.substring(0, 100).replace("\n", " ").trim() + "...";
+ }
mBuilder.setTicker(lastMessage);
}
if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java
index 43e98c98..adedc4e9 100644
--- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java
+++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java
@@ -8,6 +8,9 @@
package org.telegram.android;
+import android.graphics.Bitmap;
+import android.net.Uri;
+
import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager;
@@ -198,6 +201,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (message.obj == messageObject) {
message.obj.messageOwner.videoEditedInfo = null;
message.obj.messageOwner.message = "-1";
+ message.obj.messageOwner.media.video.size = (int)finalSize;
ArrayList messages = new ArrayList();
messages.add(message.obj.messageOwner);
@@ -213,6 +217,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} else if (id == NotificationCenter.FilePreparingFailed) {
MessageObject messageObject = (MessageObject)args[0];
String finalPath = (String)args[1];
+ stopVideoService(messageObject.messageOwner.attachPath);
ArrayList arr = delayedMessages.get(finalPath);
if (arr != null) {
@@ -949,6 +954,20 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
}
}
+ private void stopVideoService(final String path) {
+ MessagesStorage.getInstance().storageQueue.postRunnable(new Runnable() {
+ @Override
+ public void run() {
+ AndroidUtilities.RunOnUIThread(new Runnable() {
+ @Override
+ public void run() {
+ NotificationCenter.getInstance().postNotificationName(NotificationCenter.stopEncodingService, path);
+ }
+ });
+ }
+ });
+ }
+
private void performSendMessageRequest(final TLObject req, final MessageObject newMsgObj, final String originalPath) {
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
@Override
@@ -957,6 +976,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
final int oldId = newMsgObj.messageOwner.id;
final boolean isBroadcast = req instanceof TLRPC.TL_messages_sendBroadcast;
final ArrayList sentMessages = new ArrayList();
+ final String attachPath = newMsgObj.messageOwner.attachPath;
if (response instanceof TLRPC.messages_SentMessage) {
TLRPC.messages_SentMessage res = (TLRPC.messages_SentMessage) response;
@@ -1009,6 +1029,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
processSentMessage(oldId);
}
});
+ if (newMsgObj.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ stopVideoService(attachPath);
+ }
}
});
} else {
@@ -1019,6 +1042,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.messageOwner.id);
processSentMessage(newMsgObj.messageOwner.id);
+ if (newMsgObj.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ stopVideoService(newMsgObj.messageOwner.attachPath);
+ }
}
});
}
@@ -1100,6 +1126,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
public void run(TLObject response, TLRPC.TL_error error) {
if (newMsgObj != null) {
if (error == null) {
+ final String attachPath = newMsgObj.messageOwner.attachPath;
final TLRPC.messages_SentEncryptedMessage res = (TLRPC.messages_SentEncryptedMessage) response;
newMsgObj.messageOwner.date = res.date;
if (res.file instanceof TLRPC.TL_encryptedFile) {
@@ -1115,6 +1142,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SENT;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageReceivedByServer, newMsgObj.messageOwner.id, newMsgObj.messageOwner.id, newMsgObj);
processSentMessage(newMsgObj.messageOwner.id);
+ if (newMsgObj.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ stopVideoService(attachPath);
+ }
}
});
}
@@ -1127,6 +1157,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsgObj.messageOwner.send_state = MessageObject.MESSAGE_SEND_STATE_SEND_ERROR;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.messageSendError, newMsgObj.messageOwner.id);
processSentMessage(newMsgObj.messageOwner.id);
+ if (newMsgObj.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
+ stopVideoService(newMsgObj.messageOwner.attachPath);
+ }
}
});
}
@@ -1185,11 +1218,21 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
size2.location = size.location;
}
}
+
sentMessage.message = newMsg.message;
- sentMessage.attachPath = newMsg.attachPath;
newMsg.media.video.dc_id = sentMessage.media.video.dc_id;
newMsg.media.video.id = sentMessage.media.video.id;
newMsg.media.video.access_hash = sentMessage.media.video.access_hash;
+
+ if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
+ File cacheFile = new File(newMsg.attachPath);
+ File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.video);
+ if (!cacheFile.renameTo(cacheFile2)) {
+ sentMessage.attachPath = newMsg.attachPath;
+ }
+ } else {
+ sentMessage.attachPath = newMsg.attachPath;
+ }
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaDocument && sentMessage.media.document != null && newMsg.media instanceof TLRPC.TL_messageMediaDocument && newMsg.media.document != null) {
MessagesStorage.getInstance().putSentFile(originalPath, sentMessage.media.document, 1);
@@ -1206,37 +1249,39 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
size2.location = size.location;
}
}
+
+ newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
+ newMsg.media.document.id = sentMessage.media.document.id;
+ newMsg.media.document.access_hash = sentMessage.media.document.access_hash;
+
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.document);
- boolean result = cacheFile.renameTo(cacheFile2);
- if (result) {
- newMsg.attachPath = null;
- } else {
+ if (!cacheFile.renameTo(cacheFile2)) {
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
+ } else {
+ newMsg.attachPath = "";
}
} else {
sentMessage.attachPath = newMsg.attachPath;
sentMessage.message = newMsg.message;
}
- newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
- newMsg.media.document.id = sentMessage.media.document.id;
- newMsg.media.document.access_hash = sentMessage.media.document.access_hash;
} else if (sentMessage.media instanceof TLRPC.TL_messageMediaAudio && sentMessage.media.audio != null && newMsg.media instanceof TLRPC.TL_messageMediaAudio && newMsg.media.audio != null) {
sentMessage.message = newMsg.message;
- sentMessage.attachPath = newMsg.attachPath;
String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg";
+ newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id;
+ newMsg.media.audio.id = sentMessage.media.audio.id;
+ newMsg.media.audio.access_hash = sentMessage.media.audio.access_hash;
String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".ogg";
if (!fileName.equals(fileName2)) {
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.audio);
- cacheFile.renameTo(cacheFile2);
+ if (!cacheFile.renameTo(cacheFile2)) {
+ sentMessage.attachPath = newMsg.attachPath;
+ }
}
- newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id;
- newMsg.media.audio.id = sentMessage.media.audio.id;
- newMsg.media.audio.access_hash = sentMessage.media.audio.access_hash;
}
} else if (file != null) {
if (newMsg.media instanceof TLRPC.TL_messageMediaPhoto && newMsg.media.photo != null) {
@@ -1252,7 +1297,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
String fileName2 = size.location.volume_id + "_" + size.location.local_id;
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg");
File cacheFile2 = FileLoader.getPathToAttach(size);
- boolean result = cacheFile.renameTo(cacheFile2);
+ cacheFile.renameTo(cacheFile2);
ImageLoader.getInstance().replaceImageInCache(fileName, fileName2);
ArrayList arr = new ArrayList();
arr.add(newMsg);
@@ -1276,6 +1321,15 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.media.video.key = decryptedMessage.media.key;
newMsg.media.video.iv = decryptedMessage.media.iv;
newMsg.media.video.mime_type = video.mime_type;
+
+ if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
+ File cacheFile = new File(newMsg.attachPath);
+ File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.video);
+ if (cacheFile.renameTo(cacheFile2)) {
+ newMsg.attachPath = "";
+ }
+ }
+
ArrayList arr = new ArrayList();
arr.add(newMsg);
MessagesStorage.getInstance().putMessages(arr, false, true, false, 0);
@@ -1299,7 +1353,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) {
File cacheFile = new File(newMsg.attachPath);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.document);
- cacheFile.renameTo(cacheFile2);
+ if (cacheFile.renameTo(cacheFile2)) {
+ newMsg.attachPath = "";
+ }
}
ArrayList arr = new ArrayList();
@@ -1326,7 +1382,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (!fileName.equals(fileName2)) {
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.audio);
- cacheFile.renameTo(cacheFile2);
+ if (cacheFile.renameTo(cacheFile2)) {
+ newMsg.attachPath = "";
+ }
}
ArrayList arr = new ArrayList();
@@ -1485,94 +1543,38 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
});
}
- /*
- private void startConvert() throws Exception {
- IsoFile isoFile = new IsoFile(videoPath);
- TrackBox trackBox = (TrackBox) Path.getPath(isoFile, "/moov/trak/mdia/minf/stbl/stsd/avc1/../../../../../");
- AvcConfigurationBox avcConfigurationBox = (AvcConfigurationBox) Path.getPath(trackBox, "mdia/minf/stbl/stsd/avc1/avcC");
- avcConfigurationBox.parseDetails();
-
- Movie movie = MovieCreator.build(videoPath);
-
- List