Show media descriptions in timeline when previews are disabled. (#1284)

This commit is contained in:
Ivan Kupalov 2019-06-22 20:38:54 +02:00 committed by Konrad Pozniak
parent b825f42c7a
commit d827bd120f
5 changed files with 189 additions and 49 deletions

View File

@ -13,12 +13,12 @@ import android.widget.ImageView;
import android.widget.RadioButton; import android.widget.RadioButton;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.emoji.text.EmojiCompat; import androidx.emoji.text.EmojiCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -49,6 +49,7 @@ import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import at.connyduck.sparkbutton.SparkButton; import at.connyduck.sparkbutton.SparkButton;
import at.connyduck.sparkbutton.SparkEventListener; import at.connyduck.sparkbutton.SparkEventListener;
@ -71,7 +72,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
private ImageView[] mediaOverlays; private ImageView[] mediaOverlays;
private TextView sensitiveMediaWarning; private TextView sensitiveMediaWarning;
private View sensitiveMediaShow; private View sensitiveMediaShow;
protected TextView mediaLabel; protected TextView[] mediaLabels;
private ToggleButton contentWarningButton; private ToggleButton contentWarningButton;
protected ImageView avatarInset; protected ImageView avatarInset;
@ -124,7 +125,12 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}; };
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning); sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
sensitiveMediaShow = itemView.findViewById(R.id.status_sensitive_media_button); sensitiveMediaShow = itemView.findViewById(R.id.status_sensitive_media_button);
mediaLabel = itemView.findViewById(R.id.status_media_label); mediaLabels = new TextView[]{
itemView.findViewById(R.id.status_media_label_1),
itemView.findViewById(R.id.status_media_label_2),
itemView.findViewById(R.id.status_media_label_3),
itemView.findViewById(R.id.status_media_label_4)
};
contentWarningDescription = itemView.findViewById(R.id.status_content_warning_description); contentWarningDescription = itemView.findViewById(R.id.status_content_warning_description);
contentWarningButton = itemView.findViewById(R.id.status_content_warning_button); contentWarningButton = itemView.findViewById(R.id.status_content_warning_button);
avatarInset = itemView.findViewById(R.id.status_avatar_inset); avatarInset = itemView.findViewById(R.id.status_avatar_inset);
@ -435,12 +441,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
mediaOverlays[i].setVisibility(View.GONE); mediaOverlays[i].setVisibility(View.GONE);
} }
final int urlIndex = i; setAttachmentClickListeners(mediaPreviews[i], listener, i, attachments.get(i));
mediaPreviews[i].setOnClickListener(v -> {
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onViewMedia(getAdapterPosition(), urlIndex, v);
}
});
if (n <= 2) { if (n <= 2) {
mediaPreviews[0].getLayoutParams().height = getMediaPreviewHeight(context) * 2; mediaPreviews[0].getLayoutParams().height = getMediaPreviewHeight(context) * 2;
@ -490,18 +491,6 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
} }
@NonNull
private static String getLabelTypeText(Context context, Attachment.Type type) {
switch (type) {
default:
case IMAGE:
return context.getString(R.string.status_media_images);
case GIFV:
case VIDEO:
return context.getString(R.string.status_media_video);
}
}
@DrawableRes @DrawableRes
private static int getLabelIcon(Attachment.Type type) { private static int getLabelIcon(Attachment.Type type) {
switch (type) { switch (type) {
@ -515,29 +504,54 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
protected void setMediaLabel(List<Attachment> attachments, boolean sensitive, protected void setMediaLabel(List<Attachment> attachments, boolean sensitive,
final StatusActionListener listener) { final StatusActionListener listener, boolean showingContent) {
if (attachments.size() == 0) {
mediaLabel.setVisibility(View.GONE);
return;
}
mediaLabel.setVisibility(View.VISIBLE);
// Set the label's text.
Context context = itemView.getContext(); Context context = itemView.getContext();
String labelText = getLabelTypeText(context, attachments.get(0).getType()); for (int i = 0; i < mediaLabels.length; i++) {
if (sensitive) { TextView mediaLabel = mediaLabels[i];
String sensitiveText = context.getString(R.string.status_sensitive_media_title); if (i < attachments.size()) {
labelText += String.format(" (%s)", sensitiveText); Attachment attachment = attachments.get(i);
mediaLabel.setVisibility(View.VISIBLE);
if (sensitive && !showingContent) {
mediaLabel.setText(R.string.status_sensitive_media_title);
} else {
mediaLabel.setText(getAttachmentDescription(context, attachment));
}
// Set the icon next to the label.
int drawableId = getLabelIcon(attachments.get(0).getType());
Drawable drawable = Objects.requireNonNull(context.getDrawable(drawableId));
ThemeUtils.setDrawableTint(context, drawable, android.R.attr.textColorTertiary);
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
setAttachmentClickListeners(mediaLabel, listener, i, attachment);
} else {
mediaLabel.setVisibility(View.GONE);
}
} }
mediaLabel.setText(labelText); }
// Set the icon next to the label. private void setAttachmentClickListeners(View view, StatusActionListener listener,
int drawableId = getLabelIcon(attachments.get(0).getType()); int index, Attachment attachment) {
Drawable drawable = AppCompatResources.getDrawable(context, drawableId); view.setOnClickListener(v -> {
ThemeUtils.setDrawableTint(context, drawable, android.R.attr.textColorTertiary); if (getAdapterPosition() != RecyclerView.NO_POSITION) {
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); listener.onViewMedia(getAdapterPosition(), index, null);
}
});
view.setOnLongClickListener(v -> {
CharSequence description = getAttachmentDescription(view.getContext(), attachment);
Toast.makeText(view.getContext(), description, Toast.LENGTH_LONG).show();
return true;
});
}
mediaLabel.setOnClickListener(v -> listener.onViewMedia(getAdapterPosition(), 0, null)); private CharSequence getAttachmentDescription(Context context, Attachment attachment) {
if (TextUtils.isEmpty(attachment.getDescription())) {
return context
.getString(R.string.description_status_media_no_description_placeholder);
} else {
return attachment.getDescription();
}
} }
protected void hideSensitiveMediaWarning() { protected void hideSensitiveMediaWarning() {
@ -641,9 +655,11 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
hideSensitiveMediaWarning(); hideSensitiveMediaWarning();
} }
// Hide the unused label. // Hide the unused label.
mediaLabel.setVisibility(View.GONE); for (TextView mediaLabel : mediaLabels) {
mediaLabel.setVisibility(View.GONE);
}
} else { } else {
setMediaLabel(attachments, sensitive, listener); setMediaLabel(attachments, sensitive, listener, status.isShowingContent());
// Hide all unused views. // Hide all unused views.
mediaPreviews[0].setVisibility(View.GONE); mediaPreviews[0].setVisibility(View.GONE);
mediaPreviews[1].setVisibility(View.GONE); mediaPreviews[1].setVisibility(View.GONE);

View File

@ -24,6 +24,9 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.keylesspalace.tusky.R; import com.keylesspalace.tusky.R;
import com.keylesspalace.tusky.adapter.StatusBaseViewHolder; import com.keylesspalace.tusky.adapter.StatusBaseViewHolder;
import com.keylesspalace.tusky.entity.Attachment; import com.keylesspalace.tusky.entity.Attachment;
@ -33,8 +36,6 @@ import com.keylesspalace.tusky.util.SmartLengthInputFilter;
import java.util.List; import java.util.List;
import androidx.recyclerview.widget.RecyclerView;
public class ConversationViewHolder extends StatusBaseViewHolder { public class ConversationViewHolder extends StatusBaseViewHolder {
private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE}; private static final InputFilter[] COLLAPSE_INPUT_FILTER = new InputFilter[]{SmartLengthInputFilter.INSTANCE};
private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0]; private static final InputFilter[] NO_INPUT_FILTER = new InputFilter[0];
@ -87,9 +88,11 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
hideSensitiveMediaWarning(); hideSensitiveMediaWarning();
} }
// Hide the unused label. // Hide the unused label.
mediaLabel.setVisibility(View.GONE); for (TextView mediaLabel : mediaLabels) {
mediaLabel.setVisibility(View.GONE);
}
} else { } else {
setMediaLabel(attachments, sensitive, listener); setMediaLabel(attachments, sensitive, listener, status.getShowingHiddenContent());
// Hide all unused views. // Hide all unused views.
mediaPreviews[0].setVisibility(View.GONE); mediaPreviews[0].setVisibility(View.GONE);
mediaPreviews[1].setVisibility(View.GONE); mediaPreviews[1].setVisibility(View.GONE);

View File

@ -328,17 +328,58 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/status_media_label" android:id="@+id/status_media_label_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp" android:drawablePadding="4dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium" android:textSize="?attr/status_text_medium"
android:visibility="gone" android:visibility="gone"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/status_media_label_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_1" />
<TextView
android:id="@+id/status_media_label_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_2" />
<TextView
android:id="@+id/status_media_label_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_3" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.emoji.widget.EmojiTextView <androidx.emoji.widget.EmojiTextView

View File

@ -313,7 +313,7 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/status_media_label" android:id="@+id/status_media_label_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
@ -325,6 +325,45 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/status_media_label_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_1" />
<TextView
android:id="@+id/status_media_label_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_2" />
<TextView
android:id="@+id/status_media_label_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_3" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<androidx.emoji.widget.EmojiTextView <androidx.emoji.widget.EmojiTextView

View File

@ -327,17 +327,58 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/status_media_label" android:id="@+id/status_media_label_1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp" android:drawablePadding="4dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium" android:textSize="?attr/status_text_medium"
android:visibility="gone" android:visibility="gone"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/status_media_label_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_1" />
<TextView
android:id="@+id/status_media_label_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_2" />
<TextView
android:id="@+id/status_media_label_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawablePadding="4dp"
android:gravity="center_vertical"
android:importantForAccessibility="no"
android:textSize="?attr/status_text_medium"
android:visibility="gone"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/status_media_label_3" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>