mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
[android] address review comments for rejecting unsupported images
This commit is contained in:
@@ -106,8 +106,7 @@ class AttachmentCreationTask {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidMimeType(@Nullable String mimeType) {
|
private boolean isValidMimeType(String mimeType) {
|
||||||
if (mimeType == null) return false;
|
|
||||||
for (String supportedType : IMAGE_MIME_TYPES) {
|
for (String supportedType : IMAGE_MIME_TYPES) {
|
||||||
if (supportedType.equals(mimeType)) return true;
|
if (supportedType.equals(mimeType)) return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,31 +64,35 @@ public class AttachmentCreator {
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
public LiveData<AttachmentResult> storeAttachments(
|
public LiveData<AttachmentResult> storeAttachments(
|
||||||
LiveData<GroupId> groupId, Collection<Uri> newUris, boolean restart) {
|
LiveData<GroupId> groupId, Collection<Uri> newUris) {
|
||||||
MutableLiveData<AttachmentResult> result;
|
if (this.result != null || !uris.isEmpty())
|
||||||
if (restart) {
|
throw new IllegalStateException();
|
||||||
// This can happen due to configuration changes.
|
MutableLiveData<AttachmentResult> result = new MutableLiveData<>();
|
||||||
// So don't create new attachments. They are already being created
|
this.result = result;
|
||||||
// and returned by the existing LiveData.
|
uris.addAll(newUris);
|
||||||
result = this.result;
|
observeForeverOnce(groupId, id -> {
|
||||||
if (task == null || uris.isEmpty() || result == null)
|
if (id == null) throw new IllegalStateException();
|
||||||
throw new IllegalStateException();
|
boolean needsSize = uris.size() == 1;
|
||||||
// A task is already running. It will update the result LiveData.
|
task = new AttachmentCreationTask(messagingManager,
|
||||||
// So nothing more to do here.
|
app.getContentResolver(), this, id, uris, needsSize);
|
||||||
} else {
|
ioExecutor.execute(() -> task.storeAttachments());
|
||||||
if (this.result != null || !uris.isEmpty())
|
});
|
||||||
throw new IllegalStateException();
|
return result;
|
||||||
result = new MutableLiveData<>();
|
}
|
||||||
this.result = result;
|
|
||||||
uris.addAll(newUris);
|
/**
|
||||||
observeForeverOnce(groupId, id -> {
|
* This should be only called after configuration changes.
|
||||||
if (id == null) throw new IllegalStateException();
|
* In this case we should not create new attachments.
|
||||||
boolean needsSize = uris.size() == 1;
|
* They are already being created and returned by the existing LiveData.
|
||||||
task = new AttachmentCreationTask(messagingManager,
|
*/
|
||||||
app.getContentResolver(), this, id, uris, needsSize);
|
@UiThread
|
||||||
ioExecutor.execute(() -> task.storeAttachments());
|
public LiveData<AttachmentResult> getLiveAttachments() {
|
||||||
});
|
//
|
||||||
}
|
MutableLiveData<AttachmentResult> result = this.result;
|
||||||
|
if (task == null || uris.isEmpty() || result == null)
|
||||||
|
throw new IllegalStateException();
|
||||||
|
// A task is already running. It will update the result LiveData.
|
||||||
|
// So nothing more to do here.
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -199,9 +199,12 @@ public class ConversationViewModel extends AndroidViewModel
|
|||||||
@UiThread
|
@UiThread
|
||||||
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
public LiveData<AttachmentResult> storeAttachments(Collection<Uri> uris,
|
||||||
boolean restart) {
|
boolean restart) {
|
||||||
// messagingGroupId is loaded with the contact
|
if (restart) {
|
||||||
return attachmentCreator
|
return attachmentCreator.getLiveAttachments();
|
||||||
.storeAttachments(messagingGroupId, uris, restart);
|
} else {
|
||||||
|
// messagingGroupId is loaded with the contact
|
||||||
|
return attachmentCreator.storeAttachments(messagingGroupId, uris);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user