Search in sources :

Example 1 with Mention

use of com.applozic.mobicomkit.api.mention.Mention in project Applozic-Android-SDK by AppLozic.

the class MentionAdapter method getView.

@NonNull
@Override
@SuppressWarnings("unchecked")
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    final ViewHolder holder;
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.layout_mention_item, parent, false);
        holder = new ViewHolder(convertView);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Mention item = getItem(position);
    if (item != null) {
        holder.userIdView.setText(item.getUserId());
        final CharSequence displayName = item.getDisplayName();
        if (!TextUtils.isEmpty(displayName)) {
            holder.displayNameView.setText(displayName);
        } else {
            holder.displayNameView.setText(item.getUserId());
        }
        final String profileImageUrl = item.getProfileImage();
        if (!TextUtils.isEmpty(profileImageUrl)) {
            Glide.with(getContext()).load(profileImageUrl).into(holder.profileImage);
        }
    }
    return convertView;
}
Also used : Mention(com.applozic.mobicomkit.api.mention.Mention) SpannableString(android.text.SpannableString) NonNull(androidx.annotation.NonNull)

Example 2 with Mention

use of com.applozic.mobicomkit.api.mention.Mention 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)2 Mention (com.applozic.mobicomkit.api.mention.Mention)2 NonNull (androidx.annotation.NonNull)1 MentionMetadataModel (com.applozic.mobicomkit.api.conversation.MentionMetadataModel)1 Matcher (java.util.regex.Matcher)1