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