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;
}
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();
}
}
Aggregations