Skip to content

Commit

Permalink
#289 πŸ“Ž Add more sources to upload attachments
Browse files Browse the repository at this point in the history
Fix contact picker

Signed-off-by: Stefan Niedermann <info@niedermann.it>
  • Loading branch information
stefan-niedermann committed Oct 29, 2020
1 parent d773e16 commit 704273e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
case REQUEST_CODE_PICK_CONTACT: {
if (resultCode == RESULT_OK) {
try {
uploadNewAttachment(VCardUtil.getVCardContentUri(requireContext()));
uploadNewAttachment(VCardUtil.getVCardContentUri(requireContext(), Uri.parse(data.getDataString())));
} catch (Exception e) {
ExceptionDialogFragment.newInstance(e, viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
Expand All @@ -220,10 +220,6 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
case REQUEST_CODE_CAPTURE_IMAGE:
case REQUEST_CODE_ADD_FILE: {
if (resultCode == RESULT_OK) {
if (data == null) {
ExceptionDialogFragment.newInstance(new UploadAttachmentFailedException("Intent data is null"), viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
return;
}
try {
uploadNewAttachment(data.getData());
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ private VCardUtil() {
// You shall not pass
}

public static Uri getVCardContentUri(@NonNull Context context) throws NoSuchElementException {
public static Uri getVCardContentUri(@NonNull Context context, @NonNull Uri contactUri) throws NoSuchElementException {
final ContentResolver cr = context.getContentResolver();
try (final Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null)) {
try (final Cursor cursor = cr.query(contactUri, null, null, null, null)) {
if (cursor.moveToFirst()) {
final String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
return Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
Expand Down

0 comments on commit 704273e

Please sign in to comment.