use of com.github.moko256.twitlatte.text.style.ClickableBoldSpan in project twicalico by moko256.
the class TwitterStringUtils method getLinkedSequence.
public static CharSequence getLinkedSequence(AccessToken accessToken, String text, Link[] links) {
if (links == null) {
return text;
}
SpannableString spannableString = new SpannableString(text);
for (Link link : links) {
Object span;
final Uri uri = Uri.parse(link.getUrl());
if (uri.getScheme() != null && uri.getHost() != null && uri.getScheme().equals("twitlatte")) {
switch(uri.getHost()) {
case "symbol":
span = new ClickableNoLineSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
context.startActivity(SearchResultActivity.getIntent(context, "$" + uri.getLastPathSegment()));
}
};
break;
case "hashtag":
span = new ClickableNoLineSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
context.startActivity(SearchResultActivity.getIntent(context, "#" + uri.getLastPathSegment()));
}
};
break;
case "user":
String name = uri.getLastPathSegment();
if (name != null) {
if (name.split("@")[0].equals(accessToken.getScreenName())) {
span = new ClickableBoldSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
context.startActivity(ShowUserActivity.getIntent(context, name));
}
};
} else {
span = new ClickableNoLineSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
context.startActivity(ShowUserActivity.getIntent(context, name));
}
};
}
} else {
span = null;
}
break;
default:
span = new ClickableNoLineSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
context.startActivity(SearchResultActivity.getIntent(context, uri.getLastPathSegment()));
}
};
break;
}
} else {
span = new ClickableNoLineSpan() {
@Override
public void onClick(@NonNull View view) {
Context context = view.getContext();
AppCustomTabsKt.launchChromeCustomTabs(context, uri, false);
}
};
}
int nowLength = text.length();
int start = link.getStart();
int end = link.getEnd();
if (start < end && end <= nowLength) {
spannableString.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return spannableString;
}
Aggregations