Search in sources :

Example 1 with MediaPreviewImageView

use of com.keylesspalace.tusky.view.MediaPreviewImageView in project Tusky by Vavassor.

the class StatusBaseViewHolder method setMediaPreviews.

protected void setMediaPreviews(final List<Attachment> attachments, boolean sensitive, final StatusActionListener listener, boolean showingContent, boolean useBlurhash) {
    Context context = itemView.getContext();
    final int n = Math.min(attachments.size(), Status.MAX_MEDIA_ATTACHMENTS);
    final int mediaPreviewHeight = getMediaPreviewHeight(context);
    if (n <= 2) {
        mediaPreviews[0].getLayoutParams().height = mediaPreviewHeight * 2;
        mediaPreviews[1].getLayoutParams().height = mediaPreviewHeight * 2;
    } else {
        mediaPreviews[0].getLayoutParams().height = mediaPreviewHeight;
        mediaPreviews[1].getLayoutParams().height = mediaPreviewHeight;
        mediaPreviews[2].getLayoutParams().height = mediaPreviewHeight;
        mediaPreviews[3].getLayoutParams().height = mediaPreviewHeight;
    }
    for (int i = 0; i < n; i++) {
        Attachment attachment = attachments.get(i);
        String previewUrl = attachment.getPreviewUrl();
        String description = attachment.getDescription();
        MediaPreviewImageView imageView = mediaPreviews[i];
        imageView.setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(description)) {
            imageView.setContentDescription(imageView.getContext().getString(R.string.action_view_media));
        } else {
            imageView.setContentDescription(description);
        }
        loadImage(imageView, showingContent ? previewUrl : null, attachment.getMeta(), useBlurhash ? attachment.getBlurhash() : null);
        final Attachment.Type type = attachment.getType();
        if (showingContent && (type == Attachment.Type.VIDEO || type == Attachment.Type.GIFV)) {
            mediaOverlays[i].setVisibility(View.VISIBLE);
        } else {
            mediaOverlays[i].setVisibility(View.GONE);
        }
        setAttachmentClickListener(imageView, listener, i, attachment, true);
    }
    if (sensitive) {
        sensitiveMediaWarning.setText(R.string.status_sensitive_media_title);
    } else {
        sensitiveMediaWarning.setText(R.string.status_media_hidden_title);
    }
    sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
    sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
    sensitiveMediaShow.setOnClickListener(v -> {
        if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
            listener.onContentHiddenChange(false, getBindingAdapterPosition());
        }
        v.setVisibility(View.GONE);
        sensitiveMediaWarning.setVisibility(View.VISIBLE);
    });
    sensitiveMediaWarning.setOnClickListener(v -> {
        if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
            listener.onContentHiddenChange(true, getBindingAdapterPosition());
        }
        v.setVisibility(View.GONE);
        sensitiveMediaShow.setVisibility(View.VISIBLE);
    });
    // Hide any of the placeholder previews beyond the ones set.
    for (int i = n; i < Status.MAX_MEDIA_ATTACHMENTS; i++) {
        mediaPreviews[i].setVisibility(View.GONE);
    }
}
Also used : Context(android.content.Context) Attachment(com.keylesspalace.tusky.entity.Attachment) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView)

Aggregations

Context (android.content.Context)1 Attachment (com.keylesspalace.tusky.entity.Attachment)1 MediaPreviewImageView (com.keylesspalace.tusky.view.MediaPreviewImageView)1