diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java index 00ea52c9..7eb0ebdd 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Card.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Card.java @@ -11,6 +11,7 @@ import org.joinmastodon.android.ui.utils.BlurHashDecoder; import org.joinmastodon.android.ui.utils.BlurHashDrawable; import org.parceler.Parcel; +import java.time.Instant; import java.util.List; @Parcel @@ -34,11 +35,14 @@ public class Card extends BaseModel{ public String embedUrl; public String blurhash; public List history; + public Instant publishedAt; public transient Drawable blurhashPlaceholder; @Override public void postprocess() throws ObjectValidationException{ + if(type==null) + type=Type.LINK; super.postprocess(); if(blurhash!=null){ Bitmap placeholder=BlurHashDecoder.decode(blurhash, 16, 16); @@ -64,6 +68,7 @@ public class Card extends BaseModel{ ", embedUrl='"+embedUrl+'\''+ ", blurhash='"+blurhash+'\''+ ", history="+history+ + ", publishedAt="+publishedAt+ '}'; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java index 2be16125..3572242a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/LinkCardStatusDisplayItem.java @@ -1,6 +1,8 @@ package org.joinmastodon.android.ui.displayitems; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; import android.net.Uri; import android.text.TextUtils; @@ -13,6 +15,7 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.model.Card; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.drawables.BlurhashCrossfadeDrawable; import org.joinmastodon.android.ui.utils.UiUtils; @@ -35,7 +38,7 @@ public class LinkCardStatusDisplayItem extends StatusDisplayItem{ @Override public Type getType(){ - return Type.CARD; + return status.card.type==Card.Type.VIDEO || (status.card.image!=null && status.card.width>status.card.height) ? Type.CARD_LARGE : Type.CARD_COMPACT; } @Override @@ -49,36 +52,65 @@ public class LinkCardStatusDisplayItem extends StatusDisplayItem{ } public static class Holder extends StatusDisplayItem.Holder implements ImageLoaderViewHolder{ - private final TextView title, description, domain; + private final TextView title, description, domain, timestamp; private final ImageView photo; private BlurhashCrossfadeDrawable crossfadeDrawable=new BlurhashCrossfadeDrawable(); private boolean didClear; + private final View inner; + private final boolean isLarge; - public Holder(Context context, ViewGroup parent){ - super(context, R.layout.display_item_link_card, parent); + public Holder(Context context, ViewGroup parent, boolean isLarge){ + super(context, isLarge ? R.layout.display_item_link_card : R.layout.display_item_link_card_compact, parent); + this.isLarge=isLarge; title=findViewById(R.id.title); description=findViewById(R.id.description); domain=findViewById(R.id.domain); + timestamp=findViewById(R.id.timestamp); photo=findViewById(R.id.photo); - findViewById(R.id.inner).setOnClickListener(this::onClick); + inner=findViewById(R.id.inner); + inner.setOnClickListener(this::onClick); + inner.setOutlineProvider(OutlineProviders.roundedRect(12)); + inner.setClipToOutline(true); } + @SuppressLint("SetTextI18n") @Override public void onBind(LinkCardStatusDisplayItem item){ Card card=item.status.card; title.setText(card.title); - description.setText(card.description); - description.setVisibility(TextUtils.isEmpty(card.description) ? View.GONE : View.VISIBLE); - domain.setText(Uri.parse(card.url).getHost()); + if(description!=null){ + description.setText(card.description); + description.setVisibility(TextUtils.isEmpty(card.description) ? View.GONE : View.VISIBLE); + } + String cardDomain=Uri.parse(card.url).getHost(); + if(isLarge && !TextUtils.isEmpty(card.authorName)){ + domain.setText(itemView.getContext().getString(R.string.article_by_author, card.authorName)+" · "+cardDomain); + }else{ + domain.setText(cardDomain); + } + if(card.publishedAt!=null){ + timestamp.setVisibility(View.VISIBLE); + timestamp.setText(" · "+UiUtils.formatRelativeTimestamp(itemView.getContext(), card.publishedAt)); + }else{ + timestamp.setVisibility(View.GONE); + } photo.setImageDrawable(null); if(item.imgRequest!=null){ + photo.setScaleType(ImageView.ScaleType.CENTER_CROP); + photo.setBackground(null); + photo.setImageTintList(null); crossfadeDrawable.setSize(card.width, card.height); crossfadeDrawable.setBlurhashDrawable(card.blurhashPlaceholder); crossfadeDrawable.setCrossfadeAlpha(0f); photo.setImageDrawable(null); photo.setImageDrawable(crossfadeDrawable); didClear=false; + }else{ + photo.setBackgroundColor(UiUtils.getThemeColor(itemView.getContext(), R.attr.colorM3SurfaceVariant)); + photo.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(itemView.getContext(), R.attr.colorM3Outline))); + photo.setScaleType(ImageView.ScaleType.CENTER); + photo.setImageResource(R.drawable.ic_feed_48px); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java index 76d4fd92..eca37160 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java @@ -68,7 +68,8 @@ public abstract class StatusDisplayItem{ case AUDIO -> new AudioStatusDisplayItem.Holder(activity, parent); case POLL_OPTION -> new PollOptionStatusDisplayItem.Holder(activity, parent); case POLL_FOOTER -> new PollFooterStatusDisplayItem.Holder(activity, parent); - case CARD -> new LinkCardStatusDisplayItem.Holder(activity, parent); + case CARD_LARGE -> new LinkCardStatusDisplayItem.Holder(activity, parent, true); + case CARD_COMPACT -> new LinkCardStatusDisplayItem.Holder(activity, parent, false); case FOOTER -> new FooterStatusDisplayItem.Holder(activity, parent); case ACCOUNT -> new AccountStatusDisplayItem.Holder(new AccountViewHolder(parentFragment, parent, null)); case HASHTAG -> new HashtagStatusDisplayItem.Holder(activity, parent); @@ -208,7 +209,8 @@ public abstract class StatusDisplayItem{ AUDIO, POLL_OPTION, POLL_FOOTER, - CARD, + CARD_LARGE, + CARD_COMPACT, FOOTER, ACCOUNT, HASHTAG, diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java index afc26c9a..b63f49d8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java @@ -87,7 +87,7 @@ public class InsetStatusItemDecoration extends RecyclerView.ItemDecoration{ boolean topSiblingInset=pos>0 && displayItems.get(pos-1).inset; boolean bottomSiblingInset=pos + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/ic_feed_48px.xml b/mastodon/src/main/res/drawable/ic_feed_48px.xml new file mode 100644 index 00000000..72fc5dc6 --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_feed_48px.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/layout/display_item_link_card.xml b/mastodon/src/main/res/layout/display_item_link_card.xml index f807cfd7..e58d64f4 100644 --- a/mastodon/src/main/res/layout/display_item_link_card.xml +++ b/mastodon/src/main/res/layout/display_item_link_card.xml @@ -3,54 +3,75 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + android:paddingHorizontal="16dp" + android:paddingBottom="8dp"> - - - - - + android:layout_marginHorizontal="16dp" + android:layout_marginTop="16dp" + android:textAppearance="@style/m3_title_medium" + android:maxLines="3" + android:ellipsize="end" + android:textColor="?colorM3OnSurface" + tools:text="Link title"/> + + - - + + + \ No newline at end of file diff --git a/mastodon/src/main/res/layout/display_item_link_card_compact.xml b/mastodon/src/main/res/layout/display_item_link_card_compact.xml new file mode 100644 index 00000000..3cc79302 --- /dev/null +++ b/mastodon/src/main/res/layout/display_item_link_card_compact.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/values/attrs.xml b/mastodon/src/main/res/values/attrs.xml index 6153f9ab..d2966e16 100644 --- a/mastodon/src/main/res/values/attrs.xml +++ b/mastodon/src/main/res/values/attrs.xml @@ -54,4 +54,9 @@ + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings.xml b/mastodon/src/main/res/values/strings.xml index 2020280c..d19b1362 100644 --- a/mastodon/src/main/res/values/strings.xml +++ b/mastodon/src/main/res/values/strings.xml @@ -665,4 +665,5 @@ Version number copied to clipboard You curate your own home feed.
The more people you follow, the more active and interesting it will be. Personalize your home feed + By %s \ No newline at end of file diff --git a/mastodon/src/main/res/values/styles.xml b/mastodon/src/main/res/values/styles.xml index 0d3107a6..e0d0ee78 100644 --- a/mastodon/src/main/res/values/styles.xml +++ b/mastodon/src/main/res/values/styles.xml @@ -375,6 +375,7 @@