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:
parent
865ba5909f
commit
98eb324aa0
3 changed files with 37 additions and 38 deletions
|
@ -416,15 +416,13 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
return ImageLoadingHelper.decodeBlurHash(this.avatar.getContext(), blurhash);
|
return ImageLoadingHelper.decodeBlurHash(this.avatar.getContext(), blurhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadImage(View wrapper,
|
private void loadImage(MediaPreviewImageView imageView,
|
||||||
MediaPreviewImageView imageView,
|
|
||||||
@Nullable String previewUrl,
|
@Nullable String previewUrl,
|
||||||
@Nullable MetaData meta,
|
@Nullable MetaData meta,
|
||||||
@Nullable String blurhash) {
|
@Nullable String blurhash) {
|
||||||
|
|
||||||
Drawable placeholder = blurhash != null ? decodeBlurHash(blurhash) : mediaPreviewUnloaded;
|
Drawable placeholder = blurhash != null ? decodeBlurHash(blurhash) : mediaPreviewUnloaded;
|
||||||
|
|
||||||
ViewKt.doOnLayout(wrapper, view -> {
|
|
||||||
if (TextUtils.isEmpty(previewUrl)) {
|
if (TextUtils.isEmpty(previewUrl)) {
|
||||||
imageView.removeFocalPoint();
|
imageView.removeFocalPoint();
|
||||||
|
|
||||||
|
@ -432,7 +430,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
.load(placeholder)
|
.load(placeholder)
|
||||||
.centerInside()
|
.centerInside()
|
||||||
.into(imageView);
|
.into(imageView);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Focus focus = meta != null ? meta.getFocus() : null;
|
Focus focus = meta != null ? meta.getFocus() : null;
|
||||||
|
|
||||||
|
@ -455,18 +452,20 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
.into(imageView);
|
.into(imageView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setMediaPreviews(final List<Attachment> attachments, boolean sensitive,
|
protected void setMediaPreviews(
|
||||||
final StatusActionListener listener, boolean showingContent,
|
final List<Attachment> attachments,
|
||||||
boolean useBlurhash) {
|
boolean sensitive,
|
||||||
|
final StatusActionListener listener,
|
||||||
|
boolean showingContent,
|
||||||
|
boolean useBlurhash
|
||||||
|
) {
|
||||||
|
|
||||||
mediaPreview.setVisibility(View.VISIBLE);
|
mediaPreview.setVisibility(View.VISIBLE);
|
||||||
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments));
|
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments));
|
||||||
|
|
||||||
mediaPreview.forEachIndexed((i, wrapper, imageView, descriptionIndicator) -> {
|
mediaPreview.forEachIndexed((i, imageView, descriptionIndicator) -> {
|
||||||
Attachment attachment = attachments.get(i);
|
Attachment attachment = attachments.get(i);
|
||||||
String previewUrl = attachment.getPreviewUrl();
|
String previewUrl = attachment.getPreviewUrl();
|
||||||
String description = attachment.getDescription();
|
String description = attachment.getDescription();
|
||||||
|
@ -477,10 +476,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
} else {
|
} else {
|
||||||
imageView.setContentDescription(imageView.getContext().getString(R.string.action_view_media));
|
imageView.setContentDescription(imageView.getContext().getString(R.string.action_view_media));
|
||||||
}
|
}
|
||||||
descriptionIndicator.setVisibility(hasDescription ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
loadImage(
|
loadImage(
|
||||||
wrapper,
|
|
||||||
imageView,
|
imageView,
|
||||||
showingContent ? previewUrl : null,
|
showingContent ? previewUrl : null,
|
||||||
attachment.getMeta(),
|
attachment.getMeta(),
|
||||||
|
@ -504,6 +501,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
|
sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
|
||||||
sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
|
sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
descriptionIndicator.setVisibility(hasDescription && showingContent ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
sensitiveMediaShow.setOnClickListener(v -> {
|
sensitiveMediaShow.setOnClickListener(v -> {
|
||||||
if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
|
if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
|
||||||
listener.onContentHiddenChange(false, getBindingAdapterPosition());
|
listener.onContentHiddenChange(false, getBindingAdapterPosition());
|
||||||
|
|
|
@ -129,7 +129,7 @@ class ViewEditsAdapter(
|
||||||
binding.statusEditMediaPreview.show()
|
binding.statusEditMediaPreview.show()
|
||||||
binding.statusEditMediaPreview.aspectRatios = edit.mediaAttachments.aspectRatios()
|
binding.statusEditMediaPreview.aspectRatios = edit.mediaAttachments.aspectRatios()
|
||||||
|
|
||||||
binding.statusEditMediaPreview.forEachIndexed { index, _, imageView, descriptionIndicator ->
|
binding.statusEditMediaPreview.forEachIndexed { index, imageView, descriptionIndicator ->
|
||||||
|
|
||||||
val attachment = edit.mediaAttachments[index]
|
val attachment = edit.mediaAttachments[index]
|
||||||
val hasDescription = !attachment.description.isNullOrBlank()
|
val hasDescription = !attachment.description.isNullOrBlank()
|
||||||
|
|
|
@ -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) {
|
for (index in 0 until childCount) {
|
||||||
val wrapper = getChildAt(index)
|
val wrapper = getChildAt(index)
|
||||||
action(
|
action(
|
||||||
index,
|
index,
|
||||||
wrapper,
|
|
||||||
wrapper.findViewById(R.id.preview_image_view) as MediaPreviewImageView,
|
wrapper.findViewById(R.id.preview_image_view) as MediaPreviewImageView,
|
||||||
wrapper.findViewById(R.id.preview_media_description_indicator) as TextView
|
wrapper.findViewById(R.id.preview_media_description_indicator) as TextView
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue