From 33b8dd36e4191b32362b2b0d6170b3165546dd73 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 28 Jan 2023 16:47:56 +0100 Subject: [PATCH] Add support to edit media --- .../endpoints/MastodonStatusesService.java | 6 ++++-- .../android/mastodon/jobs/ComposeWorker.java | 16 +++++++++++++++- .../mastodon/ui/drawer/ComposeAdapter.java | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonStatusesService.java b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonStatusesService.java index 29d5c784..975fc291 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonStatusesService.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/endpoints/MastodonStatusesService.java @@ -91,10 +91,12 @@ public interface MastodonStatusesService { @Field("sensitive") Boolean sensitive, @Field("spoiler_text") String spoiler_text, @Field("visibility") String visibility, - @Field("language") String language + @Field("language") String language, + @Field("media_attributes[id][]") List media_id, + @Field("media_attributes[description][]") List media_description, + @Field("media_attributes[focus][]") List focus ); - //Post a scheduled status @FormUrlEncoded @POST("statuses") diff --git a/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java b/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java index 7c23ef88..d010d1b4 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java +++ b/app/src/main/java/app/fedilab/android/mastodon/jobs/ComposeWorker.java @@ -158,6 +158,9 @@ public class ComposeWorker extends Worker { } dataPost.messageToSend = statuses.size() - startingPosition; dataPost.messageSent = 0; + List media_edit_id = null; + List media_edit_description = null; + List media_edit_focus = null; for (int i = startingPosition; i < statuses.size(); i++) { if (dataPost.notificationBuilder != null) { dataPost.notificationBuilder.setProgress(100, dataPost.messageSent * 100 / dataPost.messageToSend, true); @@ -170,7 +173,15 @@ public class ComposeWorker extends Worker { attachmentIds = new ArrayList<>(); for (Attachment attachment : statuses.get(i).media_attachments) { if (attachment.id != null) { + if (media_edit_id == null) { + media_edit_id = new ArrayList<>(); + media_edit_description = new ArrayList<>(); + media_edit_focus = new ArrayList<>(); + } attachmentIds.add(attachment.id); + media_edit_id.add(attachment.id); + media_edit_description.add(attachment.description); + media_edit_focus.add(attachment.focus); } else { MultipartBody.Part fileMultipartBody; if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) { @@ -221,13 +232,16 @@ public class ComposeWorker extends Worker { if (statuses.get(i).local_only) { statuses.get(i).text += " \uD83D\uDC41"; } + if (dataPost.scheduledDate == null) { if (dataPost.statusEditId == null) { statusCall = mastodonStatusesService.createStatus(null, dataPost.token, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in, poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language, statuses.get(i).quote_id, statuses.get(i).content_type); } else { //Status is edited statusCall = mastodonStatusesService.updateStatus(null, dataPost.token, dataPost.statusEditId, statuses.get(i).text, attachmentIds, poll_options, poll_expire_in, - poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language); + poll_multiple, poll_hide_totals, statuses.get(i).quote_id == null ? in_reply_to_status : null, statuses.get(i).sensitive, + statuses.get(i).spoilerChecked ? statuses.get(i).spoiler_text : null, statuses.get(i).visibility.toLowerCase(), language, + media_edit_id, media_edit_description, media_edit_focus); } try { Response statusResponse = statusCall.execute(); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java index 8e287bd1..ce010b12 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java @@ -1046,12 +1046,12 @@ public class ComposeAdapter extends RecyclerView.Adapter