refactor(inline-avatar): find displayname using string search

This commit is contained in:
FineFindus
2024-03-19 15:43:21 +01:00
parent 39f3e72a47
commit 6ae234cf42

View File

@@ -21,7 +21,6 @@ import org.joinmastodon.android.model.Emoji;
import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.StatusPrivacy; import org.joinmastodon.android.model.StatusPrivacy;
import org.joinmastodon.android.ui.text.AvatarSpan; import org.joinmastodon.android.ui.text.AvatarSpan;
import org.joinmastodon.android.ui.text.CustomEmojiSpan;
import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.text.SpacerSpan; import org.joinmastodon.android.ui.text.SpacerSpan;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper; import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
@@ -48,7 +47,6 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
public boolean needBottomPadding; public boolean needBottomPadding;
ReblogOrReplyLineStatusDisplayItem extra; ReblogOrReplyLineStatusDisplayItem extra;
CharSequence fullText; CharSequence fullText;
CharSequence boostingTimestamp;
public ReblogOrReplyLineStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, CharSequence text, List<Emoji> emojis, @DrawableRes int icon, StatusPrivacy visibility, @Nullable View.OnClickListener handleClick, Status status) { public ReblogOrReplyLineStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, CharSequence text, List<Emoji> emojis, @DrawableRes int icon, StatusPrivacy visibility, @Nullable View.OnClickListener handleClick, Status status) {
this(parentID, parentFragment, text, emojis, icon, visibility, handleClick, text, status, null); this(parentID, parentFragment, text, emojis, icon, visibility, handleClick, text, status, null);
@@ -59,25 +57,14 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
SpannableStringBuilder ssb=new SpannableStringBuilder(text); SpannableStringBuilder ssb=new SpannableStringBuilder(text);
if(AccountSessionManager.get(parentFragment.getAccountID()).getLocalPreferences().customEmojiInNames) if(AccountSessionManager.get(parentFragment.getAccountID()).getLocalPreferences().customEmojiInNames)
HtmlParser.parseCustomEmoji(ssb, emojis); HtmlParser.parseCustomEmoji(ssb, emojis);
//this is fine, since the display name is surround by '\u2068' and '\u2069'
if(status.reblog!=null&&handleClick!=null){ int nameLoc=account!=null ? text.toString().indexOf(account.getDisplayName()) : -1;
//add temp chars for span replacement, should be same as spans added below if(nameLoc!=-1&&ssb.length()>=nameLoc&&handleClick!=null){
ssb.insert(0, " "); //add temp chars for span replacement, length should be the same as the amount of spans replacing below
ssb.setSpan(new AvatarSpan(status.account), 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ssb.insert(nameLoc, " ");
ssb.setSpan(new SpacerSpan(15, 20), 1, 2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ssb.setSpan(new SpacerSpan(15, 20), nameLoc+1, nameLoc+2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} ssb.setSpan(new AvatarSpan(account), nameLoc+1, nameLoc+2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
int replyPrefixLength=context.getString(R.string.in_reply_to).length()-2; //subtract 2 for placeholder ssb.setSpan(new SpacerSpan(15, 20), nameLoc+2, nameLoc+3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
boolean shortText=false;
if(account!=null&&text.toString().equals(account.getDisplayName())){
replyPrefixLength=0;
shortText=true;
}
if((status.inReplyToAccountId!=null || shortText) && ssb.length()>=replyPrefixLength && account!=null){
//add temp chars for span replacement, should be same as spans added below
ssb.insert(replyPrefixLength, " ");
ssb.setSpan(new SpacerSpan(15, 20), replyPrefixLength+1, replyPrefixLength+2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
ssb.setSpan(new AvatarSpan(account), replyPrefixLength+1, replyPrefixLength+2, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
ssb.setSpan(new SpacerSpan(15, 20), replyPrefixLength+2, replyPrefixLength+3, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} }
this.text=ssb; this.text=ssb;
emojiHelper.setText(ssb); emojiHelper.setText(ssb);