mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
[android] Only retrieve image sizes for single images in messages
We need to do this to know the height of messages when binding the view. The size of single images can be different (e.g. due to orientation). For multiple images, we use a fixed size, so no retrieval is required.
This commit is contained in:
@@ -92,19 +92,32 @@ class AttachmentController {
|
||||
|
||||
List<AttachmentItem> getAttachmentItems(
|
||||
List<Pair<AttachmentHeader, Attachment>> attachments) {
|
||||
boolean needsSize = attachments.size() == 1;
|
||||
List<AttachmentItem> items = new ArrayList<>(attachments.size());
|
||||
for (Pair<AttachmentHeader, Attachment> a : attachments) {
|
||||
AttachmentItem item =
|
||||
getAttachmentItem(a.getFirst(), a.getSecond());
|
||||
getAttachmentItem(a.getFirst(), a.getSecond(), needsSize);
|
||||
items.add(item);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private AttachmentItem getAttachmentItem(AttachmentHeader h, Attachment a) {
|
||||
private AttachmentItem getAttachmentItem(AttachmentHeader h, Attachment a,
|
||||
boolean needsSize) {
|
||||
MessageId messageId = h.getMessageId();
|
||||
Size size = new Size();
|
||||
if (!needsSize) {
|
||||
String mimeType = h.getContentType();
|
||||
String extension = getExtensionFromMimeType(mimeType);
|
||||
boolean hasError = false;
|
||||
if (extension == null) {
|
||||
extension = "";
|
||||
hasError = true;
|
||||
}
|
||||
return new AttachmentItem(messageId, 0, 0, mimeType, extension, 0,
|
||||
0, hasError);
|
||||
}
|
||||
|
||||
Size size = new Size();
|
||||
InputStream is = a.getStream();
|
||||
is.mark(Integer.MAX_VALUE);
|
||||
try {
|
||||
@@ -134,8 +147,7 @@ class AttachmentController {
|
||||
getThumbnailSize(size.width, size.height, size.mimeType);
|
||||
}
|
||||
// get file extension
|
||||
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||
String extension = mimeTypeMap.getExtensionFromMimeType(size.mimeType);
|
||||
String extension = getExtensionFromMimeType(size.mimeType);
|
||||
if (extension == null) {
|
||||
return new AttachmentItem(messageId, 0, 0, "", "", 0, 0, true);
|
||||
}
|
||||
@@ -144,6 +156,12 @@ class AttachmentController {
|
||||
size.error);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getExtensionFromMimeType(String mimeType) {
|
||||
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
|
||||
return mimeTypeMap.getExtensionFromMimeType(mimeType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of a JPEG {@link InputStream} if EXIF info is available.
|
||||
*/
|
||||
|
||||
@@ -397,7 +397,7 @@ public class ConversationActivity extends BriarActivity
|
||||
textCache.put(id, text);
|
||||
}
|
||||
}
|
||||
if (!h.getAttachmentHeaders().isEmpty()) {
|
||||
if (h.getAttachmentHeaders().size() == 1) {
|
||||
List<AttachmentItem> items =
|
||||
attachmentController.get(id);
|
||||
if (items == null) {
|
||||
@@ -486,7 +486,7 @@ public class ConversationActivity extends BriarActivity
|
||||
try {
|
||||
List<Pair<AttachmentHeader, Attachment>> attachments =
|
||||
attachmentController.getMessageAttachments(headers);
|
||||
// TODO move getting the items off to the IoExecutor
|
||||
// TODO move getting the items off to IoExecutor, if size == 1
|
||||
List<AttachmentItem> items =
|
||||
attachmentController.getAttachmentItems(attachments);
|
||||
displayMessageAttachments(messageId, items);
|
||||
|
||||
Reference in New Issue
Block a user