Content warnings now show/hide on all timelines.
This commit is contained in:
parent
1429dfc7b5
commit
2b6bc8a5c7
5 changed files with 88 additions and 14 deletions
|
@ -15,8 +15,6 @@
|
|||
|
||||
package com.keylesspalace.tusky;
|
||||
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
@ -52,10 +50,11 @@ public class Status {
|
|||
private boolean reblogged;
|
||||
/** whether the authenticated user has favourited this status */
|
||||
private boolean favourited;
|
||||
private boolean sensitive;
|
||||
private String spoilerText;
|
||||
private Visibility visibility;
|
||||
private MediaAttachment[] attachments;
|
||||
private Mention[] mentions;
|
||||
private boolean sensitive;
|
||||
|
||||
public static final int MAX_MEDIA_ATTACHMENTS = 4;
|
||||
|
||||
|
@ -71,6 +70,7 @@ public class Status {
|
|||
this.createdAt = createdAt;
|
||||
this.reblogged = reblogged;
|
||||
this.favourited = favourited;
|
||||
this.spoilerText = "";
|
||||
this.visibility = Visibility.valueOf(visibility.toUpperCase());
|
||||
this.attachments = new MediaAttachment[0];
|
||||
this.mentions = new Mention[0];
|
||||
|
@ -116,6 +116,14 @@ public class Status {
|
|||
return favourited;
|
||||
}
|
||||
|
||||
public boolean getSensitive() {
|
||||
return sensitive;
|
||||
}
|
||||
|
||||
public String getSpoilerText() {
|
||||
return spoilerText;
|
||||
}
|
||||
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
@ -128,10 +136,6 @@ public class Status {
|
|||
return mentions;
|
||||
}
|
||||
|
||||
public boolean getSensitive() {
|
||||
return sensitive;
|
||||
}
|
||||
|
||||
public void setRebloggedByUsername(String name) {
|
||||
rebloggedByUsername = name;
|
||||
}
|
||||
|
@ -144,6 +148,10 @@ public class Status {
|
|||
this.favourited = favourited;
|
||||
}
|
||||
|
||||
public void setSpoilerText(String spoilerText) {
|
||||
this.spoilerText = spoilerText;
|
||||
}
|
||||
|
||||
public void setMentions(Mention[] mentions) {
|
||||
this.mentions = mentions;
|
||||
}
|
||||
|
@ -188,6 +196,7 @@ public class Status {
|
|||
Date createdAt = parseDate(object.getString("created_at"));
|
||||
boolean reblogged = object.getBoolean("reblogged");
|
||||
boolean favourited = object.getBoolean("favourited");
|
||||
String spoilerText = object.getString("spoiler_text");
|
||||
boolean sensitive = object.optBoolean("sensitive");
|
||||
String visibility = object.getString("visibility");
|
||||
|
||||
|
@ -260,6 +269,9 @@ public class Status {
|
|||
if (attachments != null) {
|
||||
status.setAttachments(attachments, sensitive);
|
||||
}
|
||||
if (!spoilerText.isEmpty()) {
|
||||
status.setSpoilerText(spoilerText);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -21,23 +21,19 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.method.MovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.android.volley.toolbox.ImageLoader;
|
||||
import com.android.volley.toolbox.NetworkImageView;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class StatusViewHolder extends RecyclerView.ViewHolder {
|
||||
private View container;
|
||||
|
@ -59,6 +55,9 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
private NetworkImageView mediaPreview2;
|
||||
private NetworkImageView mediaPreview3;
|
||||
private View sensitiveMediaWarning;
|
||||
private View contentWarningBar;
|
||||
private TextView contentWarningDescription;
|
||||
private ToggleButton contentWarningButton;
|
||||
|
||||
public StatusViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -87,6 +86,11 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
mediaPreview2.setDefaultImageResId(R.drawable.media_preview_unloaded);
|
||||
mediaPreview3.setDefaultImageResId(R.drawable.media_preview_unloaded);
|
||||
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
|
||||
contentWarningBar = itemView.findViewById(R.id.status_content_warning_bar);
|
||||
contentWarningDescription =
|
||||
(TextView) itemView.findViewById(R.id.status_content_warning_description);
|
||||
contentWarningButton =
|
||||
(ToggleButton) itemView.findViewById(R.id.status_content_warning_button);
|
||||
}
|
||||
|
||||
public void setDisplayName(String name) {
|
||||
|
@ -258,6 +262,23 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
sensitiveMediaWarning.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void setSpoilerText(String spoilerText) {
|
||||
contentWarningDescription.setText(spoilerText);
|
||||
contentWarningBar.setVisibility(View.VISIBLE);
|
||||
content.setVisibility(View.GONE);
|
||||
contentWarningButton.setOnCheckedChangeListener(
|
||||
new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
content.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
content.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setupButtons(final StatusActionListener listener, final int position) {
|
||||
avatar.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -329,5 +350,8 @@ public class StatusViewHolder extends RecyclerView.ViewHolder {
|
|||
if (status.getVisibility() == Status.Visibility.PRIVATE) {
|
||||
disableReblogging();
|
||||
}
|
||||
if (!status.getSpoilerText().isEmpty()) {
|
||||
setSpoilerText(status.getSpoilerText());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue