diff options
Diffstat (limited to '')
3 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/de/pixart/messenger/Config.java b/src/main/java/de/pixart/messenger/Config.java index 83bea23b1..42fd879a5 100644 --- a/src/main/java/de/pixart/messenger/Config.java +++ b/src/main/java/de/pixart/messenger/Config.java @@ -68,6 +68,8 @@ public final class Config { public static final int CONNECT_DISCO_TIMEOUT = 30; public static final int MINI_GRACE_PERIOD = 750; + public static final int FILE_SIZE = 1048576; // 1 MiB + public static final int AVATAR_SIZE = 480; public static final Bitmap.CompressFormat AVATAR_FORMAT = Bitmap.CompressFormat.JPEG; diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index f942ba8c5..43f362993 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -153,7 +153,7 @@ public class FileBackend { } } - private static long getFileSize(Context context, Uri uri) { + public static long getFileSize(Context context, Uri uri) { try { final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { @@ -273,7 +273,7 @@ public class FileBackend { options.inJustDecodeBounds = true; try { BitmapFactory.decodeStream(mXmppConnectionService.getContentResolver().openInputStream(uri), null, options); - if (options == null || options.outMimeType == null || options.outHeight <= 0 || options.outWidth <= 0) { + if (options.outMimeType == null || options.outHeight <= 0 || options.outWidth <= 0) { return false; } return (options.outWidth <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outHeight <= mXmppConnectionService.getCompressImageResolutionPreference() && options.outMimeType.contains(Config.IMAGE_FORMAT.name().toLowerCase())); diff --git a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java index 207267d0b..3f15fb883 100644 --- a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java +++ b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java @@ -8,6 +8,7 @@ import android.util.Log; import net.ypresto.androidtranscoder.MediaTranscoder; import net.ypresto.androidtranscoder.format.MediaFormatStrategyPresets; +import java.io.File; import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.text.SimpleDateFormat; @@ -32,6 +33,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod private final Uri uri; private final UiCallback<Message> callback; private final boolean isVideoMessage; + private final long originalFileSize; private int currentProgress = -1; public AttachFileToConversationRunnable(XmppConnectionService xmppConnectionService, Uri uri, Message message, UiCallback<Message> callback) { @@ -40,7 +42,12 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod this.message = message; this.callback = callback; final String mimeType = MimeUtils.guessMimeTypeFromUri(mXmppConnectionService, uri); - this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/") && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2)) && !getFileBackend().useFileAsIs(uri); + final int autoAcceptFileSize = Config.FILE_SIZE; + this.originalFileSize = FileBackend.getFileSize(mXmppConnectionService, uri); + this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/") + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) + && originalFileSize > autoAcceptFileSize + && !getFileBackend().useFileAsIs(uri); } public boolean isVideoMessage() { @@ -111,6 +118,18 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod @Override public void onTranscodeCompleted() { mXmppConnectionService.stopForcingForegroundNotification(); + final File file = mXmppConnectionService.getFileBackend().getFile(message); + long convertedFileSize = mXmppConnectionService.getFileBackend().getFile(message).getSize(); + Log.d(Config.LOGTAG, "originalFileSize = " + originalFileSize + " convertedFileSize = " + convertedFileSize); + if (originalFileSize != 0 && convertedFileSize >= originalFileSize) { + if (file.delete()) { + Log.d(Config.LOGTAG, "original file size was smaller. Deleting and processing as file"); + processAsFile(); + return; + } else { + Log.d(Config.LOGTAG, "unable to delete converted file"); + } + } mXmppConnectionService.getFileBackend().updateFileParams(message); if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) { mXmppConnectionService.getPgpEngine().encrypt(message, callback); |