2017-01-23 16:19:30 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
|
|
|
import android.content.Context;
|
2017-06-26 19:15:47 +10:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-07-15 08:18:29 +10:00
|
|
|
import android.os.Build;
|
2017-05-05 08:55:34 +10:00
|
|
|
import android.preference.PreferenceManager;
|
2017-06-26 19:15:47 +10:00
|
|
|
import android.support.annotation.DrawableRes;
|
2017-07-09 05:44:08 +10:00
|
|
|
import android.support.annotation.NonNull;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.support.annotation.Nullable;
|
2017-07-29 01:54:57 +10:00
|
|
|
import android.support.v7.content.res.AppCompatResources;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
|
import android.text.Spanned;
|
|
|
|
import android.view.View;
|
2017-02-01 10:42:05 +11:00
|
|
|
import android.widget.CompoundButton;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.widget.ImageButton;
|
2017-03-07 11:31:05 +11:00
|
|
|
import android.widget.ImageView;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.widget.TextView;
|
2017-02-01 10:42:05 +11:00
|
|
|
import android.widget.ToggleButton;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.R;
|
2017-03-09 10:27:37 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
2017-07-14 15:06:32 +10:00
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.util.DateUtils;
|
|
|
|
import com.keylesspalace.tusky.util.LinkHelper;
|
|
|
|
import com.keylesspalace.tusky.util.ThemeUtils;
|
2017-07-14 15:06:32 +10:00
|
|
|
import com.keylesspalace.tusky.view.RoundedTransformation;
|
2017-07-13 05:54:52 +10:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
2017-03-07 11:31:05 +11:00
|
|
|
import com.squareup.picasso.Picasso;
|
2017-03-08 08:23:17 +11:00
|
|
|
import com.varunest.sparkbutton.SparkButton;
|
|
|
|
import com.varunest.sparkbutton.SparkEventListener;
|
2017-07-14 15:06:32 +10:00
|
|
|
import com.varunest.sparkbutton.helpers.Utils;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
public class StatusViewHolder extends RecyclerView.ViewHolder {
|
2017-01-23 16:19:30 +11:00
|
|
|
private View container;
|
|
|
|
private TextView displayName;
|
|
|
|
private TextView username;
|
|
|
|
private TextView content;
|
2017-03-07 11:31:05 +11:00
|
|
|
private ImageView avatar;
|
2017-07-14 15:06:32 +10:00
|
|
|
private ImageView avatarReblog;
|
2017-02-13 16:18:17 +11:00
|
|
|
private View rebloggedBar;
|
2017-02-17 05:52:55 +11:00
|
|
|
private TextView rebloggedByDisplayName;
|
2017-01-23 16:19:30 +11:00
|
|
|
private ImageButton replyButton;
|
2017-03-08 08:23:17 +11:00
|
|
|
private SparkButton reblogButton;
|
|
|
|
private SparkButton favouriteButton;
|
2017-01-23 16:19:30 +11:00
|
|
|
private ImageButton moreButton;
|
|
|
|
private boolean favourited;
|
|
|
|
private boolean reblogged;
|
2017-03-07 21:59:54 +11:00
|
|
|
private ImageView mediaPreview0;
|
|
|
|
private ImageView mediaPreview1;
|
|
|
|
private ImageView mediaPreview2;
|
|
|
|
private ImageView mediaPreview3;
|
2017-01-23 16:19:30 +11:00
|
|
|
private View sensitiveMediaWarning;
|
2017-06-27 09:04:05 +10:00
|
|
|
private View videoIndicator;
|
2017-06-26 19:15:47 +10:00
|
|
|
private TextView mediaLabel;
|
2017-02-01 10:42:05 +11:00
|
|
|
private View contentWarningBar;
|
|
|
|
private TextView contentWarningDescription;
|
|
|
|
private ToggleButton contentWarningButton;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-08-03 14:29:31 +10:00
|
|
|
TextView timestamp;
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
StatusViewHolder(View itemView) {
|
2017-01-23 16:19:30 +11:00
|
|
|
super(itemView);
|
|
|
|
container = itemView.findViewById(R.id.status_container);
|
|
|
|
displayName = (TextView) itemView.findViewById(R.id.status_display_name);
|
|
|
|
username = (TextView) itemView.findViewById(R.id.status_username);
|
2017-08-03 14:29:31 +10:00
|
|
|
timestamp = (TextView) itemView.findViewById(R.id.status_timestamp);
|
2017-01-23 16:19:30 +11:00
|
|
|
content = (TextView) itemView.findViewById(R.id.status_content);
|
2017-03-07 11:31:05 +11:00
|
|
|
avatar = (ImageView) itemView.findViewById(R.id.status_avatar);
|
2017-07-14 15:06:32 +10:00
|
|
|
avatarReblog = (ImageView) itemView.findViewById(R.id.status_avatar_reblog);
|
2017-02-13 16:18:17 +11:00
|
|
|
rebloggedBar = itemView.findViewById(R.id.status_reblogged_bar);
|
2017-02-17 05:52:55 +11:00
|
|
|
rebloggedByDisplayName = (TextView) itemView.findViewById(R.id.status_reblogged);
|
2017-01-23 16:19:30 +11:00
|
|
|
replyButton = (ImageButton) itemView.findViewById(R.id.status_reply);
|
2017-03-08 08:23:17 +11:00
|
|
|
reblogButton = (SparkButton) itemView.findViewById(R.id.status_reblog);
|
|
|
|
favouriteButton = (SparkButton) itemView.findViewById(R.id.status_favourite);
|
2017-01-23 16:19:30 +11:00
|
|
|
moreButton = (ImageButton) itemView.findViewById(R.id.status_more);
|
|
|
|
reblogged = false;
|
|
|
|
favourited = false;
|
2017-03-07 21:59:54 +11:00
|
|
|
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);
|
2017-01-23 16:19:30 +11:00
|
|
|
sensitiveMediaWarning = itemView.findViewById(R.id.status_sensitive_media_warning);
|
2017-06-27 09:04:05 +10:00
|
|
|
videoIndicator = itemView.findViewById(R.id.status_video_indicator);
|
2017-06-26 19:15:47 +10:00
|
|
|
mediaLabel = (TextView) itemView.findViewById(R.id.status_media_label);
|
2017-02-01 10:42:05 +11:00
|
|
|
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);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void setDisplayName(String name) {
|
2017-01-23 16:19:30 +11:00
|
|
|
displayName.setText(name);
|
|
|
|
}
|
|
|
|
|
2017-03-03 11:25:35 +11:00
|
|
|
private void setUsername(String name) {
|
2017-01-23 16:19:30 +11:00
|
|
|
Context context = username.getContext();
|
|
|
|
String format = context.getString(R.string.status_username_format);
|
|
|
|
String usernameText = String.format(format, name);
|
|
|
|
username.setText(usernameText);
|
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void setContent(Spanned content, Status.Mention[] mentions,
|
2017-04-25 21:30:57 +10:00
|
|
|
StatusActionListener listener) {
|
2017-02-02 07:20:39 +11:00
|
|
|
/* Redirect URLSpan's in the status content to the listener for viewing tag pages and
|
|
|
|
* account pages. */
|
2017-05-05 08:55:34 +10:00
|
|
|
Context context = this.content.getContext();
|
|
|
|
boolean useCustomTabs = PreferenceManager.getDefaultSharedPreferences(context)
|
2017-07-29 01:59:32 +10:00
|
|
|
.getBoolean("customTabs", true);
|
2017-05-05 08:55:34 +10:00
|
|
|
LinkHelper.setClickableText(this.content, content, mentions, useCustomTabs, listener);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-07-14 15:06:32 +10:00
|
|
|
private void setAvatar(String url, @Nullable String rebloggedUrl) {
|
|
|
|
Context context = avatar.getContext();
|
|
|
|
boolean hasReblog = rebloggedUrl != null && !rebloggedUrl.isEmpty();
|
|
|
|
int padding = hasReblog ? Utils.dpToPx(context, 12) : 0;
|
2017-07-15 13:23:14 +10:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
avatar.setPaddingRelative(0, 0, padding, padding);
|
2017-07-15 08:18:29 +10:00
|
|
|
} else {
|
|
|
|
avatar.setPadding(0, 0, padding, padding);
|
|
|
|
}
|
2017-07-14 15:06:32 +10:00
|
|
|
|
2017-01-31 15:51:02 +11:00
|
|
|
if (url.isEmpty()) {
|
2017-07-14 15:06:32 +10:00
|
|
|
avatar.setImageResource(R.drawable.avatar_default);
|
|
|
|
} else {
|
|
|
|
Picasso.with(context)
|
|
|
|
.load(url)
|
|
|
|
.placeholder(R.drawable.avatar_default)
|
|
|
|
.error(R.drawable.avatar_error)
|
|
|
|
.transform(new RoundedTransformation(7, 0))
|
|
|
|
.into(avatar);
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:29:31 +10:00
|
|
|
if (avatarReblog != null) {
|
|
|
|
if (hasReblog) {
|
|
|
|
avatarReblog.setVisibility(View.VISIBLE);
|
|
|
|
Picasso.with(context)
|
|
|
|
.load(rebloggedUrl)
|
|
|
|
.fit()
|
|
|
|
.transform(new RoundedTransformation(7, 0))
|
|
|
|
.into(avatarReblog);
|
|
|
|
} else {
|
|
|
|
avatarReblog.setVisibility(View.GONE);
|
|
|
|
}
|
2017-01-31 15:51:02 +11:00
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-08-03 14:29:31 +10:00
|
|
|
protected void setCreatedAt(@Nullable Date createdAt) {
|
2017-04-15 10:23:07 +10:00
|
|
|
// This is the visible timestamp.
|
2017-01-23 16:19:30 +11:00
|
|
|
String readout;
|
2017-04-15 10:23:07 +10:00
|
|
|
/* This one is for screen-readers. Frequently, they would mispronounce timestamps like "17m"
|
|
|
|
* as 17 meters instead of minutes. */
|
|
|
|
CharSequence readoutAloud;
|
2017-01-23 16:19:30 +11:00
|
|
|
if (createdAt != null) {
|
|
|
|
long then = createdAt.getTime();
|
|
|
|
long now = new Date().getTime();
|
2017-08-03 14:29:31 +10:00
|
|
|
readout = DateUtils.getRelativeTimeSpanString(timestamp.getContext(), then, now);
|
2017-04-15 10:23:07 +10:00
|
|
|
readoutAloud = android.text.format.DateUtils.getRelativeTimeSpanString(then, now,
|
|
|
|
android.text.format.DateUtils.SECOND_IN_MILLIS,
|
|
|
|
android.text.format.DateUtils.FORMAT_ABBREV_RELATIVE);
|
2017-01-23 16:19:30 +11:00
|
|
|
} else {
|
2017-04-15 10:23:07 +10:00
|
|
|
// unknown minutes~
|
|
|
|
readout = "?m";
|
|
|
|
readoutAloud = "? minutes";
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-08-03 14:29:31 +10:00
|
|
|
timestamp.setText(readout);
|
|
|
|
timestamp.setContentDescription(readoutAloud);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void setRebloggedByDisplayName(String name) {
|
2017-08-03 14:29:31 +10:00
|
|
|
if (rebloggedByDisplayName == null || rebloggedBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-17 05:52:55 +11:00
|
|
|
Context context = rebloggedByDisplayName.getContext();
|
2017-01-23 16:19:30 +11:00
|
|
|
String format = context.getString(R.string.status_boosted_format);
|
|
|
|
String boostedText = String.format(format, name);
|
2017-02-17 05:52:55 +11:00
|
|
|
rebloggedByDisplayName.setText(boostedText);
|
2017-02-13 16:18:17 +11:00
|
|
|
rebloggedBar.setVisibility(View.VISIBLE);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void hideRebloggedByDisplayName() {
|
2017-08-03 14:29:31 +10:00
|
|
|
if (rebloggedBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-13 16:18:17 +11:00
|
|
|
rebloggedBar.setVisibility(View.GONE);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void setReblogged(boolean reblogged) {
|
2017-01-23 16:19:30 +11:00
|
|
|
this.reblogged = reblogged;
|
2017-03-08 08:23:17 +11:00
|
|
|
reblogButton.setChecked(reblogged);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
// This should only be called after setReblogged, in order to override the tint correctly.
|
2017-07-09 05:44:08 +10:00
|
|
|
private void setRebloggingEnabled(boolean enabled, Status.Visibility visibility) {
|
2017-02-13 16:18:17 +11:00
|
|
|
reblogButton.setEnabled(enabled);
|
2017-03-08 08:23:17 +11:00
|
|
|
|
2017-02-18 15:33:10 +11:00
|
|
|
if (enabled) {
|
2017-03-08 15:52:17 +11:00
|
|
|
int inactiveId = ThemeUtils.getDrawableId(reblogButton.getContext(),
|
|
|
|
R.attr.status_reblog_inactive_drawable, R.drawable.reblog_inactive_dark);
|
|
|
|
reblogButton.setInactiveImage(inactiveId);
|
2017-03-08 08:23:17 +11:00
|
|
|
reblogButton.setActiveImage(R.drawable.reblog_active);
|
2017-02-18 15:33:10 +11:00
|
|
|
} else {
|
2017-07-09 05:44:08 +10:00
|
|
|
int disabledId;
|
|
|
|
if (visibility == Status.Visibility.DIRECT) {
|
|
|
|
disabledId = ThemeUtils.getDrawableId(reblogButton.getContext(),
|
|
|
|
R.attr.status_reblog_direct_drawable, R.drawable.reblog_direct_dark);
|
|
|
|
} else {
|
|
|
|
disabledId = ThemeUtils.getDrawableId(reblogButton.getContext(),
|
|
|
|
R.attr.status_reblog_disabled_drawable, R.drawable.reblog_disabled_dark);
|
|
|
|
}
|
2017-03-08 15:52:17 +11:00
|
|
|
reblogButton.setInactiveImage(disabledId);
|
|
|
|
reblogButton.setActiveImage(disabledId);
|
2017-02-13 16:18:17 +11:00
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void setFavourited(boolean favourited) {
|
2017-01-23 16:19:30 +11:00
|
|
|
this.favourited = favourited;
|
2017-03-08 08:23:17 +11:00
|
|
|
favouriteButton.setChecked(favourited);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-06-26 19:15:47 +10:00
|
|
|
private void setMediaPreviews(final Status.MediaAttachment[] attachments, boolean sensitive,
|
2017-07-13 05:54:52 +10:00
|
|
|
final StatusActionListener listener, boolean showingSensitive) {
|
2017-03-07 21:59:54 +11:00
|
|
|
final ImageView[] previews = {
|
2017-01-23 16:19:30 +11:00
|
|
|
mediaPreview0,
|
|
|
|
mediaPreview1,
|
|
|
|
mediaPreview2,
|
|
|
|
mediaPreview3
|
|
|
|
};
|
|
|
|
Context context = mediaPreview0.getContext();
|
2017-03-07 21:59:54 +11:00
|
|
|
|
|
|
|
int mediaPreviewUnloadedId = ThemeUtils.getDrawableId(itemView.getContext(),
|
|
|
|
R.attr.media_preview_unloaded_drawable, android.R.color.black);
|
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
final int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
|
2017-03-07 21:59:54 +11:00
|
|
|
|
2017-06-25 15:07:41 +10:00
|
|
|
final String[] urls = new String[n];
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
urls[i] = attachments[i].url;
|
|
|
|
}
|
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
for (int i = 0; i < n; i++) {
|
2017-03-09 10:27:37 +11:00
|
|
|
String previewUrl = attachments[i].previewUrl;
|
2017-03-07 21:59:54 +11:00
|
|
|
|
|
|
|
previews[i].setVisibility(View.VISIBLE);
|
|
|
|
|
2017-06-26 19:15:47 +10:00
|
|
|
if (previewUrl == null || previewUrl.isEmpty()) {
|
2017-04-17 19:03:05 +10:00
|
|
|
Picasso.with(context)
|
|
|
|
.load(mediaPreviewUnloadedId)
|
|
|
|
.into(previews[i]);
|
|
|
|
} else {
|
|
|
|
Picasso.with(context)
|
|
|
|
.load(previewUrl)
|
|
|
|
.placeholder(mediaPreviewUnloadedId)
|
|
|
|
.into(previews[i]);
|
|
|
|
}
|
2017-03-07 21:59:54 +11:00
|
|
|
|
2017-06-27 09:04:05 +10:00
|
|
|
final Status.MediaAttachment.Type type = attachments[i].type;
|
|
|
|
if (type == Status.MediaAttachment.Type.VIDEO
|
|
|
|
| type == Status.MediaAttachment.Type.GIFV) {
|
|
|
|
videoIndicator.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2017-06-25 15:07:41 +10:00
|
|
|
if (urls[i] == null || urls[i].isEmpty()) {
|
2017-04-17 19:03:05 +10:00
|
|
|
previews[i].setOnClickListener(null);
|
|
|
|
} else {
|
2017-06-25 15:07:41 +10:00
|
|
|
final int urlIndex = i;
|
2017-04-17 19:03:05 +10:00
|
|
|
previews[i].setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-14 15:26:58 +10:00
|
|
|
listener.onViewMedia(urls, urlIndex, type, v);
|
2017-04-17 19:03:05 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-03-07 21:59:54 +11:00
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
if (sensitive) {
|
2017-07-13 05:54:52 +10:00
|
|
|
sensitiveMediaWarning.setVisibility(showingSensitive ? View.GONE : View.VISIBLE);
|
2017-01-23 16:19:30 +11:00
|
|
|
sensitiveMediaWarning.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-13 05:54:52 +10:00
|
|
|
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onContentHiddenChange(true, getAdapterPosition());
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
v.setVisibility(View.GONE);
|
|
|
|
v.setOnClickListener(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-03-07 21:59:54 +11:00
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
// Hide any of the placeholder previews beyond the ones set.
|
|
|
|
for (int i = n; i < Status.MAX_MEDIA_ATTACHMENTS; i++) {
|
|
|
|
previews[i].setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-09 05:44:08 +10:00
|
|
|
@NonNull
|
2017-06-26 19:15:47 +10:00
|
|
|
private static String getLabelTypeText(Context context, Status.MediaAttachment.Type type) {
|
|
|
|
switch (type) {
|
|
|
|
default:
|
2017-07-13 05:54:52 +10:00
|
|
|
case IMAGE:
|
|
|
|
return context.getString(R.string.status_media_images);
|
2017-06-26 19:15:47 +10:00
|
|
|
case GIFV:
|
2017-07-13 05:54:52 +10:00
|
|
|
case VIDEO:
|
|
|
|
return context.getString(R.string.status_media_video);
|
2017-06-26 19:15:47 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
@DrawableRes
|
2017-07-21 11:17:36 +10:00
|
|
|
private static int getLabelIcon(Status.MediaAttachment.Type type) {
|
2017-06-26 19:15:47 +10:00
|
|
|
switch (type) {
|
|
|
|
default:
|
2017-07-13 05:54:52 +10:00
|
|
|
case IMAGE:
|
|
|
|
return R.drawable.ic_photo_24dp;
|
2017-06-26 19:15:47 +10:00
|
|
|
case GIFV:
|
2017-07-13 05:54:52 +10:00
|
|
|
case VIDEO:
|
|
|
|
return R.drawable.ic_videocam_24dp;
|
2017-06-26 19:15:47 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setMediaLabel(Status.MediaAttachment[] attachments, boolean sensitive,
|
2017-07-13 05:54:52 +10:00
|
|
|
final StatusActionListener listener) {
|
2017-06-26 19:15:47 +10:00
|
|
|
if (attachments.length == 0) {
|
|
|
|
mediaLabel.setVisibility(View.GONE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mediaLabel.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
// Set the label's text.
|
|
|
|
Context context = itemView.getContext();
|
|
|
|
String labelText = getLabelTypeText(context, attachments[0].type);
|
|
|
|
if (sensitive) {
|
|
|
|
String sensitiveText = context.getString(R.string.status_sensitive_media_title);
|
|
|
|
labelText += String.format(" (%s)", sensitiveText);
|
|
|
|
}
|
|
|
|
mediaLabel.setText(labelText);
|
|
|
|
|
|
|
|
// Set the icon next to the label.
|
|
|
|
int drawableId = getLabelIcon(attachments[0].type);
|
2017-07-29 01:54:57 +10:00
|
|
|
Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
|
2017-06-26 19:15:47 +10:00
|
|
|
ThemeUtils.setDrawableTint(context, drawable, android.R.attr.textColorTertiary);
|
|
|
|
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
|
|
|
|
|
|
|
// Set the listener for the media view action.
|
|
|
|
int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
|
|
|
|
final String[] urls = new String[n];
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
urls[i] = attachments[i].url;
|
|
|
|
}
|
|
|
|
final Status.MediaAttachment.Type type = attachments[0].type;
|
|
|
|
mediaLabel.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-07-14 15:26:58 +10:00
|
|
|
listener.onViewMedia(urls, 0, type, null);
|
2017-06-26 19:15:47 +10:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void hideSensitiveMediaWarning() {
|
2017-01-23 16:19:30 +11:00
|
|
|
sensitiveMediaWarning.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2017-07-15 13:23:14 +10:00
|
|
|
private void setSpoilerText(String spoilerText, final boolean expanded,
|
|
|
|
final StatusActionListener listener) {
|
2017-02-01 10:42:05 +11:00
|
|
|
contentWarningDescription.setText(spoilerText);
|
|
|
|
contentWarningBar.setVisibility(View.VISIBLE);
|
2017-07-13 05:54:52 +10:00
|
|
|
contentWarningButton.setChecked(expanded);
|
2017-02-01 10:42:05 +11:00
|
|
|
contentWarningButton.setOnCheckedChangeListener(
|
|
|
|
new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
2017-07-13 05:54:52 +10:00
|
|
|
if (getAdapterPosition() != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onExpandedChange(isChecked, getAdapterPosition());
|
|
|
|
}
|
2017-02-01 10:42:05 +11:00
|
|
|
if (isChecked) {
|
|
|
|
content.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
content.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2017-07-13 05:54:52 +10:00
|
|
|
if (expanded) {
|
|
|
|
content.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
content.setVisibility(View.GONE);
|
|
|
|
}
|
2017-02-01 10:42:05 +11:00
|
|
|
}
|
|
|
|
|
2017-02-23 06:13:51 +11:00
|
|
|
private void hideSpoilerText() {
|
2017-02-01 20:25:22 +11:00
|
|
|
contentWarningBar.setVisibility(View.GONE);
|
|
|
|
content.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2017-03-03 11:25:35 +11:00
|
|
|
private void setupButtons(final StatusActionListener listener, final String accountId) {
|
2017-03-04 12:44:44 +11:00
|
|
|
/* Originally position was passed through to all these listeners, but it caused several
|
|
|
|
* bugs where other statuses in the list would be removed or added and cause the position
|
|
|
|
* here to become outdated. So, getting the adapter position at the time the listener is
|
|
|
|
* actually called is the appropriate solution. */
|
2017-01-28 14:33:43 +11:00
|
|
|
avatar.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-03 11:25:35 +11:00
|
|
|
listener.onViewAccount(accountId);
|
2017-01-28 14:33:43 +11:00
|
|
|
}
|
|
|
|
});
|
2017-01-23 16:19:30 +11:00
|
|
|
replyButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-20 13:38:39 +11:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onReply(position);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
});
|
2017-03-08 08:23:17 +11:00
|
|
|
reblogButton.setEventListener(new SparkEventListener() {
|
2017-07-13 05:54:52 +10:00
|
|
|
@Override
|
|
|
|
public void onEvent(ImageView button, boolean buttonState) {
|
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onReblog(!reblogged, position);
|
2017-06-26 19:15:47 +10:00
|
|
|
}
|
2017-07-13 05:54:52 +10:00
|
|
|
}
|
2017-06-26 19:15:47 +10:00
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
@Override
|
|
|
|
public void onEventAnimationEnd(ImageView button, boolean buttonState) {
|
|
|
|
}
|
2017-06-26 19:15:47 +10:00
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
@Override
|
|
|
|
public void onEventAnimationStart(ImageView button, boolean buttonState) {
|
|
|
|
}
|
2017-06-26 19:15:47 +10:00
|
|
|
});
|
2017-03-08 08:23:17 +11:00
|
|
|
favouriteButton.setEventListener(new SparkEventListener() {
|
2017-01-23 16:19:30 +11:00
|
|
|
@Override
|
2017-03-08 08:23:17 +11:00
|
|
|
public void onEvent(ImageView button, boolean buttonState) {
|
2017-03-20 13:38:39 +11:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onFavourite(!favourited, position);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-05-05 00:16:24 +10:00
|
|
|
|
|
|
|
@Override
|
2017-07-13 05:54:52 +10:00
|
|
|
public void onEventAnimationEnd(ImageView button, boolean buttonState) {
|
|
|
|
}
|
2017-05-05 00:16:24 +10:00
|
|
|
|
|
|
|
@Override
|
2017-07-13 05:54:52 +10:00
|
|
|
public void onEventAnimationStart(ImageView button, boolean buttonState) {
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
});
|
|
|
|
moreButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-20 13:38:39 +11:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onMore(v, position);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
});
|
2017-01-28 14:33:43 +11:00
|
|
|
/* Even though the content TextView is a child of the container, it won't respond to clicks
|
|
|
|
* if it contains URLSpans without also setting its listener. The surrounding spans will
|
|
|
|
* just eat the clicks instead of deferring to the parent listener, but WILL respond to a
|
|
|
|
* listener directly on the TextView, for whatever reason. */
|
|
|
|
View.OnClickListener viewThreadListener = new View.OnClickListener() {
|
2017-01-23 16:19:30 +11:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2017-03-20 13:38:39 +11:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onViewThread(position);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
};
|
|
|
|
content.setOnClickListener(viewThreadListener);
|
|
|
|
container.setOnClickListener(viewThreadListener);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
void setupWithStatus(StatusViewData status, final StatusActionListener listener,
|
2017-06-28 18:10:56 +10:00
|
|
|
boolean mediaPreviewEnabled) {
|
2017-07-13 05:54:52 +10:00
|
|
|
setDisplayName(status.getUserFullName());
|
|
|
|
setUsername(status.getNickname());
|
|
|
|
setCreatedAt(status.getCreatedAt());
|
|
|
|
setContent(status.getContent(), status.getMentions(), listener);
|
2017-07-14 15:06:32 +10:00
|
|
|
setAvatar(status.getAvatar(), status.getRebloggedAvatar());
|
2017-07-13 05:54:52 +10:00
|
|
|
setReblogged(status.isReblogged());
|
|
|
|
setFavourited(status.isFavourited());
|
|
|
|
String rebloggedByDisplayName = status.getRebloggedByUsername();
|
|
|
|
if (rebloggedByDisplayName == null) {
|
2017-02-17 05:52:55 +11:00
|
|
|
hideRebloggedByDisplayName();
|
2017-01-23 16:19:30 +11:00
|
|
|
} else {
|
2017-02-17 05:52:55 +11:00
|
|
|
setRebloggedByDisplayName(rebloggedByDisplayName);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-07-13 05:54:52 +10:00
|
|
|
Status.MediaAttachment[] attachments = status.getAttachments();
|
|
|
|
boolean sensitive = status.isSensitive();
|
2017-06-26 19:15:47 +10:00
|
|
|
if (mediaPreviewEnabled) {
|
2017-07-13 05:54:52 +10:00
|
|
|
setMediaPreviews(attachments, sensitive, listener, status.isShowingSensitiveContent());
|
2017-06-26 19:15:47 +10:00
|
|
|
/* A status without attachments is sometimes still marked sensitive, so it's necessary
|
|
|
|
* to check both whether there are any attachments and if it's marked sensitive. */
|
|
|
|
if (!sensitive || attachments.length == 0) {
|
|
|
|
hideSensitiveMediaWarning();
|
|
|
|
}
|
2017-06-27 09:04:05 +10:00
|
|
|
if (attachments.length == 0) {
|
|
|
|
videoIndicator.setVisibility(View.GONE);
|
|
|
|
}
|
2017-06-26 19:15:47 +10:00
|
|
|
// Hide the unused label.
|
|
|
|
mediaLabel.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
setMediaLabel(attachments, sensitive, listener);
|
|
|
|
// Hide all unused views.
|
|
|
|
mediaPreview0.setVisibility(View.GONE);
|
|
|
|
mediaPreview1.setVisibility(View.GONE);
|
|
|
|
mediaPreview2.setVisibility(View.GONE);
|
|
|
|
mediaPreview3.setVisibility(View.GONE);
|
2017-01-23 16:19:30 +11:00
|
|
|
hideSensitiveMediaWarning();
|
2017-06-27 09:04:05 +10:00
|
|
|
videoIndicator.setVisibility(View.GONE);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
2017-06-26 19:15:47 +10:00
|
|
|
|
2017-07-13 05:54:52 +10:00
|
|
|
setupButtons(listener, status.getSenderId());
|
|
|
|
setRebloggingEnabled(status.getRebloggingEnabled(), status.getVisibility());
|
|
|
|
if (status.getSpoilerText() == null || status.getSpoilerText().isEmpty()) {
|
2017-02-01 20:25:22 +11:00
|
|
|
hideSpoilerText();
|
|
|
|
} else {
|
2017-07-13 05:54:52 +10:00
|
|
|
setSpoilerText(status.getSpoilerText(), status.isExpanded(), listener);
|
2017-02-01 10:42:05 +11:00
|
|
|
}
|
2017-06-28 18:10:56 +10:00
|
|
|
|
|
|
|
// I think it's not efficient to create new object every time we bind a holder.
|
|
|
|
// More efficient approach would be creating View.OnClickListener during holder creation
|
|
|
|
// and storing StatusActionListener in a variable after binding.
|
2017-08-03 14:29:31 +10:00
|
|
|
if (rebloggedBar != null) {
|
|
|
|
rebloggedBar.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
listener.onOpenReblog(getAdapterPosition());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
}
|