summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java155
1 files changed, 114 insertions, 41 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java
index cd3bd4225..f370b928c 100644
--- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java
+++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java
@@ -37,6 +37,7 @@ import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
+import android.util.Patterns;
import android.view.View;
import com.bumptech.glide.Glide;
@@ -58,9 +59,11 @@ import java.util.regex.Pattern;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.activities.HashTagActivity;
+import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.PeertubeActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
+import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.helper.CrossActions;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveEmojiInterface;
@@ -119,6 +122,7 @@ public class Status implements Parcelable{
private String conversationId;
private boolean isExpanded = false;
private int numberLines = -1;
+ private boolean showSpoiler = false;
public Status(){}
private List<String> conversationProfilePicture;
@@ -126,6 +130,8 @@ public class Status implements Parcelable{
private boolean isBoostAnimated = false, isFavAnimated = false;
private String scheduled_at;
+ private String contentType;
+ private boolean isNotice = false;
@Override
public void writeToParcel(Parcel dest, int flags) {
@@ -179,6 +185,9 @@ public class Status implements Parcelable{
dest.writeByte(this.isBoostAnimated ? (byte) 1 : (byte) 0);
dest.writeByte(this.isFavAnimated ? (byte) 1 : (byte) 0);
dest.writeString(this.scheduled_at);
+ dest.writeString(this.contentType);
+ dest.writeByte(this.showSpoiler ? (byte) 1 : (byte) 0);
+ dest.writeByte(this.isNotice ? (byte) 1 : (byte) 0);
}
protected Status(Parcel in) {
@@ -234,6 +243,9 @@ public class Status implements Parcelable{
this.isBoostAnimated = in.readByte() != 0;
this.isFavAnimated = in.readByte() != 0;
this.scheduled_at = in.readString();
+ this.contentType = in.readString();
+ this.showSpoiler = in.readByte() != 0;
+ this.isNotice = in.readByte() != 0;
}
public static final Creator<Status> CREATOR = new Creator<Status>() {
@@ -560,6 +572,40 @@ public class Status implements Parcelable{
}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);
SpannableString displayNameSpan = new SpannableString(displayName);
status.setDisplayNameSpan(displayNameSpan);
}
@@ -802,14 +848,14 @@ public class Status implements Parcelable{
if( matchEnd <= spannableString.toString().length() && matchEnd >= matchStart)
spannableString.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
+ 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(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -844,12 +890,12 @@ public class Status implements Parcelable{
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
spannableStringT.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
+ public void onClick(@NonNull View textView) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+twittername.substring(1).replace("@twitter.com","")));
context.startActivity(intent);
}
@Override
- public void updateDrawState(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -872,11 +918,11 @@ public class Status implements Parcelable{
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
+ public void onClick(@NonNull View textView) {
CrossActions.doCrossProfile(context,account);
}
@Override
- public void updateDrawState(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -887,8 +933,8 @@ public class Status implements Parcelable{
ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot));
}
},
- startPosition, endPosition,
- Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
+ startPosition, endPosition,
+ Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
}
@@ -908,7 +954,7 @@ public class Status implements Parcelable{
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition) {
spannableStringT.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
+ public void onClick(@NonNull View textView) {
String finalUrl = url;
Pattern link = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/(@[\\w._-]*[0-9]*)(\\/[0-9]{1,})?$");
Matcher matcherLink = link.matcher(url);
@@ -943,7 +989,7 @@ public class Status implements Parcelable{
}
}
@Override
- public void updateDrawState(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -977,7 +1023,7 @@ public class Status implements Parcelable{
if (endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
+ public void onClick(@NonNull View textView) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", mention.getId());
@@ -986,7 +1032,7 @@ public class Status implements Parcelable{
}
@Override
- public void updateDrawState(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -1008,28 +1054,28 @@ public class Status implements Parcelable{
int endPosition = startPosition + targetedAccount.length();
if( endPosition <= spannableStringT.toString().length() && endPosition >= startPosition)
spannableStringT.setSpan(new ClickableSpan() {
- @Override
- public void onClick(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(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);
+ @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);
}
}
}
@@ -1042,15 +1088,17 @@ public class Status implements Parcelable{
if( matchEnd <= spannableStringT.toString().length() && matchEnd >= matchStart)
spannableStringT.setSpan(new ClickableSpan() {
@Override
- public void onClick(View textView) {
- Intent intent = new Intent(context, HashTagActivity.class);
- Bundle b = new Bundle();
- b.putString("tag", tag.substring(1));
- intent.putExtras(b);
- context.startActivity(intent);
+ public void onClick(@NonNull View textView) {
+ 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);
+ }
}
@Override
- public void updateDrawState(TextPaint ds) {
+ public void updateDrawState(@NonNull TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
if (theme == THEME_DARK)
@@ -1245,4 +1293,29 @@ public class Status implements Parcelable{
public void setScheduled_at(String scheduled_at) {
this.scheduled_at = scheduled_at;
}
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public boolean isShowSpoiler() {
+ return showSpoiler;
+ }
+
+ public void setShowSpoiler(boolean showSpoiler) {
+ this.showSpoiler = showSpoiler;
+ }
+
+
+ public boolean isNotice() {
+ return isNotice;
+ }
+
+ public void setNotice(boolean notice) {
+ isNotice = notice;
+ }
}