package com.alwaysallthetime.messagebeast;

import android.text.SpannableStringBuilder;
import android.text.style.CharacterStyle;

import com.alwaysallthetime.adnlib.data.AbstractPost;
import com.alwaysallthetime.adnlib.data.Entities;

import java.util.List;

public class EntityStyler {

    public static CharSequence getStyledText(AbstractPost post, List<CharacterStyle> mentionStyles, List<CharacterStyle> hashtagStyles, List<CharacterStyle> linkStyles) {
        SpannableStringBuilder string = new SpannableStringBuilder(post.getText());

        Entities entities = post.getEntities();
        if(entities != null) {
            if(mentionStyles != null) {
                applyStylesToEntities(string, entities.getMentions(), mentionStyles);
            }
            if(hashtagStyles != null) {
                applyStylesToEntities(string, entities.getHashtags(), hashtagStyles);
            }
            if(linkStyles != null) {
                applyStylesToEntities(string, entities.getLinks(), linkStyles);
            }
        }

        return string;
    }

    private static void applyStylesToEntities(SpannableStringBuilder spannableString, List<? extends Entities.Entity> entities, List<CharacterStyle> styles) {
        for(Entities.Entity e : entities) {
            for(CharacterStyle s : styles) {
                spannableString.setSpan(CharacterStyle.wrap(s), e.getPos(), e.getPos() + e.getLen(), 0);
            }
        }
    }
}

@@ -257,36 +257,2674 @@
 t;%0A%0A
-public class EntityStyler %7B%0A
+/**%0A * A utility for applying Character styles to entities.%0A */%0Apublic class EntityStyler %7B%0A%0A    /**%0A     * Get styled hashtags. If none exist, then the returned CharSequence has no styled spans.%0A     *%0A     * @param post the post or Message whose hashtags should be styled%0A     * @param hashtagStyles the CharacterStyles to apply to the hashtags%0A     * @return A CharSequence with styled spans%0A     */%0A    public static CharSequence getStyledHashtags(AbstractPost post, List%3CCharacterStyle%3E hashtagStyles) %7B%0A        SpannableStringBuilder string = new SpannableStringBuilder(post.getText());%0A%0A        Entities entities = post.getEntities();%0A        if(entities != null) %7B%0A            applyStylesToEntities(string, entities.getHashtags(), hashtagStyles);%0A        %7D%0A        return string;%0A    %7D%0A%0A    /**%0A     * Get styled links. If none exist, then the returned CharSequence has no styled spans.%0A     *%0A     * @param post the post or Message whose links should be styled%0A     * @param linkStyles the CharacterStyles to apply to the links%0A     * @return A CharSequence with styled spans%0A     */%0A    public static CharSequence getStyledLinks(AbstractPost post, List%3CCharacterStyle%3E linkStyles) %7B%0A        SpannableStringBuilder string = new SpannableStringBuilder(post.getText());%0A%0A        Entities entities = post.getEntities();%0A        if(entities != null) %7B%0A            applyStylesToEntities(string, entities.getLinks(), linkStyles);%0A        %7D%0A        return string;%0A    %7D%0A%0A    /**%0A     * Get styled mentions. If none exist, then the returned CharSequence has no styled spans.%0A     *%0A     * @param post the post or Message whose mentions should be styled%0A     * @param mentionStyles the CharacterStyles to apply to the mentions%0A     * @return A CharSequence with styled spans%0A     */%0A    public static CharSequence getStyledMentions(AbstractPost post, List%3CCharacterStyle%3E mentionStyles) %7B%0A        SpannableStringBuilder string = new SpannableStringBuilder(post.getText());%0A%0A        Entities entities = post.getEntities();%0A        if(entities != null) %7B%0A            applyStylesToEntities(string, entities.getMentions(), mentionStyles);%0A        %7D%0A        return string;%0A    %7D%0A%0A    /**%0A     * Get styled entities. If none exist, then the returned CharSequence has no styled spans.%0A     *%0A     * @param post the post or Message whose entities should be styled%0A     * @param mentionStyles the CharacterStyles to apply to the mentions. may be null.%0A     * @param hashtagStyles the CharacterStyles to apply to the hashtags. may be null.%0A     * @param linkStyles the CharacterStyles to apply to the links. may be null.%0A     * @return A CharSequence with styled spans%0A     */
 %0A   

add methods for individual entity types, javadocs