Manages eomjis in helper

This commit is contained in:
tom79 2017-10-20 07:11:44 +02:00
parent 6cdfcd49c1
commit a22d61c63d
3 changed files with 19 additions and 4 deletions

View File

@ -296,7 +296,7 @@ public class NotificationsListAdapter extends BaseAdapter implements OnPostActio
}
SpannableString spannableString = Helper.clickableElements(context, content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true);
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), status.getEmojis(), true);
Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/DroidSans-Regular.ttf");
holder.notification_status_content.setTypeface(tf);
holder.notification_status_content.setText(spannableString, TextView.BufferType.SPANNABLE);

View File

@ -445,7 +445,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
if( status.getContent_translated() != null && status.getContent_translated().length() > 0){
holder.status_content_translated.setMovementMethod(null);
SpannableString spannableStringTrans = Helper.clickableElements(context, status.getContent_translated(),
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), false);
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), status.getEmojis(), false);
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
@Override
@ -472,7 +472,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
content = content.substring(0,content.length() -10);
holder.status_content.setMovementMethod(null);
final SpannableString spannableString = Helper.clickableElements(context,content,
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), true);
status.getReblog() != null?status.getReblog().getMentions():status.getMentions(), status.getEmojis(), true);
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
@Override

View File

@ -130,6 +130,7 @@ import fr.gouv.etalab.mastodon.activities.WebviewActivity;
import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
@ -1133,8 +1134,21 @@ public class Helper {
* @param mentions List<Mention>
* @return TextView
*/
public static SpannableString clickableElements(final Context context, String fullContent, List<Mention> mentions, boolean useHTML) {
public static SpannableString clickableElements(final Context context, String fullContent, List<Mention> mentions, List<Emojis> emojis, boolean useHTML) {
SpannableString spannableString;
//Deals with custom emojis to change them in image
if( emojis != null && emojis.size() > 0 ) {
//Looping through accounts which are mentioned
for (final Emojis emoji : emojis) {
String targetedEmoji = ":" + emoji + ":";
if (fullContent.contains(targetedEmoji)) {
fullContent = fullContent.replace(targetedEmoji, "<img src=\""+ emoji.getUrl()+"\" />");
}
}
}
if( useHTML) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
spannableString = new SpannableString(Html.fromHtml(fullContent, Html.FROM_HTML_MODE_LEGACY));
@ -1210,6 +1224,7 @@ public class Helper {
}
}
Matcher matcher = hashtagPattern.matcher(spannableString);
while (matcher.find()){
int matchStart = matcher.start(1);