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
|
@ -416,15 +416,13 @@ 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)) {
|
||||
imageView.removeFocalPoint();
|
||||
|
||||
|
@ -432,7 +430,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
.load(placeholder)
|
||||
.centerInside()
|
||||
.into(imageView);
|
||||
|
||||
} else {
|
||||
Focus focus = meta != null ? meta.getFocus() : null;
|
||||
|
||||
|
@ -455,18 +452,20 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
.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());
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue