Skip to content

Commit

Permalink
#289 πŸ“Ž Add more sources to upload attachments
Browse files Browse the repository at this point in the history
Minor clean up

Signed-off-by: Stefan Niedermann <info@niedermann.it>
  • Loading branch information
stefan-niedermann committed Oct 29, 2020
1 parent 9929931 commit d773e16
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
switch (requestCode) {
case REQUEST_CODE_PICK_CONTACT: {
if (resultCode == RESULT_OK) {
final Uri sourceUri = VCardUtil.getVCardContentUri(requireContext());
try {
uploadNewAttachment(sourceUri);
} catch (UploadAttachmentFailedException | IOException e) {
uploadNewAttachment(VCardUtil.getVCardContentUri(requireContext()));
} catch (Exception e) {
ExceptionDialogFragment.newInstance(e, viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
}
Expand All @@ -225,10 +224,9 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d
ExceptionDialogFragment.newInstance(new UploadAttachmentFailedException("Intent data is null"), viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
return;
}
final Uri sourceUri = data.getData();
try {
uploadNewAttachment(sourceUri);
} catch (UploadAttachmentFailedException | IOException e) {
uploadNewAttachment(data.getData());
} catch (Exception e) {
ExceptionDialogFragment.newInstance(e, viewModel.getAccount()).show(getChildFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

public class VCardUtil {

private static final String TAG = VCardUtil.class.getSimpleName();

private VCardUtil() {
// You shall not pass
}

public static Uri getVCardContentUri(@NonNull Context context) {
public static Uri getVCardContentUri(@NonNull Context context) throws NoSuchElementException {
final ContentResolver cr = context.getContentResolver();
try (final Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null)) {
if (cursor.moveToFirst()) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/dialog_attachment_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:contentDescription="@null"
android:src="@drawable/ic_baseline_photo_camera_24" />
app:srcCompat="@drawable/ic_baseline_photo_camera_24" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -43,7 +43,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:contentDescription="@null"
android:src="@drawable/ic_baseline_contact_mail_24" />
app:srcCompat="@drawable/ic_baseline_contact_mail_24" />

<TextView
android:layout_width="wrap_content"
Expand All @@ -64,7 +64,7 @@
android:layout_width="36dp"
android:layout_height="36dp"
android:contentDescription="@null"
android:src="@drawable/ic_attach_file_grey600_24dp" />
app:srcCompat="@drawable/ic_attach_file_grey600_24dp" />

<TextView
android:layout_width="wrap_content"
Expand Down

0 comments on commit d773e16

Please sign in to comment.