Fixes issue with custom emoji from other instances
This commit is contained in:
parent
9961e31335
commit
78605a6568
|
@ -1507,7 +1507,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveEmoji(int position, SpannableString spannableString, Boolean error) {
|
||||
public void onRetrieveEmoji(Status status, SpannableString spannableString, Boolean error) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -264,11 +264,14 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
if (content.endsWith("<br/><br/>"))
|
||||
content = content.substring(0, content.length() - 10);
|
||||
}
|
||||
|
||||
SpannableString spannableString = Helper.clickableElements(context, content,
|
||||
status, true, NotificationsListAdapter.this);
|
||||
/*SpannableString spannableString = Helper.clickableElements(context, content,
|
||||
status.getReblog() != null ? status.getReblog().getMentions() : status.getMentions(),
|
||||
status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis(),
|
||||
position,
|
||||
true, NotificationsListAdapter.this);
|
||||
true, NotificationsListAdapter.this);*/
|
||||
|
||||
holder.notification_status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
|
@ -693,6 +696,13 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
}
|
||||
|
||||
|
||||
private Notification getItemAt(int position){
|
||||
if( notifications.size() > position)
|
||||
return notifications.get(position);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a validation message for notification deletion
|
||||
* @param notification Notification
|
||||
|
@ -892,12 +902,20 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
|
|||
holder.status_show_more.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRetrieveEmoji(int position, SpannableString spannableString, Boolean error) {
|
||||
notifications.get(position).getStatus().setContents(spannableString);
|
||||
if( !notifications.get(position).getStatus().isEmojiFound()) {
|
||||
notifications.get(position).getStatus().setEmojiFound(true);
|
||||
notificationsListAdapter.notifyDataSetChanged();
|
||||
public void onRetrieveEmoji(Status status, SpannableString spannableString, Boolean error) {
|
||||
status.setContents(spannableString);
|
||||
if( !status.isEmojiFound()) {
|
||||
for (int i = 0; i < notificationsListAdapter.getItemCount(); i++) {
|
||||
if (notificationsListAdapter.getItemAt(i) != null && notificationsListAdapter.getItemAt(i).getId().equals(status.getId())) {
|
||||
if( notificationsListAdapter.getItemAt(i).getStatus() != null) {
|
||||
notificationsListAdapter.getItemAt(i).getStatus().setEmojiFound(true);
|
||||
notificationsListAdapter.notifyItemChanged(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ 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.Notification;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.translation.Translate;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
|
@ -158,6 +159,13 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
return statuses.size();
|
||||
}
|
||||
|
||||
private Status getItemAt(int position){
|
||||
if( statuses.size() > position)
|
||||
return statuses.get(position);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveReplies(int position, APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null || apiResponse.getStatuses() == null || apiResponse.getStatuses().size() == 0){
|
||||
|
@ -534,10 +542,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
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(),
|
||||
status.getReblog() != null?status.getReblog().getEmojis():status.getEmojis(),
|
||||
position,
|
||||
SpannableString spannableStringTrans = Helper.clickableElements(context,status.getContent_translated(), status,
|
||||
true, StatusListAdapter.this);
|
||||
holder.status_content_translated.setText(spannableStringTrans, TextView.BufferType.SPANNABLE);
|
||||
holder.status_content_translated.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
@ -559,10 +564,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
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);
|
||||
status, true, StatusListAdapter.this);
|
||||
holder.status_content.setText(spannableString, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
holder.status_content.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
@ -1366,11 +1368,18 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveEmoji(int position, SpannableString spannableString, Boolean error) {
|
||||
statuses.get(position).setContents(spannableString);
|
||||
if( !statuses.get(position).isEmojiFound()) {
|
||||
statuses.get(position).setEmojiFound(true);
|
||||
statusListAdapter.notifyDataSetChanged();
|
||||
public void onRetrieveEmoji(Status status, SpannableString spannableString, Boolean error) {
|
||||
status.setContents(spannableString);
|
||||
if( !status.isEmojiFound()) {
|
||||
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
|
||||
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
|
||||
if( statusListAdapter.getItemAt(i) != null) {
|
||||
statusListAdapter.getItemAt(i).setEmojiFound(true);
|
||||
statusListAdapter.notifyItemChanged(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1168,11 +1168,13 @@ public class Helper {
|
|||
* Click on tag => HashTagActivity
|
||||
* @param context Context
|
||||
* @param fullContent String, should be the st
|
||||
* @param mentions List<Mention>
|
||||
* @param status Status
|
||||
* @return TextView
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
public static SpannableString clickableElements(final Context context, String fullContent, List<Mention> mentions, final List<Emojis> emojis, final int position, boolean useHTML, final OnRetrieveEmojiInterface listener) {
|
||||
public static SpannableString clickableElements(final Context context, String fullContent, final Status status, boolean useHTML, final OnRetrieveEmojiInterface listener) {
|
||||
List<Mention> mentions = status.getReblog() != null ? status.getReblog().getMentions() : status.getMentions();
|
||||
final List<Emojis> emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis();
|
||||
final SpannableString spannableString;
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
if( useHTML) {
|
||||
|
@ -1230,8 +1232,15 @@ public class Helper {
|
|||
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
|
||||
imageLoader = ImageLoader.getInstance();
|
||||
for (final Emojis emoji : emojis) {
|
||||
if( instance != null && emoji.getUrl().contains(instance))
|
||||
boolean sameInstance;
|
||||
if( instance != null) {
|
||||
if (status.getReblog() == null)
|
||||
sameInstance = status.getUri().contains(instance);
|
||||
else
|
||||
sameInstance = status.getReblog().getUri().contains(instance);
|
||||
if (sameInstance)
|
||||
storeEmoji(context, db, emoji);
|
||||
}
|
||||
NonViewAware imageAware = new NonViewAware(new ImageSize(50, 50), ViewScaleType.CROP);
|
||||
imageLoader.displayImage(emoji.getUrl(), imageAware, options, new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
|
@ -1251,13 +1260,13 @@ public class Helper {
|
|||
}
|
||||
i[0]++;
|
||||
if( i[0] == (emojis.size()))
|
||||
listener.onRetrieveEmoji(position, spannableString, false);
|
||||
listener.onRetrieveEmoji(status, spannableString, false);
|
||||
}
|
||||
@Override
|
||||
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason) {
|
||||
i[0]++;
|
||||
if( i[0] == (emojis.size()))
|
||||
listener.onRetrieveEmoji(position, spannableString, false);
|
||||
listener.onRetrieveEmoji(status, spannableString, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1421,7 +1430,7 @@ public class Helper {
|
|||
try {
|
||||
String[] val = search.split("@");
|
||||
if( val.length > 0 ) {
|
||||
String username, instance;
|
||||
String username;
|
||||
if( val.length == 2){
|
||||
username = val[1];
|
||||
Pattern urlAccountPattern = Pattern.compile(
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.text.SpannableString;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -26,6 +27,6 @@ import fr.gouv.etalab.mastodon.client.Entities.Emojis;
|
|||
* Interface when retrieving emojis
|
||||
*/
|
||||
public interface OnRetrieveEmojiInterface {
|
||||
void onRetrieveEmoji(int position, SpannableString spannableString, Boolean error);
|
||||
void onRetrieveEmoji(Status status, SpannableString spannableString, Boolean error);
|
||||
void onRetrieveSearchEmoji(List<Emojis> emojis);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
@SuppressWarnings("WeakerAccess")
|
||||
public class Sqlite extends SQLiteOpenHelper {
|
||||
|
||||
public static final int DB_VERSION = 5;
|
||||
public static final int DB_VERSION = 6;
|
||||
public static final String DB_NAME = "mastodon_etalab_db";
|
||||
public static SQLiteDatabase db;
|
||||
private static Sqlite sInstance;
|
||||
|
@ -130,6 +130,8 @@ public class Sqlite extends SQLiteOpenHelper {
|
|||
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
+ COL_SHORTCODE + " TEXT NOT NULL, " + COL_INSTANCE + " TEXT NOT NULL, "
|
||||
+ COL_URL + " TEXT NOT NULL, " + COL_URL_STATIC + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)");
|
||||
case 5:
|
||||
db.execSQL("delete from "+ TABLE_CUSTOM_EMOJI); //Reset table due to bugs
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue