Search in sources :

Example 1 with PlayerSpan

use of io.plaidapp.ui.span.PlayerSpan in project plaid by nickbutcher.

the class DribbbleUtils method parseDribbbleHtml.

/**
     * An extension to {@link HtmlUtils#parseHtml(String, ColorStateList, int)} which adds Dribbble
     * specific behaviour.
     */
public static Spanned parseDribbbleHtml(String input, ColorStateList linkTextColor, @ColorInt int linkHighlightColor) {
    SpannableStringBuilder ssb = HtmlUtils.parseHtml(input, linkTextColor, linkHighlightColor);
    TouchableUrlSpan[] urlSpans = ssb.getSpans(0, ssb.length(), TouchableUrlSpan.class);
    for (TouchableUrlSpan urlSpan : urlSpans) {
        int start = ssb.getSpanStart(urlSpan);
        if (ssb.subSequence(start, start + 1).toString().equals("@")) {
            int end = ssb.getSpanEnd(urlSpan);
            ssb.removeSpan(urlSpan);
            HttpUrl url = HttpUrl.parse(urlSpan.getURL());
            long playerId = -1l;
            String playerUsername = null;
            try {
                playerId = Long.parseLong(url.pathSegments().get(0));
            } catch (NumberFormatException nfe) {
                playerUsername = url.pathSegments().get(0);
            }
            ssb.setSpan(new PlayerSpan(urlSpan.getURL(), ssb.subSequence(start + 1, end).toString(), playerId, playerUsername, linkTextColor, linkHighlightColor), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return ssb;
}
Also used : TouchableUrlSpan(in.uncod.android.bypass.style.TouchableUrlSpan) PlayerSpan(io.plaidapp.ui.span.PlayerSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) HttpUrl(okhttp3.HttpUrl)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)1 TouchableUrlSpan (in.uncod.android.bypass.style.TouchableUrlSpan)1 PlayerSpan (io.plaidapp.ui.span.PlayerSpan)1 HttpUrl (okhttp3.HttpUrl)1