fedilab-Android-App/app/src/main/java/app/fedilab/android/client/Entities/Status.java

1413 lines
60 KiB
Java
Raw Normal View History

2017-05-05 16:36:04 +02:00
/* Copyright 2017 Thomas Schneider
*
2019-05-18 11:10:30 +02:00
* This file is a part of Fedilab
2017-05-05 16:36:04 +02:00
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
2019-05-18 11:10:30 +02:00
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
2017-05-05 16:36:04 +02:00
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
2019-05-18 11:10:30 +02:00
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
2017-05-05 16:36:04 +02:00
* see <http://www.gnu.org/licenses>. */
2019-05-18 11:10:30 +02:00
package app.fedilab.android.client.Entities;
2017-05-05 16:36:04 +02:00
2018-01-11 07:32:19 +01:00
import android.app.Activity;
2017-12-03 10:56:54 +01:00
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
2017-12-03 10:56:54 +01:00
import android.graphics.Bitmap;
2018-08-14 18:27:21 +02:00
import android.net.Uri;
2017-12-03 10:56:54 +01:00
import android.os.Build;
import android.os.Bundle;
2017-05-26 17:20:36 +02:00
import android.os.Parcel;
import android.os.Parcelable;
2019-06-11 19:38:26 +02:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
2017-12-03 10:56:54 +01:00
import android.text.Html;
import android.text.Spannable;
2017-10-20 19:58:46 +02:00
import android.text.SpannableString;
2017-12-03 10:56:54 +01:00
import android.text.Spanned;
import android.text.TextPaint;
2019-01-16 13:58:05 +01:00
import android.text.TextUtils;
2017-12-03 10:56:54 +01:00
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Patterns;
2017-12-03 10:56:54 +01:00
import android.view.View;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
2017-10-20 19:58:46 +02:00
import java.util.ArrayList;
2017-05-05 16:36:04 +02:00
import java.util.Date;
2018-09-15 12:43:36 +02:00
import java.util.HashMap;
import java.util.Iterator;
2017-05-05 16:36:04 +02:00
import java.util.List;
2018-09-15 12:43:36 +02:00
import java.util.Map;
2017-12-03 10:56:54 +01:00
import java.util.regex.Matcher;
2018-09-01 12:42:22 +02:00
import java.util.regex.Pattern;
2017-12-03 10:56:54 +01:00
2019-05-18 11:10:30 +02:00
import app.fedilab.android.R;
import app.fedilab.android.activities.HashTagActivity;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.PeertubeActivity;
import app.fedilab.android.activities.ShowAccountActivity;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.helper.CrossActions;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.interfaces.OnRetrieveEmojiInterface;
2017-05-05 16:36:04 +02:00
2019-05-18 11:10:30 +02:00
import static app.fedilab.android.helper.Helper.THEME_BLACK;
import static app.fedilab.android.helper.Helper.THEME_DARK;
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
2018-09-01 15:59:16 +02:00
2017-05-05 16:36:04 +02:00
/**
* Created by Thomas on 23/04/2017.
2017-05-26 17:20:36 +02:00
* Manage Status (ie: toots)
2017-05-05 16:36:04 +02:00
*/
2017-12-15 18:03:06 +01:00
public class Status implements Parcelable{
2017-05-05 16:36:04 +02:00
private String id;
private String uri;
private String url;
private Account account;
private String in_reply_to_id;
private String in_reply_to_account_id;
private Status reblog;
private Date created_at;
private int reblogs_count;
private int favourites_count;
2018-08-19 15:21:39 +02:00
private int replies_count;
2017-05-05 16:36:04 +02:00
private boolean reblogged;
private boolean favourited;
2018-02-15 07:55:24 +01:00
private boolean muted;
private boolean pinned;
2017-05-05 16:36:04 +02:00
private boolean sensitive;
private boolean bookmarked;
2017-05-05 16:36:04 +02:00
private String visibility;
private boolean attachmentShown = false;
2017-06-07 16:52:53 +02:00
private boolean spoilerShown = false;
private ArrayList<Attachment> media_attachments;
private Attachment art_attachment;
private List<Mention> mentions;
2017-10-20 06:57:53 +02:00
private List<Emojis> emojis;
private List<Tag> tags;
private Application application;
2017-12-20 13:57:28 +01:00
private Card card;
private String language;
private boolean isTranslated = false;
2017-10-20 19:58:46 +02:00
private boolean isEmojiFound = false;
2017-12-03 14:17:57 +01:00
private boolean isEmojiTranslateFound = false;
2017-12-03 10:56:54 +01:00
private boolean isClickable = false;
private boolean isTranslationShown = false;
2017-09-08 18:30:49 +02:00
private boolean isNew = false;
private boolean isVisible = true;
private boolean fetchMore = false;
2017-12-03 14:17:57 +01:00
private String content, contentCW, contentTranslated;
2018-08-17 11:53:21 +02:00
private SpannableString contentSpan, displayNameSpan, contentSpanCW, contentSpanTranslated;
private RetrieveFeedsAsyncTask.Type type;
private int itemViewType;
2018-11-21 18:04:10 +01:00
private String conversationId;
2018-11-28 09:44:19 +01:00
private boolean isExpanded = false;
private int numberLines = -1;
2019-01-31 18:01:08 +01:00
private boolean showSpoiler = false;
2017-12-03 10:56:54 +01:00
2018-11-16 15:39:53 +01:00
public Status(){}
2018-10-29 18:32:55 +01:00
private List<String> conversationProfilePicture;
2018-11-07 11:03:32 +01:00
private String webviewURL = null;
2017-05-05 16:36:04 +02:00
2018-12-03 19:19:36 +01:00
private boolean isBoostAnimated = false, isFavAnimated = false;
2019-01-19 19:41:55 +01:00
private String scheduled_at;
2019-01-26 20:01:11 +01:00
private String contentType;
2019-02-05 18:05:21 +01:00
private boolean isNotice = false;
2019-03-24 16:38:12 +01:00
private Poll poll = null;
2017-05-26 17:20:36 +02:00
2019-05-08 09:37:17 +02:00
private int media_height;
2019-05-12 11:39:25 +02:00
private boolean cached = false;
2019-05-22 18:08:43 +02:00
private boolean autoHiddenCW = false;
2019-06-10 18:33:54 +02:00
private boolean customFeaturesDisplayed = false;
2019-05-08 09:37:17 +02:00
2018-11-15 19:09:44 +01:00
@Override
public void writeToParcel(Parcel dest, int flags) {
2019-01-16 13:58:05 +01:00
dest.writeString(this.id);
dest.writeString(this.uri);
dest.writeString(this.url);
dest.writeParcelable(this.account, flags);
dest.writeString(this.in_reply_to_id);
dest.writeString(this.in_reply_to_account_id);
dest.writeParcelable(this.reblog, flags);
dest.writeLong(this.created_at != null ? this.created_at.getTime() : -1);
dest.writeInt(this.reblogs_count);
dest.writeInt(this.favourites_count);
dest.writeInt(this.replies_count);
dest.writeByte(this.reblogged ? (byte) 1 : (byte) 0);
dest.writeByte(this.favourited ? (byte) 1 : (byte) 0);
dest.writeByte(this.muted ? (byte) 1 : (byte) 0);
dest.writeByte(this.pinned ? (byte) 1 : (byte) 0);
dest.writeByte(this.sensitive ? (byte) 1 : (byte) 0);
dest.writeByte(this.bookmarked ? (byte) 1 : (byte) 0);
dest.writeString(this.visibility);
dest.writeByte(this.attachmentShown ? (byte) 1 : (byte) 0);
dest.writeByte(this.spoilerShown ? (byte) 1 : (byte) 0);
dest.writeTypedList(this.media_attachments);
dest.writeParcelable(this.art_attachment, flags);
dest.writeTypedList(this.mentions);
dest.writeTypedList(this.emojis);
dest.writeTypedList(this.tags);
dest.writeParcelable(this.application, flags);
dest.writeParcelable(this.card, flags);
dest.writeString(this.language);
dest.writeByte(this.isTranslated ? (byte) 1 : (byte) 0);
dest.writeByte(this.isTranslationShown ? (byte) 1 : (byte) 0);
dest.writeByte(this.isNew ? (byte) 1 : (byte) 0);
dest.writeByte(this.isVisible ? (byte) 1 : (byte) 0);
dest.writeByte(this.fetchMore ? (byte) 1 : (byte) 0);
dest.writeString(this.content);
dest.writeString(this.contentCW);
dest.writeString(this.contentTranslated);
TextUtils.writeToParcel(this.contentSpan, dest, flags);
TextUtils.writeToParcel(this.displayNameSpan, dest, flags);
TextUtils.writeToParcel(this.contentSpanCW, dest, flags);
TextUtils.writeToParcel(this.contentSpanTranslated, dest, flags);
dest.writeInt(this.type == null ? -1 : this.type.ordinal());
dest.writeInt(this.itemViewType);
dest.writeString(this.conversationId);
dest.writeByte(this.isExpanded ? (byte) 1 : (byte) 0);
dest.writeInt(this.numberLines);
dest.writeStringList(this.conversationProfilePicture);
dest.writeString(this.webviewURL);
dest.writeByte(this.isBoostAnimated ? (byte) 1 : (byte) 0);
dest.writeByte(this.isFavAnimated ? (byte) 1 : (byte) 0);
2019-01-19 19:41:55 +01:00
dest.writeString(this.scheduled_at);
2019-01-26 20:01:11 +01:00
dest.writeString(this.contentType);
2019-01-31 18:01:08 +01:00
dest.writeByte(this.showSpoiler ? (byte) 1 : (byte) 0);
2019-02-05 18:05:21 +01:00
dest.writeByte(this.isNotice ? (byte) 1 : (byte) 0);
2019-03-24 16:38:12 +01:00
dest.writeParcelable(this.poll, flags);
2019-05-08 09:37:17 +02:00
dest.writeInt(this.media_height);
2019-05-12 11:39:25 +02:00
dest.writeByte(this.cached ? (byte) 1 : (byte) 0);
2019-05-22 18:08:43 +02:00
dest.writeByte(this.autoHiddenCW ? (byte) 1 : (byte) 0);
2019-06-10 18:33:54 +02:00
dest.writeByte(this.customFeaturesDisplayed ? (byte) 1 : (byte) 0);
2018-11-15 19:09:44 +01:00
}
2017-12-03 10:56:54 +01:00
2019-01-16 13:58:05 +01:00
protected Status(Parcel in) {
this.id = in.readString();
this.uri = in.readString();
this.url = in.readString();
this.account = in.readParcelable(Account.class.getClassLoader());
this.in_reply_to_id = in.readString();
this.in_reply_to_account_id = in.readString();
this.reblog = in.readParcelable(Status.class.getClassLoader());
long tmpCreated_at = in.readLong();
this.created_at = tmpCreated_at == -1 ? null : new Date(tmpCreated_at);
this.reblogs_count = in.readInt();
this.favourites_count = in.readInt();
this.replies_count = in.readInt();
this.reblogged = in.readByte() != 0;
this.favourited = in.readByte() != 0;
this.muted = in.readByte() != 0;
this.pinned = in.readByte() != 0;
this.sensitive = in.readByte() != 0;
this.bookmarked = in.readByte() != 0;
this.visibility = in.readString();
this.attachmentShown = in.readByte() != 0;
this.spoilerShown = in.readByte() != 0;
this.media_attachments = in.createTypedArrayList(Attachment.CREATOR);
this.art_attachment = in.readParcelable(Attachment.class.getClassLoader());
this.mentions = in.createTypedArrayList(Mention.CREATOR);
this.emojis = in.createTypedArrayList(Emojis.CREATOR);
this.tags = in.createTypedArrayList(Tag.CREATOR);
this.application = in.readParcelable(Application.class.getClassLoader());
this.card = in.readParcelable(Card.class.getClassLoader());
this.language = in.readString();
this.isTranslated = in.readByte() != 0;
this.isTranslationShown = in.readByte() != 0;
this.isNew = in.readByte() != 0;
this.isVisible = in.readByte() != 0;
this.fetchMore = in.readByte() != 0;
this.content = in.readString();
this.contentCW = in.readString();
this.contentTranslated = in.readString();
this.contentSpan = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
this.displayNameSpan = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
this.contentSpanCW = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
this.contentSpanTranslated = (SpannableString) TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
int tmpType = in.readInt();
this.type = tmpType == -1 ? null : RetrieveFeedsAsyncTask.Type.values()[tmpType];
this.itemViewType = in.readInt();
this.conversationId = in.readString();
this.isExpanded = in.readByte() != 0;
this.numberLines = in.readInt();
this.conversationProfilePicture = in.createStringArrayList();
this.webviewURL = in.readString();
this.isBoostAnimated = in.readByte() != 0;
this.isFavAnimated = in.readByte() != 0;
2019-01-19 19:41:55 +01:00
this.scheduled_at = in.readString();
2019-01-26 20:01:11 +01:00
this.contentType = in.readString();
2019-01-31 18:01:08 +01:00
this.showSpoiler = in.readByte() != 0;
2019-02-05 18:05:21 +01:00
this.isNotice = in.readByte() != 0;
2019-03-24 16:38:12 +01:00
this.poll = in.readParcelable(Poll.class.getClassLoader());
2019-05-08 09:37:17 +02:00
this.media_height = in.readInt();
2019-05-12 11:39:25 +02:00
this.cached = in.readByte() != 0;
2019-05-22 18:08:43 +02:00
this.autoHiddenCW = in.readByte() != 0;
2019-06-10 18:33:54 +02:00
this.customFeaturesDisplayed = in.readByte() != 0;
2019-01-16 13:58:05 +01:00
}
2017-05-26 17:20:36 +02:00
public static final Creator<Status> CREATOR = new Creator<Status>() {
@Override
2019-01-16 13:58:05 +01:00
public Status createFromParcel(Parcel source) {
return new Status(source);
2017-05-26 17:20:36 +02:00
}
@Override
public Status[] newArray(int size) {
return new Status[size];
}
};
2019-01-16 13:58:05 +01:00
2017-05-05 16:36:04 +02:00
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public String getIn_reply_to_id() {
return in_reply_to_id;
}
public void setIn_reply_to_id(String in_reply_to_id) {
this.in_reply_to_id = in_reply_to_id;
}
public String getIn_reply_to_account_id() {
return in_reply_to_account_id;
}
public void setIn_reply_to_account_id(String in_reply_to_account_id) {
this.in_reply_to_account_id = in_reply_to_account_id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
//Remove UTM by default
2019-04-17 16:25:42 +02:00
this.content = Helper.remove_tracking_param(content);
2017-05-05 16:36:04 +02:00
}
public Status getReblog() {
return reblog;
}
public void setReblog(Status reblog) {
this.reblog = reblog;
}
public int getReblogs_count() {
return reblogs_count;
}
public void setReblogs_count(int reblogs_count) {
this.reblogs_count = reblogs_count;
}
public Date getCreated_at() {
return created_at;
}
public void setCreated_at(Date created_at) {
this.created_at = created_at;
}
public int getFavourites_count() {
return favourites_count;
}
public void setFavourites_count(int favourites_count) {
this.favourites_count = favourites_count;
}
2018-08-17 11:53:21 +02:00
public SpannableString getDisplayNameSpan(){
2018-08-17 16:22:26 +02:00
return this.displayNameSpan;
2018-08-17 11:53:21 +02:00
}
public void setDisplayNameSpan(SpannableString displayNameSpan){
this.displayNameSpan = displayNameSpan;
}
2017-05-05 16:36:04 +02:00
public boolean isReblogged() {
return reblogged;
}
public void setReblogged(boolean reblogged) {
this.reblogged = reblogged;
}
public boolean isFavourited() {
return favourited;
}
public void setFavourited(boolean favourited) {
this.favourited = favourited;
}
public void setPinned(boolean pinned) { this.pinned = pinned; }
public boolean isPinned() { return pinned; }
2017-05-05 16:36:04 +02:00
public boolean isSensitive() {
return sensitive;
}
public void setSensitive(boolean sensitive) {
this.sensitive = sensitive;
}
public String getSpoiler_text() {
2017-12-03 14:17:57 +01:00
return contentCW;
2017-05-05 16:36:04 +02:00
}
public void setSpoiler_text(String spoiler_text) {
2017-12-03 14:17:57 +01:00
this.contentCW = spoiler_text;
2017-05-05 16:36:04 +02:00
}
public ArrayList<Attachment> getMedia_attachments() {
2017-05-05 16:36:04 +02:00
return media_attachments;
}
public void setMedia_attachments(ArrayList<Attachment> media_attachments) {
2017-05-05 16:36:04 +02:00
this.media_attachments = media_attachments;
}
public List<Mention> getMentions() {
return mentions;
}
public void setMentions(List<Mention> mentions) {
this.mentions = mentions;
}
public List<Tag> getTags() {
return tags;
}
public String getTagsString() {
//iterate through tags and create comma delimited string of tag names
String tag_names = "";
for (Tag t : tags) {
if (tag_names.equals("")) {
tag_names = t.getName();
} else {
tag_names = tag_names + ", " + t.getName();
}
}
return tag_names;
}
2017-05-05 16:36:04 +02:00
public void setTags(List<Tag> tags) {
this.tags = tags;
}
public Application getApplication() {
return application;
}
public void setApplication(Application application) {
this.application = application;
}
public String getVisibility() {
return visibility;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}
public boolean isAttachmentShown() {
return attachmentShown;
}
public void setAttachmentShown(boolean attachmentShown) {
this.attachmentShown = attachmentShown;
}
2017-05-26 17:20:36 +02:00
2017-06-07 16:52:53 +02:00
public boolean isSpoilerShown() {
return spoilerShown;
}
public void setSpoilerShown(boolean spoilerShown) {
this.spoilerShown = spoilerShown;
2017-05-26 17:20:36 +02:00
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public boolean isTranslated() {
return isTranslated;
}
public void setTranslated(boolean translated) {
isTranslated = translated;
}
public boolean isTranslationShown() {
return isTranslationShown;
}
public void setTranslationShown(boolean translationShown) {
isTranslationShown = translationShown;
}
2017-12-03 14:17:57 +01:00
public String getContentTranslated() {
return contentTranslated;
}
2017-12-03 14:17:57 +01:00
public void setContentTranslated(String content_translated) {
this.contentTranslated = content_translated;
}
2017-08-16 18:08:16 +02:00
2017-09-08 18:30:49 +02:00
public boolean isNew() {
return isNew;
}
public void setNew(boolean aNew) {
isNew = aNew;
}
2017-09-18 20:32:36 +02:00
public boolean isVisible() {
return isVisible;
}
public void setVisible(boolean visible) {
isVisible = visible;
}
2017-10-20 06:54:21 +02:00
2017-10-20 06:57:53 +02:00
public List<Emojis> getEmojis() {
2017-10-20 06:54:21 +02:00
return emojis;
}
2017-10-20 06:57:53 +02:00
public void setEmojis(List<Emojis> emojis) {
2017-10-20 06:54:21 +02:00
this.emojis = emojis;
}
2017-10-20 19:58:46 +02:00
2017-12-03 10:56:54 +01:00
public boolean isEmojiFound() {
return isEmojiFound;
2017-10-20 19:58:46 +02:00
}
2018-11-15 19:09:44 +01:00
2017-12-03 10:56:54 +01:00
public void setEmojiFound(boolean emojiFound) {
isEmojiFound = emojiFound;
2017-10-20 19:58:46 +02:00
}
2017-12-03 10:56:54 +01:00
2018-11-16 07:33:19 +01:00
public static void transform(Context context, Status status){
2017-12-03 10:56:54 +01:00
if( ((Activity)context).isFinishing() || status == null)
2018-01-11 07:32:19 +01:00
return;
2017-12-03 11:14:52 +01:00
SpannableString spannableStringContent, spannableStringCW;
2018-04-28 16:54:06 +02:00
if( (status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null))
return;
2019-05-28 17:40:00 +02:00
String content = status.getReblog() != null ?status.getReblog().getContent():status.getContent();
Pattern aLink = Pattern.compile("<a href=\"([^\"]*)\"[^>]*(((?!<\\/a).)*)<\\/a>");
Matcher matcherALink = aLink.matcher(content);
while (matcherALink.find()){
String beforemodification;
String urlText = matcherALink.group(2);
2019-05-29 18:15:55 +02:00
2019-05-28 17:40:00 +02:00
urlText = urlText.substring(1);
beforemodification = urlText;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
urlText = new SpannableString(Html.fromHtml(urlText, Html.FROM_HTML_MODE_LEGACY)).toString();
else
urlText = new SpannableString(Html.fromHtml(urlText)).toString();
if( urlText.startsWith("http") ){
urlText = urlText.replace("http://","").replace("https://","").replace("www.","");
if( urlText.length() > 31){
urlText = urlText.substring(0,30);
urlText += '…';
}
}
2019-06-08 17:45:40 +02:00
content = content.replace(beforemodification,urlText);
2019-05-28 17:40:00 +02:00
}
spannableStringContent = new SpannableString(content);
2018-12-07 20:11:50 +01:00
String spoilerText = "";
if( status.getReblog() != null && status.getReblog().getSpoiler_text() != null)
spoilerText = status.getReblog().getSpoiler_text();
else if( status.getSpoiler_text() != null)
spoilerText = status.getSpoiler_text();
2017-12-03 10:56:54 +01:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
2018-12-07 20:11:50 +01:00
spannableStringCW = new SpannableString(Html.fromHtml(spoilerText, Html.FROM_HTML_MODE_LEGACY));
2017-12-03 10:56:54 +01:00
else
//noinspection deprecation
2018-12-07 20:11:50 +01:00
spannableStringCW = new SpannableString(Html.fromHtml(spoilerText));
2018-11-15 19:09:44 +01:00
if( spannableStringContent.length() > 0)
status.setContentSpan(treatment(context, spannableStringContent, status));
if( spannableStringCW.length() > 0)
status.setContentSpanCW(treatment(context, spannableStringCW, status));
2018-11-18 08:38:33 +01:00
SpannableString displayNameSpan = new SpannableString(status.reblog!=null?status.getReblog().getAccount().getDisplay_name():status.getAccount().getDisplay_name());
status.setDisplayNameSpan(displayNameSpan);
2018-11-15 19:09:44 +01:00
status.setClickable(true);
2017-12-03 11:14:52 +01:00
}
2018-11-16 07:33:19 +01:00
public static void transformTranslation(Context context, Status status){
2017-12-03 11:14:52 +01:00
if( ((Activity)context).isFinishing() || status == null)
2018-01-11 07:32:19 +01:00
return;
2018-04-28 16:54:06 +02:00
if( (status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null))
return;
2017-12-03 11:14:52 +01:00
SpannableString spannableStringTranslated;
2017-12-03 10:56:54 +01:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
2018-09-19 09:08:15 +02:00
spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated(), Html.FROM_HTML_MODE_LEGACY));
2017-12-03 10:56:54 +01:00
else
//noinspection deprecation
2017-12-03 14:17:57 +01:00
spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated()));
2017-12-03 10:56:54 +01:00
2018-11-15 19:09:44 +01:00
status.setContentSpanTranslated(treatment(context, spannableStringTranslated, status));
2018-11-16 07:33:19 +01:00
String displayName;
if( status.getReblog() != null){
displayName = status.getReblog().getAccount().getDisplay_name();
}else {
displayName = status.getAccount().getDisplay_name();
}
SpannableString contentSpanTranslated = status.getContentSpanTranslated();
Matcher matcherALink = Patterns.WEB_URL.matcher(contentSpanTranslated.toString());
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
while (matcherALink.find()){
int matchStart = matcherALink.start();
int matchEnd = matcherALink.end();
final String url = contentSpanTranslated.toString().substring(matcherALink.start(1), matcherALink.end(1));
if( matchEnd <= contentSpanTranslated.toString().length() && matchEnd >= matchStart)
contentSpanTranslated.setSpan(new ClickableSpan() {
@Override
public void onClick(@NonNull View textView) {
String finalUrl = url;
if( !url.startsWith("http://") && ! url.startsWith("https://"))
finalUrl = "http://" + url;
Helper.openBrowser(context, finalUrl);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
}
},
matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
status.setContentSpanTranslated(contentSpanTranslated);
2018-11-16 07:33:19 +01:00
SpannableString displayNameSpan = new SpannableString(displayName);
status.setDisplayNameSpan(displayNameSpan);
2017-12-03 10:56:54 +01:00
}
2018-11-15 19:19:24 +01:00
public static void makeEmojis(final Context context, final OnRetrieveEmojiInterface listener, Status status){
2017-12-03 10:56:54 +01:00
2018-01-11 07:32:19 +01:00
if( ((Activity)context).isFinishing() )
return;
if( status.getAccount() == null)
return;
2018-09-07 18:51:47 +02:00
if( status.getReblog() != null && status.getReblog().getEmojis() == null)
return;
if( status.getReblog() == null && status.getEmojis() == null)
return;
2017-12-03 10:56:54 +01:00
final List<Emojis> emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis();
2018-09-08 15:34:25 +02:00
final List<Emojis> emojisAccounts = status.getReblog() != null ?status.getReblog().getAccount().getEmojis():status.getAccount().getEmojis();
2018-08-17 16:22:26 +02:00
2018-12-23 20:01:19 +01:00
status.getAccount().makeAccountNameEmoji(context, null, status.getAccount());
2018-11-16 07:33:19 +01:00
SpannableString displayNameSpan = status.getDisplayNameSpan();
SpannableString contentSpan = status.getContentSpan();
SpannableString contentSpanCW = status.getContentSpanCW();
2018-08-17 16:22:26 +02:00
if( emojisAccounts != null)
emojis.addAll(emojisAccounts);
2017-12-03 10:56:54 +01:00
if( emojis != null && emojis.size() > 0 ) {
final int[] i = {0};
for (final Emojis emoji : emojis) {
Glide.with(context)
.asBitmap()
.load(emoji.getUrl())
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
i[0]++;
if( i[0] == (emojis.size())) {
2017-12-03 14:17:57 +01:00
listener.onRetrieveEmoji(status,false);
2017-12-03 10:56:54 +01:00
}
return false;
}
})
.into(new SimpleTarget<Bitmap>() {
@Override
2018-04-28 16:54:06 +02:00
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
2017-12-03 10:56:54 +01:00
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
2018-11-16 07:33:19 +01:00
if (contentSpan != null && contentSpan.toString().contains(targetedEmoji)) {
2017-12-03 10:56:54 +01:00
//emojis can be used several times so we have to loop
for (int startPosition = -1; (startPosition = contentSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
2017-12-03 10:56:54 +01:00
final int endPosition = startPosition + targetedEmoji.length();
2018-08-17 11:53:21 +02:00
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition)
2018-04-28 16:54:06 +02:00
contentSpan.setSpan(
2017-12-03 10:56:54 +01:00
new ImageSpan(context,
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
2018-11-16 07:33:19 +01:00
if (displayNameSpan != null && displayNameSpan.toString().contains(targetedEmoji)) {
2018-08-17 11:53:21 +02:00
//emojis can be used several times so we have to loop
for (int startPosition = -1; (startPosition = displayNameSpan.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
final int endPosition = startPosition + targetedEmoji.length();
if(endPosition <= displayNameSpan.toString().length() && endPosition >= startPosition)
displayNameSpan.setSpan(
new ImageSpan(context,
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
2018-11-16 07:33:19 +01:00
status.setDisplayNameSpan(displayNameSpan);
if (contentSpanCW != null && contentSpanCW.toString().contains(targetedEmoji)) {
2017-12-03 10:56:54 +01:00
//emojis can be used several times so we have to loop
for (int startPosition = -1; (startPosition = contentSpanCW.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
2017-12-03 10:56:54 +01:00
final int endPosition = startPosition + targetedEmoji.length();
2018-08-17 11:53:21 +02:00
if( endPosition <= contentSpan.toString().length() && endPosition >= startPosition)
2018-04-28 16:54:06 +02:00
contentSpanCW.setSpan(
2017-12-03 10:56:54 +01:00
new ImageSpan(context,
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
2017-12-03 14:17:57 +01:00
i[0]++;
if( i[0] == (emojis.size())) {
2018-11-15 19:09:44 +01:00
status.setContentSpan(contentSpan);
status.setContentSpanCW(contentSpanCW);
2018-11-15 19:19:24 +01:00
status.setEmojiFound(true);
2017-12-03 14:17:57 +01:00
listener.onRetrieveEmoji(status, false);
}
}
});
}
}
}
2018-11-15 19:19:24 +01:00
public static void makeEmojisTranslation(final Context context, final OnRetrieveEmojiInterface listener, Status status){
2017-12-03 14:17:57 +01:00
2018-01-11 07:32:19 +01:00
if( ((Activity)context).isFinishing() )
return;
2017-12-03 14:17:57 +01:00
SpannableString spannableStringTranslated = null;
2018-05-12 09:41:47 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
2017-12-03 14:17:57 +01:00
if( status.getContentTranslated() != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
2018-09-19 09:08:15 +02:00
spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated(), Html.FROM_HTML_MODE_LEGACY));
2017-12-03 14:17:57 +01:00
else
//noinspection deprecation
spannableStringTranslated = new SpannableString(Html.fromHtml(status.getContentTranslated()));
}
final List<Emojis> emojis = status.getReblog() != null ? status.getReblog().getEmojis() : status.getEmojis();
if( emojis != null && emojis.size() > 0 ) {
final int[] i = {0};
for (final Emojis emoji : emojis) {
final SpannableString finalSpannableStringTranslated = spannableStringTranslated;
Glide.with(context)
.asBitmap()
.load(emoji.getUrl())
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
i[0]++;
if( i[0] == (emojis.size())) {
if( finalSpannableStringTranslated != null)
status.setContentSpanTranslated(finalSpannableStringTranslated);
listener.onRetrieveEmoji(status, true);
}
return false;
}
})
.into(new SimpleTarget<Bitmap>() {
@Override
2018-08-17 16:22:26 +02:00
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
2017-12-03 14:17:57 +01:00
final String targetedEmoji = ":" + emoji.getShortcode() + ":";
2017-12-03 11:14:52 +01:00
if (finalSpannableStringTranslated != null && finalSpannableStringTranslated.toString().contains(targetedEmoji)) {
2017-12-03 10:56:54 +01:00
//emojis can be used several times so we have to loop
2017-12-03 11:14:52 +01:00
for (int startPosition = -1; (startPosition = finalSpannableStringTranslated.toString().indexOf(targetedEmoji, startPosition + 1)) != -1; startPosition++) {
2017-12-03 10:56:54 +01:00
final int endPosition = startPosition + targetedEmoji.length();
2018-08-17 16:22:26 +02:00
if( endPosition <= finalSpannableStringTranslated.toString().length() && endPosition >= startPosition)
2018-04-28 16:54:06 +02:00
finalSpannableStringTranslated.setSpan(
2017-12-03 10:56:54 +01:00
new ImageSpan(context,
Bitmap.createScaledBitmap(resource, (int) Helper.convertDpToPixel(20, context),
(int) Helper.convertDpToPixel(20, context), false)), startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
i[0]++;
if( i[0] == (emojis.size())) {
2017-12-03 11:14:52 +01:00
if( finalSpannableStringTranslated != null)
status.setContentSpanTranslated(finalSpannableStringTranslated);
2018-11-15 19:19:24 +01:00
status.setEmojiTranslateFound(true);
2017-12-03 14:17:57 +01:00
listener.onRetrieveEmoji(status, true);
2017-12-03 10:56:54 +01:00
}
}
});
}
}
2017-10-20 19:58:46 +02:00
}
2017-12-03 10:56:54 +01:00
2018-11-15 19:09:44 +01:00
private static SpannableString treatment(final Context context, final SpannableString spannableString, Status status){
2017-12-03 10:56:54 +01:00
URLSpan[] urls = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for(URLSpan span : urls)
spannableString.removeSpan(span);
2018-11-15 19:09:44 +01:00
List<Mention> mentions = status.getReblog() != null ? status.getReblog().getMentions() : status.getMentions();
2018-09-25 17:49:11 +02:00
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
Matcher matcher;
2018-09-15 12:43:36 +02:00
Pattern linkPattern = Pattern.compile("<a href=\"([^\"]*)\"[^>]*(((?!<\\/a).)*)<\\/a>");
matcher = linkPattern.matcher(spannableString);
HashMap<String, String> targetedURL = new HashMap<>();
while (matcher.find()){
String key;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
key = new SpannableString(Html.fromHtml(matcher.group(2), Html.FROM_HTML_MODE_LEGACY)).toString();
else
//noinspection deprecation
key = new SpannableString(Html.fromHtml(matcher.group(2))).toString();
key = key.substring(1);
2018-10-11 07:41:26 +02:00
if( !key.startsWith("#") && !key.startsWith("@") && !key.trim().equals("") && !matcher.group(1).contains("search?tag=")) {
2018-09-25 17:49:11 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
targetedURL.put(key, Html.fromHtml(matcher.group(1), Html.FROM_HTML_MODE_LEGACY).toString());
}
else
targetedURL.put(key, Html.fromHtml(matcher.group(1)).toString());
}
2018-09-15 12:43:36 +02:00
}
2018-09-15 14:36:19 +02:00
String currentInstance = Helper.getLiveInstance(context);
2018-09-15 09:04:41 +02:00
//Get url to account that are unknown
2018-09-22 19:13:55 +02:00
Pattern aLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
2018-09-01 12:42:22 +02:00
Matcher matcherALink = aLink.matcher(spannableString.toString());
2018-09-15 09:04:41 +02:00
ArrayList<Account> accountsMentionUnknown = new ArrayList<>();
while (matcherALink.find()){
String acct = matcherALink.group(3).replace("@","");
String instance = matcherALink.group(2);
2018-09-15 14:36:19 +02:00
boolean addAccount = true;
for(Mention mention: mentions){
String[] accountMentionAcct = mention.getAcct().split("@");
//Different isntance
if( accountMentionAcct.length > 1){
if( mention.getAcct().equals(acct+"@"+instance))
addAccount = false;
}else {
if( (mention.getUsername()+"@"+currentInstance).equals(acct+"@"+instance))
addAccount = false;
}
}
2018-09-16 16:23:35 +02:00
if( addAccount) {
Account account = new Account();
account.setAcct(acct);
account.setInstance(instance);
accountsMentionUnknown.add(account);
}
2018-09-15 09:04:41 +02:00
}
2018-09-22 19:13:55 +02:00
aLink = Pattern.compile("(<\\s?a\\s?href=\"(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10}[\\/]?[^\"@(\\/tags\\/)]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)");
2018-09-15 09:04:41 +02:00
matcherALink = aLink.matcher(spannableString.toString());
2018-09-01 12:42:22 +02:00
while (matcherALink.find()){
int matchStart = matcherALink.start();
int matchEnd = matcherALink.end();
final String url = spannableString.toString().substring(matcherALink.start(1), matcherALink.end(1));
2018-09-25 17:49:11 +02:00
2018-09-01 12:42:22 +02:00
if( matchEnd <= spannableString.toString().length() && matchEnd >= matchStart)
spannableString.setSpan(new ClickableSpan() {
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2018-09-01 12:42:22 +02:00
String finalUrl = url;
if( !url.startsWith("http://") && ! url.startsWith("https://"))
finalUrl = "http://" + url;
Helper.openBrowser(context, finalUrl);
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-09-01 12:42:22 +02:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-09-01 12:42:22 +02:00
}
},
matchStart, matchEnd,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2018-11-02 14:42:29 +01:00
2018-09-01 12:42:22 +02:00
}
SpannableString spannableStringT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
2019-04-16 18:44:51 +02:00
spannableStringT = new SpannableString(Html.fromHtml(spannableString.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>","").replaceAll("<br />","<br/>").replaceAll("[\\s]{2}","&nbsp;&nbsp;"), Html.FROM_HTML_MODE_LEGACY));
2018-09-01 12:42:22 +02:00
else
//noinspection deprecation
2019-04-16 18:44:51 +02:00
spannableStringT = new SpannableString(Html.fromHtml(spannableString.toString().replaceAll("^<p>","").replaceAll("<p>","<br/><br/>").replaceAll("</p>","").replaceAll("<br />","<br/>").replaceAll("[\\s]{2}","&nbsp;&nbsp;")));
2018-11-15 19:19:24 +01:00
2018-10-10 07:58:28 +02:00
URLSpan[] spans = spannableStringT.getSpans(0, spannableStringT.length(), URLSpan.class);
for (URLSpan span : spans) {
spannableStringT.removeSpan(span);
}
2018-08-14 18:27:21 +02:00
matcher = Helper.twitterPattern.matcher(spannableStringT);
2018-08-14 18:27:21 +02:00
while (matcher.find()){
int matchStart = matcher.start(2);
int matchEnd = matcher.end();
final String twittername = matcher.group(2);
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
spannableStringT.setSpan(new ClickableSpan() {
2018-08-14 18:27:21 +02:00
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2018-08-14 18:27:21 +02:00
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+twittername.substring(1).replace("@twitter.com","")));
context.startActivity(intent);
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-08-14 18:27:21 +02:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-08-14 18:27:21 +02:00
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
2018-09-15 09:04:41 +02:00
if( accountsMentionUnknown.size() > 0 ) {
for(Account account: accountsMentionUnknown){
String targetedAccount = "@" + account.getAcct();
if (spannableStringT.toString().toLowerCase().contains(targetedAccount.toLowerCase())) {
//Accounts can be mentioned several times so we have to loop
for(int startPosition = -1 ; (startPosition = spannableStringT.toString().toLowerCase().indexOf(targetedAccount.toLowerCase(), startPosition + 1)) != -1 ; startPosition++){
int endPosition = startPosition + targetedAccount.length();
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2018-09-15 09:04:41 +02:00
CrossActions.doCrossProfile(context,account);
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-09-15 09:04:41 +02:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-09-15 09:04:41 +02:00
}
},
2019-01-24 11:49:23 +01:00
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2018-09-15 09:04:41 +02:00
}
}
}
}
2018-09-15 12:43:36 +02:00
if( targetedURL.size() > 0 ){
Iterator it = targetedURL.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
String key = (String) pair.getKey();
String url = (String) pair.getValue();
if (spannableStringT.toString().toLowerCase().contains(key.toLowerCase())) {
//Accounts can be mentioned several times so we have to loop
for(int startPosition = -1 ; (startPosition = spannableStringT.toString().toLowerCase().indexOf(key.toLowerCase(), startPosition + 1)) != -1 ; startPosition++){
int endPosition = startPosition + key.length();
2018-10-10 07:58:28 +02:00
2018-09-29 14:11:42 +02:00
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition) {
2018-09-15 12:43:36 +02:00
spannableStringT.setSpan(new ClickableSpan() {
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2018-09-15 12:43:36 +02:00
String finalUrl = url;
2018-09-22 19:13:55 +02:00
Pattern link = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\w._-]*[0-9]*)(\\/[0-9]{1,})?$");
2018-09-15 12:43:36 +02:00
Matcher matcherLink = link.matcher(url);
if( matcherLink.find()){
2018-12-07 16:35:52 +01:00
if( matcherLink.group(3) != null && matcherLink.group(3).length() > 0 ){ //It's a toot
CrossActions.doCrossConversation(context, finalUrl);
}else{//It's an account
Account account = status.getAccount();
account.setAcct(matcherLink.group(2));
account.setInstance(matcherLink.group(1));
CrossActions.doCrossProfile(context, account);
}
2018-09-15 12:43:36 +02:00
}else {
2018-09-29 14:11:42 +02:00
link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/watch\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
matcherLink = link.matcher(url);
if( matcherLink.find()){ //Peertubee video
2018-10-14 17:36:18 +02:00
Intent intent = new Intent(context, PeertubeActivity.class);
2018-09-29 14:11:42 +02:00
Bundle b = new Bundle();
2018-10-14 17:36:18 +02:00
String url = matcherLink.group(1) + "/videos/watch/" + matcherLink.group(2);
2018-09-29 14:11:42 +02:00
b.putString("peertubeLinkToFetch", url);
2018-10-14 17:36:18 +02:00
b.putString("peertube_instance", matcherLink.group(1).replace("https://","").replace("http://",""));
b.putString("video_id", matcherLink.group(2));
2018-09-29 14:11:42 +02:00
intent.putExtras(b);
context.startActivity(intent);
}else {
if( !url.startsWith("http://") && ! url.startsWith("https://"))
finalUrl = "http://" + url;
Helper.openBrowser(context, finalUrl);
}
2018-09-15 12:43:36 +02:00
}
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-09-15 12:43:36 +02:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-09-15 12:43:36 +02:00
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2018-09-29 14:11:42 +02:00
}
2018-09-15 12:43:36 +02:00
}
}
it.remove();
}
}
2017-12-03 10:56:54 +01:00
//Deals with mention to make them clickable
if( mentions != null && mentions.size() > 0 ) {
//Looping through accounts which are mentioned
for (final Mention mention : mentions) {
String targetedAccount = "@" + mention.getUsername();
2018-11-18 11:57:15 +01:00
if(spannableStringT.toString().toLowerCase().contains(("@" + mention.getAcct()).toLowerCase())) {
2018-11-24 19:07:39 +01:00
targetedAccount = "@" + mention.getAcct();
2018-11-18 11:57:15 +01:00
if (spannableStringT.toString().toLowerCase().contains(targetedAccount.toLowerCase())) {
//Accounts can be mentioned several times so we have to loop
for (int startPosition = -1; (startPosition = spannableStringT.toString().toLowerCase().indexOf(targetedAccount.toLowerCase(), startPosition + 1)) != -1; startPosition++) {
int endPosition = startPosition + targetedAccount.length();
if (endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2018-11-18 11:57:15 +01:00
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-11-18 11:57:15 +01:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-11-18 11:57:15 +01:00
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}else if (spannableStringT.toString().toLowerCase().contains(targetedAccount.toLowerCase())) {
2017-12-03 10:56:54 +01:00
//Accounts can be mentioned several times so we have to loop
2018-09-01 12:42:22 +02:00
for(int startPosition = -1 ; (startPosition = spannableStringT.toString().toLowerCase().indexOf(targetedAccount.toLowerCase(), startPosition + 1)) != -1 ; startPosition++){
2017-12-03 10:56:54 +01:00
int endPosition = startPosition + targetedAccount.length();
2018-09-01 12:42:22 +02:00
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
2019-01-24 11:49:23 +01:00
@Override
public void onClick(@NonNull View textView) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
intent.putExtras(b);
context.startActivity(intent);
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
}
},
startPosition, endPosition,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2017-12-03 10:56:54 +01:00
}
}
}
}
2018-09-01 12:42:22 +02:00
matcher = Helper.hashtagPattern.matcher(spannableStringT);
2017-12-03 10:56:54 +01:00
while (matcher.find()){
int matchStart = matcher.start(1);
int matchEnd = matcher.end();
2018-09-01 12:42:22 +02:00
final String tag = spannableStringT.toString().substring(matchStart, matchEnd);
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
spannableStringT.setSpan(new ClickableSpan() {
2018-04-28 16:54:06 +02:00
@Override
2019-01-24 11:49:23 +01:00
public void onClick(@NonNull View textView) {
2019-02-08 19:13:40 +01:00
if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
Intent intent = new Intent(context, HashTagActivity.class);
Bundle b = new Bundle();
b.putString("tag", tag.substring(1));
intent.putExtras(b);
context.startActivity(intent);
}
2018-04-28 16:54:06 +02:00
}
@Override
2019-01-24 11:49:23 +01:00
public void updateDrawState(@NonNull TextPaint ds) {
2018-04-28 16:54:06 +02:00
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot));
else if (theme == THEME_BLACK)
ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot));
else if (theme == THEME_LIGHT)
2018-12-15 11:05:09 +01:00
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
2018-04-28 16:54:06 +02:00
}
}, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
2017-12-03 10:56:54 +01:00
}
2018-09-01 12:42:22 +02:00
return spannableStringT;
2017-10-20 19:58:46 +02:00
}
2017-12-03 10:56:54 +01:00
public SpannableString getContentSpan() {
return contentSpan;
2017-10-20 19:58:46 +02:00
}
2017-12-03 10:56:54 +01:00
public void setContentSpan(SpannableString contentSpan) {
this.contentSpan = contentSpan;
}
public SpannableString getContentSpanCW() {
return contentSpanCW;
}
public void setContentSpanCW(SpannableString contentSpanCW) {
this.contentSpanCW = contentSpanCW;
}
public SpannableString getContentSpanTranslated() {
return contentSpanTranslated;
}
public void setContentSpanTranslated(SpannableString contentSpanTranslated) {
this.contentSpanTranslated = contentSpanTranslated;
}
2018-11-15 19:09:44 +01:00
public void setClickable(boolean clickable) {
isClickable = clickable;
}
2017-12-03 10:56:54 +01:00
public boolean isClickable() {
return isClickable;
2017-10-20 19:58:46 +02:00
}
2017-12-03 14:17:57 +01:00
public boolean isEmojiTranslateFound() {
return isEmojiTranslateFound;
}
public void setEmojiTranslateFound(boolean emojiTranslateFound) {
isEmojiTranslateFound = emojiTranslateFound;
}
public boolean isFetchMore() {
return fetchMore;
}
public void setFetchMore(boolean fetchMore) {
this.fetchMore = fetchMore;
}
2017-12-07 17:48:03 +01:00
@Override
public boolean equals(Object otherStatus) {
return otherStatus != null && (otherStatus == this || otherStatus instanceof Status && this.getId().equals(((Status) otherStatus).getId()));
}
2017-12-20 13:57:28 +01:00
public Card getCard() {
return card;
}
public void setCard(Card card) {
this.card = card;
}
2018-02-15 07:55:24 +01:00
public boolean isMuted() {
return muted;
}
public void setMuted(boolean muted) {
this.muted = muted;
}
public boolean isBookmarked() {
return bookmarked;
}
public void setBookmarked(boolean bookmarked) {
this.bookmarked = bookmarked;
}
2018-08-19 15:21:39 +02:00
public int getReplies_count() {
return replies_count;
}
public void setReplies_count(int replies_count) {
this.replies_count = replies_count;
}
public RetrieveFeedsAsyncTask.Type getType() {
return type;
}
public void setType(RetrieveFeedsAsyncTask.Type type) {
this.type = type;
}
2018-10-29 18:32:55 +01:00
public List<String> getConversationProfilePicture() {
return conversationProfilePicture;
}
public void setConversationProfilePicture(List<String> conversationProfilePicture) {
this.conversationProfilePicture = conversationProfilePicture;
}
2018-11-07 11:03:32 +01:00
public String getWebviewURL() {
return webviewURL;
}
public void setWebviewURL(String webviewURL) {
this.webviewURL = webviewURL;
}
public int getItemViewType() {
return itemViewType;
}
public void setItemViewType(int itemViewType) {
this.itemViewType = itemViewType;
}
2018-11-21 18:04:10 +01:00
public String getConversationId() {
return conversationId;
}
public void setConversationId(String conversationId) {
this.conversationId = conversationId;
}
2018-11-28 09:44:19 +01:00
public boolean isExpanded() {
return isExpanded;
}
public void setExpanded(boolean expanded) {
isExpanded = expanded;
}
public int getNumberLines() {
return numberLines;
}
public void setNumberLines(int numberLines) {
this.numberLines = numberLines;
}
2018-12-03 19:19:36 +01:00
public boolean isBoostAnimated() {
return isBoostAnimated;
}
public void setBoostAnimated(boolean boostAnimated) {
isBoostAnimated = boostAnimated;
}
public boolean isFavAnimated() {
return isFavAnimated;
}
public void setFavAnimated(boolean favAnimated) {
isFavAnimated = favAnimated;
}
public Attachment getArt_attachment() {
return art_attachment;
}
public void setArt_attachment(Attachment art_attachment) {
this.art_attachment = art_attachment;
}
2019-01-16 13:58:05 +01:00
@Override
public int describeContents() {
return 0;
}
2019-01-19 19:41:55 +01:00
public String getScheduled_at() {
return scheduled_at;
}
public void setScheduled_at(String scheduled_at) {
this.scheduled_at = scheduled_at;
}
2019-01-26 20:01:11 +01:00
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
2019-01-31 18:01:08 +01:00
public boolean isShowSpoiler() {
return showSpoiler;
}
public void setShowSpoiler(boolean showSpoiler) {
this.showSpoiler = showSpoiler;
}
2019-02-05 18:05:21 +01:00
public boolean isNotice() {
return isNotice;
}
public void setNotice(boolean notice) {
isNotice = notice;
}
2019-03-24 16:38:12 +01:00
public Poll getPoll() {
return poll;
}
public void setPoll(Poll poll) {
this.poll = poll;
}
2019-05-08 09:37:17 +02:00
public int getMedia_height() {
return media_height;
}
public void setMedia_height(int media_height) {
this.media_height = media_height;
}
2019-05-12 11:39:25 +02:00
public boolean iscached() {
return cached;
}
2019-05-12 11:39:25 +02:00
public void setcached(boolean cached) {
this.cached = cached;
}
2019-05-22 18:08:43 +02:00
public boolean isAutoHiddenCW() {
return autoHiddenCW;
}
public void setAutoHiddenCW(boolean autoHiddenCW) {
this.autoHiddenCW = autoHiddenCW;
}
2019-06-10 18:33:54 +02:00
public boolean isCustomFeaturesDisplayed() {
return customFeaturesDisplayed;
}
public void setCustomFeaturesDisplayed(boolean customFeaturesDisplayed) {
this.customFeaturesDisplayed = customFeaturesDisplayed;
}
2017-05-05 16:36:04 +02:00
}