diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java | 21 |
1 files changed, 20 insertions, 1 deletions
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); |