[android] Add assertions to TextAttachmentController

parent 70d29af2
...@@ -94,6 +94,7 @@ public class TextAttachmentController extends TextSendController ...@@ -94,6 +94,7 @@ public class TextAttachmentController extends TextSendController
@Override @Override
public void onSendEvent() { public void onSendEvent() {
if (canSend()) { if (canSend()) {
if (loadingUris) throw new AssertionError();
listener.onSendClick(textInput.getText(), listener.onSendClick(textInput.getText(),
attachmentManager.getAttachmentHeaders()); attachmentManager.getAttachmentHeaders());
reset(); reset();
...@@ -139,6 +140,7 @@ public class TextAttachmentController extends TextSendController ...@@ -139,6 +140,7 @@ public class TextAttachmentController extends TextSendController
public void onImageReceived(@Nullable Intent resultData) { public void onImageReceived(@Nullable Intent resultData) {
if (resultData == null) return; if (resultData == null) return;
if (loadingUris) throw new AssertionError();
if (resultData.getData() != null) { if (resultData.getData() != null) {
imageUris = new ArrayList<>(1); imageUris = new ArrayList<>(1);
imageUris.add(resultData.getData()); imageUris.add(resultData.getData());
...@@ -155,6 +157,7 @@ public class TextAttachmentController extends TextSendController ...@@ -155,6 +157,7 @@ public class TextAttachmentController extends TextSendController
private void onNewUris() { private void onNewUris() {
if (imageUris.isEmpty()) return; if (imageUris.isEmpty()) return;
if (loadingUris || urisLoaded != 0) throw new AssertionError();
loadingUris = true; loadingUris = true;
updateViewState(); updateViewState();
textInput.setHint(R.string.image_caption_hint); textInput.setHint(R.string.image_caption_hint);
...@@ -169,6 +172,7 @@ public class TextAttachmentController extends TextSendController ...@@ -169,6 +172,7 @@ public class TextAttachmentController extends TextSendController
} }
private void onAttachmentResultReceived(AttachmentResult result) { private void onAttachmentResultReceived(AttachmentResult result) {
if (!loadingUris) return; // if this is false, the user cancelled
if (result.isError() || result.getUri() == null) { if (result.isError() || result.getUri() == null) {
onError(result.getErrorMsg()); onError(result.getErrorMsg());
} else { } else {
...@@ -227,6 +231,7 @@ public class TextAttachmentController extends TextSendController ...@@ -227,6 +231,7 @@ public class TextAttachmentController extends TextSendController
} }
private void checkAllUrisLoaded() { private void checkAllUrisLoaded() {
if (!loadingUris) throw new AssertionError();
if (urisLoaded == imageUris.size()) { if (urisLoaded == imageUris.size()) {
loadingUris = false; loadingUris = false;
// all images were turned into attachments // all images were turned into attachments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment