sensitive media previews are now hidden and shown with a click

This commit is contained in:
Vavassor 2017-01-10 15:41:50 -05:00
parent e551de7521
commit bab33a0715
5 changed files with 77 additions and 13 deletions

View File

@ -42,7 +42,8 @@ public class Status {
/** whether the authenticated user has favourited this status */
private boolean favourited;
private Visibility visibility;
private MediaAttachment[] attachments = null;
private MediaAttachment[] attachments;
private boolean sensitive;
public static final int MAX_MEDIA_ATTACHMENTS = 4;
@ -110,6 +111,10 @@ public class Status {
return attachments;
}
public boolean getSensitive() {
return sensitive;
}
public void setRebloggedByUsername(String name) {
rebloggedByUsername = name;
}
@ -122,8 +127,9 @@ public class Status {
this.favourited = favourited;
}
public void setAttachments(MediaAttachment[] attachments) {
public void setAttachments(MediaAttachment[] attachments, boolean sensitive) {
this.attachments = attachments;
this.sensitive = sensitive;
}
@Override
@ -181,6 +187,7 @@ public class Status {
Date createdAt = parseDate(object.getString("created_at"));
boolean reblogged = object.getBoolean("reblogged");
boolean favourited = object.getBoolean("favourited");
boolean sensitive = object.optBoolean("sensitive");
String visibility = object.getString("visibility");
JSONObject account = object.getJSONObject("account");
@ -225,7 +232,7 @@ public class Status {
reblogged, favourited, visibility);
}
if (attachments != null) {
status.setAttachments(attachments);
status.setAttachments(attachments, sensitive);
}
return status;
}

View File

@ -55,7 +55,11 @@ public class TimelineAdapter extends RecyclerView.Adapter {
} else {
holder.setRebloggedByUsername(rebloggedByUsername);
}
holder.setMediaPreviews(status.getAttachments(), listener);
boolean sensitive = status.getSensitive();
holder.setMediaPreviews(status.getAttachments(), sensitive, listener);
if (!sensitive) {
holder.hideSensitiveMediaWarning();
}
holder.setupButtons(listener, position);
if (status.getVisibility() == Status.Visibility.PRIVATE) {
holder.disableReblogging();
@ -119,7 +123,7 @@ public class TimelineAdapter extends RecyclerView.Adapter {
private NetworkImageView mediaPreview1;
private NetworkImageView mediaPreview2;
private NetworkImageView mediaPreview3;
private String[] mediaAttachmentUrls;
private View sensitiveMediaWarning;
public ViewHolder(View itemView) {
super(itemView);
@ -140,6 +144,7 @@ public class TimelineAdapter extends RecyclerView.Adapter {
mediaPreview1 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_1);
mediaPreview2 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_2);
mediaPreview3 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_3);
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
}
public void setDisplayName(String name) {
@ -247,7 +252,7 @@ public class TimelineAdapter extends RecyclerView.Adapter {
}
public void setMediaPreviews(final Status.MediaAttachment[] attachments,
final StatusActionListener listener) {
boolean sensitive, final StatusActionListener listener) {
final NetworkImageView[] previews = {
mediaPreview0,
mediaPreview1,
@ -256,11 +261,15 @@ public class TimelineAdapter extends RecyclerView.Adapter {
};
Context context = mediaPreview0.getContext();
ImageLoader imageLoader = VolleySingleton.getInstance(context).getImageLoader();
int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
final int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
for (int i = 0; i < n; i++) {
String previewUrl = attachments[i].getPreviewUrl();
previews[i].setImageUrl(previewUrl, imageLoader);
previews[i].setVisibility(View.VISIBLE);
if (!sensitive) {
previews[i].setVisibility(View.VISIBLE);
} else {
previews[i].setVisibility(View.GONE);
}
final String url = attachments[i].getUrl();
final Status.MediaAttachment.Type type = attachments[i].getType();
previews[i].setOnClickListener(new View.OnClickListener() {
@ -270,6 +279,19 @@ public class TimelineAdapter extends RecyclerView.Adapter {
}
});
}
if (sensitive) {
sensitiveMediaWarning.setVisibility(View.VISIBLE);
sensitiveMediaWarning.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setVisibility(View.GONE);
for (int i = 0; i < n; i++) {
previews[i].setVisibility(View.VISIBLE);
}
v.setOnClickListener(null);
}
});
}
// Hide any of the placeholder previews beyond the ones set.
for (int i = n; i < Status.MAX_MEDIA_ATTACHMENTS; i++) {
previews[i].setImageUrl(null, imageLoader);
@ -277,6 +299,10 @@ public class TimelineAdapter extends RecyclerView.Adapter {
}
}
public void hideSensitiveMediaWarning() {
sensitiveMediaWarning.setVisibility(View.GONE);
}
public void setupButtons(final StatusActionListener listener, final int position) {
reblogButton.setOnClickListener(new View.OnClickListener() {
@Override

View File

@ -84,6 +84,33 @@
android:layout_below="@+id/status_content"
android:layout_toRightOf="@+id/status_avatar">
<LinearLayout
android:id="@+id/status_sensitive_media_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/status_media_preview_top_margin"
android:padding="8dp"
android:background="@color/sensitive_media_warning_background"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/status_sensitive_media_title"
android:textColor="@android:color/white"
android:textStyle="normal|italic" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="@string/status_sensitive_media_directions"
android:textColor="@android:color/white" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
@ -92,7 +119,7 @@
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/status_media_preview_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop"
android:layout_marginTop="@dimen/status_media_preview_top_margin" />
@ -100,7 +127,7 @@
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/status_media_preview_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop"
android:layout_marginTop="@dimen/status_media_preview_top_margin" />
@ -114,13 +141,14 @@
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/status_media_preview_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop" />
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/status_media_preview_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:scaleType="centerCrop" />
</LinearLayout>

View File

@ -5,4 +5,5 @@
<color name="colorAccent">#FF4081</color>
<color name="gray">#4F4F4F</color>
<color name="view_video_background">#000000</color>
<color name="sensitive_media_warning_background">#303030</color>
</resources>

View File

@ -49,6 +49,8 @@
<string name="status_username_format">\@%s</string>
<string name="status_boosted_format">%s boosted</string>
<string name="status_sensitive_media_title">Sensitive Media</string>
<string name="status_sensitive_media_directions">Click to view.</string>
<string name="notification_reblog_format">%s boosted your status</string>
<string name="notification_favourite_format">%s favourited your status</string>