Search in sources :

Example 6 with MentionMetadataModel

use of com.applozic.mobicomkit.api.conversation.MentionMetadataModel in project Applozic-Android-SDK by AppLozic.

the class MentionAutoCompleteTextView method recreateMentionsSpanAndData.

private void recreateMentionsSpanAndData(Spannable spannable, Pattern pattern) {
    try {
        final Matcher matcher = pattern.matcher(spannable);
        while (matcher.find()) {
            // the character index after mention token start char (i.e. '@')
            final int start = matcher.start() + 1;
            final int end = matcher.end();
            String possibleMention = matcher.group(1);
            for (Mention mention : mentionAdapter.getMentions()) {
                if (mention.getMentionIdentifier().equals(possibleMention)) {
                    MentionMetadataModel mentionMetadataModel = new MentionMetadataModel();
                    mentionMetadataModel.userId = mention.getUserId().toString();
                    if (mention.getDisplayName() != null && !mention.getDisplayName().equals(Utils.EMPTY_STRING)) {
                        mentionMetadataModel.displayName = mention.getDisplayName().toString();
                    }
                    int[] indices = new int[2];
                    // for sorting
                    indices[0] = start;
                    mentionMetadataModel.indices = indices;
                    mentionMetadataModels.add(mentionMetadataModel);
                    final MentionClickableSpan span = new MentionClickableSpan();
                    spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    if (span instanceof MentionClickableSpan) {
                        span.userId = mention.getUserId();
                    }
                }
            }
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
Also used : Matcher(java.util.regex.Matcher) Mention(com.applozic.mobicomkit.api.mention.Mention) SpannableString(android.text.SpannableString) MentionMetadataModel(com.applozic.mobicomkit.api.conversation.MentionMetadataModel)

Aggregations

SpannableString (android.text.SpannableString)6 MentionMetadataModel (com.applozic.mobicomkit.api.conversation.MentionMetadataModel)6 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 SpannableStringBuilder (android.text.SpannableStringBuilder)1 CharacterStyle (android.text.style.CharacterStyle)1 Mention (com.applozic.mobicomkit.api.mention.Mention)1 AppContactService (com.applozic.mobicomkit.contact.AppContactService)1 Contact (com.applozic.mobicommons.people.contact.Contact)1 JsonParseException (com.google.gson.JsonParseException)1 Matcher (java.util.regex.Matcher)1