Search in sources :

Example 1 with GranularRoundedCorners

use of com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners in project Tusky by Vavassor.

the class StatusBaseViewHolder method setupCard.

protected void setupCard(StatusViewData.Concrete status, CardViewMode cardViewMode, StatusDisplayOptions statusDisplayOptions, final StatusActionListener listener) {
    final Card card = status.getActionable().getCard();
    if (cardViewMode != CardViewMode.NONE && status.getActionable().getAttachments().size() == 0 && card != null && !TextUtils.isEmpty(card.getUrl()) && (!status.isCollapsible() || !status.isCollapsed())) {
        cardView.setVisibility(View.VISIBLE);
        cardTitle.setText(card.getTitle());
        if (TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) {
            cardDescription.setVisibility(View.GONE);
        } else {
            cardDescription.setVisibility(View.VISIBLE);
            if (TextUtils.isEmpty(card.getDescription())) {
                cardDescription.setText(card.getAuthorName());
            } else {
                cardDescription.setText(card.getDescription());
            }
        }
        cardUrl.setText(card.getUrl());
        // If media previews are disabled, show placeholder for cards as well
        if (statusDisplayOptions.mediaPreviewEnabled() && !status.getActionable().getSensitive() && !TextUtils.isEmpty(card.getImage())) {
            int topLeftRadius = 0;
            int topRightRadius = 0;
            int bottomRightRadius = 0;
            int bottomLeftRadius = 0;
            int radius = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_radius);
            if (card.getWidth() > card.getHeight()) {
                cardView.setOrientation(LinearLayout.VERTICAL);
                cardImage.getLayoutParams().height = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_vertical_height);
                cardImage.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
                topLeftRadius = radius;
                topRightRadius = radius;
            } else {
                cardView.setOrientation(LinearLayout.HORIZONTAL);
                cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
                cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
                cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                topLeftRadius = radius;
                bottomLeftRadius = radius;
            }
            RequestBuilder<Drawable> builder = Glide.with(cardImage).load(card.getImage());
            if (statusDisplayOptions.useBlurhash() && !TextUtils.isEmpty(card.getBlurhash())) {
                builder = builder.placeholder(decodeBlurHash(card.getBlurhash()));
            }
            builder.transform(new CenterCrop(), new GranularRoundedCorners(topLeftRadius, topRightRadius, bottomRightRadius, bottomLeftRadius)).into(cardImage);
        } else if (statusDisplayOptions.useBlurhash() && !TextUtils.isEmpty(card.getBlurhash())) {
            int radius = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_radius);
            cardView.setOrientation(LinearLayout.HORIZONTAL);
            cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
            cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
            Glide.with(cardImage).load(decodeBlurHash(card.getBlurhash())).transform(new CenterCrop(), new GranularRoundedCorners(radius, 0, 0, radius)).into(cardImage);
        } else {
            cardView.setOrientation(LinearLayout.HORIZONTAL);
            cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.getLayoutParams().width = cardImage.getContext().getResources().getDimensionPixelSize(R.dimen.card_image_horizontal_width);
            cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
            cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
            cardImage.setImageResource(R.drawable.card_image_placeholder);
        }
        View.OnClickListener visitLink = v -> listener.onViewUrl(card.getUrl());
        View.OnClickListener openImage = v -> cardView.getContext().startActivity(ViewMediaActivity.newSingleImageIntent(cardView.getContext(), card.getEmbed_url()));
        cardInfo.setOnClickListener(visitLink);
        // View embedded photos in our image viewer instead of opening the browser
        cardImage.setOnClickListener(card.getType().equals(Card.TYPE_PHOTO) && !TextUtils.isEmpty(card.getEmbed_url()) ? openImage : visitLink);
        cardView.setClipToOutline(true);
    } else {
        cardView.setVisibility(View.GONE);
    }
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) DateUtils(android.text.format.DateUtils) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) RequestBuilder(com.bumptech.glide.RequestBuilder) Utils(at.connyduck.sparkbutton.helpers.Utils) ColorDrawable(android.graphics.drawable.ColorDrawable) DrawableRes(androidx.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) Card(com.keylesspalace.tusky.entity.Card) Locale(java.util.Locale) View(android.view.View) Button(android.widget.Button) MetaData(com.keylesspalace.tusky.entity.Attachment.MetaData) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewMediaActivity(com.keylesspalace.tusky.ViewMediaActivity) SparkButton(at.connyduck.sparkbutton.SparkButton) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) Focus(com.keylesspalace.tusky.entity.Attachment.Focus) StatusViewData(com.keylesspalace.tusky.viewdata.StatusViewData) StatusActionListener(com.keylesspalace.tusky.interfaces.StatusActionListener) HtmlCompat(androidx.core.text.HtmlCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ViewGroup(android.view.ViewGroup) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) StatusDisplayOptions(com.keylesspalace.tusky.util.StatusDisplayOptions) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Attachment(com.keylesspalace.tusky.entity.Attachment) PollOptionViewData(com.keylesspalace.tusky.viewdata.PollOptionViewData) CollectionsKt(kotlin.collections.CollectionsKt) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TimestampUtils(com.keylesspalace.tusky.util.TimestampUtils) PollViewDataKt(com.keylesspalace.tusky.viewdata.PollViewDataKt) Context(android.content.Context) Spanned(android.text.Spanned) AlertDialog(androidx.appcompat.app.AlertDialog) PollViewData(com.keylesspalace.tusky.viewdata.PollViewData) Status(com.keylesspalace.tusky.entity.Status) SimpleDateFormat(java.text.SimpleDateFormat) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) NumberFormat(java.text.NumberFormat) MaterialButton(com.google.android.material.button.MaterialButton) R(com.keylesspalace.tusky.R) CardViewMode(com.keylesspalace.tusky.util.CardViewMode) CustomEmojiHelper(com.keylesspalace.tusky.util.CustomEmojiHelper) Toast(android.widget.Toast) PollViewDataKt.buildDescription(com.keylesspalace.tusky.viewdata.PollViewDataKt.buildDescription) ThemeUtils(com.keylesspalace.tusky.util.ThemeUtils) Emoji(com.keylesspalace.tusky.entity.Emoji) LinkHelper(com.keylesspalace.tusky.util.LinkHelper) TextUtils(android.text.TextUtils) Glide(com.bumptech.glide.Glide) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) ImageLoadingHelper(com.keylesspalace.tusky.util.ImageLoadingHelper) GranularRoundedCorners(com.bumptech.glide.load.resource.bitmap.GranularRoundedCorners) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MediaPreviewImageView(com.keylesspalace.tusky.view.MediaPreviewImageView) Card(com.keylesspalace.tusky.entity.Card)

Aggregations

Context (android.content.Context)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Spanned (android.text.Spanned)1 TextUtils (android.text.TextUtils)1 DateUtils (android.text.format.DateUtils)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 DrawableRes (androidx.annotation.DrawableRes)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 HtmlCompat (androidx.core.text.HtmlCompat)1