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 { ...@@ -80,7 +80,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 8 minSdkVersion 8
targetSdkVersion 19 targetSdkVersion 19
versionCode 328 versionCode 329
versionName "1.9.0" versionName "1.9.0"
} }
} }
...@@ -66,7 +66,7 @@ int isSemiPlanarYUV(int colorFormat) { ...@@ -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) { if (!src || !dest || !destFormat) {
return 0; return 0;
} }
...@@ -78,16 +78,31 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *en ...@@ -78,16 +78,31 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *en
int half_height = (height + 1) / 2; int half_height = (height + 1) / 2;
if (!isSemiPlanarYUV(destFormat)) { if (!isSemiPlanarYUV(destFormat)) {
if (!swap) {
ARGBToI420(srcBuff, width * 4, ARGBToI420(srcBuff, width * 4,
destBuff, width, destBuff, width,
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width, destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
destBuff + width * height + padding, half_width, destBuff + width * height + padding, half_width,
width, height); width, height);
} else { } 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 {
if (!swap) {
ARGBToNV21(srcBuff, width * 4, ARGBToNV21(srcBuff, width * 4,
destBuff, width, destBuff, width,
destBuff + width * height + padding, half_width * 2, destBuff + width * height + padding, half_width * 2,
width, height); width, height);
} else {
ARGBToNV12(srcBuff, width * 4,
destBuff, width,
destBuff + width * height + padding, half_width * 2,
width, height);
}
} }
return 1; return 1;
......
...@@ -42,6 +42,7 @@ public class AndroidUtilities { ...@@ -42,6 +42,7 @@ public class AndroidUtilities {
public static float density = 1; public static float density = 1;
public static Point displaySize = new Point(); public static Point displaySize = new Point();
private static Boolean isTablet = 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[] arrColors = {0xffee4928, 0xff41a903, 0xffe09602, 0xff0f94ed, 0xff8f3bf7, 0xfffc4380, 0xff00a1c4, 0xffeb7002};
public static int[] arrUsersAvatars = { public static int[] arrUsersAvatars = {
...@@ -275,6 +276,33 @@ public class AndroidUtilities { ...@@ -275,6 +276,33 @@ public class AndroidUtilities {
return isTablet; 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) { public static int getColorIndex(int id) {
int[] arr; int[] arr;
if (id >= 0) { if (id >= 0) {
......
...@@ -18,12 +18,14 @@ import android.media.ExifInterface; ...@@ -18,12 +18,14 @@ import android.media.ExifInterface;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Environment;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.provider.MediaStore; import android.provider.MediaStore;
import org.telegram.messenger.DispatchQueue; import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
...@@ -576,12 +578,43 @@ public class ImageLoader { ...@@ -576,12 +578,43 @@ public class ImageLoader {
}); });
} }
} }
});
@Override FileLoader.getInstance().setMediaDirs(createMediaPaths());
public File getCacheDir() {
return AndroidUtilities.getCacheDir();
} }
});
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) { private void performReplace(String oldKey, String newKey) {
...@@ -746,7 +779,12 @@ public class ImageLoader { ...@@ -746,7 +779,12 @@ public class ImageLoader {
if (!added) { if (!added) {
boolean onlyCache = false; 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 != null) {
if (!httpUrl.startsWith("http")) { if (!httpUrl.startsWith("http")) {
onlyCache = true; onlyCache = true;
...@@ -779,11 +817,12 @@ public class ImageLoader { ...@@ -779,11 +817,12 @@ public class ImageLoader {
img.addImageView(imageView); img.addImageView(imageView);
imageLoadingByUrl.put(url, img); imageLoadingByUrl.put(url, img);
if (httpUrl == null) { if (httpUrl == null) {
FileLoader.getInstance().loadFile(fileLocation, size); FileLoader.getInstance().loadFile(fileLocation, size, size == 0 || fileLocation.key != null);
} else { } else {
String file = Utilities.MD5(httpUrl); String file = Utilities.MD5(httpUrl);
img.tempFilePath = new File(AndroidUtilities.getCacheDir(), file + "_temp.jpg"); File cacheDir = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE);
img.finalFilePath = new File(AndroidUtilities.getCacheDir(), file + ".jpg"); img.tempFilePath = new File(cacheDir, file + "_temp.jpg");
img.finalFilePath = cacheFile;
img.httpTask = new HttpTask(img); img.httpTask = new HttpTask(img);
httpTasks.add(img.httpTask); httpTasks.add(img.httpTask);
runHttpTasks(false); runHttpTasks(false);
...@@ -1002,7 +1041,7 @@ public class ImageLoader { ...@@ -1002,7 +1041,7 @@ public class ImageLoader {
try { try {
if (!cache) { if (!cache) {
String fileName = location.volume_id + "_" + location.local_id + ".jpg"; 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); FileOutputStream stream = new FileOutputStream(cacheFile);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream); scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
size.size = (int)stream.getChannel().size(); size.size = (int)stream.getChannel().size();
......
...@@ -591,7 +591,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -591,7 +591,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
if (downloadObject.object instanceof TLRPC.Audio) { if (downloadObject.object instanceof TLRPC.Audio) {
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false); FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
} else if (downloadObject.object instanceof TLRPC.PhotoSize) { } 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) { } else if (downloadObject.object instanceof TLRPC.Video) {
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object); FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
} else if (downloadObject.object instanceof TLRPC.Document) { } else if (downloadObject.object instanceof TLRPC.Document) {
...@@ -1152,7 +1152,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1152,7 +1152,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
return true; return true;
} }
clenupPlayer(true); clenupPlayer(true);
final File cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName()); final File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) { if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
synchronized (playerObjectSync) { synchronized (playerObjectSync) {
...@@ -1376,7 +1376,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1376,7 +1376,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--; UserConfig.lastLocalId--;
UserConfig.saveConfig(false); 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 { try {
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) { if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
...@@ -1515,7 +1515,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1515,7 +1515,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
} }
if (file == null) { if (file == null) {
file = new File(AndroidUtilities.getCacheDir(), path); file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), path);
} }
final File sourceFile = file; final File sourceFile = file;
...@@ -1647,7 +1647,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1647,7 +1647,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
} }
} }
if (cacheFile == null) { if (cacheFile == null) {
cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName()); cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
} }
try { try {
currentGifDrawable = new GifDrawable(cacheFile); currentGifDrawable = new GifDrawable(cacheFile);
...@@ -1726,7 +1726,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel ...@@ -1726,7 +1726,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel
UserConfig.lastLocalId--; UserConfig.lastLocalId--;
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r"); parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
input = new FileInputStream(parcelFD.getFileDescriptor()); 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); output = new FileOutputStream(f);
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel()); input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
UserConfig.saveConfig(false); UserConfig.saveConfig(false);
......
...@@ -21,7 +21,6 @@ import org.telegram.messenger.FileLog; ...@@ -21,7 +21,6 @@ import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -418,7 +417,7 @@ public class MessageObject { ...@@ -418,7 +417,7 @@ public class MessageObject {
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) { } else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes; ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
if (sizes.size() > 0) { if (sizes.size() > 0) {
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800); TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, 800, 800);
if (sizeFull != null) { if (sizeFull != null) {
return FileLoader.getAttachFileName(sizeFull); return FileLoader.getAttachFileName(sizeFull);
} }
...@@ -444,15 +443,10 @@ public class MessageObject { ...@@ -444,15 +443,10 @@ public class MessageObject {
int maxWidth; int maxWidth;
if (AndroidUtilities.isTablet()) { 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) { if (messageOwner.to_id.chat_id != 0) {
maxWidth = min - leftWidth - AndroidUtilities.dp(122); maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
} else { } else {
maxWidth = min - leftWidth - AndroidUtilities.dp(80); maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
} }
} else { } else {
if (messageOwner.to_id.chat_id != 0) { if (messageOwner.to_id.chat_id != 0) {
......
...@@ -228,8 +228,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -228,8 +228,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} }
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response; TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes; ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100); TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000); TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
user.photo = new TLRPC.TL_userProfilePhoto(); user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id; user.photo.photo_id = photo.photo.id;
if (smallSize != null) { if (smallSize != null) {
...@@ -908,7 +908,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter ...@@ -908,7 +908,7 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) { public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
if (bigPhoto != null) { 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); FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
} }
} }
......
...@@ -21,6 +21,7 @@ import org.telegram.messenger.BuffersStorage; ...@@ -21,6 +21,7 @@ import org.telegram.messenger.BuffersStorage;
import org.telegram.messenger.ByteBufferDesc; import org.telegram.messenger.ByteBufferDesc;
import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.ConnectionsManager;
import org.telegram.messenger.DispatchQueue; import org.telegram.messenger.DispatchQueue;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.FileLog; import org.telegram.messenger.FileLog;
import org.telegram.messenger.TLClassStore; import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject; import org.telegram.messenger.TLObject;
...@@ -2587,7 +2588,7 @@ public class MessagesStorage { ...@@ -2587,7 +2588,7 @@ public class MessagesStorage {
} }
} else if (message.media instanceof TLRPC.TL_messageMediaPhoto) { } else if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
if ((downloadMask & MediaController.AUTODOWNLOAD_MASK_PHOTO) != 0) { 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) { if (photoSize != null) {
id = message.media.photo.id; id = message.media.photo.id;
type = MediaController.AUTODOWNLOAD_MASK_PHOTO; type = MediaController.AUTODOWNLOAD_MASK_PHOTO;
......
...@@ -67,26 +67,4 @@ public class PhotoObject { ...@@ -67,26 +67,4 @@ public class PhotoObject {
} }
return closestObject; 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 { ...@@ -50,6 +50,8 @@ public class FileLoadOperation {
private String ext; private String ext;
private RandomAccessFile fileOutputStream; private RandomAccessFile fileOutputStream;
private RandomAccessFile fiv; private RandomAccessFile fiv;
private File storePath = null;
private File tempPath = null;
public static interface FileLoadOperationDelegate { public static interface FileLoadOperationDelegate {
public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile, File tempFile); public abstract void didFinishLoadingFile(FileLoadOperation operation, File finalFile, File tempFile);
...@@ -113,7 +115,7 @@ public class FileLoadOperation { ...@@ -113,7 +115,7 @@ public class FileLoadOperation {
location.access_hash = audioLocation.access_hash; location.access_hash = audioLocation.access_hash;
} }
totalBytesCount = audioLocation.size; totalBytesCount = audioLocation.size;
ext = ".m4a"; ext = ".ogg";
} }
public FileLoadOperation(TLRPC.Document documentLocation) { public FileLoadOperation(TLRPC.Document documentLocation) {
...@@ -144,6 +146,11 @@ public class FileLoadOperation { ...@@ -144,6 +146,11 @@ public class FileLoadOperation {
} }
} }
public void setPaths(File store, File temp) {
storePath = store;
tempPath = temp;
}
public void start() { public void start() {
if (state != stateIdle) { if (state != stateIdle) {
return; return;
...@@ -186,7 +193,7 @@ public class FileLoadOperation { ...@@ -186,7 +193,7 @@ public class FileLoadOperation {
} }
} }
cacheFileFinal = new File(FileLoader.getInstance().getCacheDir(), fileNameFinal); cacheFileFinal = new File(storePath, fileNameFinal);
boolean exist = cacheFileFinal.exists(); boolean exist = cacheFileFinal.exists();
if (exist && totalBytesCount != 0 && totalBytesCount != cacheFileFinal.length()) { if (exist && totalBytesCount != 0 && totalBytesCount != cacheFileFinal.length()) {
exist = false; exist = false;
...@@ -194,13 +201,13 @@ public class FileLoadOperation { ...@@ -194,13 +201,13 @@ public class FileLoadOperation {
} }
if (!cacheFileFinal.exists()) { if (!cacheFileFinal.exists()) {
cacheFileTemp = new File(FileLoader.getInstance().getCacheDir(), fileNameTemp); cacheFileTemp = new File(tempPath, fileNameTemp);
if (cacheFileTemp.exists()) { if (cacheFileTemp.exists()) {
downloadedBytes = (int)cacheFileTemp.length(); downloadedBytes = (int)cacheFileTemp.length();
nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024; nextDownloadOffset = downloadedBytes = downloadedBytes / 1024 * 1024;
} }
if (fileNameIv != null) { if (fileNameIv != null) {
cacheIvTemp = new File(FileLoader.getInstance().getCacheDir(), fileNameIv); cacheIvTemp = new File(tempPath, fileNameIv);
try { try {
fiv = new RandomAccessFile(cacheIvTemp, "rws"); fiv = new RandomAccessFile(cacheIvTemp, "rws");
long len = cacheIvTemp.length(); long len = cacheIvTemp.length();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
package org.telegram.messenger; package org.telegram.messenger;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -23,10 +24,15 @@ public class FileLoader { ...@@ -23,10 +24,15 @@ public class FileLoader {
public abstract void fileDidLoaded(String location, File finalFile, File tempFile); public abstract void fileDidLoaded(String location, File finalFile, File tempFile);
public abstract void fileDidFailedLoad(String location, boolean canceled); public abstract void fileDidFailedLoad(String location, boolean canceled);
public abstract void fileLoadProgressChanged(String location, float progress); 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 volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue");
private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>(); private LinkedList<FileUploadOperation> uploadOperationQueue = new LinkedList<FileUploadOperation>();
...@@ -62,6 +68,18 @@ public class FileLoader { ...@@ -62,6 +68,18 @@ public class FileLoader {
return localInstance; 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) { public void cancelUploadFile(final String location, final boolean enc) {
fileLoaderQueue.postRunnable(new Runnable() { fileLoaderQueue.postRunnable(new Runnable() {
@Override @Override
...@@ -325,26 +343,26 @@ public class FileLoader { ...@@ -325,26 +343,26 @@ public class FileLoader {
} }
public void loadFile(TLRPC.Video video) { 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) { public void loadFile(TLRPC.PhotoSize photo, boolean cacheOnly) {
loadFile(null, null, null, photo.location, photo.size, false); 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) { 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) { 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) { public void loadFile(TLRPC.FileLocation location, int size, boolean cacheOnly) {
loadFile(null, null, null, location, size, true); 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() { fileLoaderQueue.postRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -385,15 +403,31 @@ public class FileLoader { ...@@ -385,15 +403,31 @@ public class FileLoader {
return; return;
} }
File tempDir = getDirectory(MEDIA_DIR_CACHE);
File storeDir = tempDir;
if (video != null) { if (video != null) {
operation = new FileLoadOperation(video); operation = new FileLoadOperation(video);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_VIDEO);
}
} else if (location != null) { } else if (location != null) {
operation = new FileLoadOperation(location, locationSize); operation = new FileLoadOperation(location, locationSize);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_IMAGE);
}
} else if (document != null) { } else if (document != null) {
operation = new FileLoadOperation(document); operation = new FileLoadOperation(document);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_DOCUMENT);
}
} else if (audio != null) { } else if (audio != null) {
operation = new FileLoadOperation(audio); operation = new FileLoadOperation(audio);
if (!cacheOnly) {
storeDir = getDirectory(MEDIA_DIR_AUDIO);
}
} }
operation.setPaths(storeDir, tempDir);
final String arg1 = fileName; final String arg1 = fileName;
loadOperationPaths.put(fileName, operation); loadOperationPaths.put(fileName, operation);
...@@ -532,8 +566,92 @@ public class FileLoader { ...@@ -532,8 +566,92 @@ public class FileLoader {
this.delegate = delegate; this.delegate = delegate;
} }
protected File getCacheDir() { public static File getPathToMessage(TLRPC.Message message) {
return delegate == null ? null : delegate.getCacheDir(); 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) { public static String getAttachFileName(TLObject attach) {
...@@ -562,7 +680,7 @@ public class FileLoader { ...@@ -562,7 +680,7 @@ public class FileLoader {
return photo.location.volume_id + "_" + photo.location.local_id + ".jpg"; return photo.location.volume_id + "_" + photo.location.local_id + ".jpg";
} else if (attach instanceof TLRPC.Audio) { } else if (attach instanceof TLRPC.Audio) {
TLRPC.Audio audio = (TLRPC.Audio)attach; 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) { } else if (attach instanceof TLRPC.FileLocation) {
TLRPC.FileLocation location = (TLRPC.FileLocation)attach; TLRPC.FileLocation location = (TLRPC.FileLocation)attach;
return location.volume_id + "_" + location.local_id + ".jpg"; return location.volume_id + "_" + location.local_id + ".jpg";
......
...@@ -113,7 +113,7 @@ public class Utilities { ...@@ -113,7 +113,7 @@ public class Utilities {
public native static long doPQNative(long _what); 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 loadBitmap(String path, int[] bitmap, int scale, int format, int width, int height);
public native static void blurBitmap(Object bitmap); 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); 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) { 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 ...@@ -217,7 +217,7 @@ public class ChatAudioCell extends ChatBaseCell implements SeekBar.SeekBarDelega
public void updateButtonState() { public void updateButtonState() {
String fileName = currentMessageObject.getFileName(); String fileName = currentMessageObject.getFileName();
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) { if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this); MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject); boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject);
......
...@@ -133,16 +133,11 @@ public class ChatMessageCell extends ChatBaseCell { ...@@ -133,16 +133,11 @@ public class ChatMessageCell extends ChatBaseCell {
int maxWidth; int maxWidth;
if (AndroidUtilities.isTablet()) { 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()) { if (isChat && !messageObject.isOut()) {
maxWidth = min - leftWidth - AndroidUtilities.dp(122); maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
drawName = true; drawName = true;
} else { } else {
maxWidth = min - leftWidth - AndroidUtilities.dp(80); maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
drawName = false; drawName = false;
} }
} else { } else {
......
...@@ -1104,7 +1104,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ...@@ -1104,7 +1104,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} }
} }
if (!canSave) { if (!canSave) {
File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName()); File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) { if (f.exists()) {
canSave = true; canSave = true;
} }
...@@ -1152,7 +1152,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ...@@ -1152,7 +1152,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} }
} }
if (!canSave) { if (!canSave) {
File f = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName()); File f = FileLoader.getPathToMessage(messageObject.messageOwner);
if (f.exists()) { if (f.exists()) {
canSave = true; canSave = true;
} }
...@@ -2855,7 +2855,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ...@@ -2855,7 +2855,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} }
} }
if (locFile == null) { if (locFile == null) {
File f = new File(AndroidUtilities.getCacheDir(), selectedObject.getFileName()); File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
if (f.exists()) { if (f.exists()) {
locFile = f; locFile = f;
} }
...@@ -3316,7 +3316,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ...@@ -3316,7 +3316,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
f = new File(message.messageOwner.attachPath); f = new File(message.messageOwner.attachPath);
} }
if (f == null || f != null && !f.exists()) { 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 intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(f), "video/mp4"); intent.setDataAndType(Uri.fromFile(f), "video/mp4");
...@@ -3338,7 +3338,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not ...@@ -3338,7 +3338,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
f = new File(message.messageOwner.attachPath); f = new File(message.messageOwner.attachPath);
} }
if (f == null || f != null && !f.exists()) { if (f == null || f != null && !f.exists()) {
f = new File(AndroidUtilities.getCacheDir(), fileName); f = FileLoader.getPathToMessage(message.messageOwner);
} }
if (f != null && f.exists()) { if (f != null && f.exists()) {
String realMimeType = null; String realMimeType = null;
......
...@@ -12,6 +12,7 @@ import android.app.Activity; ...@@ -12,6 +12,7 @@ import android.app.Activity;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
...@@ -25,6 +26,7 @@ import android.view.ViewGroup; ...@@ -25,6 +26,7 @@ import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.Window; import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -69,6 +71,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -69,6 +71,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
private FrameLayout shadowTablet = null; private FrameLayout shadowTablet = null;
private LinearLayout buttonLayoutTablet = null; private LinearLayout buttonLayoutTablet = null;
private FrameLayout shadowTabletSide = null; private FrameLayout shadowTabletSide = null;
private ImageView backgroundTablet = null;
private boolean tabletFullSize = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -106,6 +110,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -106,6 +110,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
shadowTablet = (FrameLayout)findViewById(R.id.shadow_tablet); shadowTablet = (FrameLayout)findViewById(R.id.shadow_tablet);
buttonLayoutTablet = (LinearLayout)findViewById(R.id.launch_button_layout); buttonLayoutTablet = (LinearLayout)findViewById(R.id.launch_button_layout);
shadowTabletSide = (FrameLayout)findViewById(R.id.shadow_tablet_side); shadowTabletSide = (FrameLayout)findViewById(R.id.shadow_tablet_side);
backgroundTablet = (ImageView)findViewById(R.id.launch_background);
shadowTablet.setOnTouchListener(new View.OnTouchListener() { shadowTablet.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
...@@ -144,8 +149,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -144,8 +149,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
rightActionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout.setLayoutParams(relativeLayoutParams);
rightActionBarLayout.init(rightFragmentsStack); rightActionBarLayout.init(rightFragmentsStack);
rightActionBarLayout.setDelegate(this); rightActionBarLayout.setDelegate(this);
rightActionBarLayout.setVisibility(rightFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
buttonLayoutTablet.setVisibility(rightFragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
TextView button = (TextView)findViewById(R.id.new_group_button); TextView button = (TextView)findViewById(R.id.new_group_button);
button.setText(LocaleController.getString("NewGroup", R.string.NewGroup)); button.setText(LocaleController.getString("NewGroup", R.string.NewGroup));
...@@ -649,6 +652,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -649,6 +652,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
public void needLayout() { public void needLayout() {
if (AndroidUtilities.isTablet()) { if (AndroidUtilities.isTablet()) {
if (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
tabletFullSize = false;
int leftWidth = AndroidUtilities.displaySize.x / 100 * 35; int leftWidth = AndroidUtilities.displaySize.x / 100 * 35;
if (leftWidth < AndroidUtilities.dp(320)) { if (leftWidth < AndroidUtilities.dp(320)) {
leftWidth = AndroidUtilities.dp(320); leftWidth = AndroidUtilities.dp(320);
...@@ -674,6 +679,38 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -674,6 +679,38 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
relativeLayoutParams.height = RelativeLayout.LayoutParams.WRAP_CONTENT; relativeLayoutParams.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
relativeLayoutParams.leftMargin = leftWidth; relativeLayoutParams.leftMargin = leftWidth;
buttonLayoutTablet.setLayoutParams(relativeLayoutParams); buttonLayoutTablet.setLayoutParams(relativeLayoutParams);
if (AndroidUtilities.isSmallTablet() && mainFragmentsStack.size() == 2) {
BaseFragment chatFragment = mainFragmentsStack.get(1);
mainFragmentsStack.remove(1);
actionBarLayout.showLastFragment();
rightFragmentsStack.add(chatFragment);
rightActionBarLayout.showLastFragment();
}
rightActionBarLayout.setVisibility(rightFragmentsStack.isEmpty() ? View.GONE : View.VISIBLE);
buttonLayoutTablet.setVisibility(!mainFragmentsStack.isEmpty() && rightFragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
backgroundTablet.setVisibility(rightFragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
shadowTabletSide.setVisibility(!mainFragmentsStack.isEmpty() ? View.VISIBLE : View.GONE);
} else {
tabletFullSize = true;
RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams();
relativeLayoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT;
actionBarLayout.setLayoutParams(relativeLayoutParams);
shadowTabletSide.setVisibility(View.GONE);
rightActionBarLayout.setVisibility(View.GONE);
backgroundTablet.setVisibility(View.GONE);
buttonLayoutTablet.setVisibility(View.GONE);
if (rightFragmentsStack.size() == 1) {
BaseFragment chatFragment = rightFragmentsStack.get(0);
rightFragmentsStack.remove(0);
actionBarLayout.presentFragment(chatFragment, false, true);
}
}
} }
} }
...@@ -909,26 +946,39 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -909,26 +946,39 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation); actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation);
layersActionBarLayout.removeAllFragments(); layersActionBarLayout.removeAllFragments();
layersActionBarLayout.setVisibility(View.GONE); layersActionBarLayout.setVisibility(View.GONE);
if (!tabletFullSize) {
shadowTabletSide.setVisibility(View.VISIBLE);
if (rightFragmentsStack.isEmpty()) { if (rightFragmentsStack.isEmpty()) {
buttonLayoutTablet.setVisibility(View.VISIBLE); buttonLayoutTablet.setVisibility(View.VISIBLE);
backgroundTablet.setVisibility(View.VISIBLE);
}
} }
return false; return false;
} }
} else if (fragment instanceof ChatActivity) { } else if (fragment instanceof ChatActivity) {
if (layout != rightActionBarLayout) { if (!tabletFullSize && layout != rightActionBarLayout) {
rightActionBarLayout.setVisibility(View.VISIBLE); rightActionBarLayout.setVisibility(View.VISIBLE);
buttonLayoutTablet.setVisibility(View.GONE); buttonLayoutTablet.setVisibility(View.GONE);
backgroundTablet.setVisibility(View.GONE);
rightActionBarLayout.removeAllFragments(); rightActionBarLayout.removeAllFragments();
rightActionBarLayout.presentFragment(fragment, removeLast, true); rightActionBarLayout.presentFragment(fragment, removeLast, true);
if (removeLast) { if (removeLast) {
layout.closeLastFragment(true); layout.closeLastFragment(true);
} }
return false; return false;
} else if (tabletFullSize && layout != actionBarLayout) {
actionBarLayout.presentFragment(fragment, false, forceWithoutAnimation);
if (removeLast) {
layout.closeLastFragment(true);
}
return false;
} }
} else if (layout != layersActionBarLayout) { } else if (layout != layersActionBarLayout) {
layersActionBarLayout.setVisibility(View.VISIBLE); layersActionBarLayout.setVisibility(View.VISIBLE);
if (fragment instanceof LoginActivity) { if (fragment instanceof LoginActivity) {
buttonLayoutTablet.setVisibility(View.GONE); buttonLayoutTablet.setVisibility(View.GONE);
backgroundTablet.setVisibility(View.VISIBLE);
shadowTabletSide.setVisibility(View.GONE);
shadowTablet.setBackgroundColor(0x00000000); shadowTablet.setBackgroundColor(0x00000000);
} else { } else {
shadowTablet.setBackgroundColor(0x7F000000); shadowTablet.setBackgroundColor(0x7F000000);
...@@ -952,23 +1002,33 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -952,23 +1002,33 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
actionBarLayout.addFragmentToStack(fragment); actionBarLayout.addFragmentToStack(fragment);
layersActionBarLayout.removeAllFragments(); layersActionBarLayout.removeAllFragments();
layersActionBarLayout.setVisibility(View.GONE); layersActionBarLayout.setVisibility(View.GONE);
if (!tabletFullSize) {
shadowTabletSide.setVisibility(View.VISIBLE);
if (rightFragmentsStack.isEmpty()) { if (rightFragmentsStack.isEmpty()) {
buttonLayoutTablet.setVisibility(View.VISIBLE); buttonLayoutTablet.setVisibility(View.VISIBLE);
backgroundTablet.setVisibility(View.VISIBLE);
}
} }
return false; return false;
} }
} else if (fragment instanceof ChatActivity) { } else if (fragment instanceof ChatActivity) {
if (layout != rightActionBarLayout) { if (!tabletFullSize && layout != rightActionBarLayout) {
rightActionBarLayout.setVisibility(View.VISIBLE); rightActionBarLayout.setVisibility(View.VISIBLE);
buttonLayoutTablet.setVisibility(View.GONE); buttonLayoutTablet.setVisibility(View.GONE);
backgroundTablet.setVisibility(View.GONE);
rightActionBarLayout.removeAllFragments(); rightActionBarLayout.removeAllFragments();
rightActionBarLayout.addFragmentToStack(fragment); rightActionBarLayout.addFragmentToStack(fragment);
return false; return false;
} else if (tabletFullSize && layout != actionBarLayout) {
actionBarLayout.addFragmentToStack(fragment);
return false;
} }
} else if (layout != layersActionBarLayout) { } else if (layout != layersActionBarLayout) {
layersActionBarLayout.setVisibility(View.VISIBLE); layersActionBarLayout.setVisibility(View.VISIBLE);
if (fragment instanceof LoginActivity) { if (fragment instanceof LoginActivity) {
buttonLayoutTablet.setVisibility(View.GONE); buttonLayoutTablet.setVisibility(View.GONE);
backgroundTablet.setVisibility(View.VISIBLE);
shadowTabletSide.setVisibility(View.GONE);
shadowTablet.setBackgroundColor(0x00000000); shadowTablet.setBackgroundColor(0x00000000);
} else { } else {
shadowTablet.setBackgroundColor(0x7F000000); shadowTablet.setBackgroundColor(0x7F000000);
...@@ -990,7 +1050,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa ...@@ -990,7 +1050,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
finish(); finish();
return false; return false;
} else if (layout == rightActionBarLayout) { } else if (layout == rightActionBarLayout) {
if (!tabletFullSize) {
buttonLayoutTablet.setVisibility(View.VISIBLE); buttonLayoutTablet.setVisibility(View.VISIBLE);
backgroundTablet.setVisibility(View.VISIBLE);
}
} }
} else { } else {
if (layout.fragmentsStack.size() <= 1) { if (layout.fragmentsStack.size() <= 1) {
......
...@@ -25,12 +25,12 @@ import android.widget.TextView; ...@@ -25,12 +25,12 @@ import android.widget.TextView;
import org.telegram.android.AndroidUtilities; import org.telegram.android.AndroidUtilities;
import org.telegram.android.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.TLRPC; import org.telegram.messenger.TLRPC;
import org.telegram.android.MessageObject; import org.telegram.android.MessageObject;
import org.telegram.android.MessagesController; import org.telegram.android.MessagesController;
import org.telegram.android.NotificationCenter; import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter; import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.BackupImageView;
...@@ -413,7 +413,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No ...@@ -413,7 +413,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
if (message.imagePreview != null) { if (message.imagePreview != null) {
imageView.setImageBitmap(message.imagePreview); imageView.setImageBitmap(message.imagePreview);
} else { } 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); imageView.setImage(photoSize.location, null, R.drawable.photo_placeholder_in);
} }
} else { } else {
......
...@@ -61,7 +61,6 @@ import org.telegram.messenger.TLRPC; ...@@ -61,7 +61,6 @@ import org.telegram.messenger.TLRPC;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.android.MessageObject; import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Views.ActionBar.ActionBar; import org.telegram.ui.Views.ActionBar.ActionBar;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenu;
...@@ -336,7 +335,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -336,7 +335,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) { if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) {
continue; continue;
} }
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(photo.sizes, 640, 640); TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 640, 640);
if (sizeFull != null) { if (sizeFull != null) {
if (currentFileLocation != null) { if (currentFileLocation != null) {
for (TLRPC.PhotoSize size : photo.sizes) { for (TLRPC.PhotoSize size : photo.sizes) {
...@@ -561,8 +560,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -561,8 +560,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
@Override @Override
public boolean canOpenMenu() { public boolean canOpenMenu() {
if (currentFileName != null) { if (currentMessageObject != null) {
File f = new File(AndroidUtilities.getCacheDir(), currentFileName); File f = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (f.exists()) {
return true;
}
} else if (currentFileLocation != null) {
File f = FileLoader.getPathToAttach(currentFileLocation);
if (f.exists()) { if (f.exists()) {
return true; return true;
} }
...@@ -601,14 +605,15 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -601,14 +605,15 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return; return;
} }
try { try {
String fileName = getFileName(currentIndex, null); int size[] = new int[1];
if (fileName == null) { TLRPC.FileLocation fileLocation = getFileLocation(currentIndex, size);
if (fileLocation == null) {
return; return;
} }
File f = new File(AndroidUtilities.getCacheDir(), fileName); File f = FileLoader.getPathToAttach(fileLocation);
if (f.exists()) { if (f.exists()) {
Intent intent = new Intent(Intent.ACTION_SEND); Intent intent = new Intent(Intent.ACTION_SEND);
if (fileName.endsWith("mp4")) { if (f.toString().endsWith("mp4")) {
intent.setType("video/mp4"); intent.setType("video/mp4");
} else { } else {
intent.setType("image/jpeg"); intent.setType("image/jpeg");
...@@ -940,7 +945,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -940,7 +945,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) { if (message.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
return message.messageOwner.action.newUserPhoto.photo_big; return message.messageOwner.action.newUserPhoto.photo_big;
} else { } 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) { if (sizeFull != null) {
size[0] = sizeFull.size; size[0] = sizeFull.size;
if (size[0] == 0) { if (size[0] == 0) {
...@@ -952,7 +957,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -952,7 +957,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} }
} }
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto && message.messageOwner.media.photo != null) { } 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) { if (sizeFull != null) {
size[0] = sizeFull.size; size[0] = sizeFull.size;
if (size[0] == 0) { if (size[0] == 0) {
...@@ -1003,7 +1008,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -1003,7 +1008,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
location.secret = sizeFull.secret; location.secret = sizeFull.secret;
return location; return location;
} else { } 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) { if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation(); TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id; location.local_id = sizeFull.location.local_id;
...@@ -1014,7 +1019,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -1014,7 +1019,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} }
} }
} else if (message.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) { } 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) { if (sizeFull != null) {
TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation(); TLRPC.TL_inputFileLocation location = new TLRPC.TL_inputFileLocation();
location.local_id = sizeFull.location.local_id; location.local_id = sizeFull.location.local_id;
...@@ -1067,7 +1072,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -1067,7 +1072,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
load = true; load = true;
} }
} else { } else {
File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName); File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) { if (cacheFile.exists()) {
currentOverlay.actionButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo)); currentOverlay.actionButton.setText(LocaleController.getString("ViewVideo", R.string.ViewVideo));
} else { } else {
...@@ -1326,7 +1331,12 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -1326,7 +1331,12 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} }
if (currentFileName != null) { 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()) { if (f.exists()) {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} else { } else {
...@@ -2285,7 +2295,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat ...@@ -2285,7 +2295,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
loadFile = true; loadFile = true;
} }
} else { } else {
File cacheFile = new File(AndroidUtilities.getCacheDir(), currentFileName); File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) { if (cacheFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(cacheFile), "video/mp4"); intent.setDataAndType(Uri.fromFile(cacheFile), "video/mp4");
......
...@@ -449,9 +449,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC ...@@ -449,9 +449,8 @@ public class PopupNotificationActivity extends Activity implements NotificationC
boolean photoSet = false; boolean photoSet = false;
if (currentPhotoObject != null) { if (currentPhotoObject != null) {
boolean photoExist = true; boolean photoExist = true;
String fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner);
if (messageObject.type == 1) { if (messageObject.type == 1) {
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
if (!cacheFile.exists()) { if (!cacheFile.exists()) {
photoExist = false; photoExist = false;
} }
......
...@@ -40,6 +40,7 @@ import org.telegram.PhoneFormat.PhoneFormat; ...@@ -40,6 +40,7 @@ import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.android.MediaController; import org.telegram.android.MediaController;
import org.telegram.messenger.BuildVars; import org.telegram.messenger.BuildVars;
import org.telegram.android.LocaleController; import org.telegram.android.LocaleController;
import org.telegram.messenger.FileLoader;
import org.telegram.messenger.SerializedData; import org.telegram.messenger.SerializedData;
import org.telegram.messenger.TLClassStore; import org.telegram.messenger.TLClassStore;
import org.telegram.messenger.TLObject; import org.telegram.messenger.TLObject;
...@@ -53,7 +54,6 @@ import org.telegram.messenger.R; ...@@ -53,7 +54,6 @@ import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest; import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserConfig;
import org.telegram.android.MessageObject; import org.telegram.android.MessageObject;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter; import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarLayer;
import org.telegram.ui.Views.AvatarUpdater; import org.telegram.ui.Views.AvatarUpdater;
...@@ -142,8 +142,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter ...@@ -142,8 +142,8 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} }
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response; TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo)response;
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes; ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100); TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000); TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
user.photo = new TLRPC.TL_userProfilePhoto(); user.photo = new TLRPC.TL_userProfilePhoto();
user.photo.photo_id = photo.photo.id; user.photo.photo_id = photo.photo.id;
if (smallSize != null) { if (smallSize != null) {
......
...@@ -42,7 +42,6 @@ import org.telegram.android.NotificationCenter; ...@@ -42,7 +42,6 @@ import org.telegram.android.NotificationCenter;
import org.telegram.messenger.R; import org.telegram.messenger.R;
import org.telegram.messenger.RPCRequest; import org.telegram.messenger.RPCRequest;
import org.telegram.messenger.Utilities; import org.telegram.messenger.Utilities;
import org.telegram.android.PhotoObject;
import org.telegram.ui.Adapters.BaseFragmentAdapter; import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.BackupImageView;
import org.telegram.ui.Views.ActionBar.BaseFragment; import org.telegram.ui.Views.ActionBar.BaseFragment;
...@@ -120,9 +119,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -120,9 +119,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
width = height; width = height;
height = temp; 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"; 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"); File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
try { try {
done = Utilities.copyFile(f, toFile); done = Utilities.copyFile(f, toFile);
...@@ -274,9 +273,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -274,9 +273,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
width = height; width = height;
height = temp; 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"; 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()) { if (!f.exists()) {
progressBar.setProgress(0); progressBar.setProgress(0);
loadingFile = fileName; loadingFile = fileName;
...@@ -285,7 +284,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -285,7 +284,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
loadingSize = size; loadingSize = size;
selectedColor = 0; selectedColor = 0;
FileLoader.getInstance().loadFile(size); FileLoader.getInstance().loadFile(size, true);
backgroundImage.setBackgroundColor(0); backgroundImage.setBackgroundColor(0);
} else { } else {
if (loadingFile != null) { if (loadingFile != null) {
...@@ -533,7 +532,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica ...@@ -533,7 +532,7 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica
BackupImageView image = (BackupImageView)view.findViewById(R.id.image); BackupImageView image = (BackupImageView)view.findViewById(R.id.image);
View selection = view.findViewById(R.id.selection); View selection = view.findViewById(R.id.selection);
TLRPC.WallPaper wallPaper = wallPapers.get(i - 1); 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) { if (size != null && size.location != null) {
image.setImage(size.location, "100_100", 0); image.setImage(size.location, "100_100", 0);
} }
......
...@@ -128,7 +128,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg ...@@ -128,7 +128,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
} }
} else { } else {
UserConfig.saveConfig(false); 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.FileDidUpload);
NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload); NotificationCenter.getInstance().addObserver(AvatarUpdater.this, NotificationCenter.FileDidFailUpload);
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true); FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
......
...@@ -287,7 +287,7 @@ public class PopupAudioView extends BaseCell implements SeekBar.SeekBarDelegate, ...@@ -287,7 +287,7 @@ public class PopupAudioView extends BaseCell implements SeekBar.SeekBarDelegate,
public void updateButtonState() { public void updateButtonState() {
String fileName = currentMessageObject.getFileName(); String fileName = currentMessageObject.getFileName();
File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner);
if (cacheFile.exists()) { if (cacheFile.exists()) {
MediaController.getInstance().removeLoadingFileObserver(this); MediaController.getInstance().removeLoadingFileObserver(this);
boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject); 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