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 6f001fb5..5a30b66a 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 @@ -858,7 +858,8 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana dialog.dismiss(); }); - materialAlertDialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> { + materialAlertDialogBuilder.setNegativeButton(R.string.add_description, (dialog, id) -> { + composeAdapter.openMissingDescription(); dialog.cancel(); }); AlertDialog alert = materialAlertDialogBuilder.create(); 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 5a3cc06c..257adf8e 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 @@ -169,6 +169,8 @@ public class ComposeAdapter extends RecyclerView.Adapter emojisList = new ArrayList<>(); private boolean unlisted_changed = false; + private RecyclerView mRecyclerView; + public ComposeAdapter(List statusList, int statusCount, BaseAccount account, Account mentionedAccount, String visibility, String editMessageId) { this.statusList = statusList; this.statusCount = statusCount; @@ -1134,34 +1136,7 @@ public class ComposeAdapter extends RecyclerView.Adapter { - AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(context); - // builderInner.setTitle(R.string.upload_form_description); - PopupMediaDescriptionBinding popupMediaDescriptionBinding = PopupMediaDescriptionBinding.inflate(LayoutInflater.from(context), null, false); - builderInner.setView(popupMediaDescriptionBinding.getRoot()); - - popupMediaDescriptionBinding.mediaDescription.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); - popupMediaDescriptionBinding.mediaDescription.requestFocus(); - Glide.with(popupMediaDescriptionBinding.mediaPicture.getContext()) - .load(attachmentPath) - .apply(new RequestOptions().transform(new RoundedCorners(30))) - .into(popupMediaDescriptionBinding.mediaPicture); - builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); - if (attachment.description != null) { - popupMediaDescriptionBinding.mediaDescription.setText(attachment.description); - popupMediaDescriptionBinding.mediaDescription.setSelection(popupMediaDescriptionBinding.mediaDescription.getText().length()); - } - builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { - attachment.description = popupMediaDescriptionBinding.mediaDescription.getText().toString(); - displayAttachments(holder, position, finalMediaPosition); - dialog.dismiss(); - }); - AlertDialog alertDialog = builderInner.create(); - Objects.requireNonNull(alertDialog.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); - alertDialog.show(); - popupMediaDescriptionBinding.mediaDescription.requestFocus(); - - }); + composeAttachmentItemBinding.buttonDescription.setOnClickListener(v -> openDescription(holder, attachment, position, finalMediaPosition)); composeAttachmentItemBinding.buttonOrderUp.setOnClickListener(v -> { if (finalMediaPosition > 0 && attachmentList.size() > 1) { @@ -1231,6 +1206,66 @@ public class ComposeAdapter extends RecyclerView.Adapter 0) { + int mediaPosition = 0; + for (Attachment attachment : status.media_attachments) { + if (attachment.description == null || attachment.description.trim().isEmpty()) { + ComposeViewHolder composeViewHolder = (ComposeViewHolder) mRecyclerView.findViewHolderForAdapterPosition(position); + openDescription(composeViewHolder, attachment, position, mediaPosition); + return; + } + mediaPosition++; + } + } + } + position++; + } + } + + + private void openDescription(ComposeViewHolder holder, Attachment attachment, int messagePosition, int mediaPosition) { + String attachmentPath = attachment.local_path != null && !attachment.local_path.trim().isEmpty() ? attachment.local_path : attachment.preview_url; + AlertDialog.Builder builderInner = new MaterialAlertDialogBuilder(context); + // builderInner.setTitle(R.string.upload_form_description); + PopupMediaDescriptionBinding popupMediaDescriptionBinding = PopupMediaDescriptionBinding.inflate(LayoutInflater.from(context), null, false); + builderInner.setView(popupMediaDescriptionBinding.getRoot()); + + popupMediaDescriptionBinding.mediaDescription.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); + popupMediaDescriptionBinding.mediaDescription.requestFocus(); + Glide.with(popupMediaDescriptionBinding.mediaPicture.getContext()) + .load(attachmentPath) + .apply(new RequestOptions().transform(new RoundedCorners(30))) + .into(popupMediaDescriptionBinding.mediaPicture); + builderInner.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()); + if (attachment.description != null) { + popupMediaDescriptionBinding.mediaDescription.setText(attachment.description); + popupMediaDescriptionBinding.mediaDescription.setSelection(popupMediaDescriptionBinding.mediaDescription.getText().length()); + } + builderInner.setPositiveButton(R.string.validate, (dialog, which) -> { + attachment.description = popupMediaDescriptionBinding.mediaDescription.getText().toString(); + displayAttachments(holder, messagePosition, mediaPosition); + dialog.dismiss(); + }); + AlertDialog alertDialog = builderInner.create(); + Objects.requireNonNull(alertDialog.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + alertDialog.show(); + popupMediaDescriptionBinding.mediaDescription.requestFocus(); + } + /** * Manage state of media and poll button * diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1f24432f..1a945948 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1959,4 +1959,5 @@ Media cannot be loaded! Automatically fetch remote media when they are not available Fetching messages + Add a description \ No newline at end of file diff --git a/src/fdroid/fastlane/metadata/android/en/changelogs/485.txt b/src/fdroid/fastlane/metadata/android/en/changelogs/485.txt index de9fa0a6..142f1e40 100644 --- a/src/fdroid/fastlane/metadata/android/en/changelogs/485.txt +++ b/src/fdroid/fastlane/metadata/android/en/changelogs/485.txt @@ -1,5 +1,6 @@ Added: - Visual indicator when fetching missing messages +- Open media description when it is missing in the warning dialog Changed: - Maths formula aligned to the left