[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,21 +64,10 @@ 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 (restart) {
// This can happen due to configuration changes.
// So don't create new attachments. They are already being created
// and returned by the existing LiveData.
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.
} else {
if (this.result != null || !uris.isEmpty()) if (this.result != null || !uris.isEmpty())
throw new IllegalStateException(); throw new IllegalStateException();
result = new MutableLiveData<>(); MutableLiveData<AttachmentResult> result = new MutableLiveData<>();
this.result = result; this.result = result;
uris.addAll(newUris); uris.addAll(newUris);
observeForeverOnce(groupId, id -> { observeForeverOnce(groupId, id -> {
@@ -88,7 +77,22 @@ public class AttachmentCreator {
app.getContentResolver(), this, id, uris, needsSize); app.getContentResolver(), this, id, uris, needsSize);
ioExecutor.execute(() -> task.storeAttachments()); ioExecutor.execute(() -> task.storeAttachments());
}); });
return result;
} }
/**
* This should be only called after configuration changes.
* In this case we should not create new attachments.
* They are already being created and returned by the existing LiveData.
*/
@UiThread
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) {
if (restart) {
return attachmentCreator.getLiveAttachments();
} else {
// messagingGroupId is loaded with the contact // messagingGroupId is loaded with the contact
return attachmentCreator return attachmentCreator.storeAttachments(messagingGroupId, uris);
.storeAttachments(messagingGroupId, uris, restart); }
} }
@Override @Override