request storage permission when sending gif. fixes #2589

This commit is contained in:
Daniel Gultsch 2017-08-22 16:51:42 +02:00
parent 9b4cb37477
commit 26f7702c39
2 changed files with 13 additions and 13 deletions

View File

@ -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<Integer, Intent> 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);
}

View File

@ -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);