diff --git a/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreationTask.java b/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreationTask.java index 1a1a5b7d2..d9e77d1d8 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreationTask.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreationTask.java @@ -106,8 +106,7 @@ class AttachmentCreationTask { return h; } - private boolean isValidMimeType(@Nullable String mimeType) { - if (mimeType == null) return false; + private boolean isValidMimeType(String mimeType) { for (String supportedType : IMAGE_MIME_TYPES) { if (supportedType.equals(mimeType)) return true; } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java b/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java index d694868b7..a8af9d89a 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/attachment/AttachmentCreator.java @@ -64,31 +64,35 @@ public class AttachmentCreator { @UiThread public LiveData storeAttachments( - LiveData groupId, Collection newUris, boolean restart) { - MutableLiveData 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()) - throw new IllegalStateException(); - result = new MutableLiveData<>(); - this.result = result; - uris.addAll(newUris); - observeForeverOnce(groupId, id -> { - if (id == null) throw new IllegalStateException(); - boolean needsSize = uris.size() == 1; - task = new AttachmentCreationTask(messagingManager, - app.getContentResolver(), this, id, uris, needsSize); - ioExecutor.execute(() -> task.storeAttachments()); - }); - } + LiveData groupId, Collection newUris) { + if (this.result != null || !uris.isEmpty()) + throw new IllegalStateException(); + MutableLiveData result = new MutableLiveData<>(); + this.result = result; + uris.addAll(newUris); + observeForeverOnce(groupId, id -> { + if (id == null) throw new IllegalStateException(); + boolean needsSize = uris.size() == 1; + task = new AttachmentCreationTask(messagingManager, + app.getContentResolver(), this, id, uris, needsSize); + 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 getLiveAttachments() { + // + MutableLiveData 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; } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationViewModel.java b/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationViewModel.java index 85a208228..a746f8ac6 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationViewModel.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/conversation/ConversationViewModel.java @@ -199,9 +199,12 @@ public class ConversationViewModel extends AndroidViewModel @UiThread public LiveData storeAttachments(Collection uris, boolean restart) { - // messagingGroupId is loaded with the contact - return attachmentCreator - .storeAttachments(messagingGroupId, uris, restart); + if (restart) { + return attachmentCreator.getLiveAttachments(); + } else { + // messagingGroupId is loaded with the contact + return attachmentCreator.storeAttachments(messagingGroupId, uris); + } } @Override