Skip to content

Commit ab44b87

Browse files
author
DrKLO
committed
Changed small Tablets portrait layout, changes media store path to sdcard/Telegram (need testing)
1 parent 4d5b43f commit ab44b87

40 files changed

+587
-249
lines changed

TMessagesProj/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ android {
8080
defaultConfig {
8181
minSdkVersion 8
8282
targetSdkVersion 19
83-
versionCode 328
83+
versionCode 329
8484
versionName "1.9.0"
8585
}
8686
}

TMessagesProj/jni/video.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int isSemiPlanarYUV(int colorFormat) {
6666
}
6767
}
6868

69-
JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *env, jclass class, jobject src, jobject dest, int destFormat, int width, int height, int padding) {
69+
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) {
7070
if (!src || !dest || !destFormat) {
7171
return 0;
7272
}
@@ -78,16 +78,31 @@ JNIEXPORT int Java_org_telegram_messenger_Utilities_convertVideoFrame(JNIEnv *en
7878
int half_height = (height + 1) / 2;
7979

8080
if (!isSemiPlanarYUV(destFormat)) {
81-
ARGBToI420(srcBuff, width * 4,
82-
destBuff, width,
83-
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
84-
destBuff + width * height + padding, half_width,
85-
width, height);
81+
if (!swap) {
82+
ARGBToI420(srcBuff, width * 4,
83+
destBuff, width,
84+
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
85+
destBuff + width * height + padding, half_width,
86+
width, height);
87+
} else {
88+
ARGBToI420(srcBuff, width * 4,
89+
destBuff, width,
90+
destBuff + width * height + padding, half_width,
91+
destBuff + width * height + half_width * half_height + padding * 5 / 4, half_width,
92+
width, height);
93+
}
8694
} else {
87-
ARGBToNV21(srcBuff, width * 4,
88-
destBuff, width,
89-
destBuff + width * height + padding, half_width * 2,
90-
width, height);
95+
if (!swap) {
96+
ARGBToNV21(srcBuff, width * 4,
97+
destBuff, width,
98+
destBuff + width * height + padding, half_width * 2,
99+
width, height);
100+
} else {
101+
ARGBToNV12(srcBuff, width * 4,
102+
destBuff, width,
103+
destBuff + width * height + padding, half_width * 2,
104+
width, height);
105+
}
91106
}
92107

93108
return 1;
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class AndroidUtilities {
4242
public static float density = 1;
4343
public static Point displaySize = new Point();
4444
private static Boolean isTablet = null;
45+
private static Boolean isSmallTablet = null;
4546

4647
public static int[] arrColors = {0xffee4928, 0xff41a903, 0xffe09602, 0xff0f94ed, 0xff8f3bf7, 0xfffc4380, 0xff00a1c4, 0xffeb7002};
4748
public static int[] arrUsersAvatars = {
@@ -275,6 +276,33 @@ public static boolean isTablet() {
275276
return isTablet;
276277
}
277278

279+
public static boolean isSmallTablet() {
280+
if (isSmallTablet == null) {
281+
float minSide = Math.min(displaySize.x, displaySize.y) / density;
282+
isSmallTablet = minSide <= 700;
283+
}
284+
return isSmallTablet;
285+
}
286+
287+
public static int getMinTabletSide() {
288+
if (!isSmallTablet()) {
289+
int smallSide = Math.min(displaySize.x, displaySize.y);
290+
int leftSide = smallSide * 35 / 100;
291+
if (leftSide < dp(320)) {
292+
leftSide = dp(320);
293+
}
294+
return smallSide - leftSide;
295+
} else {
296+
int smallSide = Math.min(displaySize.x, displaySize.y);
297+
int maxSide = Math.max(displaySize.x, displaySize.y);
298+
int leftSide = maxSide * 35 / 100;
299+
if (leftSide < dp(320)) {
300+
leftSide = dp(320);
301+
}
302+
return Math.min(smallSide, maxSide - leftSide);
303+
}
304+
}
305+
278306
public static int getColorIndex(int id) {
279307
int[] arr;
280308
if (id >= 0) {

TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import android.net.Uri;
1919
import android.os.AsyncTask;
2020
import android.os.Build;
21+
import android.os.Environment;
2122
import android.os.ParcelFileDescriptor;
2223
import android.provider.MediaStore;
2324

2425
import org.telegram.messenger.DispatchQueue;
2526
import org.telegram.messenger.FileLoader;
2627
import org.telegram.messenger.FileLog;
28+
import org.telegram.messenger.R;
2729
import org.telegram.messenger.TLRPC;
2830
import org.telegram.messenger.UserConfig;
2931
import org.telegram.messenger.Utilities;
@@ -576,12 +578,43 @@ public void run() {
576578
});
577579
}
578580
}
581+
});
579582

580-
@Override
581-
public File getCacheDir() {
582-
return AndroidUtilities.getCacheDir();
583+
FileLoader.getInstance().setMediaDirs(createMediaPaths());
584+
}
585+
586+
private HashMap<Integer, File> createMediaPaths() {
587+
HashMap<Integer, File> mediaDirs = new HashMap<Integer, File>();
588+
mediaDirs.put(FileLoader.MEDIA_DIR_CACHE, AndroidUtilities.getCacheDir());
589+
try {
590+
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
591+
File telegramPath = new File(Environment.getExternalStorageDirectory(), LocaleController.getString("AppName", R.string.AppName));
592+
telegramPath.mkdirs();
593+
594+
File imagePath = new File(telegramPath, "Images");
595+
imagePath.mkdir();
596+
new File(imagePath, ".nomedia").createNewFile();
597+
mediaDirs.put(FileLoader.MEDIA_DIR_IMAGE, imagePath);
598+
599+
File videoPath = new File(telegramPath, "Video");
600+
videoPath.mkdir();
601+
new File(videoPath, ".nomedia").createNewFile();
602+
mediaDirs.put(FileLoader.MEDIA_DIR_VIDEO, videoPath);
603+
604+
File audioPath = new File(telegramPath, "Audio");
605+
audioPath.mkdir();
606+
new File(audioPath, ".nomedia").createNewFile();
607+
mediaDirs.put(FileLoader.MEDIA_DIR_AUDIO, audioPath);
608+
609+
File documentPath = new File(telegramPath, "Documents");
610+
documentPath.mkdir();
611+
new File(documentPath, ".nomedia").createNewFile();
612+
mediaDirs.put(FileLoader.MEDIA_DIR_DOCUMENT, documentPath);
583613
}
584-
});
614+
} catch (Exception e) {
615+
FileLog.e("tmessages", e);
616+
}
617+
return mediaDirs;
585618
}
586619

