Search in sources :

Example 1 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by tuskyapp.

the class StatusBaseViewHolder method setMediaPreviews.

private void setMediaPreviews(final Attachment[] attachments, boolean sensitive, final StatusActionListener listener, boolean showingContent) {
    final ImageView[] previews = { mediaPreview0, mediaPreview1, mediaPreview2, mediaPreview3 };
    final ImageView[] overlays = { mediaOverlay0, mediaOverlay1, mediaOverlay2, mediaOverlay3 };
    Context context = mediaPreview0.getContext();
    int mediaPreviewUnloadedId = ThemeUtils.getDrawableId(itemView.getContext(), R.attr.media_preview_unloaded_drawable, android.R.color.black);
    final int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
    final String[] urls = new String[n];
    for (int i = 0; i < n; i++) {
        urls[i] = attachments[i].getUrl();
    }
    for (int i = 0; i < n; i++) {
        String previewUrl = attachments[i].getPreviewUrl();
        String description = attachments[i].getDescription();
        if (TextUtils.isEmpty(description)) {
            previews[i].setContentDescription(context.getString(R.string.action_view_media));
        } else {
            previews[i].setContentDescription(description);
        }
        previews[i].setVisibility(View.VISIBLE);
        if (TextUtils.isEmpty(previewUrl)) {
            Picasso.with(context).load(mediaPreviewUnloadedId).into(previews[i]);
        } else {
            Picasso.with(context).load(previewUrl).placeholder(mediaPreviewUnloadedId).into(previews[i]);
        }
        final Attachment.Type type = attachments[i].getType();
        if (type == Attachment.Type.VIDEO | type == Attachment.Type.GIFV) {
            overlays[i].setVisibility(View.VISIBLE);
        } else {
            overlays[i].setVisibility(View.GONE);
        }
        if (urls[i] == null || urls[i].isEmpty()) {
            previews[i].setOnClickListener(null);
        } else {
            final int urlIndex = i;
            previews[i].setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    listener.onViewMedia(urls, urlIndex, type, v);
                }
            });
        }
        if (n <= 2) {
            previews[0].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
            previews[1].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
        } else {
            previews[0].getLayoutParams().height = getMediaPreviewHeight(context);
            previews[1].getLayoutParams().height = getMediaPreviewHeight(context);
            previews[2].getLayoutParams().height = getMediaPreviewHeight(context);
            previews[3].getLayoutParams().height = getMediaPreviewHeight(context);
        }
    }
    String hiddenContentText;
    if (sensitive) {
        hiddenContentText = context.getString(R.string.status_sensitive_media_template, context.getString(R.string.status_sensitive_media_title), context.getString(R.string.status_sensitive_media_directions));
    } else {
        hiddenContentText = context.getString(R.string.status_sensitive_media_template, context.getString(R.string.status_media_hidden_title), context.getString(R.string.status_sensitive_media_directions));
    }
    sensitiveMediaWarning.setText(HtmlUtils.fromHtml(hiddenContentText));
    sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
    sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
    sensitiveMediaShow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getAdapterPosition() != RecyclerView.NO_POSITION) {
                listener.onContentHiddenChange(false, getAdapterPosition());
            }
            v.setVisibility(View.GONE);
            sensitiveMediaWarning.setVisibility(View.VISIBLE);
        }
    });
    sensitiveMediaWarning.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (getAdapterPosition() != RecyclerView.NO_POSITION) {
                listener.onContentHiddenChange(true, getAdapterPosition());
            }
            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++) {
        previews[i].setVisibility(View.GONE);
    }
}
Also used : Context(android.content.Context) Attachment(com.keylesspalace.tusky.entity.Attachment) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 2 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by tuskyapp.

the class StatusBaseViewHolder method setMediaLabel.

private void setMediaLabel(Attachment[] attachments, boolean sensitive, final StatusActionListener listener) {
    if (attachments.length == 0) {
        mediaLabel.setVisibility(View.GONE);
        return;
    }
    mediaLabel.setVisibility(View.VISIBLE);
    // Set the label's text.
    Context context = itemView.getContext();
    String labelText = getLabelTypeText(context, attachments[0].getType());
    if (sensitive) {
        String sensitiveText = context.getString(R.string.status_sensitive_media_title);
        labelText += String.format(" (%s)", sensitiveText);
    }
    mediaLabel.setText(labelText);
    // Set the icon next to the label.
    int drawableId = getLabelIcon(attachments[0].getType());
    Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
    ThemeUtils.setDrawableTint(context, drawable, android.R.attr.textColorTertiary);
    mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
    // Set the listener for the media view action.
    int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
    final String[] urls = new String[n];
    for (int i = 0; i < n; i++) {
        urls[i] = attachments[i].getUrl();
    }
    final Attachment.Type type = attachments[0].getType();
    mediaLabel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            listener.onViewMedia(urls, 0, type, null);
        }
    });
}
Also used : Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) Attachment(com.keylesspalace.tusky.entity.Attachment) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 3 with Attachment

use of com.keylesspalace.tusky.entity.Attachment 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)

Example 4 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by Vavassor.

the class StatusBaseViewHolder method setMediaLabel.

