issue 2890: Add an "ALT" sticker to the media preview container (#2942)

* issue 2890: Add an "ALT" sticker to the media preview container if there are descriptions

* issue 2890: Use end and start for positioning

* issue 2890: Adapt to new media view group

* issue 2890: Use an indicator overlay for every (single) preview image

* issue 2890: Reduce radius to match that of the preview layout

* issue 2890: Remove (again) unused code

* issue 2890: Set visibility in any case

* issue 2890: Use a translatable text for ALT

* issue 2890: Show ALT flag only when showing media

* issue 2890: Call doOnLayout on the layout wrapper
This commit is contained in:
UlrichKu 2022-12-18 16:50:30 +01:00 committed by GitHub
commit 6aed1c6806
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 13 deletions

View file

@ -411,14 +411,15 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
return ImageLoadingHelper.decodeBlurHash(this.avatar.getContext(), blurhash);
}
private void loadImage(MediaPreviewImageView imageView,
private void loadImage(View wrapper,
MediaPreviewImageView imageView,
@Nullable String previewUrl,
@Nullable MetaData meta,
@Nullable String blurhash) {
Drawable placeholder = blurhash != null ? decodeBlurHash(blurhash) : mediaPreviewUnloaded;
ViewKt.doOnLayout(imageView, view -> {
ViewKt.doOnLayout(wrapper, view -> {
if (TextUtils.isEmpty(previewUrl)) {
imageView.removeFocalPoint();
@ -433,7 +434,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (focus != null) { // If there is a focal point for this attachment:
imageView.setFocalPoint(focus);
Glide.with(imageView)
Glide.with(imageView.getContext())
.load(previewUrl)
.placeholder(placeholder)
.centerInside()
@ -460,19 +461,21 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
mediaPreview.setVisibility(View.VISIBLE);
mediaPreview.setAspectRatios(AttachmentHelper.aspectRatios(attachments));
mediaPreview.forEachIndexed((i, imageView) -> {
mediaPreview.forEachIndexed((i, wrapper, imageView, descriptionIndicator) -> {
Attachment attachment = attachments.get(i);
String previewUrl = attachment.getPreviewUrl();
String description = attachment.getDescription();
boolean hasDescription = !TextUtils.isEmpty(description);
if (TextUtils.isEmpty(description)) {
imageView.setContentDescription(imageView.getContext()
.getString(R.string.action_view_media));
} else {
if (hasDescription) {
imageView.setContentDescription(description);
} 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(),
@ -502,6 +505,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}
v.setVisibility(View.GONE);
sensitiveMediaWarning.setVisibility(View.VISIBLE);
descriptionIndicator.setVisibility(View.GONE);
});
sensitiveMediaWarning.setOnClickListener(v -> {
if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
@ -509,6 +513,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}
v.setVisibility(View.GONE);
sensitiveMediaShow.setVisibility(View.VISIBLE);
descriptionIndicator.setVisibility(hasDescription ? View.VISIBLE : View.GONE);
});
return null;

View file

@ -2,9 +2,11 @@ package com.keylesspalace.tusky.view
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.keylesspalace.tusky.R
import kotlin.math.roundToInt
@ -26,7 +28,9 @@ class MediaPreviewLayout(context: Context, attrs: AttributeSet? = null) :
attachImageViews()
}
private val imageViewCache = Array(4) { MediaPreviewImageView(context) }
private val imageViewCache = Array(4) {
LayoutInflater.from(context).inflate(R.layout.item_image_preview_overlay, this, false)
}
private var measuredOrientation = LinearLayout.VERTICAL
@ -180,9 +184,15 @@ class MediaPreviewLayout(context: Context, attrs: AttributeSet? = null) :
}
}
inline fun forEachIndexed(action: (Int, MediaPreviewImageView) -> Unit) {
inline fun forEachIndexed(action: (Int, View, MediaPreviewImageView, TextView) -> Unit) {
for (index in 0 until childCount) {
action(index, getChildAt(index) as MediaPreviewImageView)
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
)
}
}
}