mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
[android] Address first round of review comments for attachments
This commit is contained in:
@@ -37,7 +37,7 @@ class AttachmentCreationTask {
|
||||
private final List<Uri> uris;
|
||||
private final boolean needsSize;
|
||||
@Nullable
|
||||
private AttachmentCreator attachmentCreator;
|
||||
private volatile AttachmentCreator attachmentCreator;
|
||||
|
||||
private volatile boolean canceled = false;
|
||||
|
||||
@@ -61,9 +61,10 @@ class AttachmentCreationTask {
|
||||
@IoExecutor
|
||||
public void storeAttachments() {
|
||||
for (Uri uri: uris) processUri(uri);
|
||||
AttachmentCreator attachmentCreator = this.attachmentCreator;
|
||||
if (!canceled && attachmentCreator != null)
|
||||
attachmentCreator.onAttachmentCreationFinished();
|
||||
attachmentCreator = null;
|
||||
this.attachmentCreator = null;
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
@@ -71,16 +72,17 @@ class AttachmentCreationTask {
|
||||
if (canceled) return;
|
||||
try {
|
||||
AttachmentHeader h = storeAttachment(uri);
|
||||
AttachmentCreator attachmentCreator = this.attachmentCreator;
|
||||
if (attachmentCreator != null) {
|
||||
attachmentCreator
|
||||
.onAttachmentHeaderReceived(uri, h, needsSize);
|
||||
attachmentCreator.onAttachmentHeaderReceived(uri, h, needsSize);
|
||||
}
|
||||
} catch (DbException | IOException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
AttachmentCreator attachmentCreator = this.attachmentCreator;
|
||||
if (attachmentCreator != null) {
|
||||
attachmentCreator.onAttachmentError(uri, e);
|
||||
canceled = true;
|
||||
}
|
||||
canceled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,9 +92,10 @@ class AttachmentCreationTask {
|
||||
long start = now();
|
||||
String contentType = contentResolver.getType(uri);
|
||||
if (contentType == null) throw new IOException("null content type");
|
||||
if (!isValidMimeType(contentType))
|
||||
throw new UnsupportedMimeTypeException("", contentType,
|
||||
uri.toString());
|
||||
if (!isValidMimeType(contentType)) {
|
||||
String uriString = uri.toString();
|
||||
throw new UnsupportedMimeTypeException("", contentType, uriString);
|
||||
}
|
||||
InputStream is = contentResolver.openInputStream(uri);
|
||||
if (is == null) throw new IOException();
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class AttachmentCreator {
|
||||
@IoExecutor
|
||||
private final Executor ioExecutor;
|
||||
private final MessagingManager messagingManager;
|
||||
private final AttachmentRetriever controller;
|
||||
private final AttachmentRetriever retriever;
|
||||
|
||||
private final Map<Uri, AttachmentItem> unsentItems =
|
||||
new ConcurrentHashMap<>();
|
||||
@@ -57,12 +57,11 @@ public class AttachmentCreator {
|
||||
private AttachmentCreationTask task;
|
||||
|
||||
public AttachmentCreator(Application app, @IoExecutor Executor ioExecutor,
|
||||
MessagingManager messagingManager,
|
||||
AttachmentRetriever controller) {
|
||||
MessagingManager messagingManager, AttachmentRetriever retriever) {
|
||||
this.app = app;
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.messagingManager = messagingManager;
|
||||
this.controller = controller;
|
||||
this.retriever = retriever;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -101,8 +100,8 @@ public class AttachmentCreator {
|
||||
boolean needsSize) {
|
||||
// get and cache AttachmentItem for ImagePreview
|
||||
try {
|
||||
Attachment a = controller.getMessageAttachment(h);
|
||||
AttachmentItem item = controller.getAttachmentItem(h, a, needsSize);
|
||||
Attachment a = retriever.getMessageAttachment(h);
|
||||
AttachmentItem item = retriever.getAttachmentItem(h, a, needsSize);
|
||||
if (item.hasError()) throw new IOException();
|
||||
unsentItems.put(uri, item);
|
||||
MutableLiveData<AttachmentItemResult> result =
|
||||
@@ -156,7 +155,7 @@ public class AttachmentCreator {
|
||||
* @param id The MessageId of the sent message.
|
||||
*/
|
||||
public void onAttachmentsSent(MessageId id) {
|
||||
controller.cachePut(id, new ArrayList<>(unsentItems.values()));
|
||||
retriever.cachePut(id, new ArrayList<>(unsentItems.values()));
|
||||
resetState();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@UiThread
|
||||
public interface AttachmentManager{
|
||||
public interface AttachmentManager {
|
||||
|
||||
AttachmentResult storeAttachments(Collection<Uri> uri);
|
||||
|
||||
|
||||
@@ -138,6 +138,16 @@ public class TextAttachmentController extends TextSendController
|
||||
return intent;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called with the result Intent
|
||||
* returned by the Activity started with {@link #getAttachFileIntent()}.
|
||||
* <p>
|
||||
* This method must be called at most once per call to
|
||||
* {@link AttachImageListener#onAttachImage(Intent)}.
|
||||
* Normally, this is true if called from
|
||||
* {@link Activity#onActivityResult(int, int, Intent)} since this is called
|
||||
* at most once per call to {@link Activity#startActivityForResult(Intent, int)}.
|
||||
*/
|
||||
public void onImageReceived(@Nullable Intent resultData) {
|
||||
if (resultData == null) return;
|
||||
if (loadingUris || !imageUris.isEmpty()) throw new AssertionError();
|
||||
|
||||
Reference in New Issue
Block a user