Commit ab44b870 authored by DrKLO's avatar DrKLO

Changed small Tablets portrait layout, changes media store path to sdcard/Telegram (need testing)

parent 4d5b43f6
......@@ -80,7 +80,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 328
versionCode 329
versionName "1.9.0"
}
}
......@@ -66,7 +66,7 @@ int isSemiPlanarYUV(int colorFormat) {
}
}
JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *env, jclass class, jobject src, jobject dest, int destFormat, int width, int height, int padding) {
JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *env, jclass class, jobject src, jobject dest, int destFormat, int width, int height, int padding, int swap) {
if (!src || !dest || !destFormat) {
return 0;
}
......@@ -78,16 +78,31 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *en
int half_height = (height + 1) / 2;
if (!isSemiPlanarYUV(destFormat)) {
ARGBToI420(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
destBuff + width * height + padding, half_width,
width, height);
if (!swap) {
ARGBToI420(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
destBuff + width * height + padding, half_width,
width, height);
} else {
ARGBToI420(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + padding, half_width,
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
width, height);
}
} else {
ARGBToNV21(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + padding, half_width * 2,
width, height);
if (!swap) {
ARGBToNV21(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + padding, half_width * 2,
width, height);
} else {
ARGBToNV12(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + padding, half_width * 2,
width, height);
}
}
return 1;
......
......@@ -42,6 +42,7 @@ public class AndroidUtilities {
public static float density = 1;
public static Point displaySize = new Point();
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 = {
......@@ -275,6 +276,33 @@ public class AndroidUtilities {
return isTablet;
}
public static boolean isSmallTablet() {
if (isSmallTablet == null) {
float minSide = Math.min(displaySize.x, displaySize.y) / density;
isSmallTablet = minSide <= 700;
}
return isSmallTablet;
}
public static int getMinTabletSide() {
if (!isSmallTablet()) {
int smallSide = Math.min(displaySize.x, displaySize.y);
int leftSide = smallSide * 35 / 100;
if (leftSide < dp(320)) {
leftSide = dp(320);
}
return smallSide - leftSide;
} else {
int smallSide = Math.min(displaySize.x, displaySize.y);
int maxSide = Math.max(displaySize.x, displaySize.y);
int leftSide = maxSide * 35 / 100;
if (leftSide < dp(320)) {
leftSide = dp(320);
}
return Math.min(smallSide, maxSide - leftSide);
}
}
public static int getColorIndex(int id) {
int[] arr;
if (id >= 0) {
......
......@@ -18,12 +18,14 @@ import android.media.ExifInterface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
......@@ -576,12 +578,43 @@ public class ImageLoader {
});
}
}
});
@Override
public File getCacheDir() {
return AndroidUtilities.getCacheDir();
FileLoader.getInstance().setMediaDirs(createMediaPaths());
}
private HashMap<Integer, File> createMediaPaths() {
HashMap<Integer, File> mediaDirs = new HashMap<Integer, File>();
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, AndroidUtilities.getCacheDir());
try {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
File telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
telegramPath.mkdirs();
File imagePath = new File(telegramPath, "Images");
imagePath.mkdir();
new File(imagePath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
File videoPath = new File(telegramPath, "Video");
videoPath.mkdir();
new File(videoPath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
File audioPath = new File(telegramPath, "Audio");
audioPath.mkdir();
new File(audioPath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_AUDIO, audioPath);
File documentPath = new File(telegramPath, "Documents");
documentPath.mkdir();
new File(documentPath, ".nomedia").createNewFile();
mediaDirs.put(FileLoader.MEDIA_DIR_DOCUMENT, documentPath);
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return mediaDirs;
}
private void performReplace(String oldKey, String newKey) {
......@@ -746,7 +779,12 @@ public class ImageLoader {
if (!added) {
boolean onlyCache = false;
File cacheFile = new File(AndroidUtilities.getCacheDir(), url);
File cacheFile = null;
if (size == 0 || httpUrl != null || fileLocation != null && fileLocation.key != null) {
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), url);
} else {
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_IMAGE), url);
}
if (httpUrl != null) {
if (!httpUrl.startsWith("http")) {
onlyCache = true;
......@@ -779,11 +817,12 @@ public class ImageLoader {
img.addImageView(imageView);
imageLoadingByUrl.put(url, img);
if (httpUrl == null) {
FileLoader.getInstance().loadFile(fileLocation, size);
FileLoader.getInstance().loadFile(fileLocation, size, size == 0 || fileLocation.key != null);
} else {
String file = Utilities.MD5(httpUrl);
img.tempFilePath = new File(AndroidUtilities.getCacheDir(), file + "_temp.jpg");
img.finalFilePath = new File(AndroidUtilities.getCacheDir(), file + ".jpg");
File cacheDir = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE);
img.tempFilePath = new File(cacheDir, file + "_temp.jpg");
img.finalFilePath = cacheFile;
img.httpTask = new HttpTask(img);
httpTasks.add(img.httpTask);
runHttpTasks(false);
......@@ -1002,7 +1041,7 @@ public class ImageLoader {
try {
if (!cache) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
final File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
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();
......
......@@ -591,7 +591,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (downloadObject.object instanceof TLRPC.Audio) {
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object);
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.Video) {
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
} else if (downloadObject.object instanceof TLRPC.Document) {
......@@ -1152,7 +1152,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return true;
}
clenupPlayer(true);
final File cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
final File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
synchronized (playerObjectSync) {
......@@ -1376,7 +1376,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--;
UserConfig.saveConfig(false);
recordingAudioFile = new File(AndroidUtilities.getCacheDir(), FileLoader.getAttachFileName(recordingAudio));
recordingAudioFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), FileLoader.getAttachFileName(recordingAudio));
try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
......@@ -1515,7 +1515,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (file == null) {
file = new File(AndroidUtilities.getCacheDir(), path);
file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), path);
}
final File sourceFile = file;
......@@ -1647,7 +1647,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
}
}
if (cacheFile == null) {
cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
}
try {
currentGifDrawable = new GifDrawable(cacheFile);
......@@ -1726,7 +1726,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--;
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
input = new FileInputStream(parcelFD.getFileDescriptor());
File f = new File(AndroidUtilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext));
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), String.format(Locale.US, "%d.%s", id, ext));
output = new FileOutputStream(f);
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
UserConfig.saveConfig(false);
......
......@@ -21,7 +21,6 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import java.util.AbstractMap;
import java.util.ArrayList;
......@@ -418,7 +417,7 @@ public class MessageObject {
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
if (sizes.size() > 0) {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, 800, 800);
if (sizeFull != null) {
return FileLoader.getAttachFileName(sizeFull);
}
......@@ -444,15 +443,10 @@ public class MessageObject {
int maxWidth;
if (AndroidUtilities.isTablet()) {
int min = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
int leftWidth = min / 100 * 35;
if (leftWidth < AndroidUtilities.dp(320)) {
leftWidth = AndroidUtilities.dp(320);
}
if (messageOwner.to_id.chat_id != 0) {
maxWidth = min - leftWidth - AndroidUtilities.dp(122);
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
} else {
maxWidth = min - leftWidth - AndroidUtilities.dp(80);
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
}
} else {
if (messageOwner.to_id.chat_id != 0) {
......
......@@ -228,8 +228,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
}
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id;
if (smallSize != null) {
......@@ -908,7 +908,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) {
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
}
}
......
......@@ -21,6 +21,7 @@ import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject;
......@@ -2587,7 +2588,7 @@ public class MessagesStorage {
}
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) {
TLRPC.PhotoSize photoSize = PhotoObject.getClosestPhotoSizeWithSize(message.media.photo.sizes, 800, 800);
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.media.photo.sizes, 800, 800);
if (photoSize != null) {
id = message.media.photo.id;
type = MediaController.AUTODOWNLOAD_MASK_PHOTO;
......
......@@ -67,26 +67,4 @@ public class PhotoObject {
}
return closestObject;
}
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) {
if (sizes == null) {
return null;
}
int closestWidth = 9999;
int closestHeight = 9999;
TLRPC.PhotoSize closestObject = null;
for (TLRPC.PhotoSize obj : sizes) {
if (obj == null) {
continue;
}
int diffW = Math.abs(obj.w - width);
int diffH = Math.abs(obj.h - height);
if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || closestWidth > diffW || closestHeight > diffH) {
closestObject = obj;
closestWidth = diffW;
closestHeight = diffH;
}
}
return closestObject;
}
}
......@@ -50,6 +50,8 @@ public class FileLoadOperation {
private String ext;
private RandomAccessFile fileOutputStream;
private RandomAccessFile fiv;
private File storePath = null;
private File tempPath = null;
public static interface FileLoadOperationDelegate {
public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile, File tempFile);
......@@ -113,7 +115,7 @@ public class FileLoadOperation {
location.access_hash = audioLocation.access_hash;
}
totalBytesCount = audioLocation.size;
ext = ".m4a";
ext = ".ogg";
}
public FileLoadOperation(TLRPC.Document documentLocation) {
......@@ -144,6 +146,11 @@ public class FileLoadOperation {
}
}
public void setPaths(File store, File temp) {
storePath = store;
tempPath = temp;
}
public void start() {
if (state != stateIdle) {
return;
......@@ -186,7 +193,7 @@ public class FileLoadOperation {
}
}
cacheFileFinal = new File(FileLoader.getInstance().getCacheDir(), fileNameFinal);
cacheFileFinal = new File(storePath, fileNameFinal);
boolean exist = cacheFileFinal.exists();
if (exist && totalBytesCount != 0 && totalBytesCount != cacheFileFinal.length()) {
exist = false;
......@@ -194,13 +201,13 @@ public class FileLoadOperation {
}
if (!cacheFileFinal.exists()) {
cacheFileTemp = new File(FileLoader.getInstance().getCacheDir(), fileNameTemp);
cacheFileTemp = new File(tempPath, fileNameTemp);
if (cacheFileTemp.exists()) {
downloadedBytes = (int)cacheFileTemp.length();
nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024;
}
if (fileNameIv != null) {
cacheIvTemp = new File(FileLoader.getInstance().getCacheDir(), fileNameIv);
cacheIvTemp = new File(tempPath, fileNameIv);
try {
fiv = new RandomAccessFile(cacheIvTemp, "rws");
long len = cacheIvTemp.length();
......
......@@ -9,6 +9,7 @@
package org.telegram.messenger;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap;
......@@ -23,10 +24,15 @@ public class FileLoader {
public abstract void fileDidLoaded(String location, File finalFile, File tempFile);
public abstract void fileDidFailedLoad(String location, boolean canceled);
public abstract void fileLoadProgressChanged(String location, float progress);
public abstract File getCacheDir();
}
protected File destinationDir = null;
public static final int MEDIA_DIR_IMAGE = 0;
public static final int MEDIA_DIR_AUDIO = 1;
public static final int MEDIA_DIR_VIDEO = 2;
public static final int MEDIA_DIR_DOCUMENT = 3;
public static final int MEDIA_DIR_CACHE = 4;
private HashMap<Integer, File> mediaDirs = null;
private volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue");
private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>();
......@@ -62,6 +68,18 @@ public class FileLoader {
return localInstance;
}
public void setMediaDirs(HashMap<Integer, File> dirs) {
mediaDirs = dirs;
}
public File getDirectory(int type) {
File dir = mediaDirs.get(type);
if (dir == null && type != MEDIA_DIR_CACHE) {
return mediaDirs.get(MEDIA_DIR_CACHE);
}
return dir;
}
public void cancelUploadFile(final String location, final boolean enc) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
......@@ -325,26 +343,26 @@ public class FileLoader {
}
public void loadFile(TLRPC.Video video) {
loadFile(video, null, null, null, 0, false);
loadFile(video, null, null, null, 0, false, video != null && video.key != null);
}
public void loadFile(TLRPC.PhotoSize photo) {
loadFile(null, null, null, photo.location, photo.size, false);
public void loadFile(TLRPC.PhotoSize photo, boolean cacheOnly) {
loadFile(null, null, null, photo.location, photo.size, false, cacheOnly || (photo != null && photo.size == 0 || photo.location.key != null));
}
public void loadFile(TLRPC.Document document) {
loadFile(null, document, null, null, 0, false);
loadFile(null, document, null, null, 0, false, document != null && document.key != null);
}
public void loadFile(TLRPC.Audio audio, boolean force) {
loadFile(null, null, audio, null, 0, false);
loadFile(null, null, audio, null, 0, false, audio != null && audio.key != null);
}
public void loadFile(TLRPC.FileLocation location, int size) {
loadFile(null, null, null, location, size, true);
public void loadFile(TLRPC.FileLocation location, int size, boolean cacheOnly) {
loadFile(null, null, null, location, size, true, cacheOnly || size == 0 || (location != null && location.key != null));
}
private void loadFile(final TLRPC.Video video, final TLRPC.Document document, final TLRPC.Audio audio, final TLRPC.FileLocation location, final int locationSize, final boolean force) {
private void loadFile(final TLRPC.Video video, final TLRPC.Document document, final TLRPC.Audio audio, final TLRPC.FileLocation location, final int locationSize, final boolean force, final boolean cacheOnly) {
fileLoaderQueue.postRunnable(new Runnable() {
@Override
public void run() {
......@@ -385,15 +403,31 @@ public class FileLoader {
return;
}
File tempDir = getDirectory(MEDIA_DIR_CACHE);
File storeDir = tempDir;
if (video != null) {
operation = new FileLoadOperation(video);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_VIDEO);
}
} else if (location != null) {
operation = new FileLoadOperation(location, locationSize);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_IMAGE);
}
} else if (document != null) {
operation = new FileLoadOperation(document);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_DOCUMENT);
}
} else if (audio != null) {
operation = new FileLoadOperation(audio);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_AUDIO);
}
}
operation.setPaths(storeDir, tempDir);
final String arg1 = fileName;
loadOperationPaths.put(fileName, operation);
......@@ -532,8 +566,92 @@ public class FileLoader {
this.delegate = delegate;
}
protected File getCacheDir() {
return delegate == null ? null : delegate.getCacheDir();
public static File getPathToMessage(TLRPC.Message message) {
if (message == null) {
return new File("");
}
if (message.media instanceof TLRPC.TL_messageMediaVideo) {
return getPathToAttach(message.media.video);
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
return getPathToAttach(message.media.document);
} else if (message.media instanceof TLRPC.TL_messageMediaAudio) {
return getPathToAttach(message.media.audio);
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
ArrayList<TLRPC.PhotoSize> sizes = message.media.photo.sizes;
if (sizes.size() > 0) {
TLRPC.PhotoSize sizeFull = getClosestPhotoSizeWithSize(sizes, 800, 800);
if (sizeFull != null) {
return getPathToAttach(sizeFull);
}
}
}
return new File("");
}
public static File getPathToAttach(TLObject attach) {
File dir = null;
if (attach instanceof TLRPC.Video) {
TLRPC.Video video = (TLRPC.Video)attach;
if (video.key != null) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_VIDEO);
}
} else if (attach instanceof TLRPC.Document) {
TLRPC.Document document = (TLRPC.Document)attach;
if (document.key != null) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_DOCUMENT);
}
} else if (attach instanceof TLRPC.PhotoSize) {
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize)attach;
if (photoSize.location == null || photoSize.location.key != null) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_IMAGE);
}
} else if (attach instanceof TLRPC.Audio) {
TLRPC.Audio audio = (TLRPC.Audio)attach;
if (audio.key != null) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_AUDIO);
}
} else if (attach instanceof TLRPC.FileLocation) {
TLRPC.FileLocation fileLocation = (TLRPC.FileLocation)attach;
if (fileLocation.key != null) {
dir = getInstance().getDirectory(MEDIA_DIR_CACHE);
} else {
dir = getInstance().getDirectory(MEDIA_DIR_IMAGE);
}
}
if (dir == null) {
return new File("");
}
return new File(dir, getAttachFileName(attach));
}
public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList<TLRPC.PhotoSize> sizes, int width, int height) {
if (sizes == null) {
return null;
}
int closestWidth = 9999;
int closestHeight = 9999;
TLRPC.PhotoSize closestObject = null;
for (TLRPC.PhotoSize obj : sizes) {
if (obj == null) {
continue;
}
int diffW = Math.abs(obj.w - width);
int diffH = Math.abs(obj.h - height);
if (closestObject == null || closestObject instanceof TLRPC.TL_photoCachedSize || closestWidth > diffW || closestHeight > diffH) {
closestObject = obj;
closestWidth = diffW;
closestHeight = diffH;
}
}
return closestObject;
}
public static String getAttachFileName(TLObject attach) {
......@@ -562,7 +680,7 @@ public class FileLoader {
return photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
} else if (attach instanceof TLRPC.Audio) {
TLRPC.Audio audio = (TLRPC.Audio)attach;
return audio.dc_id + "_" + audio.id + ".m4a";
return audio.dc_id + "_" + audio.id + ".ogg";
} else if (attach instanceof TLRPC.FileLocation) {
TLRPC.FileLocation location = (TLRPC.FileLocation)attach;
return location.volume_id + "_" + location.local_id + ".jpg";
......
......@@ -113,7 +113,7 @@ public class Utilities {
public native static long doPQNative(long _what);
public native static void loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height);
public native static void blurBitmap(Object bitmap);
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding);
public native static int convertVideoFrame(ByteBuffer src, ByteBuffer dest, int destFormat, int width, int height, int padding, int swap);
private native static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, int offset, int length);
public static void aesIgeEncryption(ByteBuffer buffer, byte[] key, byte[] iv, boolean encrypt, boolean changeIv, int offset, int length) {
......
......@@ -217,7 +217,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
public void updateButtonState() {
String fileName = currentMessageObject.getFileName();
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
......
......@@ -133,16 +133,11 @@ public class ChatMessageCell extends ChatBaseCell {
int maxWidth;
if (AndroidUtilities.isTablet()) {
int min = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
int leftWidth = min / 100 * 35;
if (leftWidth < AndroidUtilities.dp(320)) {
leftWidth = AndroidUtilities.dp(320);
}
if (isChat && !messageObject.isOut()) {
maxWidth = min - leftWidth - AndroidUtilities.dp(122);
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
drawName = true;
} else {
maxWidth = min - leftWidth - AndroidUtilities.dp(80);
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
drawName = false;
}
} else {
......
......@@ -1104,7 +1104,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
if (!canSave) {
File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) {
canSave = true;
}
......@@ -1152,7 +1152,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
if (!canSave) {
File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) {
canSave = true;
}
......@@ -2855,7 +2855,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
}
if (locFile == null) {
File f = new File(AndroidUtilities.getCacheDir(), selectedObject.getFileName());
File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
if (f.exists()) {
locFile = f;
}
......@@ -3316,7 +3316,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
f = new File(message.messageOwner.attachPath);
}
if (f == null || f != null && !f.exists()) {
f = new File(AndroidUtilities.getCacheDir(), message.getFileName());
f = FileLoader.getPathToMessage(message.messageOwner);
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), "video/mp4");
......@@ -3338,7 +3338,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
f = new File(message.messageOwner.attachPath);
}
if (f == null || f != null && !f.exists()) {
f = new File(AndroidUtilities.getCacheDir(), fileName);
f = FileLoader.getPathToMessage(message.messageOwner);
}
if (f != null && f.exists()) {
String realMimeType = null;
......
......@@ -25,12 +25,12 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.TLRPC;
import org.telegram.android.MessageObject;
import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.BackupImageView;
......@@ -413,7 +413,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
if (message.imagePreview != null) {
imageView.setImageBitmap(message.imagePreview);
} else {
TLRPC.PhotoSize photoSize = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80, 80);
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80, 80);
imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
}
} else {
......
......@@ -61,7 +61,6 @@ import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBar;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu;
......@@ -336,7 +335,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
continue;
}
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(photo.sizes, 640, 640);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640, 640);
if (sizeFull != null) {
if (currentFileLocation != null) {
for (TLRPC.PhotoSize size : photo.sizes) {
......@@ -561,8 +560,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
@Override
public boolean canOpenMenu() {
if (currentFileName != null) {
File f = new File(AndroidUtilities.getCacheDir(), currentFileName);
if (currentMessageObject != null) {
File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (f.exists()) {
return true;
}
} else if (currentFileLocation != null) {
File f = FileLoader.getPathToAttach(currentFileLocation);
if (f.exists()) {
return true;
}
......@@ -601,14 +605,15 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return;
}
try {
String fileName = getFileName(currentIndex, null);
if (fileName == null) {
int size[] = new int[1];
TLRPC.FileLocation fileLocation = getFileLocation(currentIndex, size);
if (fileLocation == null) {
return;
}
File f = new File(AndroidUtilities.getCacheDir(), fileName);
File f = FileLoader.getPathToAttach(fileLocation);
if (f.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND);
if (fileName.endsWith("mp4")) {
if (f.toString().endsWith("mp4")) {
intent.setType("video/mp4");
} else {
intent.setType("image/jpeg");
......@@ -940,7 +945,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
return message.messageOwner.action.newUserPhoto.photo_big;
} else {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, 800, 800);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, 800, 800);
if (sizeFull != null) {
size[0] = sizeFull.size;
if (size[0] == 0) {
......@@ -952,7 +957,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800);
if (sizeFull != null) {
size[0] = sizeFull.size;
if (size[0] == 0) {
......@@ -1003,7 +1008,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
location.secret = sizeFull.secret;
return location;
} else {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, 800, 800);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.action.photo.sizes, 800, 800);
if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id;
......@@ -1014,7 +1019,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800);
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 800, 800);
if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id;
......@@ -1067,7 +1072,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
load = true;
}
} else {
File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName);
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) {
currentOverlay.actionButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else {
......@@ -1326,7 +1331,12 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
if (currentFileName != null) {
File f = new File(AndroidUtilities.getCacheDir(), currentFileName);
File f = null;
if (currentMessageObject != null) {
f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
} else if (currentFileLocation != null) {
f = FileLoader.getPathToAttach(currentFileLocation);
}
if (f.exists()) {
progressBar.setVisibility(View.GONE);
} else {
......@@ -2285,7 +2295,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
loadFile = true;
}
} else {
File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName);
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cacheFile), "video/mp4");
......
......@@ -449,9 +449,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC
boolean photoSet = false;
if (currentPhotoObject != null) {
boolean photoExist = true;
String fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner);
if (messageObject.type == 1) {
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
if (!cacheFile.exists()) {
photoExist = false;
}
......
......@@ -40,6 +40,7 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.MediaController;
import org.telegram.messenger.BuildVars;
import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.SerializedData;
import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject;
......@@ -53,7 +54,6 @@ import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig;
import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.AvatarUpdater;
......@@ -142,8 +142,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
}
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id;
if (smallSize != null) {
......
......@@ -42,7 +42,6 @@ import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment;
......@@ -120,9 +119,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
width = height;
height = temp;
}
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
File f = new File(AndroidUtilities.getCacheDir(), fileName);
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
try {
done = Utilities.copyFile(f, toFile);
......@@ -274,9 +273,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
width = height;
height = temp;
}
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, width, height);
String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
File f = new File(AndroidUtilities.getCacheDir(), fileName);
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
if (!f.exists()) {
progressBar.setProgress(0);
loadingFile = fileName;
......@@ -285,7 +284,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
progressBar.setVisibility(View.VISIBLE);
loadingSize = size;
selectedColor = 0;
FileLoader.getInstance().loadFile(size);
FileLoader.getInstance().loadFile(size, true);
backgroundImage.setBackgroundColor(0);
} else {
if (loadingFile != null) {
......@@ -533,7 +532,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
BackupImageView image = (BackupImageView)view.findViewById(R.id.image);
View selection = view.findViewById(R.id.selection);
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1);
TLRPC.PhotoSize size = PhotoObject.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100), AndroidUtilities.dp(100));
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes, AndroidUtilities.dp(100), AndroidUtilities.dp(100));
if (size != null && size.location != null) {
image.setImage(size.location, "100_100", 0);
}
......
......@@ -128,7 +128,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
}
} else {
UserConfig.saveConfig(false);
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
......
......@@ -287,7 +287,7 @@ public class PopupAudioView extends BaseCell implements SeekBar.SeekBarDelegate,
public void updateButtonState() {
String fileName = currentMessageObject.getFileName();
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment