From b334a5b6557afba936efe98b2a869f5e33ff3f33 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 20 Nov 2022 12:07:54 +0100 Subject: [PATCH] Fix issue #486 - Empty images when sharing from another app. --- .../android/activities/ComposeActivity.java | 22 ++++++++--------- .../android/ui/drawer/ComposeAdapter.java | 24 +++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java index 06f2ff41a..8db5bb455 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -676,20 +676,18 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana } if (sharedUriList != null && sharedUriList.size() > 0) { - - Handler handler = new Handler(); - handler.postDelayed(() -> { - List uris = new ArrayList<>(sharedUriList); - composeAdapter.addAttachment(-1, uris); - }, 1000); + List uris = new ArrayList<>(sharedUriList); + Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachment -> { + composeAdapter.addAttachment(-1, attachment); + }); } else if (sharedUri != null && !sharedUri.toString().startsWith("http")) { - Handler handler = new Handler(); - handler.postDelayed(() -> { - List uris = new ArrayList<>(); - uris.add(sharedUri); - composeAdapter.addAttachment(-1, uris); - }, 1000); + List uris = new ArrayList<>(); + uris.add(sharedUri); + Helper.createAttachmentFromUri(ComposeActivity.this, uris, attachment -> { + composeAdapter.addAttachment(-1, attachment); + }); } else if (shareURL != null) { + Helper.download(ComposeActivity.this, sharedUrlMedia, new OnDownloadInterface() { @Override public void onDownloaded(String saveFilePath, String downloadUrl, Error error) { diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java index 17bb34d8c..d2b2d6397 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/ComposeAdapter.java @@ -178,6 +178,30 @@ public class ComposeAdapter extends RecyclerView.Adapter(); + } + if (promptDraftListener != null) { + promptDraftListener.promptDraft(); + } + int finalPosition = position; + statusList.get(finalPosition).media_attachments.add(attachment); + notifyItemChanged(finalPosition); + + } + private static void updateCharacterCount(ComposeViewHolder composeViewHolder) { int charCount = MastodonHelper.countLength(composeViewHolder); composeViewHolder.binding.characterCount.setText(String.valueOf(charCount));