diff --git a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java index 5ce8954a0..e568a5a01 100644 --- a/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java +++ b/app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java @@ -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 attachments, boolean sensitive, - final StatusActionListener listener, boolean showingContent, - boolean useBlurhash) { + protected void setMediaPreviews( + final List 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()); diff --git a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/edits/ViewEditsAdapter.kt b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/edits/ViewEditsAdapter.kt index 08c4a65f5..931f88b81 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/viewthread/edits/ViewEditsAdapter.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/viewthread/edits/ViewEditsAdapter.kt @@ -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() diff --git a/app/src/main/java/com/keylesspalace/tusky/view/MediaPreviewLayout.kt b/app/src/main/java/com/keylesspalace/tusky/view/MediaPreviewLayout.kt index 9680345f8..854b72009 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/MediaPreviewLayout.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/MediaPreviewLayout.kt @@ -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 )