Fix issue #486 - Empty images when sharing from another app.

This commit is contained in:
Thomas 2022-11-20 12:07:54 +01:00
parent 2f9b1e9bcf
commit b334a5b655
2 changed files with 34 additions and 12 deletions

View File

@ -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<Uri> uris = new ArrayList<>(sharedUriList);
composeAdapter.addAttachment(-1, uris);
}, 1000);
List<Uri> 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<Uri> uris = new ArrayList<>();
uris.add(sharedUri);
composeAdapter.addAttachment(-1, uris);
}, 1000);
List<Uri> 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) {

View File

@ -178,6 +178,30 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
});
}
/**
* Add an attachment from ComposeActivity
*
* @param position int - position of the drawer that added a media
* @param attachment Attachment - media attachment
*/
public void addAttachment(int position, Attachment attachment) {
if (position == -1) {
position = statusList.size() - 1;
}
// position = statusCount-1+position;
if (statusList.get(position).media_attachments == null) {
statusList.get(position).media_attachments = new ArrayList<>();
}
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));