mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
[android] address first round of code review for attachment placeholders
This commit is contained in:
@@ -55,7 +55,7 @@ public class AttachmentItem implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Use only for {@link MISSING} or {@link LOADING} items.
|
||||
* Use only for {@link State MISSING} or {@link State LOADING} items.
|
||||
*/
|
||||
AttachmentItem(AttachmentHeader header, int width, int height,
|
||||
State state) {
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface AttachmentRetriever {
|
||||
* Retrieves item size and adds the item to the cache, if available.
|
||||
*/
|
||||
@DatabaseExecutor
|
||||
void cacheAttachmentItem(MessageId conversationMessageId,
|
||||
void cacheAttachmentItemWithSize(MessageId conversationMessageId,
|
||||
AttachmentHeader h) throws DbException;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ public interface AttachmentRetriever {
|
||||
*
|
||||
* @return a pair of the {@link MessageId} of the conversation message
|
||||
* and the {@link AttachmentItem}
|
||||
* or {@code null} when the conversation message did not yet arrive.
|
||||
* or {@code null} when the private message did not yet arrive.
|
||||
*/
|
||||
@Nullable
|
||||
@DatabaseExecutor
|
||||
|
||||
@@ -26,6 +26,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.IoUtils.tryToClose;
|
||||
import static org.briarproject.briar.android.attachment.AttachmentItem.State.AVAILABLE;
|
||||
import static org.briarproject.briar.android.attachment.AttachmentItem.State.ERROR;
|
||||
import static org.briarproject.briar.android.attachment.AttachmentItem.State.LOADING;
|
||||
@@ -93,7 +94,7 @@ class AttachmentRetrieverImpl implements AttachmentRetriever {
|
||||
|
||||
@Override
|
||||
@DatabaseExecutor
|
||||
public void cacheAttachmentItem(MessageId conversationMessageId,
|
||||
public void cacheAttachmentItemWithSize(MessageId conversationMessageId,
|
||||
AttachmentHeader h) throws DbException {
|
||||
try {
|
||||
Attachment a = messagingManager.getAttachment(h);
|
||||
@@ -135,11 +136,12 @@ class AttachmentRetrieverImpl implements AttachmentRetriever {
|
||||
boolean needsSize) {
|
||||
AttachmentHeader h = a.getHeader();
|
||||
AttachmentItem item = itemCache.get(h.getMessageId());
|
||||
if (item != null && (needsSize && item.hasSize())) return item;
|
||||
if (item != null && (needsSize == item.hasSize())) return item;
|
||||
|
||||
if (needsSize) {
|
||||
InputStream is = new BufferedInputStream(a.getStream());
|
||||
Size size = imageSizeCalculator.getSize(is, h.getContentType());
|
||||
tryToClose(is, LOG, WARNING);
|
||||
item = createAttachmentItem(h, size);
|
||||
} else {
|
||||
String extension =
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.briarproject.briar.android.attachment;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
import org.briarproject.briar.api.messaging.AttachmentHeader;
|
||||
|
||||
import javax.annotation.concurrent.Immutable;
|
||||
|
||||
@Immutable
|
||||
@NotNullByDefault
|
||||
class UnavailableItem {
|
||||
|
||||
private final MessageId conversationMessageId;
|
||||
|
||||
@@ -558,7 +558,7 @@ public class ConversationActivity extends BriarActivity
|
||||
LOG.info("Eagerly loading image size for latest message");
|
||||
AttachmentHeader header = headers.get(0);
|
||||
// get the item to retrieve its size
|
||||
attachmentRetriever.cacheAttachmentItem(h.getId(), header);
|
||||
attachmentRetriever.cacheAttachmentItemWithSize(h.getId(), header);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
|
||||
Reference in New Issue
Block a user