Fixes colors for clickable elements in toots

This commit is contained in:
stom79 2018-11-09 18:46:57 +01:00
parent b3833cb4a6
commit 2e8b11528d
2 changed files with 49 additions and 75 deletions

View File

@ -36,6 +36,7 @@ import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
import com.bumptech.glide.Glide;
@ -516,9 +517,9 @@ public class Status implements Parcelable{
status.getAccount().makeEmojisAccount(context, null);
String displayName;
if( status.getReblog() != null){
displayName = String.format("@%s",status.getReblog().getAccount().getAcct());
displayName = status.getReblog().getAccount().getDisplay_name();
}else {
displayName = String.format("@%s",status.getAccount().getAcct());
displayName = status.getAccount().getDisplay_name();
}
displayNameSpan = new SpannableString(displayName);
@ -746,21 +747,16 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if( matchEnd <= spannableString.toString().length() && matchEnd >= matchStart){
if( theme == THEME_DARK)
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == THEME_BLACK)
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if( theme == THEME_LIGHT)
spannableString.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
SpannableString spannableStringT;
@ -791,20 +787,14 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
if( matchEnd <= spannableString.toString().length() && matchEnd >= matchStart) {
if (theme == THEME_DARK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_BLACK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_LIGHT)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
if( accountsMentionUnknown.size() > 0 ) {
@ -824,21 +814,16 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if(endPosition <= spannableStringT.toString().length() && endPosition >= startPosition){
if (theme == THEME_DARK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_BLACK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_LIGHT)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
}
@ -891,22 +876,17 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
if(endPosition <= spannableStringT.toString().length() && endPosition >= startPosition){
if (theme == THEME_DARK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_BLACK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_LIGHT)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
it.remove();
@ -936,21 +916,16 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if(endPosition <= spannableStringT.toString().length() && endPosition >= startPosition){
if (theme == THEME_DARK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_BLACK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_link_toot)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_LIGHT)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
@ -975,19 +950,15 @@ public class Status implements Parcelable{
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.mastodonC4));
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart){
if (theme == THEME_DARK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.dark_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_BLACK)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.black_link_toot)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else if (theme == THEME_LIGHT)
spannableStringT.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.mastodonC4)), matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
return spannableStringT;
}

View File

@ -39,6 +39,7 @@ import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
@ -726,7 +727,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
holder.status_account_displayname.setVisibility(View.VISIBLE);
holder.status_account_displayname.setText(context.getResources().getString(R.string.reblog_by, status.getAccount().getUsername()));
if( status.getReblog().getAccount().getDisplay_name().length() > 0)
holder.status_account_displayname_owner.setText( status.getReblog().getAccount().getDisplay_name());
holder.status_account_displayname_owner.setText( status.getDisplayNameSpan(), TextView.BufferType.SPANNABLE);
else
holder.status_account_displayname_owner.setText( status.getReblog().getAccount().getAcct().replace("@",""));
holder.status_account_displayname_owner.setVisibility(View.VISIBLE);
@ -742,14 +743,16 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
//-------- END -> Displays name & emoji in toot header
//Change the color in gray for accounts in DARK Theme only
Spannable wordtoSpan = status.getDisplayNameSpan();
Spannable wordtoSpan;
Pattern hashAcct;
if( status.getReblog() != null) {
wordtoSpan = new SpannableString("@" + status.getReblog().getAccount().getAcct());
hashAcct = Pattern.compile("(@" + status.getReblog().getAccount().getAcct() + ")");
}else
hashAcct = Pattern.compile("(@"+status.getAccount().getAcct()+")");
if( wordtoSpan != null && hashAcct != null){
}else {
wordtoSpan = new SpannableString("@" + status.getAccount().getAcct());
hashAcct = Pattern.compile("(@" + status.getAccount().getAcct() + ")");
}
if( hashAcct != null){
Matcher matcherAcct = hashAcct.matcher(wordtoSpan);
while (matcherAcct.find()){
int matchStart = matcherAcct.start(1);