GitNex/app/src/main/java/org/mian/gitnex/helpers/UserMentions.java
opyale a26737e510 Rewriting deprecated code and adding view bindings to all fragments and activities. (#809)
Remove jetbrain import

Merge branch 'master' into deprecations

View bindings #3

View bindings #2

View bindings #1

Rewriting deprecated code.

Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/809
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
Co-Authored-By: opyale <opyale@noreply.codeberg.org>
Co-Committed-By: opyale <opyale@noreply.codeberg.org>
2021-01-26 16:10:31 +01:00

37 lines
1.1 KiB
Java

package org.mian.gitnex.helpers;
import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import androidx.core.content.res.ResourcesCompat;
import org.mian.gitnex.R;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Author M M Arif
*/
public class UserMentions {
public static Spannable UserMentionsFunc(Context mCtx, CharSequence bodyWithMD) {
Spannable bodyWithMentions = new SpannableString(bodyWithMD);
Pattern pattern = Pattern.compile("@\\w+");
Matcher matcher = pattern.matcher(bodyWithMD);
while (matcher.find())
{
int indexStart = String.valueOf(bodyWithMD).indexOf(matcher.group());
int indexEnd = indexStart + matcher.group().length();
bodyWithMentions.setSpan(new ForegroundColorSpan(ResourcesCompat.getColor(mCtx.getResources(), R.color.colorDarkGreen, null)), indexStart, indexEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return bodyWithMentions;
}
}