From 26f7702c39a5d78e54e9c294637bf801cf24ea94 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 22 Aug 2017 16:51:42 +0200 Subject: [PATCH] request storage permission when sending gif. fixes #2589 --- .../ui/ConversationActivity.java | 6 ++++++ .../ui/ConversationFragment.java | 20 +++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index e4b681431..44c31b45b 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -85,6 +85,7 @@ public class ConversationActivity extends XmppActivity public static final int REQUEST_TRUST_KEYS_TEXT = 0x0208; public static final int REQUEST_TRUST_KEYS_MENU = 0x0209; public static final int REQUEST_START_DOWNLOAD = 0x0210; + public static final int REQUEST_ADD_EDITOR_CONTENT = 0x0211; public static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; public static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; public static final int ATTACHMENT_CHOICE_CHOOSE_FILE = 0x0303; @@ -123,6 +124,7 @@ public class ConversationActivity extends XmppActivity private AtomicBoolean mRedirected = new AtomicBoolean(false); private Pair mPostponedActivityResult; private boolean mUnprocessedNewIntent = false; + public Uri mPendingEditorContent = null; public Conversation getSelectedConversation() { return this.mSelectedConversation; @@ -644,6 +646,10 @@ public class ConversationActivity extends XmppActivity if (this.mPendingDownloadableMessage != null) { startDownloadable(this.mPendingDownloadableMessage); } + } else if (requestCode == REQUEST_ADD_EDITOR_CONTENT) { + if (this.mPendingEditorContent != null) { + attachImageToConversation(this.mPendingEditorContent); + } } else { attachFile(requestCode); } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index b03a0a8e6..692b8f69f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -312,17 +312,11 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa return false; } } - - // send the image - activity.attachImageToConversation(inputContentInfo.getContentUri()); - - // TODO: revoke permissions? - // since uploading an image is async its tough to wire a callback to when - // the image has finished uploading. - // According to the docs: "calling IC#releasePermission() is just to be a - // good citizen. Even if we failed to call that method, the system would eventually revoke - // the permission sometime after inputContentInfo object gets garbage-collected." - // See: https://developer.android.com/samples/CommitContentSampleApp/src/com.example.android.commitcontent.app/MainActivity.html#l164 + if (activity.hasStoragePermission(ConversationActivity.REQUEST_ADD_EDITOR_CONTENT)) { + activity.attachImageToConversation(inputContentInfo.getContentUri()); + } else { + activity.mPendingEditorContent = inputContentInfo.getContentUri(); + } return true; } }; @@ -455,7 +449,6 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa final View view = inflater.inflate(R.layout.fragment_conversation, container, false); view.setOnClickListener(null); - String[] allImagesMimeType = {"image/*"}; mEditMessage = (EditMessage) view.findViewById(R.id.textinput); mEditMessage.setOnClickListener(new OnClickListener() { @@ -466,8 +459,9 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } } }); + mEditMessage.setOnEditorActionListener(mEditorActionListener); - mEditMessage.setRichContentListener(allImagesMimeType, mEditorContentListener); + mEditMessage.setRichContentListener(new String[]{"image/*"}, mEditorContentListener); mSendButton = (ImageButton) view.findViewById(R.id.textSendButton); mSendButton.setOnClickListener(this.mSendButtonListener);