Fix a crash when adding a media

This commit is contained in:
Thomas 2025-03-06 10:16:16 +01:00
parent 65dea8bf56
commit ab30fc7bf2
2 changed files with 11 additions and 9 deletions

View file

@ -1152,15 +1152,17 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class); StatusesVM statusesVM = new ViewModelProvider((ViewModelStoreOwner) context).get(StatusesVM.class);
statusesVM.getAttachment(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, attachment.id) statusesVM.getAttachment(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, attachment.id)
.observe((LifecycleOwner) context, attachmentReceived -> { .observe((LifecycleOwner) context, attachmentReceived -> {
if(attachmentReceived != null) {
List<Attachment> attachments = statusList.get(position).media_attachments; List<Attachment> attachments = statusList.get(position).media_attachments;
for(Attachment attach : attachments) { for(Attachment attach : attachments) {
if(attach.id.equals(attachment.id)) { if(attach.id != null && attach.id.equals(attachment.id)) {
statusList.get(position).media_attachments.remove(attachment); statusList.get(position).media_attachments.remove(attachment);
break; break;
} }
} }
statusList.get(position).media_attachments.add(attachmentReceived); statusList.get(position).media_attachments.add(attachmentReceived);
notifyItemChanged(position); notifyItemChanged(position);
}
}); });
} }
ComposeAttachmentItemBinding composeAttachmentItemBinding = ComposeAttachmentItemBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false); ComposeAttachmentItemBinding composeAttachmentItemBinding = ComposeAttachmentItemBinding.inflate(LayoutInflater.from(context), holder.binding.attachmentsList, false);

View file

@ -135,9 +135,9 @@ public class StatusDraftAdapter extends RecyclerView.Adapter<StatusDraftAdapter.
} }
} }
//If there are media, we need to remove them first. //If there are media, we need to remove them first.
if (attachments.size() > 0) { if (!attachments.isEmpty()) {
for (Attachment attachment : attachments) { for (Attachment attachment : attachments) {
if (attachment.local_path != null) { if (attachment != null && attachment.local_path != null) {
File fileToDelete = new File(attachment.local_path); File fileToDelete = new File(attachment.local_path);
if (fileToDelete.exists()) { if (fileToDelete.exists()) {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored