mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
[android] Get image extension from MimeTypeMap and store it in AttachmentItem
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.res.Resources;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.media.ExifInterface;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import org.briarproject.bramble.api.Pair;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
@@ -132,8 +133,14 @@ class AttachmentController {
|
||||
thumbnailSize =
|
||||
getThumbnailSize(size.width, size.height, size.mimeType);
|
||||
}
|
||||
// get file extension
|
||||
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||
String extension = mimeTypeMap.getExtensionFromMimeType(size.mimeType);
|
||||
if (extension == null) {
|
||||
return new AttachmentItem(messageId, 0, 0, "", "", 0, 0, true);
|
||||
}
|
||||
return new AttachmentItem(messageId, size.width, size.height,
|
||||
size.mimeType, thumbnailSize.width, thumbnailSize.height,
|
||||
size.mimeType, extension, thumbnailSize.width, thumbnailSize.height,
|
||||
size.error);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class AttachmentItem implements Parcelable {
|
||||
|
||||
private final MessageId messageId;
|
||||
private final int width, height;
|
||||
private final String mimeType;
|
||||
private final String mimeType, extension;
|
||||
private final int thumbnailWidth, thumbnailHeight;
|
||||
private final boolean hasError;
|
||||
|
||||
@@ -32,11 +32,13 @@ public class AttachmentItem implements Parcelable {
|
||||
};
|
||||
|
||||
AttachmentItem(MessageId messageId, int width, int height, String mimeType,
|
||||
int thumbnailWidth, int thumbnailHeight, boolean hasError) {
|
||||
String extension, int thumbnailWidth, int thumbnailHeight,
|
||||
boolean hasError) {
|
||||
this.messageId = messageId;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.mimeType = mimeType;
|
||||
this.extension = extension;
|
||||
this.thumbnailWidth = thumbnailWidth;
|
||||
this.thumbnailHeight = thumbnailHeight;
|
||||
this.hasError = hasError;
|
||||
@@ -49,6 +51,7 @@ public class AttachmentItem implements Parcelable {
|
||||
width = in.readInt();
|
||||
height = in.readInt();
|
||||
mimeType = in.readString();
|
||||
extension = in.readString();
|
||||
thumbnailWidth = in.readInt();
|
||||
thumbnailHeight = in.readInt();
|
||||
hasError = in.readByte() != 0;
|
||||
@@ -70,6 +73,10 @@ public class AttachmentItem implements Parcelable {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
String getExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
int getThumbnailWidth() {
|
||||
return thumbnailWidth;
|
||||
}
|
||||
@@ -98,6 +105,7 @@ public class AttachmentItem implements Parcelable {
|
||||
dest.writeInt(width);
|
||||
dest.writeInt(height);
|
||||
dest.writeString(mimeType);
|
||||
dest.writeString(extension);
|
||||
dest.writeInt(thumbnailWidth);
|
||||
dest.writeInt(thumbnailHeight);
|
||||
dest.writeByte((byte) (hasError ? 1 : 0));
|
||||
|
||||
@@ -94,10 +94,8 @@ public class ImageViewModel extends AndroidViewModel {
|
||||
*/
|
||||
void saveImage(AttachmentItem attachment) {
|
||||
File file = getImageFile(attachment);
|
||||
saveImage(attachment, () -> getOutputStream(file), () -> {
|
||||
scanFile(getApplication(), new String[] {file.toString()}, null,
|
||||
null);
|
||||
});
|
||||
saveImage(attachment, () -> getOutputStream(file), () -> scanFile(
|
||||
getApplication(), new String[] {file.toString()}, null, null));
|
||||
}
|
||||
|
||||
private void saveImage(AttachmentItem attachment, OutputStreamProvider osp,
|
||||
@@ -141,7 +139,7 @@ public class ImageViewModel extends AndroidViewModel {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
path.mkdirs();
|
||||
String fileName = getFileName();
|
||||
String ext = attachment.getMimeType().replaceFirst("image/", ".");
|
||||
String ext = "." + attachment.getExtension();
|
||||
File file = new File(path, fileName + ext);
|
||||
int i = 1;
|
||||
while (file.exists()) {
|
||||
|
||||
Reference in New Issue
Block a user