From ac7dd0484d9c066e012869e8120a6759b8b8c611 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 9 May 2022 16:22:34 +0200 Subject: [PATCH] Fix #41 - Delete & Redraft cannot be sent --- .../android/activities/ComposeActivity.java | 6 ++- .../android/services/PostMessageService.java | 37 +++++++++++-------- .../android/ui/drawer/ComposeAdapter.java | 4 +- .../android/ui/drawer/StatusAdapter.java | 1 + 4 files changed, 27 insertions(+), 21 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 16f99c877..14007796e 100644 --- a/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ComposeActivity.java @@ -172,9 +172,11 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana statusDraftList.add(status); //Restore a draft with all messages - if (statusDraft != null && statusDraft.statusReplyList != null) { + if (statusDraft != null) { new Thread(() -> { - statusDraft.statusReplyList = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusDraft.statusReplyList); + if (statusDraft.statusReplyList != null) { + statusDraft.statusReplyList = SpannableHelper.convertStatus(getApplication().getApplicationContext(), statusDraft.statusReplyList); + } Handler mainHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = () -> { if (statusDraft.statusReplyList != null) { diff --git a/app/src/main/java/app/fedilab/android/services/PostMessageService.java b/app/src/main/java/app/fedilab/android/services/PostMessageService.java index 1ba0097d4..218e6eb3e 100644 --- a/app/src/main/java/app/fedilab/android/services/PostMessageService.java +++ b/app/src/main/java/app/fedilab/android/services/PostMessageService.java @@ -208,27 +208,32 @@ public class PostMessageService extends IntentService { if (statuses.get(i).media_attachments != null && statuses.get(i).media_attachments.size() > 0) { attachmentIds = new ArrayList<>(); for (Attachment attachment : statuses.get(i).media_attachments) { - MultipartBody.Part fileMultipartBody; - if (watermark && attachment.mimeType.contains("image")) { - fileMultipartBody = Helper.getMultipartBodyWithWM(PostMessageService.this, watermarkText, "file", attachment); + if (attachment.id != null) { + attachmentIds.add(attachment.id); } else { - fileMultipartBody = Helper.getMultipartBody("file", attachment); - } - Call attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null); - if (attachmentCall != null) { - try { - Response attachmentResponse = attachmentCall.execute(); - if (attachmentResponse.isSuccessful()) { - Attachment attachmentReply = attachmentResponse.body(); - if (attachmentReply != null) { - attachmentIds.add(attachmentReply.id); + MultipartBody.Part fileMultipartBody; + if (watermark && attachment.mimeType.contains("image")) { + fileMultipartBody = Helper.getMultipartBodyWithWM(PostMessageService.this, watermarkText, "file", attachment); + } else { + fileMultipartBody = Helper.getMultipartBody("file", attachment); + } + Call attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null); + if (attachmentCall != null) { + try { + Response attachmentResponse = attachmentCall.execute(); + if (attachmentResponse.isSuccessful()) { + Attachment attachmentReply = attachmentResponse.body(); + if (attachmentReply != null) { + attachmentIds.add(attachmentReply.id); + } } + } catch (IOException e) { + error = true; + e.printStackTrace(); } - } catch (IOException e) { - error = true; - e.printStackTrace(); } } + } } List poll_options = null; 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 c27f46e56..95fa8f8a5 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 @@ -1181,9 +1181,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { - manageDrafts.onSubmit(prepareDraft(statusList, this, account.instance, account.user_id)); - }); + holder.binding.buttonPost.setOnClickListener(v -> manageDrafts.onSubmit(prepareDraft(statusList, this, account.instance, account.user_id))); } } diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index 7d8b1ecab..73f5bf0e1 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -1201,6 +1201,7 @@ public class StatusAdapter extends RecyclerView.Adapter StatusDraft statusDraft = new StatusDraft(); statusDraft.statusDraftList = new ArrayList<>(); statusDraft.statusReplyList = new ArrayList<>(); + statusDeleted.id = null; statusDraft.statusDraftList.add(statusDeleted); intent.putExtra(Helper.ARG_STATUS_DRAFT, statusDraft); context.startActivity(intent);