From a309b764ec3fab32ae51023b0fdb62bed7ac2cb7 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 3 Sep 2016 22:13:06 +0200 Subject: fix crash on take photo --- .../pixart/messenger/ui/ConversationActivity.java | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 00baaa6a4..5217d1be2 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -110,6 +110,7 @@ public class ConversationActivity extends XmppActivity private static final String STATE_PANEL_OPEN = "state_panel_open"; private static final String STATE_PENDING_URI = "state_pending_uri"; final private List mPendingImageUris = new ArrayList<>(); + final private List mPendingPhotoUris = new ArrayList<>(); final private List mPendingFileUris = new ArrayList<>(); final private List mPendingVideoUris = new ArrayList<>(); private String mOpenConverstaion = null; @@ -619,8 +620,8 @@ public class ConversationActivity extends XmppActivity intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); - mPendingImageUris.clear(); - mPendingImageUris.add(uri); + mPendingPhotoUris.clear(); + mPendingPhotoUris.add(uri); break; case ATTACHMENT_CHOICE_CHOOSE_FILE: chooser = true; @@ -1298,6 +1299,8 @@ public class ConversationActivity extends XmppActivity private void clearPending() { mPendingImageUris.clear(); mPendingFileUris.clear(); + mPendingVideoUris.clear(); + mPendingPhotoUris.clear(); mPendingGeoUri = null; mPostponedActivityResult = null; } @@ -1415,6 +1418,10 @@ public class ConversationActivity extends XmppActivity } } + for (Iterator i = mPendingPhotoUris.iterator(); i.hasNext(); i.remove()) { + attachPhotoToConversation(getSelectedConversation(), i.next()); + } + for (Iterator i = mPendingVideoUris.iterator(); i.hasNext(); i.remove()) { attachVideoToConversation(getSelectedConversation(), i.next()); } @@ -1784,6 +1791,39 @@ public class ConversationActivity extends XmppActivity }); } + private void attachPhotoToConversation(Conversation conversation, Uri uri) { + if (conversation == null) { + return; + } + final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG); + prepareFileToast.show(); + xmppConnectionService.attachImageToConversation(conversation, uri, + new UiCallback() { + + @Override + public void userInputRequried(PendingIntent pi, Message object) { + hidePrepareFileToast(prepareFileToast); + } + + @Override + public void success(Message message) { + hidePrepareFileToast(prepareFileToast); + xmppConnectionService.sendMessage(message); + } + + @Override + public void error(final int error, Message message) { + hidePrepareFileToast(prepareFileToast); + runOnUiThread(new Runnable() { + @Override + public void run() { + replaceToast(getString(error)); + } + }); + } + }); + } + private void attachImagesToConversation(Conversation conversation, Uri uri) { if (conversation == null) { return; -- cgit v1.2.3