Improves emojis support
This commit is contained in:
parent
f36ddba6f9
commit
c32b394160
|
@ -40,6 +40,7 @@ import android.text.SpannableString;
|
|||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -88,7 +89,6 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
|||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
|
@ -117,7 +117,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
private List<Status> statuses;
|
||||
private LayoutInflater layoutInflater;
|
||||
private ImageLoader imageLoader;
|
||||
private DisplayImageOptions options, optionsAttachment;
|
||||
private DisplayImageOptions optionsAttachment;
|
||||
private ViewHolder holder;
|
||||
private boolean isOnWifi;
|
||||
private int translator;
|
||||
|
@ -187,7 +187,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
|
||||
if( getItemViewType(position) == HIDDEN_STATUS){
|
||||
return new View(context);
|
||||
}else {
|
||||
}else if( getItemViewType(position) == DISPLAYED_STATUS){
|
||||
final Status status = statuses.get(position);
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
File cacheDir = new File(context.getCacheDir(), context.getString(R.string.app_name));
|
||||
|
@ -200,56 +200,56 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
.build();
|
||||
if( !imageLoader.isInited())
|
||||
imageLoader.init(configImg);
|
||||
options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(10)).cacheInMemory(false)
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(10)).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
optionsAttachment = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
|
||||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.drawer_status, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.loader_replies = (LinearLayout) convertView.findViewById(R.id.loader_replies);
|
||||
holder.card_status_container = (CardView) convertView.findViewById(R.id.card_status_container);
|
||||
holder.status_document_container = (LinearLayout) convertView.findViewById(R.id.status_document_container);
|
||||
holder.status_content = (TextView) convertView.findViewById(R.id.status_content);
|
||||
holder.status_content_translated = (TextView) convertView.findViewById(R.id.status_content_translated);
|
||||
holder.status_account_username = (TextView) convertView.findViewById(R.id.status_account_username);
|
||||
holder.status_account_displayname = (TextView) convertView.findViewById(R.id.status_account_displayname);
|
||||
holder.status_account_profile = (ImageView) convertView.findViewById(R.id.status_account_profile);
|
||||
holder.status_account_profile_boost = (ImageView) convertView.findViewById(R.id.status_account_profile_boost);
|
||||
holder.status_account_profile_boost_by = (ImageView) convertView.findViewById(R.id.status_account_profile_boost_by);
|
||||
holder.status_favorite_count = (TextView) convertView.findViewById(R.id.status_favorite_count);
|
||||
holder.status_reblog_count = (TextView) convertView.findViewById(R.id.status_reblog_count);
|
||||
holder.status_pin = (ImageView) convertView.findViewById(R.id.status_pin);
|
||||
holder.status_toot_date = (TextView) convertView.findViewById(R.id.status_toot_date);
|
||||
holder.status_show_more = (Button) convertView.findViewById(R.id.status_show_more);
|
||||
holder.status_more = (ImageView) convertView.findViewById(R.id.status_more);
|
||||
holder.status_prev1 = (ImageView) convertView.findViewById(R.id.status_prev1);
|
||||
holder.status_prev2 = (ImageView) convertView.findViewById(R.id.status_prev2);
|
||||
holder.status_prev3 = (ImageView) convertView.findViewById(R.id.status_prev3);
|
||||
holder.status_prev4 = (ImageView) convertView.findViewById(R.id.status_prev4);
|
||||
holder.status_prev1_play = (ImageView) convertView.findViewById(R.id.status_prev1_play);
|
||||
holder.status_prev2_play = (ImageView) convertView.findViewById(R.id.status_prev2_play);
|
||||
holder.status_prev3_play = (ImageView) convertView.findViewById(R.id.status_prev3_play);
|
||||
holder.status_prev4_play = (ImageView) convertView.findViewById(R.id.status_prev4_play);
|
||||
holder.status_container2 = (LinearLayout) convertView.findViewById(R.id.status_container2);
|
||||
holder.status_container3 = (LinearLayout) convertView.findViewById(R.id.status_container3);
|
||||
holder.status_prev4_container = (RelativeLayout) convertView.findViewById(R.id.status_prev4_container);
|
||||
holder.status_reply = (ImageView) convertView.findViewById(R.id.status_reply);
|
||||
holder.status_privacy = (ImageView) convertView.findViewById(R.id.status_privacy);
|
||||
holder.status_translate = (FloatingActionButton) convertView.findViewById(R.id.status_translate);
|
||||
holder.status_content_translated_container = (LinearLayout) convertView.findViewById(R.id.status_content_translated_container);
|
||||
holder.main_container = (LinearLayout) convertView.findViewById(R.id.main_container);
|
||||
holder.status_spoiler_container = (LinearLayout) convertView.findViewById(R.id.status_spoiler_container);
|
||||
holder.status_content_container = (LinearLayout) convertView.findViewById(R.id.status_content_container);
|
||||
holder.status_spoiler = (TextView) convertView.findViewById(R.id.status_spoiler);
|
||||
holder.status_spoiler_button = (Button) convertView.findViewById(R.id.status_spoiler_button);
|
||||
holder.yandex_translate = (TextView) convertView.findViewById(R.id.yandex_translate);
|
||||
holder.google_translate = (TextView) convertView.findViewById(R.id.google_translate);
|
||||
holder.status_replies = (LinearLayout) convertView.findViewById(R.id.status_replies);
|
||||
holder.status_replies_profile_pictures = (LinearLayout) convertView.findViewById(R.id.status_replies_profile_pictures);
|
||||
holder.status_replies_text = (TextView) convertView.findViewById(R.id.status_replies_text);
|
||||
holder.new_element = (ImageView) convertView.findViewById(R.id.new_element);
|
||||
holder.status_action_container = (LinearLayout) convertView.findViewById(R.id.status_action_container);
|
||||
holder.loader_replies = convertView.findViewById(R.id.loader_replies);
|
||||
holder.card_status_container = convertView.findViewById(R.id.card_status_container);
|
||||
holder.status_document_container = convertView.findViewById(R.id.status_document_container);
|
||||
holder.status_content = convertView.findViewById(R.id.status_content);
|
||||
holder.status_content_translated = convertView.findViewById(R.id.status_content_translated);
|
||||
holder.status_account_username = convertView.findViewById(R.id.status_account_username);
|
||||
holder.status_account_displayname = convertView.findViewById(R.id.status_account_displayname);
|
||||
holder.status_account_profile = convertView.findViewById(R.id.status_account_profile);
|
||||
holder.status_account_profile_boost = convertView.findViewById(R.id.status_account_profile_boost);
|
||||
holder.status_account_profile_boost_by = convertView.findViewById(R.id.status_account_profile_boost_by);
|
||||
holder.status_favorite_count = convertView.findViewById(R.id.status_favorite_count);
|
||||
holder.status_reblog_count = convertView.findViewById(R.id.status_reblog_count);
|
||||
holder.status_pin = convertView.findViewById(R.id.status_pin);
|
||||
holder.status_toot_date = convertView.findViewById(R.id.status_toot_date);
|
||||
holder.status_show_more = convertView.findViewById(R.id.status_show_more);
|
||||
holder.status_more = convertView.findViewById(R.id.status_more);
|
||||
holder.status_prev1 = convertView.findViewById(R.id.status_prev1);
|
||||
holder.status_prev2 = convertView.findViewById(R.id.status_prev2);
|
||||
holder.status_prev3 = convertView.findViewById(R.id.status_prev3);
|
||||
holder.status_prev4 = convertView.findViewById(R.id.status_prev4);
|
||||
holder.status_prev1_play = convertView.findViewById(R.id.status_prev1_play);
|
||||
holder.status_prev2_play = convertView.findViewById(R.id.status_prev2_play);
|
||||
holder.status_prev3_play = convertView.findViewById(R.id.status_prev3_play);
|
||||
holder.status_prev4_play = convertView.findViewById(R.id.status_prev4_play);
|
||||
holder.status_container2 = convertView.findViewById(R.id.status_container2);
|
||||
holder.status_container3 = convertView.findViewById(R.id.status_container3);
|
||||
holder.status_prev4_container = convertView.findViewById(R.id.status_prev4_container);
|
||||
holder.status_reply = convertView.findViewById(R.id.status_reply);
|
||||
holder.status_privacy = convertView.findViewById(R.id.status_privacy);
|
||||
holder.status_translate = convertView.findViewById(R.id.status_translate);
|
||||
holder.status_content_translated_container = convertView.findViewById(R.id.status_content_translated_container);
|
||||
holder.main_container = convertView.findViewById(R.id.main_container);
|
||||
holder.status_spoiler_container = convertView.findViewById(R.id.status_spoiler_container);
|
||||
holder.status_content_container = convertView.findViewById(R.id.status_content_container);
|
||||
holder.status_spoiler = convertView.findViewById(R.id.status_spoiler);
|
||||
holder.status_spoiler_button = convertView.findViewById(R.id.status_spoiler_button);
|
||||
holder.yandex_translate = convertView.findViewById(R.id.yandex_translate);
|
||||
holder.google_translate = convertView.findViewById(R.id.google_translate);
|
||||
holder.status_replies = convertView.findViewById(R.id.status_replies);
|
||||
holder.status_replies_profile_pictures = convertView.findViewById(R.id.status_replies_profile_pictures);
|
||||
holder.status_replies_text = convertView.findViewById(R.id.status_replies_text);
|
||||
holder.new_element = convertView.findViewById(R.id.new_element);
|
||||
holder.status_action_container = convertView.findViewById(R.id.status_action_container);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
|
@ -466,19 +466,21 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
});
|
||||
holder.status_content_translated.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
}
|
||||
content = content.replaceAll("</p>","<br/><br/>");
|
||||
content = content.replaceAll("<p>","");
|
||||
if( content.endsWith("<br/><br/>") )
|
||||
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(),
|
||||
status.getReblog() != null?status.getReblog().getEmojis():status.getEmojis(),
|
||||
position,
|
||||
true, StatusListAdapter.this);
|
||||
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
|
||||
|
||||
if( status.getContents() != null){
|
||||
holder.status_content.setText(status.getContents(), TextView.BufferType.SPANNABLE);
|
||||
}else{
|
||||
content = content.replaceAll("</p>","<br/><br/>");
|
||||
content = content.replaceAll("<p>","");
|
||||
if( content.endsWith("<br/><br/>") )
|
||||
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(),
|
||||
status.getReblog() != null?status.getReblog().getEmojis():status.getEmojis(),
|
||||
position,
|
||||
true, StatusListAdapter.this);
|
||||
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
|
@ -487,7 +489,6 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
return false;
|
||||
}
|
||||
});
|
||||
List<Emojis> emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis();
|
||||
|
||||
holder.status_content.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
|
@ -1123,7 +1124,7 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
|
|||
});
|
||||
return convertView;
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1134,7 +1134,7 @@ public class Helper {
|
|||
* @param mentions List<Mention>
|
||||
* @return TextView
|
||||
*/
|
||||
public static SpannableString clickableElements(final Context context, String fullContent, List<Mention> mentions, List<Emojis> emojis, final int position, boolean useHTML, final OnRetrieveEmojiInterface listener) {
|
||||
public static SpannableString clickableElements(final Context context, String fullContent, List<Mention> mentions, final List<Emojis> emojis, final int position, boolean useHTML, final OnRetrieveEmojiInterface listener) {
|
||||
final SpannableString spannableString;
|
||||
|
||||
if( useHTML) {
|
||||
|
@ -1183,6 +1183,7 @@ public class Helper {
|
|||
}
|
||||
|
||||
if( emoji != null && emojis.size() > 0 ) {
|
||||
final int[] i = {0};
|
||||
for (final Emojis emoji : emojis) {
|
||||
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
|
||||
if (spannableString.toString().contains(targetedEmoji)) {
|
||||
|
@ -1201,7 +1202,9 @@ public class Helper {
|
|||
Bitmap.createScaledBitmap(loadedImage, (int)Helper.convertDpToPixel(20, context),
|
||||
(int)Helper.convertDpToPixel(20, context), false)), finalStartPosition,
|
||||
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
listener.onRetrieveEmoji(position, spannableString, false);
|
||||
i[0]++;
|
||||
if( i[0] == emojis.size())
|
||||
listener.onRetrieveEmoji(position, spannableString, false);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason) {
|
||||
|
@ -1209,6 +1212,7 @@ public class Helper {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue