[android] address review comments for rejecting unsupported images

This commit is contained in:
Torsten Grote
2019-06-14 09:22:03 -03:00
parent 4ee4905e06
commit c07a0a2fd7
3 changed files with 36 additions and 30 deletions

View File

@@ -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;
} }

View File

@@ -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;
} }

View File

@@ -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