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