Fix media preview bugs (#3160)

* fix media preview layout issues

* make sure "ALT" label is never shown when media preview is hidden
This commit is contained in:
Konrad Pozniak 2023-01-12 19:40:51 +01:00 committed by GitHub
parent 865ba5909f
commit 98eb324aa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 38 deletions

View file

@ -416,57 +416,56 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
return ImageLoadingHelper.decodeBlurHash(this.avatar.getContext(), blurhash);
}
private void loadImage(View wrapper,
MediaPreviewImageView imageView,
private void loadImage(MediaPreviewImageView imageView,
@Nullable String previewUrl,
@Nullable MetaData meta,
@Nullable String blurhash) {
Drawable placeholder = blurhash != null ? decodeBlurHash(blurhash) : mediaPreviewUnloaded;
ViewKt.doOnLayout(wrapper, view -> {
if (TextUtils.isEmpty(previewUrl)) {
if (TextUtils.isEmpty(previewUrl)) {
imageView.removeFocalPoint();
Glide.with(imageView)
.load(placeholder)
.centerInside()
.into(imageView);
} else {
Focus focus = meta != null ? meta.getFocus() : null;
if (focus != null) { // If there is a focal point for this attachment:
imageView.setFocalPoint(focus);
Glide.with(imageView.getContext())
.load(previewUrl)
.placeholder(placeholder)
.centerInside()
.addListener(imageView)
.into(imageView);
} else {
imageView.removeFocalPoint();
Glide.with(imageView)
.load(placeholder)
.load(previewUrl)
.placeholder(placeholder)
.centerInside()
.into(imageView);
} else {
Focus focus = meta != null ? meta.getFocus() : null;
if (focus != null) { // If there is a focal point for this attachment:
imageView.setFocalPoint(focus);
Glide.with(imageView.getContext())
.load(previewUrl)
.placeholder(placeholder)
.centerInside()
.addListener(imageView)
.into(imageView);
} else {
imageView.removeFocalPoint();
Glide.with(imageView)
.load(previewUrl)
.placeholder(placeholder)
.centerInside()
.into(imageView);
}
}
return null;
});
}
}
protected void setMediaPreviews(final List<Attachment> attachments, boolean sensitive,
final StatusActionListener listener, boolean showingContent,
boolean useBlurhash) {
protected void setMediaPreviews(
final List<Attachment> attachments,
boolean sensitive,
final StatusActionListener listener,
boolean showingContent,
boolean useBlurhash
) {
mediaPreview.setVisibility(View.VISIBLE);
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments));
mediaPreview.forEachIndexed((i, wrapper, imageView, descriptionIndicator) -> {
mediaPreview.forEachIndexed((i, imageView, descriptionIndicator) -> {
Attachment attachment = attachments.get(i);
String previewUrl = attachment.getPreviewUrl();
String description = attachment.getDescription();
@ -477,10 +476,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} else {
imageView.setContentDescription(imageView.getContext().getString(R.string.action_view_media));
}
descriptionIndicator.setVisibility(hasDescription ? View.VISIBLE : View.GONE);
loadImage(
wrapper,
imageView,
showingContent ? previewUrl : null,
attachment.getMeta(),
@ -504,6 +501,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
descriptionIndicator.setVisibility(hasDescription && showingContent ? View.VISIBLE : View.GONE);
sensitiveMediaShow.setOnClickListener(v -> {
if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onContentHiddenChange(false, getBindingAdapterPosition());

View file

@ -129,7 +129,7 @@ class ViewEditsAdapter(
binding.statusEditMediaPreview.show()
binding.statusEditMediaPreview.aspectRatios = edit.mediaAttachments.aspectRatios()
binding.statusEditMediaPreview.forEachIndexed { index, _, imageView, descriptionIndicator ->
binding.statusEditMediaPreview.forEachIndexed { index, imageView, descriptionIndicator ->
val attachment = edit.mediaAttachments[index]
val hasDescription = !attachment.description.isNullOrBlank()

View file

@ -184,12 +184,11 @@ class MediaPreviewLayout(context: Context, attrs: AttributeSet? = null) :
}
}
inline fun forEachIndexed(action: (Int, View, MediaPreviewImageView, TextView) -> Unit) {
inline fun forEachIndexed(action: (Int, MediaPreviewImageView, TextView) -> Unit) {
for (index in 0 until childCount) {
val wrapper = getChildAt(index)
action(
index,
wrapper,
wrapper.findViewById(R.id.preview_image_view) as MediaPreviewImageView,
wrapper.findViewById(R.id.preview_media_description_indicator) as TextView
)