mirror of
https://github.com/mastodon/mastodon-android.git
synced 2025-02-03 03:57:33 +01:00
Support multiple authors in link cards (mastodon/mastodon#30846)
This commit is contained in:
parent
e7094beab9
commit
461eac8932
@ -37,6 +37,7 @@ public class Card extends BaseModel{
|
||||
public List<History> history;
|
||||
public Instant publishedAt;
|
||||
public Account authorAccount;
|
||||
public List<Author> authors;
|
||||
|
||||
public transient Drawable blurhashPlaceholder;
|
||||
|
||||
@ -52,6 +53,11 @@ public class Card extends BaseModel{
|
||||
}
|
||||
if(authorAccount!=null)
|
||||
authorAccount.postprocess();
|
||||
if(authors!=null){
|
||||
for(Author a:authors){
|
||||
a.postprocess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -85,4 +91,19 @@ public class Card extends BaseModel{
|
||||
@SerializedName("rich")
|
||||
RICH
|
||||
}
|
||||
|
||||
@Parcel
|
||||
public static class Author extends BaseModel{
|
||||
@RequiredField
|
||||
public String name;
|
||||
public String url;
|
||||
public Account account;
|
||||
|
||||
@Override
|
||||
public void postprocess() throws ObjectValidationException{
|
||||
super.postprocess();
|
||||
if(account!=null)
|
||||
account.postprocess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||
|
||||
import org.joinmastodon.android.GlobalUserPreferences;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.Card;
|
||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
||||
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
|
||||
@ -26,12 +27,18 @@ public class CardViewModel{
|
||||
this.parentObject=parentObject;
|
||||
this.imageRequest=TextUtils.isEmpty(card.image) ? null : new UrlImageLoaderRequest(card.image, V.dp(width), V.dp(height));
|
||||
|
||||
if(card.authorAccount!=null){
|
||||
parsedAuthorName=new SpannableStringBuilder(card.authorAccount.displayName);
|
||||
Account authorAccount;
|
||||
if(card.authors!=null && !card.authors.isEmpty() && card.authors.get(0).account!=null)
|
||||
authorAccount=card.authors.get(0).account;
|
||||
else
|
||||
authorAccount=card.authorAccount;
|
||||
|
||||
if(authorAccount!=null){
|
||||
parsedAuthorName=new SpannableStringBuilder(authorAccount.displayName);
|
||||
if(AccountSessionManager.get(accountID).getLocalPreferences().customEmojiInNames)
|
||||
HtmlParser.parseCustomEmoji(parsedAuthorName, card.authorAccount.emojis);
|
||||
HtmlParser.parseCustomEmoji(parsedAuthorName, authorAccount.emojis);
|
||||
authorNameEmojiHelper.setText(parsedAuthorName);
|
||||
authorAvaRequest=new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? card.authorAccount.avatar : card.authorAccount.avatarStatic, V.dp(50), V.dp(50));
|
||||
authorAvaRequest=new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? authorAccount.avatar : authorAccount.avatarStatic, V.dp(50), V.dp(50));
|
||||
}else{
|
||||
parsedAuthorName=null;
|
||||
authorAvaRequest=null;
|
||||
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.Card;
|
||||
import org.joinmastodon.android.model.viewmodel.CardViewModel;
|
||||
import org.joinmastodon.android.ui.OutlineProviders;
|
||||
@ -86,7 +87,9 @@ public class LinkCardHolder<T extends LinkCardHolder.LinkCardProvider> extends S
|
||||
}
|
||||
String cardDomain=HtmlParser.normalizeDomain(Objects.requireNonNull(Uri.parse(card.url).getHost()));
|
||||
domain.setText(TextUtils.isEmpty(card.providerName) ? cardDomain : card.providerName);
|
||||
if(card.authorAccount!=null){
|
||||
String authorName=card.authors!=null && !card.authors.isEmpty() ? card.authors.get(0).name : null;
|
||||
|
||||
if(cardVM.parsedAuthorName!=null){
|
||||
authorFooter.setVisibility(View.VISIBLE);
|
||||
authorChip.setVisibility(View.VISIBLE);
|
||||
authorBefore.setVisibility(View.VISIBLE);
|
||||
@ -102,15 +105,15 @@ public class LinkCardHolder<T extends LinkCardHolder.LinkCardProvider> extends S
|
||||
authorAfter.setVisibility(View.VISIBLE);
|
||||
authorAfter.setText(after);
|
||||
}
|
||||
authorName.setText(cardVM.parsedAuthorName);
|
||||
this.authorName.setText(cardVM.parsedAuthorName);
|
||||
authorBefore.setCompoundDrawablesRelative(logoIcon, null, null, null);
|
||||
}else if(!TextUtils.isEmpty(card.authorName)){
|
||||
}else if(!TextUtils.isEmpty(authorName)){
|
||||
authorFooter.setVisibility(View.VISIBLE);
|
||||
authorBefore.setVisibility(View.VISIBLE);
|
||||
authorBefore.setCompoundDrawables(null, null, null, null);
|
||||
authorChip.setVisibility(View.GONE);
|
||||
authorAfter.setVisibility(View.GONE);
|
||||
authorBefore.setText(itemView.getContext().getString(R.string.article_by_author, card.authorName));
|
||||
authorBefore.setText(itemView.getContext().getString(R.string.article_by_author, authorName));
|
||||
}else{
|
||||
authorFooter.setVisibility(View.GONE);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user