protected void setMediaLabel(List<Attachment> attachments, boolean sensitive, final StatusActionListener listener, boolean showingContent) {
    Context context = itemView.getContext();
    for (int i = 0; i < mediaLabels.length; i++) {
        TextView mediaLabel = mediaLabels[i];
        if (i < attachments.size()) {
            Attachment attachment = attachments.get(i);
            mediaLabel.setVisibility(View.VISIBLE);
            mediaDescriptions[i] = getAttachmentDescription(context, attachment);
            updateMediaLabel(i, sensitive, showingContent);
            // Set the icon next to the label.
            int drawableId = getLabelIcon(attachments.get(0).getType());
            mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawableId, 0, 0, 0);
            setAttachmentClickListener(mediaLabel, listener, i, attachment, false);
        } else {
            mediaLabel.setVisibility(View.GONE);
        }
    }
}
Also used : Context(android.content.Context) TextView(android.widget.TextView) Attachment(com.keylesspalace.tusky.entity.Attachment)

Example 5 with Attachment

use of com.keylesspalace.tusky.entity.Attachment in project Tusky by Vavassor.

the class StatusBaseViewHolder method setupWithStatus.

public void setupWithStatus(StatusViewData.Concrete status, final StatusActionListener listener, StatusDisplayOptions statusDisplayOptions, @Nullable Object payloads) {
    if (payloads == null) {
        Status actionable = status.getActionable();
        setDisplayName(actionable.getAccount().getDisplayName(), actionable.getAccount().getEmojis(), statusDisplayOptions);
        setUsername(status.getUsername());
        setCreatedAt(actionable.getCreatedAt(), statusDisplayOptions);
        setIsReply(actionable.getInReplyToId() != null);
        setAvatar(actionable.getAccount().getAvatar(), status.getRebloggedAvatar(), actionable.getAccount().getBot(), statusDisplayOptions);
        setReblogged(actionable.getReblogged());
        setFavourited(actionable.getFavourited());
        setBookmarked(actionable.getBookmarked());
        List<Attachment> attachments = actionable.getAttachments();
        boolean sensitive = actionable.getSensitive();
        if (statusDisplayOptions.mediaPreviewEnabled() && hasPreviewableAttachment(attachments)) {
            setMediaPreviews(attachments, sensitive, listener, status.isShowingContent(), statusDisplayOptions.useBlurhash());
            if (attachments.size() == 0) {
                hideSensitiveMediaWarning();
            }
            // Hide the unused label.
            for (TextView mediaLabel : mediaLabels) {
                mediaLabel.setVisibility(View.GONE);
            }
        } else {
            setMediaLabel(attachments, sensitive, listener, status.isShowingContent());
            // Hide all unused views.
            mediaPreviews[0].setVisibility(View.GONE);
            mediaPreviews[1].setVisibility(View.GONE);
            mediaPreviews[2].setVisibility(View.GONE);
            mediaPreviews[3].setVisibility(View.GONE);
            hideSensitiveMediaWarning();
        }
        if (cardView != null) {
            setupCard(status, statusDisplayOptions.cardViewMode(), statusDisplayOptions, listener);
        }
        setupButtons(listener, actionable.getAccount().getId(), status.getContent().toString(), statusDisplayOptions);
        setRebloggingEnabled(actionable.rebloggingAllowed(), actionable.getVisibility());
        setSpoilerAndContent(status.isExpanded(), status.getContent(), status.getSpoilerText(), actionable.getMentions(), actionable.getEmojis(), PollViewDataKt.toViewData(actionable.getPoll()), statusDisplayOptions, listener);
        setDescriptionForStatus(status, statusDisplayOptions);
        // Workaround for RecyclerView 1.0.0 / androidx.core 1.0.0
        // RecyclerView tries to set AccessibilityDelegateCompat to null
        // but ViewCompat code replaces is with the default one. RecyclerView never
        // fetches another one from its delegate because it checks that it's set so we remove it
        // and let RecyclerView ask for a new delegate.
        itemView.setAccessibilityDelegate(null);
    } else {
        if (payloads instanceof List)
            for (Object item : (List<?>) payloads) {
                if (Key.KEY_CREATED.equals(item)) {
                    setCreatedAt(status.getActionable().getCreatedAt(), statusDisplayOptions);
                }
            }
    }
}
Also used : Status(com.keylesspalace.tusky.entity.Status) Attachment(com.keylesspalace.tusky.entity.Attachment) TextView(android.widget.TextView) List(java.util.List)

Aggregations

Attachment (com.keylesspalace.tusky.entity.Attachment)9 TextView (android.widget.TextView)6 Context (android.content.Context)5 SuppressLint (android.annotation.SuppressLint)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 MimeTypeMap (android.webkit.MimeTypeMap)2 ImageView (android.widget.ImageView)2 ProgressRequestBody (com.keylesspalace.tusky.network.ProgressRequestBody)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 MultipartBody (okhttp3.MultipartBody)2 Manifest (android.Manifest)1 DownloadManager (android.app.DownloadManager)1 ProgressDialog (android.app.ProgressDialog)1 ContentResolver (android.content.ContentResolver)1 DialogInterface (android.content.DialogInterface)1