diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index e21615dc1..b3bc04019 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 328 + versionCode 329 versionName "1.9.0" } } diff --git a/TMessagesProj/jni/video.c b/TMessagesProj/jni/video.c index 17771111c..90c3410e7 100644 --- a/TMessagesProj/jni/video.c +++ b/TMessagesProj/jni/video.c @@ -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; diff --git a/TMessagesProj/libs/armeabi-v7a/libtmessages.so b/TMessagesProj/libs/armeabi-v7a/libtmessages.so index 96100725e..57e76551e 100755 Binary files a/TMessagesProj/libs/armeabi-v7a/libtmessages.so and b/TMessagesProj/libs/armeabi-v7a/libtmessages.so differ diff --git a/TMessagesProj/libs/armeabi/libtmessages.so b/TMessagesProj/libs/armeabi/libtmessages.so index 74b229f10..3397e351f 100755 Binary files a/TMessagesProj/libs/armeabi/libtmessages.so and b/TMessagesProj/libs/armeabi/libtmessages.so differ diff --git a/TMessagesProj/libs/x86/libtmessages.so b/TMessagesProj/libs/x86/libtmessages.so index 041687e31..4ec139a3b 100755 Binary files a/TMessagesProj/libs/x86/libtmessages.so and b/TMessagesProj/libs/x86/libtmessages.so differ diff --git a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java index 5eacf9f48..cc8a2439c 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java @@ -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) { diff --git a/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java b/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java index 818343f03..c8d4627f1 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/android/ImageLoader.java @@ -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 createMediaPaths() { + HashMap mediaDirs = new HashMap(); + 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(); diff --git a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java index 829b29ee8..b97a7add8 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MediaController.java @@ -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); diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java index 9dff025bc..16bd5fdee 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessageObject.java @@ -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 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) { diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java index 072e92da0..419994308 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesController.java @@ -228,8 +228,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter } TLRPC.TL_photos_photo photo = (TLRPC.TL_photos_photo) response; ArrayList 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); } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index 42120c533..17e2008e7 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -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; diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java index 597a2660a..10e7c3b61 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationsController.java @@ -50,6 +50,7 @@ public class NotificationsController { public ArrayList popupMessages = new ArrayList(); private long openned_dialog_id = 0; private int total_unread_count = 0; + private int personal_count = 0; private boolean notifyCheck = false; private static volatile NotificationsController Instance = null; @@ -73,6 +74,7 @@ public class NotificationsController { public void cleanup() { openned_dialog_id = 0; total_unread_count = 0; + personal_count = 0; pushMessages.clear(); pushMessagesDict.clear(); pushDialogs.clear(); @@ -88,7 +90,7 @@ public class NotificationsController { openned_dialog_id = dialog_id; } - private String getStringForMessage(MessageObject messageObject) { + private String getStringForMessage(MessageObject messageObject, boolean shortMessage) { long dialog_id = messageObject.messageOwner.dialog_id; int chat_id = messageObject.messageOwner.to_id.chat_id; int user_id = messageObject.messageOwner.to_id.user_id; @@ -129,13 +131,17 @@ public class NotificationsController { } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) { msg = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, ContactsController.formatName(user.first_name, user.last_name)); } else if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) { - String date = String.format("%s %s %s", LocaleController.formatterYear.format(((long)messageObject.messageOwner.date) * 1000), LocaleController.getString("OtherAt", R.string.OtherAt), LocaleController.formatterDay.format(((long)messageObject.messageOwner.date) * 1000)); + String date = String.format("%s %s %s", LocaleController.formatterYear.format(((long) messageObject.messageOwner.date) * 1000), LocaleController.getString("OtherAt", R.string.OtherAt), LocaleController.formatterDay.format(((long) messageObject.messageOwner.date) * 1000)); msg = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, UserConfig.getCurrentUser().first_name, date, messageObject.messageOwner.action.title, messageObject.messageOwner.action.address); } } else { if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) { - if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) { - msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, ContactsController.formatName(user.first_name, user.last_name), messageObject.messageOwner.message); + if (!shortMessage) { + if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) { + msg = LocaleController.formatString("NotificationMessageText", R.string.NotificationMessageText, ContactsController.formatName(user.first_name, user.last_name), messageObject.messageOwner.message); + } else { + msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, ContactsController.formatName(user.first_name, user.last_name)); + } } else { msg = LocaleController.formatString("NotificationMessageNoText", R.string.NotificationMessageNoText, ContactsController.formatName(user.first_name, user.last_name)); } @@ -191,7 +197,7 @@ public class NotificationsController { } } else { if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) { - if (messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) { + if (!shortMessage && messageObject.messageOwner.message != null && messageObject.messageOwner.message.length() != 0) { msg = LocaleController.formatString("NotificationMessageGroupText", R.string.NotificationMessageGroupText, ContactsController.formatName(user.first_name, user.last_name), chat.title, messageObject.messageOwner.message); } else { msg = LocaleController.formatString("NotificationMessageGroupNoText", R.string.NotificationMessageGroupNoText, ContactsController.formatName(user.first_name, user.last_name), chat.title); @@ -221,9 +227,17 @@ public class NotificationsController { } private void scheduleNotificationRepeat() { - PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); - AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE); - alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000, pintent); + try { + AlarmManager alarm = (AlarmManager) ApplicationLoader.applicationContext.getSystemService(Context.ALARM_SERVICE); + PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0, new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0); + if (personal_count > 0) { + alarm.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60 * 60 * 1000, pintent); + } else { + alarm.cancel(pintent); + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } } protected void repeatNotificationMaybe() { @@ -376,8 +390,10 @@ public class NotificationsController { .setContentIntent(contentIntent); String lastMessage = null; + String lastMessageFull = null; if (pushMessages.size() == 1) { - String message = lastMessage = getStringForMessage(pushMessages.get(0)); + String message = lastMessageFull = getStringForMessage(pushMessages.get(0), false); + lastMessage = getStringForMessage(pushMessages.get(0), true); if (message == null) { return; } @@ -396,12 +412,13 @@ public class NotificationsController { inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); for (int i = 0; i < count; i++) { - String message = getStringForMessage(pushMessages.get(i)); + String message = getStringForMessage(pushMessages.get(i), false); if (message == null) { continue; } if (i == 0) { - lastMessage = message; + lastMessageFull = message; + lastMessage = getStringForMessage(pushMessages.get(i), true); } if (pushDialogs.size() == 1) { if (replace) { @@ -461,7 +478,7 @@ public class NotificationsController { notificationManager.notify(1, mBuilder.build()); if (preferences.getBoolean("EnablePebbleNotifications", false)) { - sendAlertToPebble(lastMessage); + sendAlertToPebble(lastMessageFull); } scheduleNotificationRepeat(); } catch (Exception e) { @@ -507,6 +524,9 @@ public class NotificationsController { for (Integer id : readMessages) { MessageObject messageObject = pushMessagesDict.get(id); if (messageObject != null) { + if (isPersonalMessage(messageObject)) { + personal_count--; + } pushMessages.remove(messageObject); popupMessages.remove(messageObject); pushMessagesDict.remove(id); @@ -534,6 +554,9 @@ public class NotificationsController { } } if (remove) { + if (isPersonalMessage(messageObject)) { + personal_count--; + } pushMessages.remove(a); popupMessages.remove(messageObject); pushMessagesDict.remove(messageObject.messageOwner.id); @@ -566,6 +589,9 @@ public class NotificationsController { if (dialog_id == openned_dialog_id && ApplicationLoader.isScreenOn) { continue; } + if (isPersonalMessage(messageObject)) { + personal_count++; + } added = true; Boolean value = settingsCache.get(dialog_id); @@ -628,6 +654,9 @@ public class NotificationsController { for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); if (messageObject.getDialogId() == dialog_id) { + if (isPersonalMessage(messageObject)) { + personal_count--; + } pushMessages.remove(a); a--; pushMessagesDict.remove(messageObject.messageOwner.id); @@ -657,6 +686,7 @@ public class NotificationsController { pushMessages.clear(); pushMessagesDict.clear(); total_unread_count = 0; + personal_count = 0; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE); HashMap settingsCache = new HashMap(); @@ -681,6 +711,9 @@ public class NotificationsController { continue; } MessageObject messageObject = new MessageObject(message, null, 0); + if (isPersonalMessage(messageObject)) { + personal_count++; + } long dialog_id = messageObject.getDialogId(); Boolean value = settingsCache.get(dialog_id); if (value == null) { @@ -745,4 +778,9 @@ public class NotificationsController { } return null; } + + private boolean isPersonalMessage(MessageObject messageObject) { + return messageObject.messageOwner.to_id != null && messageObject.messageOwner.to_id.chat_id == 0 + && (messageObject.messageOwner.action == null || messageObject.messageOwner.action instanceof TLRPC.TL_messageActionEmpty); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/PhotoObject.java b/TMessagesProj/src/main/java/org/telegram/android/PhotoObject.java index eb079ef03..e59ce6b72 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/PhotoObject.java +++ b/TMessagesProj/src/main/java/org/telegram/android/PhotoObject.java @@ -67,26 +67,4 @@ public class PhotoObject { } return closestObject; } - - public static TLRPC.PhotoSize getClosestPhotoSizeWithSize(ArrayList 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; - } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java index 33318a4fc..4d13bab91 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java @@ -352,7 +352,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter type = 2; newMsg.message = "-1"; TLRPC.FileLocation location1 = photo.sizes.get(photo.sizes.size() - 1).location; - newMsg.attachPath = AndroidUtilities.getCacheDir() + "/" + location1.volume_id + "_" + location1.local_id + ".jpg"; + newMsg.attachPath = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + location1.volume_id + "_" + location1.local_id + ".jpg"; } else if (video != null) { newMsg = new TLRPC.TL_message(); newMsg.media = new TLRPC.TL_messageMediaVideo(); @@ -787,7 +787,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter private void performSendDelayedMessage(final DelayedMessage message) { if (message.type == 0) { - String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; + String location = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; putToDelayedMessages(location, message); if (message.sendRequest != null) { FileLoader.getInstance().uploadFile(location, false, true); @@ -803,13 +803,13 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter media = ((TLRPC.TL_messages_sendBroadcast)message.sendRequest).media; } if (media.thumb == null) { - String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; + String location = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; putToDelayedMessages(location, message); FileLoader.getInstance().uploadFile(location, false, true); } else { String location = message.videoLocation.path; if (location == null) { - location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4"; + location = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + message.videoLocation.id + ".mp4"; } putToDelayedMessages(location, message); if (message.videoLocation.estimatedSize) { @@ -821,7 +821,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } else { String location = message.videoLocation.path; if (location == null) { - location = AndroidUtilities.getCacheDir() + "/" + message.videoLocation.id + ".mp4"; + location = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + message.videoLocation.id + ".mp4"; } putToDelayedMessages(location, message); if (message.videoLocation.estimatedSize) { @@ -838,7 +838,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter media = ((TLRPC.TL_messages_sendBroadcast)message.sendRequest).media; } if (message.sendRequest != null && media.thumb == null && message.location != null) { - String location = AndroidUtilities.getCacheDir() + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; + String location = FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE) + "/" + message.location.volume_id + "_" + message.location.local_id + ".jpg"; putToDelayedMessages(location, message); FileLoader.getInstance().uploadFile(location, false, true); } else { @@ -871,11 +871,10 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter final ArrayList sentMessages = new ArrayList(); if (response instanceof TLRPC.messages_SentMessage) { - TLRPC.TL_messages_sentMessage res = (TLRPC.TL_messages_sentMessage) response; + TLRPC.messages_SentMessage res = (TLRPC.messages_SentMessage) response; newMsgObj.messageOwner.id = res.id; newMsgObj.messageOwner.date = res.date; MessagesController.getInstance().processNewDifferenceParams(res.seq, res.pts, res.date); - //TODO link check } else if (response instanceof TLRPC.messages_StatedMessage) { TLRPC.messages_StatedMessage res = (TLRPC.messages_StatedMessage) response; sentMessages.add(res.message); @@ -1064,8 +1063,8 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter if (fileName.equals(fileName2)) { break; } - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg"); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg"); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg"); + File cacheFile2 = FileLoader.getPathToAttach(size); cacheFile.renameTo(cacheFile2); ImageLoader.getInstance().replaceImageInCache(fileName, fileName2); size2.location = size.location; @@ -1086,9 +1085,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter String fileName = size2.location.volume_id + "_" + size2.location.local_id; String fileName2 = size.location.volume_id + "_" + size.location.local_id; if (!fileName.equals(fileName2)) { - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg"); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg"); - boolean result = cacheFile.renameTo(cacheFile2); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg"); + File cacheFile2 = FileLoader.getPathToAttach(size); + cacheFile.renameTo(cacheFile2); ImageLoader.getInstance().replaceImageInCache(fileName, fileName2); size2.location = size.location; } @@ -1107,16 +1106,16 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter String fileName = size2.location.volume_id + "_" + size2.location.local_id; String fileName2 = size.location.volume_id + "_" + size.location.local_id; if (!fileName.equals(fileName2)) { - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg"); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg"); - boolean result = cacheFile.renameTo(cacheFile2); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg"); + File cacheFile2 = FileLoader.getPathToAttach(size); + cacheFile.renameTo(cacheFile2); ImageLoader.getInstance().replaceImageInCache(fileName, fileName2); size2.location = size.location; } } - if (newMsg.attachPath != null && newMsg.attachPath.startsWith(AndroidUtilities.getCacheDir().getAbsolutePath())) { + if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) { File cacheFile = new File(newMsg.attachPath); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), FileLoader.getAttachFileName(sentMessage.media.document)); + File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.document); boolean result = cacheFile.renameTo(cacheFile2); if (result) { newMsg.attachPath = null; @@ -1135,11 +1134,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter sentMessage.message = newMsg.message; sentMessage.attachPath = newMsg.attachPath; - String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".m4a"; - String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".m4a"; + String fileName = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg"; + String fileName2 = sentMessage.media.audio.dc_id + "_" + sentMessage.media.audio.id + ".ogg"; if (!fileName.equals(fileName2)) { - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); + File cacheFile2 = FileLoader.getPathToAttach(sentMessage.media.audio); cacheFile.renameTo(cacheFile2); } newMsg.media.audio.dc_id = sentMessage.media.audio.dc_id; @@ -1158,8 +1157,8 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter size.location.secret = file.access_hash; size.location.local_id = file.key_fingerprint; String fileName2 = size.location.volume_id + "_" + size.location.local_id; - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName + ".jpg"); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2 + ".jpg"); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName + ".jpg"); + File cacheFile2 = FileLoader.getPathToAttach(size); boolean result = cacheFile.renameTo(cacheFile2); ImageLoader.getInstance().replaceImageInCache(fileName, fileName2); ArrayList arr = new ArrayList(); @@ -1206,9 +1205,9 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter newMsg.media.document.thumb = document.thumb; newMsg.media.document.dc_id = file.dc_id; - if (document.path != null && document.path.startsWith(AndroidUtilities.getCacheDir().getAbsolutePath())) { + if (document.path != null && document.path.startsWith(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE).getAbsolutePath())) { File cacheFile = new File(document.path); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), FileLoader.getAttachFileName(newMsg.media.document)); + File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.document); cacheFile.renameTo(cacheFile2); } @@ -1232,11 +1231,11 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter newMsg.media.audio.path = audio.path; newMsg.media.audio.mime_type = audio.mime_type; - String fileName = audio.dc_id + "_" + audio.id + ".m4a"; - String fileName2 = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".m4a"; + String fileName = audio.dc_id + "_" + audio.id + ".ogg"; + String fileName2 = newMsg.media.audio.dc_id + "_" + newMsg.media.audio.id + ".ogg"; if (!fileName.equals(fileName2)) { - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); - File cacheFile2 = new File(AndroidUtilities.getCacheDir(), fileName2); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); + File cacheFile2 = FileLoader.getPathToAttach(newMsg.media.audio); cacheFile.renameTo(cacheFile2); } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java index cb2b2165a..583466a0a 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoadOperation.java @@ -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(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java index 2fd5369f9..a210d8f14 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/FileLoader.java @@ -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 mediaDirs = null; private volatile DispatchQueue fileLoaderQueue = new DispatchQueue("fileUploadQueue"); private LinkedList uploadOperationQueue = new LinkedList(); @@ -62,6 +68,18 @@ public class FileLoader { return localInstance; } + public void setMediaDirs(HashMap 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 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 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"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index ee8f2da23..41247b7f4 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -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) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java index f231ecec0..fba3f0ccb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatAudioCell.java @@ -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); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java index 23afcd462..5de930456 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMediaCell.java @@ -49,6 +49,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD private static Drawable placeholderDocInDrawable; private static Drawable placeholderDocOutDrawable; private static Drawable videoIconDrawable; + private static Drawable docMenuInDrawable; + private static Drawable docMenuOutDrawable; private static Drawable[] buttonStatesDrawables = new Drawable[4]; private static Drawable[][] buttonStatesDrawablesDoc = new Drawable[2][2]; private static TextPaint infoPaint; @@ -56,7 +58,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD private static TextPaint namePaint; private static Paint docBackPaint; private static Paint progressPaint; - private static Paint progressBackgroundPaint; private static DecelerateInterpolator decelerateInterpolator; private GifDrawable gifDrawable = null; @@ -116,6 +117,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD buttonStatesDrawablesDoc[0][1] = getResources().getDrawable(R.drawable.docload_g); buttonStatesDrawablesDoc[1][1] = getResources().getDrawable(R.drawable.doccancel_g); videoIconDrawable = getResources().getDrawable(R.drawable.ic_video); + docMenuInDrawable = getResources().getDrawable(R.drawable.doc_actions_b); + docMenuOutDrawable = getResources().getDrawable(R.drawable.doc_actions_g); infoPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); infoPaint.setTextSize(AndroidUtilities.dp(12)); @@ -131,10 +134,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD progressPaint.setStrokeWidth(AndroidUtilities.dp(2)); decelerateInterpolator = new DecelerateInterpolator(); - - progressBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - progressBackgroundPaint.setStyle(Paint.Style.STROKE); - progressBackgroundPaint.setStrokeWidth(AndroidUtilities.dp(2)); } TAG = MediaController.getInstance().generateObserverTag(); @@ -178,9 +177,18 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD buttonPressed = 1; invalidate(); result = true; - } else if (x >= photoImage.getImageX() && x <= photoImage.getImageX() + backgroundWidth && y >= photoImage.getImageY() && y <= photoImage.getImageY() + photoImage.getImageHeight()) { - imagePressed = true; - result = true; + } else { + if (currentMessageObject.type == 9) { + if (x >= photoImage.getImageX() && x <= photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(50) && y >= photoImage.getImageY() && y <= photoImage.getImageY() + photoImage.getImageHeight()) { + imagePressed = true; + result = true; + } + } else { + if (x >= photoImage.getImageX() && x <= photoImage.getImageX() + backgroundWidth && y >= photoImage.getImageY() && y <= photoImage.getImageY() + photoImage.getImageHeight()) { + imagePressed = true; + result = true; + } + } } if (result) { startCheckLongPress(); @@ -336,9 +344,8 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } } else if (currentPhotoObject == null) { return true; - } else if (currentPhotoObject != null && photoNotSet) { - String fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner); - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + } else if (currentMessageObject != null && photoNotSet) { + File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner); if (cacheFile.exists()) { return true; } @@ -367,12 +374,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } 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); - } - maxWidth = min - leftWidth - AndroidUtilities.dp(122 + 86 + 24); + maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122 + 86 + 24); } else { maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122 + 86 + 24); } @@ -438,14 +440,14 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD if (messageObject.type == 9) { photoWidth = AndroidUtilities.dp(86); photoHeight = AndroidUtilities.dp(86); - backgroundWidth = photoWidth + Math.max(nameWidth, infoWidth) + AndroidUtilities.dp(40); + backgroundWidth = photoWidth + Math.max(nameWidth, infoWidth) + AndroidUtilities.dp(68); currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, 800, 800); if (currentPhotoObject != null) { if (currentPhotoObject.image != null) { photoImage.setImageBitmap(currentPhotoObject.image); } else { currentPhotoFilter = String.format(Locale.US, "%d_%d_b", photoWidth, photoHeight); - photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, null, currentPhotoObject.photoOwner.size); + photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, null, 0); } } else { photoImage.setImageBitmap((BitmapDrawable)null); @@ -461,12 +463,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD photoImage.setImage(currentUrl, null, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable); } else { 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); - } - photoWidth = (int)((min - leftWidth) * 0.7f); + photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f); } else { photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f); } @@ -481,6 +478,10 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD currentPhotoObject = PhotoObject.getClosestImageWithSize(messageObject.photoThumbs, 800, 800); if (currentPhotoObject != null) { + boolean noSize = false; + if (currentMessageObject.type == 3 || currentMessageObject.type == 8) { + noSize = true; + } float scale = (float) currentPhotoObject.photoOwner.w / (float) photoWidth; int w = (int) (currentPhotoObject.photoOwner.w / scale); @@ -526,7 +527,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD boolean photoExist = true; String fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner); if (messageObject.type == 1) { - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + File cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner); if (!cacheFile.exists()) { photoExist = false; } else { @@ -535,9 +536,9 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) { if (messageObject.imagePreview != null) { - photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), currentPhotoObject.photoOwner.size); + photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, new BitmapDrawable(messageObject.imagePreview), noSize ? 0 : currentPhotoObject.photoOwner.size); } else { - photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable, currentPhotoObject.photoOwner.size); + photoImage.setImage(currentPhotoObject.photoOwner.location, currentPhotoFilter, messageObject.isOut() ? placeholderOutDrawable : placeholderInDrawable, noSize ? 0 : currentPhotoObject.photoOwner.size); } } else { photoNotSet = true; @@ -570,7 +571,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD return; } fileName = FileLoader.getAttachFileName(currentPhotoObject.photoOwner); - cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner); } else if (currentMessageObject.type == 8 || currentMessageObject.type == 3 || currentMessageObject.type == 9) { if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() != 0) { File f = new File(currentMessageObject.messageOwner.attachPath); @@ -581,7 +582,7 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } if (fileName == null) { fileName = currentMessageObject.getFileName(); - cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner); } } if (fileName == null) { @@ -734,16 +735,21 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } - boolean needProgressBackground = false; if (currentMessageObject.type == 9) { + Drawable menuDrawable = null; if (currentMessageObject.isOut()) { infoPaint.setColor(0xff75b166); docBackPaint.setColor(0xffd0f3b3); + menuDrawable = docMenuOutDrawable; } else { infoPaint.setColor(0xffa1adbb); docBackPaint.setColor(0xffebf0f5); + menuDrawable = docMenuInDrawable; } + setDrawableBounds(menuDrawable, photoImage.getImageX() + backgroundWidth - AndroidUtilities.dp(50), AndroidUtilities.dp(10)); + menuDrawable.draw(canvas); + if (!imageDrawn) { canvas.drawRect(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX() + photoImage.getImageWidth(), photoImage.getImageY() + photoImage.getImageHeight(), docBackPaint); @@ -754,20 +760,15 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } if (currentMessageObject.isOut()) { progressPaint.setColor(0xff81bd72); - progressBackgroundPaint.setColor(0xffbae4a2); } else { progressPaint.setColor(0xffadbdcc); - progressBackgroundPaint.setColor(0xffd5dee7); } - needProgressBackground = true; } else { progressPaint.setColor(0xffffffff); - needProgressBackground = false; } } else { progressPaint.setColor(0xffffffff); - needProgressBackground = false; } if (buttonState >= 0 && buttonState < 4) { @@ -782,9 +783,6 @@ public class ChatMediaCell extends ChatBaseCell implements MediaController.FileD } if (progressVisible) { - if (needProgressBackground) { - canvas.drawArc(progressRect, 0, 360, false, progressBackgroundPaint); - } canvas.drawArc(progressRect, -90 + radOffset, Math.max(4, 360 * animatedProgressValue), false, progressPaint); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java index f91dcb4e0..7a9e7bbc8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatMessageCell.java @@ -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 { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 41bee33df..4119d0622 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -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; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index abfc24331..a67f2c0e0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -12,6 +12,7 @@ import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.database.Cursor; import android.net.Uri; import android.os.Build; @@ -25,6 +26,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; @@ -69,6 +71,8 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa private FrameLayout shadowTablet = null; private LinearLayout buttonLayoutTablet = null; private FrameLayout shadowTabletSide = null; + private ImageView backgroundTablet = null; + private boolean tabletFullSize = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -106,6 +110,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa shadowTablet = (FrameLayout)findViewById(R.id.shadow_tablet); buttonLayoutTablet = (LinearLayout)findViewById(R.id.launch_button_layout); shadowTabletSide = (FrameLayout)findViewById(R.id.shadow_tablet_side); + backgroundTablet = (ImageView)findViewById(R.id.launch_background); shadowTablet.setOnTouchListener(new View.OnTouchListener() { @Override @@ -144,8 +149,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa rightActionBarLayout.setLayoutParams(relativeLayoutParams); rightActionBarLayout.init(rightFragmentsStack); 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); button.setText(LocaleController.getString("NewGroup", R.string.NewGroup)); @@ -649,31 +652,65 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa public void needLayout() { if (AndroidUtilities.isTablet()) { - int leftWidth = AndroidUtilities.displaySize.x / 100 * 35; - if (leftWidth < AndroidUtilities.dp(320)) { - leftWidth = AndroidUtilities.dp(320); + if (!AndroidUtilities.isSmallTablet() || getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + tabletFullSize = false; + int leftWidth = AndroidUtilities.displaySize.x / 100 * 35; + if (leftWidth < AndroidUtilities.dp(320)) { + leftWidth = AndroidUtilities.dp(320); + } + + RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams(); + relativeLayoutParams.width = leftWidth; + relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT; + actionBarLayout.setLayoutParams(relativeLayoutParams); + + relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams(); + relativeLayoutParams.leftMargin = leftWidth; + shadowTabletSide.setLayoutParams(relativeLayoutParams); + + relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams(); + relativeLayoutParams.width = AndroidUtilities.displaySize.x - leftWidth; + relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT; + relativeLayoutParams.leftMargin = leftWidth; + rightActionBarLayout.setLayoutParams(relativeLayoutParams); + + relativeLayoutParams = (RelativeLayout.LayoutParams) buttonLayoutTablet.getLayoutParams(); + relativeLayoutParams.width = AndroidUtilities.displaySize.x - leftWidth; + relativeLayoutParams.height = RelativeLayout.LayoutParams.WRAP_CONTENT; + relativeLayoutParams.leftMargin = leftWidth; + 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); + } } - - RelativeLayout.LayoutParams relativeLayoutParams = (RelativeLayout.LayoutParams) actionBarLayout.getLayoutParams(); - relativeLayoutParams.width = leftWidth; - relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT; - actionBarLayout.setLayoutParams(relativeLayoutParams); - - relativeLayoutParams = (RelativeLayout.LayoutParams) shadowTabletSide.getLayoutParams(); - relativeLayoutParams.leftMargin = leftWidth; - shadowTabletSide.setLayoutParams(relativeLayoutParams); - - relativeLayoutParams = (RelativeLayout.LayoutParams) rightActionBarLayout.getLayoutParams(); - relativeLayoutParams.width = AndroidUtilities.displaySize.x - leftWidth; - relativeLayoutParams.height = RelativeLayout.LayoutParams.MATCH_PARENT; - relativeLayoutParams.leftMargin = leftWidth; - rightActionBarLayout.setLayoutParams(relativeLayoutParams); - - relativeLayoutParams = (RelativeLayout.LayoutParams) buttonLayoutTablet.getLayoutParams(); - relativeLayoutParams.width = AndroidUtilities.displaySize.x - leftWidth; - relativeLayoutParams.height = RelativeLayout.LayoutParams.WRAP_CONTENT; - relativeLayoutParams.leftMargin = leftWidth; - buttonLayoutTablet.setLayoutParams(relativeLayoutParams); } } @@ -909,26 +946,39 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa actionBarLayout.presentFragment(fragment, removeLast, forceWithoutAnimation); layersActionBarLayout.removeAllFragments(); layersActionBarLayout.setVisibility(View.GONE); - if (rightFragmentsStack.isEmpty()) { - buttonLayoutTablet.setVisibility(View.VISIBLE); + if (!tabletFullSize) { + shadowTabletSide.setVisibility(View.VISIBLE); + if (rightFragmentsStack.isEmpty()) { + buttonLayoutTablet.setVisibility(View.VISIBLE); + backgroundTablet.setVisibility(View.VISIBLE); + } } return false; } } else if (fragment instanceof ChatActivity) { - if (layout != rightActionBarLayout) { + if (!tabletFullSize && layout != rightActionBarLayout) { rightActionBarLayout.setVisibility(View.VISIBLE); buttonLayoutTablet.setVisibility(View.GONE); + backgroundTablet.setVisibility(View.GONE); rightActionBarLayout.removeAllFragments(); rightActionBarLayout.presentFragment(fragment, removeLast, true); if (removeLast) { layout.closeLastFragment(true); } return false; + } else if (tabletFullSize && layout != actionBarLayout) { + actionBarLayout.presentFragment(fragment, false, forceWithoutAnimation); + if (removeLast) { + layout.closeLastFragment(true); + } + return false; } } else if (layout != layersActionBarLayout) { layersActionBarLayout.setVisibility(View.VISIBLE); if (fragment instanceof LoginActivity) { buttonLayoutTablet.setVisibility(View.GONE); + backgroundTablet.setVisibility(View.VISIBLE); + shadowTabletSide.setVisibility(View.GONE); shadowTablet.setBackgroundColor(0x00000000); } else { shadowTablet.setBackgroundColor(0x7F000000); @@ -952,23 +1002,33 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa actionBarLayout.addFragmentToStack(fragment); layersActionBarLayout.removeAllFragments(); layersActionBarLayout.setVisibility(View.GONE); - if (rightFragmentsStack.isEmpty()) { - buttonLayoutTablet.setVisibility(View.VISIBLE); + if (!tabletFullSize) { + shadowTabletSide.setVisibility(View.VISIBLE); + if (rightFragmentsStack.isEmpty()) { + buttonLayoutTablet.setVisibility(View.VISIBLE); + backgroundTablet.setVisibility(View.VISIBLE); + } } return false; } } else if (fragment instanceof ChatActivity) { - if (layout != rightActionBarLayout) { + if (!tabletFullSize && layout != rightActionBarLayout) { rightActionBarLayout.setVisibility(View.VISIBLE); buttonLayoutTablet.setVisibility(View.GONE); + backgroundTablet.setVisibility(View.GONE); rightActionBarLayout.removeAllFragments(); rightActionBarLayout.addFragmentToStack(fragment); return false; + } else if (tabletFullSize && layout != actionBarLayout) { + actionBarLayout.addFragmentToStack(fragment); + return false; } } else if (layout != layersActionBarLayout) { layersActionBarLayout.setVisibility(View.VISIBLE); if (fragment instanceof LoginActivity) { buttonLayoutTablet.setVisibility(View.GONE); + backgroundTablet.setVisibility(View.VISIBLE); + shadowTabletSide.setVisibility(View.GONE); shadowTablet.setBackgroundColor(0x00000000); } else { shadowTablet.setBackgroundColor(0x7F000000); @@ -990,7 +1050,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa finish(); return false; } else if (layout == rightActionBarLayout) { - buttonLayoutTablet.setVisibility(View.VISIBLE); + if (!tabletFullSize) { + buttonLayoutTablet.setVisibility(View.VISIBLE); + backgroundTablet.setVisibility(View.VISIBLE); + } } } else { if (layout.fragmentsStack.size() <= 1) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index da71c6f4c..613b7e7d2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -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 { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index 686abc463..15c7a5811 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -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"); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java index 4486fc2cd..00432144d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PopupNotificationActivity.java @@ -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; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index f0d96c0d6..7c7b10c8b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -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 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) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 7347e7b4b..56a426b92 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -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); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java index 264f1734d..5074a4dd2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java @@ -53,6 +53,7 @@ import org.telegram.android.video.InputSurface; import org.telegram.android.video.MP4Builder; import org.telegram.android.video.Mp4Movie; import org.telegram.android.video.OutputSurface; +import org.telegram.messenger.FileLoader; import org.telegram.messenger.FileLog; import org.telegram.messenger.R; import org.telegram.messenger.UserConfig; @@ -125,7 +126,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur private Runnable progressRunnable = new Runnable() { @Override public void run() { - while (videoPlayer.isPlaying()) { + while (videoPlayer != null && videoPlayer.isPlaying()) { AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { @@ -208,6 +209,15 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur if (id == -1) { finishFragment(); } else if (id == 1) { + if (videoPlayer != null) { + try { + videoPlayer.stop(); + videoPlayer.release(); + videoPlayer = null; + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } try { //startConvert(); VideoEditWrapper.runTest(VideoEditorActivity.this); @@ -240,6 +250,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur videoTimelineView.setDelegate(new VideoTimelineView.VideoTimelineViewDelegate() { @Override public void onLeftProgressChanged(float progress) { + if (videoPlayer == null) { + return; + } try { if (videoPlayer.isPlaying()) { videoPlayer.pause(); @@ -257,6 +270,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur @Override public void onRifhtProgressChanged(float progress) { + if (videoPlayer == null) { + return; + } try { if (videoPlayer.isPlaying()) { videoPlayer.pause(); @@ -277,6 +293,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur videoSeekBarView.delegate = new VideoSeekBarView.SeekBarDelegate() { @Override public void onSeekBarDrag(float progress) { + if (videoPlayer == null) { + return; + } if (videoPlayer.isPlaying()) { try { float prog = videoTimelineView.getLeftProgress() + (videoTimelineView.getRightProgress() - videoTimelineView.getLeft()) * progress; @@ -328,6 +347,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { + if (videoPlayer == null) { + return; + } try { Surface s = new Surface(surface); videoPlayer.setSurface(s); @@ -346,6 +368,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { + if (videoPlayer == null) { + return true; + } videoPlayer.setDisplay(null); return true; } @@ -359,7 +384,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur playButton.setImageResource(R.drawable.video_play); videoSeekBarView.setProgress(videoTimelineView.getLeftProgress()); try { - videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration)); + if (videoPlayer != null) { + videoPlayer.seekTo((int) (videoTimelineView.getLeftProgress() * videoDuration)); + } } catch (Exception e) { FileLog.e("tmessages", e); } @@ -389,8 +416,16 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur esimatedDuration = (long)Math.max(1000, (videoTimelineView.getRightProgress() - videoTimelineView.getLeftProgress()) * videoDuration); estimatedSize = calculateEstimatedSize((float)esimatedDuration / videoDuration); - startTime = (long)(videoTimelineView.getLeftProgress() * videoDuration) * 1000; - endTime = (long)(videoTimelineView.getRightProgress() * videoDuration) * 1000; + if (videoTimelineView.getLeftProgress() == 0) { + startTime = -1; + } else { + startTime = (long) (videoTimelineView.getLeftProgress() * videoDuration) * 1000; + } + if (videoTimelineView.getRightProgress() == 1) { + endTime = -1; + } else { + endTime = (long) (videoTimelineView.getRightProgress() * videoDuration) * 1000; + } int minutes = (int)(esimatedDuration / 1000 / 60); int seconds = (int) Math.ceil(esimatedDuration / 1000) - minutes * 60; @@ -511,6 +546,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur } private void play() { + if (videoPlayer == null) { + return; + } if (videoPlayer.isPlaying()) { videoPlayer.pause(); playButton.setImageResource(R.drawable.video_play); @@ -659,7 +697,11 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur int muxerTrackIndex = mediaMuxer.addTrack(trackFormat, isAudio); int maxBufferSize = trackFormat.getInteger(MediaFormat.KEY_MAX_INPUT_SIZE); boolean inputDone = false; - extractor.seekTo(start, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + if (start > 0) { + extractor.seekTo(start, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + } else { + extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + } ByteBuffer buffer = ByteBuffer.allocateDirect(maxBufferSize); long startTime = -1; @@ -668,17 +710,23 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur int index = extractor.getSampleTrackIndex(); if (index == trackIndex) { info.size = extractor.readSampleData(buffer, 0); + if (info.size < 0) { info.size = 0; eof = true; } else { info.presentationTimeUs = extractor.getSampleTime(); - if (startTime == -1) { + if (start > 0 && startTime == -1) { startTime = info.presentationTimeUs; } - if (info.presentationTimeUs < end) { + if (end < 0 || info.presentationTimeUs < end) { info.offset = 0; info.flags = extractor.getSampleFlags(); + if (!isAudio) { + buffer.limit(info.offset + info.size); + buffer.position(info.offset); + buffer.putInt(info.size - 4); + } if (mediaMuxer.writeSampleData(muxerTrackIndex, buffer, info)) { didWriteData(file.toString(), 0); } @@ -729,6 +777,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur if (bitrate > 900000) { bitrate = 900000; } + videoFramesSize += sampleSizes; } else { audioFramesSize += sampleSizes; } @@ -801,7 +850,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur try { String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4"; UserConfig.lastLocalId--; - cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); UserConfig.saveConfig(false); MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); @@ -820,6 +869,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur boolean outputDone = false; boolean inputDone = false; boolean decoderDone = false; + int swapUV = 0; int videoTrackIndex = -5; long videoTime = -1; @@ -830,6 +880,9 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur colorFormat = selectColorFormat(codecInfo, MIME_TYPE); if (codecInfo.getName().contains("OMX.qcom.")) { processorType = PROCESSOR_TYPE_QCOM; + if (Build.MANUFACTURER.toLowerCase().equals("nokia")) { + swapUV = 1; + } } FileLog.e("tmessages", "codec = " + codecInfo.getName()); } else { @@ -853,7 +906,11 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur } extractor.selectTrack(videoIndex); - extractor.seekTo(startTime, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + if (startTime > 0) { + extractor.seekTo(startTime, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + } else { + extractor.seekTo(0, MediaExtractor.SEEK_TO_PREVIOUS_SYNC); + } MediaFormat inputFormat = extractor.getTrackFormat(videoIndex); MediaFormat outputFormat = MediaFormat.createVideoFormat(MIME_TYPE, resultWidth, resultHeight); @@ -1001,13 +1058,13 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur } else { doRender = info.size != 0 || info.presentationTimeUs != 0; } - if (info.presentationTimeUs >= endTime) { + if (endTime > 0 && info.presentationTimeUs >= endTime) { inputDone = true; decoderDone = true; doRender = false; info.flags |= MediaCodec.BUFFER_FLAG_END_OF_STREAM; } - if (videoTime == -1) { + if (startTime > 0 && videoTime == -1) { if (info.presentationTimeUs < startTime) { doRender = false; FileLog.e("tmessages", "drop frame startTime = " + startTime + " present time = " + info.presentationTimeUs); @@ -1036,7 +1093,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur ByteBuffer rgbBuf = outputSurface.getFrame(); ByteBuffer yuvBuf = encoderInputBuffers[inputBufIndex]; yuvBuf.clear(); - Utilities.convertVideoFrame(rgbBuf, yuvBuf, colorFormat, resultWidth, resultHeight, padding); + Utilities.convertVideoFrame(rgbBuf, yuvBuf, colorFormat, resultWidth, resultHeight, padding, swapUV); encoder.queueInputBuffer(inputBufIndex, 0, bufferSize, info.presentationTimeUs, 0); } else { FileLog.e("tmessages", "input buffer not available"); @@ -1165,7 +1222,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur String fileName = Integer.MIN_VALUE + "_" + UserConfig.lastLocalId + ".mp4"; UserConfig.lastLocalId--; - File cacheFile = new File(AndroidUtilities.getCacheDir(), fileName); + File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName); UserConfig.saveConfig(false); FileOutputStream fos = new FileOutputStream(cacheFile); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java index 2dc73ff3e..276275e4a 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java @@ -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); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/PopupAudioView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/PopupAudioView.java index d1a9cb2ff..2af5b6c6b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/PopupAudioView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/PopupAudioView.java @@ -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); diff --git a/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_b.png b/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_b.png new file mode 100755 index 000000000..3853c42d0 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_b.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_g.png b/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_g.png new file mode 100755 index 000000000..1b0aec5a9 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/doc_actions_g.png differ diff --git a/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_b.png b/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_b.png new file mode 100755 index 000000000..c9ad08121 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_b.png differ diff --git a/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_g.png b/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_g.png new file mode 100755 index 000000000..c1a124ab9 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-ldpi/doc_actions_g.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_b.png b/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_b.png new file mode 100755 index 000000000..37a56ecc4 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_b.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_g.png b/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_g.png new file mode 100755 index 000000000..3f922d7dc Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/doc_actions_g.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_b.png b/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_b.png new file mode 100755 index 000000000..787e04f9b Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_b.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_g.png b/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_g.png new file mode 100755 index 000000000..8f768c660 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/doc_actions_g.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_b.png b/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_b.png new file mode 100755 index 000000000..d05ae14d9 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_b.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_g.png b/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_g.png new file mode 100755 index 000000000..7b61accc5 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/doc_actions_g.png differ