diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java index d6b6eb74..71045432 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/ComposeActivity.java @@ -35,6 +35,7 @@ import android.os.Looper; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; +import android.util.Log; import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; @@ -552,16 +553,13 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana status.text = scheduledStatus.params.text; status.in_reply_to_id = scheduledStatus.params.in_reply_to_id; status.poll = scheduledStatus.params.poll; - if (scheduledStatus.params.media_ids != null && !scheduledStatus.params.media_ids.isEmpty()) { status.media_attachments = new ArrayList<>(); - new Thread(() -> { - StatusesVM statusesVM = new ViewModelProvider(ComposeActivity.this).get(StatusesVM.class); - for (String attachmentId : scheduledStatus.params.media_ids) { - statusesVM.getAttachment(instance, token, attachmentId) - .observe(ComposeActivity.this, attachment -> status.media_attachments.add(attachment)); - } - }).start(); + for (String attachmentId : scheduledStatus.params.media_ids) { + Attachment attachment = new Attachment(); + attachment.id = attachmentId; + status.media_attachments.add(attachment); + } } status.sensitive = scheduledStatus.params.sensitive; status.spoiler_text = scheduledStatus.params.spoiler_text; 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 38e9a388..85a52a7d 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 @@ -19,7 +19,6 @@ import static android.content.Context.INPUT_METHOD_SERVICE; import static app.fedilab.android.BaseMainActivity.emojis; import static app.fedilab.android.BaseMainActivity.instanceInfo; import static app.fedilab.android.mastodon.activities.ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE; -import static app.fedilab.android.mastodon.helper.Helper.TAG; import static de.timfreiheit.mathjax.android.MathJaxConfig.Input.TeX; import android.Manifest; @@ -134,6 +133,7 @@ import app.fedilab.android.mastodon.helper.ThemeHelper; import app.fedilab.android.mastodon.imageeditor.EditImageActivity; import app.fedilab.android.mastodon.viewmodel.mastodon.AccountsVM; import app.fedilab.android.mastodon.viewmodel.mastodon.SearchVM; +import app.fedilab.android.mastodon.viewmodel.mastodon.StatusesVM; import de.timfreiheit.mathjax.android.MathJaxConfig; import de.timfreiheit.mathjax.android.MathJaxView; import es.dmoral.toasty.Toasty; @@ -1134,7 +1134,7 @@ public class ComposeAdapter extends RecyclerView.Adapter position && statusList.get(position).media_attachments != null) { holder.binding.attachmentsList.removeAllViews(); List attachmentList = statusList.get(position).media_attachments; - if (attachmentList != null && attachmentList.size() > 0) { + if (attachmentList != null && !attachmentList.isEmpty()) { holder.binding.sensitiveMedia.setVisibility(View.VISIBLE); if (!statusList.get(position).sensitive) { if (Helper.getCurrentAccount(context) != null && Helper.getCurrentAccount(context).mastodon_account != null && Helper.getCurrentAccount(context).mastodon_account.source != null) { @@ -1148,6 +1148,21 @@ public class ComposeAdapter extends RecyclerView.Adapter statusList.get(position).sensitive = isChecked); int mediaPosition = 0; for (Attachment attachment : attachmentList) { + if(attachment.url == null) { + StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); + statusesVM.getAttachment(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, attachment.id) + .observe((LifecycleOwner) context, attachmentReceived -> { + List attachments = statusList.get(position).media_attachments; + for(Attachment attach : attachments) { + if(attach.id.equals(attachment.id)) { + statusList.get(position).media_attachments.remove(attachment); + break; + } + } + statusList.get(position).media_attachments.add(attachmentReceived); + notifyItemChanged(position); + }); + } ComposeAttachmentItemBinding composeAttachmentItemBinding = ComposeAttachmentItemBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false); composeAttachmentItemBinding.buttonPlay.setVisibility(View.GONE); String attachmentPath = attachment.local_path != null && !attachment.local_path.trim().isEmpty() ? attachment.local_path : attachment.preview_url;