mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #952 from deltachat/send-large-videos
allow sending large files and videos
This commit is contained in:
@@ -251,8 +251,12 @@ public class AttachmentManager {
|
||||
if (slide == null) {
|
||||
attachmentViewStub.get().setVisibility(View.GONE);
|
||||
result.set(false);
|
||||
} else if (!areConstraintsSatisfied(context, slide, constraints)) {
|
||||
} else if (slide.getFileSize()>1*1024*1024*1024) {
|
||||
// this is only a rough check, videos and images may be recoded
|
||||
// and the core checks more carefully later.
|
||||
attachmentViewStub.get().setVisibility(View.GONE);
|
||||
Log.w(TAG, "File too large.");
|
||||
Toast.makeText(slide.context, "File too large.", Toast.LENGTH_LONG).show();
|
||||
result.set(false);
|
||||
} else {
|
||||
setSlide(slide);
|
||||
@@ -507,15 +511,6 @@ public class AttachmentManager {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean areConstraintsSatisfied(final @NonNull Context context,
|
||||
final @Nullable Slide slide,
|
||||
final @NonNull MediaConstraints constraints)
|
||||
{
|
||||
return slide == null ||
|
||||
constraints.isSatisfied(context, slide.asAttachment()) ||
|
||||
constraints.canResize(slide.asAttachment());
|
||||
}
|
||||
|
||||
private void previewImageDraft(final @NonNull Slide slide) {
|
||||
if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getUri() != null) {
|
||||
Intent intent = new Intent(context, MediaPreviewActivity.class);
|
||||
|
||||
@@ -1,23 +1,12 @@
|
||||
package org.thoughtcrime.securesms.mms;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public abstract class MediaConstraints {
|
||||
private static final String TAG = MediaConstraints.class.getSimpleName();
|
||||
|
||||
public static MediaConstraints getPushMediaConstraints() {
|
||||
return new PushMediaConstraints();
|
||||
}
|
||||
@@ -26,35 +15,6 @@ public abstract class MediaConstraints {
|
||||
public abstract int getImageMaxHeight(Context context);
|
||||
public abstract int getImageMaxSize(Context context);
|
||||
|
||||
public abstract int getGifMaxSize(Context context);
|
||||
public abstract int getVideoMaxSize(Context context);
|
||||
public abstract int getAudioMaxSize(Context context);
|
||||
public abstract int getDocumentMaxSize(Context context);
|
||||
|
||||
public boolean isSatisfied(@NonNull Context context, @NonNull Attachment attachment) {
|
||||
try {
|
||||
return (MediaUtil.isGif(attachment) && attachment.getSize() <= getGifMaxSize(context) && isWithinBounds(context, attachment.getDataUri())) ||
|
||||
(MediaUtil.isImage(attachment) && attachment.getSize() <= getImageMaxSize(context) && isWithinBounds(context, attachment.getDataUri())) ||
|
||||
(MediaUtil.isAudio(attachment) && attachment.getSize() <= getAudioMaxSize(context)) ||
|
||||
(MediaUtil.isVideo(attachment) && attachment.getSize() <= getVideoMaxSize(context)) ||
|
||||
(MediaUtil.isFile(attachment) && attachment.getSize() <= getDocumentMaxSize(context));
|
||||
} catch (IOException ioe) {
|
||||
Log.w(TAG, "Failed to determine if media's constraints are satisfied.", ioe);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWithinBounds(Context context, Uri uri) throws IOException {
|
||||
try {
|
||||
InputStream is = PartAuthority.getAttachmentStream(context, uri);
|
||||
Pair<Integer, Integer> dimensions = BitmapUtil.getDimensions(is);
|
||||
return dimensions.first > 0 && dimensions.first <= getImageMaxWidth(context) &&
|
||||
dimensions.second > 0 && dimensions.second <= getImageMaxHeight(context);
|
||||
} catch (BitmapDecodingException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canResize(@Nullable Attachment attachment) {
|
||||
return attachment != null && MediaUtil.isImage(attachment) && !MediaUtil.isGif(attachment);
|
||||
}
|
||||
|
||||
@@ -25,24 +25,4 @@ public class PushMediaConstraints extends MediaConstraints {
|
||||
public int getImageMaxSize(Context context) {
|
||||
return 6 * MB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGifMaxSize(Context context) {
|
||||
return 25 * MB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVideoMaxSize(Context context) {
|
||||
return 100 * MB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioMaxSize(Context context) {
|
||||
return 100 * MB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDocumentMaxSize(Context context) {
|
||||
return 100 * MB;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,4 @@ public class ProfileMediaConstraints extends MediaConstraints {
|
||||
public int getImageMaxSize(Context context) {
|
||||
return 5 * 1024 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGifMaxSize(Context context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVideoMaxSize(Context context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioMaxSize(Context context) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDocumentMaxSize(Context context) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user