Skip to content

Instantly share code, notes, and snippets.

@bansalayush
Created July 25, 2019 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bansalayush/98fbac020b06dc6b99caa082d6d96d63 to your computer and use it in GitHub Desktop.
Save bansalayush/98fbac020b06dc6b99caa082d6d96d63 to your computer and use it in GitHub Desktop.
String strings = Utils.decodeString(mChannelObj.getDescription());
tvDescription.setVisibility(VISIBLE);
descriptionDivView.setVisibility(VISIBLE);
SpannableStringBuilder span = new SpannableStringBuilder(strings);
Pattern webPattern = Patterns.WEB_URL;
Matcher matcher = webPattern.matcher(Utils.decodeString(mChannelObj.getDescription()));
while (matcher.find()) {
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(@NonNull View widget) {
Logger.d(TAG, "text clicked ");
}
};
String links = matcher.group();
Logger.d(TAG, "links " + links);
int startingPoint = Utils.decodeString(mChannelObj.getDescription()).indexOf(links);
int endingPoint = Utils.decodeString(mChannelObj.getDescription()).indexOf(links) + links.length();
Logger.d(TAG, startingPoint + " - " + endingPoint);
span.setSpan(clickableSpan, startingPoint, endingPoint, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
tvDescription.setMovementMethod(LinkMovementMethod.getInstance());
tvDescription.setText(span, TextView.BufferType.SPANNABLE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment