Attachment previews also use Picasso to load, fix their layout

Fix NSFW overlay
main
Eugen Rochko 8 years ago
parent 9ec3fd47dc
commit d9f0b3c99e
  1. 49
      app/src/main/java/com/keylesspalace/tusky/StatusViewHolder.java
  2. 2
      app/src/main/res/layout/item_blocked_user.xml
  3. 73
      app/src/main/res/layout/item_status.xml
  4. 1
      app/src/main/res/values/attrs.xml
  5. 2
      app/src/main/res/values/strings.xml
  6. 3
      app/src/main/res/values/styles.xml

@ -16,6 +16,7 @@
package com.keylesspalace.tusky;
import android.content.Context;
import android.media.Image;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
@ -51,10 +52,10 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
private ImageButton moreButton;
private boolean favourited;
private boolean reblogged;
private NetworkImageView mediaPreview0;
private NetworkImageView mediaPreview1;
private NetworkImageView mediaPreview2;
private NetworkImageView mediaPreview3;
private ImageView mediaPreview0;
private ImageView mediaPreview1;
private ImageView mediaPreview2;
private ImageView mediaPreview3;
private View sensitiveMediaWarning;
private View contentWarningBar;
private TextView contentWarningDescription;
@ -76,16 +77,10 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
moreButton = (ImageButton) itemView.findViewById(R.id.status_more);
reblogged = false;
favourited = false;
mediaPreview0 = (NetworkImageView) itemView.findViewById(R.id.status_media_preview_0);
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);
int mediaPreviewUnloadedId = ThemeUtils.getDrawableId(itemView.getContext(),
R.attr.media_preview_unloaded_drawable, android.R.color.black);
mediaPreview0.setDefaultImageResId(mediaPreviewUnloadedId);
mediaPreview1.setDefaultImageResId(mediaPreviewUnloadedId);
mediaPreview2.setDefaultImageResId(mediaPreviewUnloadedId);
mediaPreview3.setDefaultImageResId(mediaPreviewUnloadedId);
mediaPreview0 = (ImageView) itemView.findViewById(R.id.status_media_preview_0);
mediaPreview1 = (ImageView) itemView.findViewById(R.id.status_media_preview_1);
mediaPreview2 = (ImageView) itemView.findViewById(R.id.status_media_preview_2);
mediaPreview3 = (ImageView) itemView.findViewById(R.id.status_media_preview_3);
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
contentWarningBar = itemView.findViewById(R.id.status_content_warning_bar);
contentWarningDescription =
@ -225,23 +220,29 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
private void setMediaPreviews(final Status.MediaAttachment[] attachments,
boolean sensitive, final StatusActionListener listener) {
final NetworkImageView[] previews = {
final ImageView[] previews = {
mediaPreview0,
mediaPreview1,
mediaPreview2,
mediaPreview3
};
Context context = mediaPreview0.getContext();
ImageLoader imageLoader = VolleySingleton.getInstance(context).getImageLoader();
int mediaPreviewUnloadedId = ThemeUtils.getDrawableId(itemView.getContext(),
R.attr.media_preview_unloaded_drawable, android.R.color.black);
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);
if (!sensitive) {
previews[i].setVisibility(View.VISIBLE);
} else {
previews[i].setVisibility(View.GONE);
}
Picasso.with(context)
.load(previewUrl)
.placeholder(mediaPreviewUnloadedId)
.into(previews[i]);
final String url = attachments[i].getUrl();
final Status.MediaAttachment.Type type = attachments[i].getType();
previews[i].setOnClickListener(new View.OnClickListener() {
@ -251,22 +252,20 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
}
});
}
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);
previews[i].setVisibility(View.GONE);
}
}

@ -48,7 +48,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/blocked_user_username"
android:textColor="?attr/status_text_color_secondary" />
android:textColor="?android:textColorSecondary" />
<Space
android:layout_width="wrap_content"

@ -117,6 +117,7 @@
android:textOff="@string/status_content_warning_show_more"
android:padding="3dp"
android:textSize="12sp"
android:textAllCaps="true"
android:background="?attr/content_warning_button" />
</com.keylesspalace.tusky.FlowLayout>
@ -126,63 +127,43 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:layout_marginBottom="4dp"
android:layout_toRightOf="@+id/status_avatar"
android:layout_toEndOf="@+id/status_avatar"
android:layout_below="@+id/status_content_warning_bar" />
<LinearLayout
<FrameLayout
android:id="@+id/status_media_preview_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
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="?attr/sensitive_media_warning_background_color"
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>
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginBottom="2dp"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
<ImageView
android:id="@+id/status_media_preview_0"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_media_preview_height"
android:layout_weight="1"
android:layout_marginRight="2dp"
android:scaleType="centerCrop"
android:layout_marginTop="@dimen/status_media_preview_top_margin" />
<com.android.volley.toolbox.NetworkImageView
<ImageView
android:id="@+id/status_media_preview_1"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_media_preview_height"
android:layout_weight="1"
android:layout_marginLeft="2dp"
android:scaleType="centerCrop"
android:layout_marginTop="@dimen/status_media_preview_top_margin" />
</LinearLayout>
@ -190,25 +171,55 @@
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_marginTop="2dp"
android:layout_height="wrap_content">
<com.android.volley.toolbox.NetworkImageView
<ImageView
android:id="@+id/status_media_preview_2"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_media_preview_height"
android:layout_weight="1"
android:layout_marginRight="2dp"
android:scaleType="centerCrop" />
<com.android.volley.toolbox.NetworkImageView
<ImageView
android:id="@+id/status_media_preview_3"
android:layout_width="wrap_content"
android:layout_height="@dimen/status_media_preview_height"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:scaleType="centerCrop" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/status_sensitive_media_warning"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/status_media_preview_top_margin"
android:padding="8dp"
android:gravity="center"
android:orientation="vertical"
android:background="?attr/sensitive_media_warning_background_color"
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="bold" />
<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>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
@ -217,7 +228,7 @@
android:layout_below="@id/status_media_preview_container"
android:layout_toRightOf="@+id/status_avatar"
android:paddingBottom="8dp"
android:paddingTop="10dp">
android:paddingTop="6dp">
<ImageButton
app:srcCompat="@drawable/ic_reply_24dp"

@ -21,7 +21,6 @@
<attr name="status_favourite_button_marked_tint" format="reference|color" />
<attr name="content_warning_button" format="reference" />
<attr name="sensitive_media_warning_background_color" format="reference|color" />
<attr name="status_text_color_secondary" format="reference|color" />
<attr name="media_preview_unloaded_drawable" format="reference" />
<attr name="status_divider_drawable" format="reference" />
<attr name="tab_page_margin_drawable" format="reference" />

@ -75,7 +75,7 @@
<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="status_sensitive_media_directions">Click to view</string>
<string name="status_content_warning_show_more">Show More</string>
<string name="status_content_warning_show_less">Show Less</string>

@ -37,7 +37,7 @@
<item name="status_favourite_button_tint">@color/status_favourite_button_dark</item>
<item name="status_favourite_button_marked_tint">@color/status_favourite_button_marked_dark</item>
<item name="content_warning_button">@drawable/toggle_small</item>
<item name="sensitive_media_warning_background_color">@color/sensitive_media_warning_background_dark</item>
<item name="sensitive_media_warning_background_color">@color/color_background_dark</item>
<item name="media_preview_unloaded_drawable">@drawable/media_preview_unloaded_dark</item>
<item name="status_divider_drawable">@drawable/status_divider_dark</item>
<item name="tab_page_margin_drawable">@drawable/tab_page_margin_dark</item>
@ -91,7 +91,6 @@
<item name="status_favourite_button_marked_tint">@color/status_favourite_button_marked_light</item>
<item name="content_warning_button">@drawable/toggle_small_light</item>
<item name="sensitive_media_warning_background_color">@color/sensitive_media_warning_background_light</item>
<item name="status_text_color_secondary">@color/status_text_secondary_light</item>
<item name="media_preview_unloaded_drawable">@drawable/media_preview_unloaded_light</item>
<item name="status_divider_drawable">@drawable/status_divider_light</item>
<item name="tab_page_margin_drawable">@drawable/tab_page_margin_light</item>

Loading…
Cancel
Save