587620
private void performReplace(String oldKey, String newKey) {
@@ -746,7 +779,12 @@ public void loadImage(final TLRPC.FileLocation fileLocation, final String httpUr
746779

747780
if (!added) {
748781
boolean onlyCache = false;
749-
File cacheFile = new File(AndroidUtilities.getCacheDir(), url);
782+
File cacheFile = null;
783+
if (size == 0 || httpUrl != null || fileLocation != null && fileLocation.key != null) {
784+
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), url);
785+
} else {
786+
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_IMAGE), url);
787+
}
750788
if (httpUrl != null) {
751789
if (!httpUrl.startsWith("http")) {
752790
onlyCache = true;
@@ -779,11 +817,12 @@ public void loadImage(final TLRPC.FileLocation fileLocation, final String httpUr
779817
img.addImageView(imageView);
780818
imageLoadingByUrl.put(url, img);
781819
if (httpUrl == null) {
782-
FileLoader.getInstance().loadFile(fileLocation, size);
820+
FileLoader.getInstance().loadFile(fileLocation, size, size == 0 || fileLocation.key != null);
783821
} else {
784822
String file = Utilities.MD5(httpUrl);
785-
img.tempFilePath = new File(AndroidUtilities.getCacheDir(), file + "_temp.jpg");
786-
img.finalFilePath = new File(AndroidUtilities.getCacheDir(), file + ".jpg");
823+
File cacheDir = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE);
824+
img.tempFilePath = new File(cacheDir, file + "_temp.jpg");
825+
img.finalFilePath = cacheFile;
787826
img.httpTask = new HttpTask(img);
788827
httpTasks.add(img.httpTask);
789828
runHttpTasks(false);
@@ -1002,7 +1041,7 @@ public static TLRPC.PhotoSize scaleAndSaveImage(Bitmap bitmap, float maxWidth, f
10021041
try {
10031042
if (!cache) {
10041043
String fileName = location.volume_id + "_" + location.local_id + ".jpg";
1005-
final File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName);
1044+
final File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
10061045
FileOutputStream stream = new FileOutputStream(cacheFile);
10071046
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, stream);
10081047
size.size = (int)stream.getChannel().size();

TMessagesProj/src/main/java/org/telegram/android/MediaController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ protected void processDownloadObjects(int type, ArrayList<DownloadObject> object
591591
if (downloadObject.object instanceof TLRPC.Audio) {
592592
FileLoader.getInstance().loadFile((TLRPC.Audio)downloadObject.object, false);
593593
} else if (downloadObject.object instanceof TLRPC.PhotoSize) {
594-
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object);
594+
FileLoader.getInstance().loadFile((TLRPC.PhotoSize)downloadObject.object, false);
595595
} else if (downloadObject.object instanceof TLRPC.Video) {
596596
FileLoader.getInstance().loadFile((TLRPC.Video)downloadObject.object);
597597
} else if (downloadObject.object instanceof TLRPC.Document) {
@@ -1152,7 +1152,7 @@ public boolean playAudio(MessageObject messageObject) {
11521152
return true;
11531153
}
11541154
clenupPlayer(true);
1155-
final File cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
1155+
final File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
11561156

11571157
if (isOpusFile(cacheFile.getAbsolutePath()) == 1) {
11581158
synchronized (playerObjectSync) {
@@ -1376,7 +1376,7 @@ public void run() {
13761376
UserConfig.lastLocalId--;
13771377
UserConfig.saveConfig(false);
13781378

1379-
recordingAudioFile = new File(AndroidUtilities.getCacheDir(), FileLoader.getAttachFileName(recordingAudio));
1379+
recordingAudioFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), FileLoader.getAttachFileName(recordingAudio));
13801380

13811381
try {
13821382
if (startRecord(recordingAudioFile.getAbsolutePath()) == 0) {
@@ -1515,7 +1515,7 @@ public static void saveFile(String path, String fullPath, Context context, final
15151515
}
15161516
}
15171517
if (file == null) {
1518-
file = new File(AndroidUtilities.getCacheDir(), path);
1518+
file = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), path);
15191519
}
15201520

15211521
final File sourceFile = file;
@@ -1647,7 +1647,7 @@ public GifDrawable getGifDrawable(ChatMediaCell cell, boolean create) {
16471647
}
16481648
}
16491649
if (cacheFile == null) {
1650-
cacheFile = new File(AndroidUtilities.getCacheDir(), messageObject.getFileName());
1650+
cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner);
16511651
}
16521652
try {
16531653
currentGifDrawable = new GifDrawable(cacheFile);
@@ -1726,7 +1726,7 @@ public static String copyDocumentToCache(Uri uri, String ext) {
17261726
UserConfig.lastLocalId--;
17271727
parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r");
17281728
input = new FileInputStream(parcelFD.getFileDescriptor());
1729-
File f = new File(AndroidUtilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext));
1729+
File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), String.format(Locale.US, "%d.%s", id, ext));
17301730
output = new FileOutputStream(f);
17311731
input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel());
17321732
UserConfig.saveConfig(false);

TMessagesProj/src/main/java/org/telegram/android/MessageObject.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.telegram.messenger.TLRPC;
2222
import org.telegram.messenger.R;
2323
import org.telegram.messenger.UserConfig;
24-
import org.telegram.messenger.Utilities;
2524

2625
import java.util.AbstractMap;
2726
import java.util.ArrayList;
@@ -418,7 +417,7 @@ public String getFileName() {
418417
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
419418
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
420419
if (sizes.size() > 0) {
421-
TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(sizes, 800, 800);
420+
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, 800, 800);
422421
if (sizeFull != null) {
423422
return FileLoader.getAttachFileName(sizeFull);
424423
}
@@ -444,15 +443,10 @@ private void generateLayout() {
444443

445444
int maxWidth;
446445
if (AndroidUtilities.isTablet()) {
447-
int min = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
448-
int leftWidth = min / 100 * 35;
449-
if (leftWidth < AndroidUtilities.dp(320)) {
450-
leftWidth = AndroidUtilities.dp(320);
451-
}
452446
if (messageOwner.to_id.chat_id != 0) {
453-
maxWidth = min - leftWidth - AndroidUtilities.dp(122);
447+
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
454448
} else {
455-
maxWidth = min - leftWidth - AndroidUtilities.dp(80);
449+
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
456450
}
457451
} else {
458452
if (messageOwner.to_id.chat_id != 0) {

TMessagesProj/src/main/java/org/telegram/android/MessagesController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ public void run(TLObject response, TLRPC.TL_error error) {
228228
}
229229
TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response;
230230
ArrayList<TLRPC.PhotoSize> sizes = photo.photo.sizes;
231-
TLRPC.PhotoSize smallSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 100, 100);
232-
TLRPC.PhotoSize bigSize = PhotoObject.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
231+
TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 100, 100);
232+
TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(sizes, 1000, 1000);
233233
user.photo = new TLRPC.TL_userProfilePhoto();
234234
user.photo.photo_id = photo.photo.id;
235235
if (smallSize != null) {
@@ -908,7 +908,7 @@ public void run() {
908908

909909
public void uploadAndApplyUserAvatar(TLRPC.PhotoSize bigPhoto) {
910910
if (bigPhoto != null) {
911-
uploadingAvatar = AndroidUtilities.getCacheDir() + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
911+
uploadingAvatar = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + bigPhoto.location.volume_id + "_" + bigPhoto.location.local_id + ".jpg";
912912
FileLoader.getInstance().uploadFile(uploadingAvatar, false, true);
913913
}
914914
}

0 commit comments

Comments
 (0)