From 684b025ccfb0472974afe31a27245e4cc2211540 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 8 Apr 2022 05:23:59 +0300 Subject: [PATCH] Use labels from pasted images as alt text --- .../api/requests/statuses/UploadAttachment.java | 13 +++++++++---- .../android/fragments/ComposeFragment.java | 15 ++++++++------- .../android/ui/views/ComposeEditText.java | 8 +++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/UploadAttachment.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/UploadAttachment.java index 22e0c562..9a570d8b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/UploadAttachment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/statuses/UploadAttachment.java @@ -3,6 +3,7 @@ package org.joinmastodon.android.api.requests.statuses; import android.database.Cursor; import android.net.Uri; import android.provider.OpenableColumns; +import android.text.TextUtils; import org.joinmastodon.android.MastodonApp; import org.joinmastodon.android.api.ContentUriRequestBody; @@ -21,15 +22,17 @@ public class UploadAttachment extends MastodonAPIRequest{ private Uri uri; private ProgressListener progressListener; private int maxImageSize; + private String description; public UploadAttachment(Uri uri){ super(HttpMethod.POST, "/media", Attachment.class); this.uri=uri; } - public UploadAttachment(Uri uri, int maxImageSize){ + public UploadAttachment(Uri uri, int maxImageSize, String description){ this(uri); this.maxImageSize=maxImageSize; + this.description=description; } public UploadAttachment setProgressListener(ProgressListener progressListener){ @@ -39,9 +42,11 @@ public class UploadAttachment extends MastodonAPIRequest{ @Override public RequestBody getRequestBody() throws IOException{ - return new MultipartBody.Builder() + MultipartBody.Builder builder=new MultipartBody.Builder() .setType(MultipartBody.FORM) - .addFormDataPart("file", UiUtils.getFileName(uri), maxImageSize>0 ? new ResizedImageRequestBody(uri, maxImageSize, progressListener) : new ContentUriRequestBody(uri, progressListener)) - .build(); + .addFormDataPart("file", UiUtils.getFileName(uri), maxImageSize>0 ? new ResizedImageRequestBody(uri, maxImageSize, progressListener) : new ContentUriRequestBody(uri, progressListener)); + if(!TextUtils.isEmpty(description)) + builder.addFormDataPart("description", description); + return builder.build(); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index 1d01ae51..7d8bf5cc 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -463,7 +463,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis ArrayList mediaUris=getArguments().getParcelableArrayList("mediaAttachments"); if(mediaUris!=null && !mediaUris.isEmpty()){ for(Uri uri:mediaUris){ - addMediaAttachment(uri); + addMediaAttachment(uri, null); } } } @@ -689,17 +689,17 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis if(requestCode==MEDIA_RESULT && resultCode==Activity.RESULT_OK){ Uri single=data.getData(); if(single!=null){ - addMediaAttachment(single); + addMediaAttachment(single, null); }else{ ClipData clipData=data.getClipData(); for(int i=0;i