2014-07-03 07:48:39 +02:00
|
|
|
package org.mariotaku.twidere.view.holder;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.database.Cursor;
|
2015-01-14 09:47:51 +01:00
|
|
|
import android.graphics.PorterDuff.Mode;
|
2014-12-13 16:14:47 +01:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.support.v7.widget.CardView;
|
2014-11-21 04:00:46 +01:00
|
|
|
import android.support.v7.widget.RecyclerView;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.view.View;
|
2014-11-21 04:00:46 +01:00
|
|
|
import android.view.View.OnClickListener;
|
2014-07-03 07:48:39 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-03-20 13:40:27 +01:00
|
|
|
import org.mariotaku.twidere.Constants;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.R;
|
2015-01-06 16:46:07 +01:00
|
|
|
import org.mariotaku.twidere.adapter.iface.ContentCardClickListener;
|
2014-11-21 04:00:46 +01:00
|
|
|
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter;
|
2015-03-14 16:11:20 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableLocation;
|
2014-11-21 04:00:46 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableMedia;
|
|
|
|
import org.mariotaku.twidere.model.ParcelableStatus;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableStatus.CursorIndices;
|
2014-12-12 14:53:18 +01:00
|
|
|
import org.mariotaku.twidere.util.AsyncTwitterWrapper;
|
2014-12-10 13:15:09 +01:00
|
|
|
import org.mariotaku.twidere.util.ImageLoadingHandler;
|
2015-03-24 16:40:47 +01:00
|
|
|
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
2015-02-17 06:49:23 +01:00
|
|
|
import org.mariotaku.twidere.util.SimpleValueSerializer;
|
2015-01-19 18:46:14 +01:00
|
|
|
import org.mariotaku.twidere.util.TwitterCardUtils;
|
2015-01-03 16:16:50 +01:00
|
|
|
import org.mariotaku.twidere.util.UserColorNameUtils;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.util.Utils;
|
2015-03-29 09:17:42 +02:00
|
|
|
import org.mariotaku.twidere.util.Utils.OnMediaClickListener;
|
2014-12-24 05:39:21 +01:00
|
|
|
import org.mariotaku.twidere.view.CardMediaContainer;
|
|
|
|
import org.mariotaku.twidere.view.ShapedImageView;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.view.ShortTimeView;
|
2015-01-14 09:47:51 +01:00
|
|
|
import org.mariotaku.twidere.view.iface.IColorLabelView;
|
2014-07-03 07:48:39 +02:00
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-12-13 16:14:47 +01:00
|
|
|
import twitter4j.TranslationResult;
|
|
|
|
|
2015-03-20 13:40:27 +01:00
|
|
|
import static org.mariotaku.twidere.util.HtmlEscapeHelper.toPlainText;
|
2014-11-22 15:12:54 +01:00
|
|
|
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
/**
|
2015-03-12 16:04:45 +01:00
|
|
|
* IDE gives me warning if I don't change default comment, so I write this XD
|
2015-03-14 16:11:20 +01:00
|
|
|
* <p/>
|
2014-11-21 04:00:46 +01:00
|
|
|
* Created by mariotaku on 14/11/19.
|
|
|
|
*/
|
2015-03-29 09:17:42 +02:00
|
|
|
public class StatusViewHolder extends RecyclerView.ViewHolder implements Constants, OnClickListener,
|
|
|
|
OnMediaClickListener {
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
private final IStatusesAdapter<?> adapter;
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
private final ImageView replyRetweetIcon;
|
2014-12-24 05:39:21 +01:00
|
|
|
private final ShapedImageView profileImageView;
|
2014-11-21 04:00:46 +01:00
|
|
|
private final ImageView profileTypeView;
|
2015-01-19 18:46:14 +01:00
|
|
|
private final ImageView extraTypeView;
|
2014-11-21 04:00:46 +01:00
|
|
|
private final TextView textView;
|
|
|
|
private final TextView nameView, screenNameView;
|
|
|
|
private final TextView replyRetweetView;
|
|
|
|
private final ShortTimeView timeView;
|
2014-12-24 05:39:21 +01:00
|
|
|
private final CardMediaContainer mediaPreviewContainer;
|
2014-11-21 04:00:46 +01:00
|
|
|
private final TextView replyCountView, retweetCountView, favoriteCountView;
|
2015-01-14 09:47:51 +01:00
|
|
|
private final IColorLabelView itemContent;
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2015-01-06 16:46:07 +01:00
|
|
|
private StatusClickListener statusClickListener;
|
|
|
|
|
2014-12-10 13:15:09 +01:00
|
|
|
|
|
|
|
public StatusViewHolder(View itemView) {
|
|
|
|
this(null, itemView);
|
|
|
|
}
|
|
|
|
|
2014-12-04 15:31:29 +01:00
|
|
|
public StatusViewHolder(IStatusesAdapter<?> adapter, View itemView) {
|
2014-11-21 04:00:46 +01:00
|
|
|
super(itemView);
|
|
|
|
this.adapter = adapter;
|
2015-01-14 09:47:51 +01:00
|
|
|
itemContent = (IColorLabelView) itemView.findViewById(R.id.item_content);
|
2014-12-24 05:39:21 +01:00
|
|
|
profileImageView = (ShapedImageView) itemView.findViewById(R.id.profile_image);
|
2014-11-21 04:00:46 +01:00
|
|
|
profileTypeView = (ImageView) itemView.findViewById(R.id.profile_type);
|
2015-01-19 18:46:14 +01:00
|
|
|
extraTypeView = (ImageView) itemView.findViewById(R.id.extra_type);
|
2014-11-21 04:00:46 +01:00
|
|
|
textView = (TextView) itemView.findViewById(R.id.text);
|
|
|
|
nameView = (TextView) itemView.findViewById(R.id.name);
|
|
|
|
screenNameView = (TextView) itemView.findViewById(R.id.screen_name);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon = (ImageView) itemView.findViewById(R.id.reply_retweet_icon);
|
2014-11-21 04:00:46 +01:00
|
|
|
replyRetweetView = (TextView) itemView.findViewById(R.id.reply_retweet_status);
|
|
|
|
timeView = (ShortTimeView) itemView.findViewById(R.id.time);
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
mediaPreviewContainer = (CardMediaContainer) itemView.findViewById(R.id.media_preview_container);
|
2014-11-21 04:00:46 +01:00
|
|
|
|
|
|
|
replyCountView = (TextView) itemView.findViewById(R.id.reply_count);
|
|
|
|
retweetCountView = (TextView) itemView.findViewById(R.id.retweet_count);
|
|
|
|
favoriteCountView = (TextView) itemView.findViewById(R.id.favorite_count);
|
2014-12-03 11:27:11 +01:00
|
|
|
//TODO
|
|
|
|
// profileImageView.setSelectorColor(ThemeUtils.getUserHighlightColor(itemView.getContext()));
|
2014-12-10 13:15:09 +01:00
|
|
|
}
|
|
|
|
|
2015-01-30 15:27:22 +01:00
|
|
|
public void displaySampleStatus() {
|
2015-03-20 13:40:27 +01:00
|
|
|
profileImageView.setImageResource(R.mipmap.ic_launcher);
|
|
|
|
nameView.setText(TWIDERE_PREVIEW_NAME);
|
|
|
|
screenNameView.setText("@" + TWIDERE_PREVIEW_SCREEN_NAME);
|
|
|
|
textView.setText(toPlainText(TWIDERE_PREVIEW_TEXT_HTML));
|
2015-01-30 15:27:22 +01:00
|
|
|
timeView.setTime(System.currentTimeMillis());
|
2015-03-20 17:51:39 +01:00
|
|
|
mediaPreviewContainer.displayMedia(R.drawable.nyan_stars_background);
|
2014-12-24 05:39:21 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
public void displayStatus(final ParcelableStatus status, final boolean displayInReplyTo) {
|
2014-12-10 13:15:09 +01:00
|
|
|
displayStatus(adapter.getContext(), adapter.getImageLoader(),
|
2015-01-01 11:38:34 +01:00
|
|
|
adapter.getImageLoadingHandler(), adapter.getTwitterWrapper(),
|
2015-03-30 14:24:51 +02:00
|
|
|
adapter.isProfileImageEnabled(),
|
2015-01-19 18:46:14 +01:00
|
|
|
adapter.isMediaPreviewEnabled(), adapter.shouldShowAccountsColor(),
|
2015-03-24 16:40:47 +01:00
|
|
|
displayInReplyTo, adapter.isNameFirst(), adapter.getProfileImageStyle(),
|
|
|
|
adapter.getMediaPreviewStyle(), status, null, displayInReplyTo);
|
2014-12-13 16:14:47 +01:00
|
|
|
}
|
|
|
|
|
2015-01-19 18:46:14 +01:00
|
|
|
public void displayStatus(@NonNull final Context context,
|
2015-03-22 18:06:25 +01:00
|
|
|
@NonNull final MediaLoaderWrapper loader,
|
2015-01-19 18:46:14 +01:00
|
|
|
@NonNull final ImageLoadingHandler handler,
|
|
|
|
@NonNull final AsyncTwitterWrapper twitter,
|
2015-03-30 14:24:51 +02:00
|
|
|
final boolean displayProfileImage, final boolean displayMediaPreview,
|
|
|
|
final boolean displayAccountsColor, final boolean displayInReplyTo,
|
|
|
|
final boolean nameFirst, final int profileImageStyle, final int mediaPreviewStyle,
|
|
|
|
@NonNull final ParcelableStatus status, @Nullable final TranslationResult translation,
|
|
|
|
boolean shouldDisplayExtraType) {
|
2014-11-21 04:00:46 +01:00
|
|
|
final ParcelableMedia[] media = status.media;
|
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setColorFilter(replyRetweetView.getCurrentTextColor(), Mode.SRC_ATOP);
|
2014-11-21 04:00:46 +01:00
|
|
|
if (status.retweet_id > 0) {
|
2015-03-11 15:15:32 +01:00
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
|
|
|
replyRetweetIcon.setVisibility(View.VISIBLE);
|
2015-01-19 18:46:14 +01:00
|
|
|
final String retweetedBy = UserColorNameUtils.getDisplayName(context, status.retweeted_by_id,
|
2015-03-24 16:40:47 +01:00
|
|
|
status.retweeted_by_name, status.retweeted_by_screen_name, nameFirst);
|
2015-01-19 18:46:14 +01:00
|
|
|
replyRetweetView.setText(context.getString(R.string.name_retweeted, retweetedBy));
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_retweet);
|
2015-03-11 15:15:32 +01:00
|
|
|
} else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id > 0 && displayInReplyTo) {
|
2014-11-21 04:00:46 +01:00
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setVisibility(View.VISIBLE);
|
2015-01-19 18:46:14 +01:00
|
|
|
final String inReplyTo = UserColorNameUtils.getDisplayName(context, status.in_reply_to_user_id,
|
2015-03-24 16:40:47 +01:00
|
|
|
status.in_reply_to_name, status.in_reply_to_screen_name, nameFirst);
|
2015-01-19 18:46:14 +01:00
|
|
|
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, inReplyTo));
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_reply);
|
2014-11-21 04:00:46 +01:00
|
|
|
} else {
|
|
|
|
replyRetweetView.setVisibility(View.GONE);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setVisibility(View.GONE);
|
2015-03-11 15:15:32 +01:00
|
|
|
replyRetweetView.setText(null);
|
2014-11-21 04:00:46 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 15:15:32 +01:00
|
|
|
|
2014-11-22 15:12:54 +01:00
|
|
|
final int typeIconRes = getUserTypeIconRes(status.user_is_verified, status.user_is_protected);
|
|
|
|
if (typeIconRes != 0) {
|
|
|
|
profileTypeView.setImageResource(typeIconRes);
|
|
|
|
profileTypeView.setVisibility(View.VISIBLE);
|
2014-11-21 04:00:46 +01:00
|
|
|
} else {
|
|
|
|
profileTypeView.setImageDrawable(null);
|
2014-11-22 15:12:54 +01:00
|
|
|
profileTypeView.setVisibility(View.GONE);
|
2014-11-21 04:00:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nameView.setText(status.user_name);
|
|
|
|
screenNameView.setText("@" + status.user_screen_name);
|
|
|
|
timeView.setTime(status.timestamp);
|
|
|
|
|
2015-01-03 16:16:50 +01:00
|
|
|
final int userColor = UserColorNameUtils.getUserColor(context, status.user_id);
|
2015-01-14 09:47:51 +01:00
|
|
|
itemContent.drawStart(userColor);
|
2015-01-17 19:58:29 +01:00
|
|
|
|
|
|
|
if (displayAccountsColor) {
|
|
|
|
itemContent.drawEnd(Utils.getAccountColor(context, status.account_id));
|
|
|
|
} else {
|
|
|
|
itemContent.drawEnd();
|
|
|
|
}
|
2015-01-01 11:38:34 +01:00
|
|
|
profileImageView.setStyle(profileImageStyle);
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2015-03-30 14:24:51 +02:00
|
|
|
if (displayProfileImage) {
|
|
|
|
profileTypeView.setVisibility(View.VISIBLE);
|
|
|
|
profileImageView.setVisibility(View.VISIBLE);
|
|
|
|
loader.displayProfileImage(profileImageView, status.user_profile_image_url);
|
|
|
|
} else {
|
|
|
|
profileTypeView.setVisibility(View.GONE);
|
|
|
|
profileImageView.setVisibility(View.GONE);
|
|
|
|
loader.cancelDisplayTask(profileImageView);
|
|
|
|
}
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2015-01-19 18:46:14 +01:00
|
|
|
if (displayMediaPreview) {
|
|
|
|
mediaPreviewContainer.setStyle(mediaPreviewStyle);
|
2015-01-23 17:09:03 +01:00
|
|
|
if (media != null && media.length > 0) {
|
|
|
|
mediaPreviewContainer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
mediaPreviewContainer.setVisibility(View.GONE);
|
|
|
|
}
|
2015-03-29 09:17:42 +02:00
|
|
|
mediaPreviewContainer.displayMedia(media, loader, status.account_id, this, handler);
|
2015-01-19 18:46:14 +01:00
|
|
|
} else {
|
|
|
|
mediaPreviewContainer.setVisibility(View.GONE);
|
|
|
|
}
|
2014-12-13 16:14:47 +01:00
|
|
|
if (translation != null) {
|
|
|
|
textView.setText(translation.getText());
|
|
|
|
} else {
|
|
|
|
textView.setText(status.text_unescaped);
|
|
|
|
}
|
2014-11-21 04:00:46 +01:00
|
|
|
|
|
|
|
if (status.reply_count > 0) {
|
|
|
|
replyCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), status.reply_count));
|
|
|
|
} else {
|
|
|
|
replyCountView.setText(null);
|
|
|
|
}
|
2014-12-13 16:14:47 +01:00
|
|
|
|
|
|
|
final long retweet_count;
|
|
|
|
if (twitter.isDestroyingStatus(status.account_id, status.my_retweet_id)) {
|
|
|
|
retweetCountView.setActivated(false);
|
|
|
|
retweet_count = Math.max(0, status.favorite_count - 1);
|
2014-11-21 04:00:46 +01:00
|
|
|
} else {
|
2014-12-13 16:14:47 +01:00
|
|
|
final boolean creatingRetweet = twitter.isCreatingRetweet(status.account_id, status.id);
|
|
|
|
retweetCountView.setActivated(creatingRetweet || Utils.isMyRetweet(status));
|
|
|
|
retweet_count = status.retweet_count + (creatingRetweet ? 1 : 0);
|
2014-11-21 04:00:46 +01:00
|
|
|
}
|
2014-12-13 16:14:47 +01:00
|
|
|
if (retweet_count > 0) {
|
|
|
|
retweetCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), retweet_count));
|
2014-11-21 04:00:46 +01:00
|
|
|
} else {
|
2014-12-13 16:14:47 +01:00
|
|
|
retweetCountView.setText(null);
|
2014-11-21 04:00:46 +01:00
|
|
|
}
|
|
|
|
retweetCountView.setEnabled(!status.user_is_protected);
|
|
|
|
|
2014-12-13 16:14:47 +01:00
|
|
|
final long favorite_count;
|
2014-12-12 14:53:18 +01:00
|
|
|
if (twitter.isDestroyingFavorite(status.account_id, status.id)) {
|
|
|
|
favoriteCountView.setActivated(false);
|
2014-12-13 16:14:47 +01:00
|
|
|
favorite_count = Math.max(0, status.favorite_count - 1);
|
2014-12-12 14:53:18 +01:00
|
|
|
} else {
|
2014-12-13 16:14:47 +01:00
|
|
|
final boolean creatingFavorite = twitter.isCreatingFavorite(status.account_id, status.id);
|
|
|
|
favoriteCountView.setActivated(creatingFavorite || status.is_favorite);
|
|
|
|
favorite_count = status.favorite_count + (creatingFavorite ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (favorite_count > 0) {
|
|
|
|
favoriteCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), favorite_count));
|
|
|
|
} else {
|
|
|
|
favoriteCountView.setText(null);
|
2014-12-12 14:53:18 +01:00
|
|
|
}
|
2015-03-18 08:34:23 +01:00
|
|
|
if (shouldDisplayExtraType) {
|
2015-04-03 19:22:00 +02:00
|
|
|
displayExtraTypeIcon(status.card_name, status.media, status.location, status.place_full_name);
|
2015-03-18 08:34:23 +01:00
|
|
|
} else {
|
|
|
|
extraTypeView.setVisibility(View.GONE);
|
|
|
|
}
|
2015-01-19 18:46:14 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 09:47:51 +01:00
|
|
|
public void displayStatus(@NonNull Cursor cursor, @NonNull CursorIndices indices,
|
|
|
|
final boolean displayInReplyTo) {
|
2015-03-22 18:06:25 +01:00
|
|
|
final MediaLoaderWrapper loader = adapter.getImageLoader();
|
2014-12-12 14:53:18 +01:00
|
|
|
final AsyncTwitterWrapper twitter = adapter.getTwitterWrapper();
|
2014-12-03 11:27:11 +01:00
|
|
|
final Context context = adapter.getContext();
|
2015-01-19 18:46:14 +01:00
|
|
|
final boolean nameFirst = adapter.isNameFirst();
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2014-12-13 16:14:47 +01:00
|
|
|
final long reply_count = cursor.getLong(indices.reply_count);
|
|
|
|
final long retweet_count;
|
|
|
|
final long favorite_count;
|
2014-12-03 11:27:11 +01:00
|
|
|
|
|
|
|
final long account_id = cursor.getLong(indices.account_id);
|
|
|
|
final long timestamp = cursor.getLong(indices.status_timestamp);
|
|
|
|
final long user_id = cursor.getLong(indices.user_id);
|
2014-12-12 14:53:18 +01:00
|
|
|
final long status_id = cursor.getLong(indices.status_id);
|
2014-12-03 11:27:11 +01:00
|
|
|
final long retweet_id = cursor.getLong(indices.retweet_id);
|
|
|
|
final long my_retweet_id = cursor.getLong(indices.my_retweet_id);
|
|
|
|
final long retweeted_by_id = cursor.getLong(indices.retweeted_by_user_id);
|
|
|
|
final long in_reply_to_status_id = cursor.getLong(indices.in_reply_to_status_id);
|
|
|
|
final long in_reply_to_user_id = cursor.getLong(indices.in_reply_to_user_id);
|
|
|
|
|
|
|
|
final boolean user_is_protected = cursor.getInt(indices.is_protected) == 1;
|
|
|
|
|
|
|
|
final String user_name = cursor.getString(indices.user_name);
|
|
|
|
final String user_screen_name = cursor.getString(indices.user_screen_name);
|
|
|
|
final String user_profile_image_url = cursor.getString(indices.user_profile_image_url);
|
|
|
|
final String retweeted_by_name = cursor.getString(indices.retweeted_by_user_name);
|
2015-01-19 18:46:14 +01:00
|
|
|
final String retweeted_by_screen_name = cursor.getString(indices.retweeted_by_user_screen_name);
|
2014-12-03 11:27:11 +01:00
|
|
|
final String in_reply_to_name = cursor.getString(indices.in_reply_to_user_name);
|
2015-01-19 18:46:14 +01:00
|
|
|
final String in_reply_to_screen_name = cursor.getString(indices.in_reply_to_user_screen_name);
|
|
|
|
final String card_name = cursor.getString(indices.card_name);
|
2015-04-03 19:22:00 +02:00
|
|
|
final String place_full_name = cursor.getString(indices.place_full_name);
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-03-14 16:11:20 +01:00
|
|
|
final ParcelableMedia[] media = SimpleValueSerializer.fromSerializedString(
|
|
|
|
cursor.getString(indices.media), ParcelableMedia.SIMPLE_CREATOR);
|
|
|
|
final ParcelableLocation location = ParcelableLocation.fromString(
|
|
|
|
cursor.getString(indices.location));
|
2014-12-03 11:27:11 +01:00
|
|
|
|
|
|
|
if (retweet_id > 0) {
|
2015-01-19 18:46:14 +01:00
|
|
|
final String retweetedBy = UserColorNameUtils.getDisplayName(context, retweeted_by_id,
|
2015-03-24 16:40:47 +01:00
|
|
|
retweeted_by_name, retweeted_by_screen_name, nameFirst);
|
2015-01-19 18:46:14 +01:00
|
|
|
replyRetweetView.setText(context.getString(R.string.name_retweeted, retweetedBy));
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_retweet);
|
2014-12-03 11:27:11 +01:00
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setVisibility(View.VISIBLE);
|
|
|
|
} else if (in_reply_to_status_id > 0 && in_reply_to_user_id > 0 && displayInReplyTo) {
|
2015-01-19 18:46:14 +01:00
|
|
|
final String inReplyTo = UserColorNameUtils.getDisplayName(context, in_reply_to_user_id,
|
2015-03-24 16:40:47 +01:00
|
|
|
in_reply_to_name, in_reply_to_screen_name, nameFirst);
|
2015-01-19 18:46:14 +01:00
|
|
|
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, inReplyTo));
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setImageResource(R.drawable.ic_activity_action_reply);
|
2014-12-03 11:27:11 +01:00
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setVisibility(View.VISIBLE);
|
2014-12-03 11:27:11 +01:00
|
|
|
} else {
|
|
|
|
replyRetweetView.setVisibility(View.GONE);
|
2015-01-14 09:47:51 +01:00
|
|
|
replyRetweetIcon.setVisibility(View.GONE);
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
final int typeIconRes = getUserTypeIconRes(cursor.getInt(indices.is_verified) == 1,
|
|
|
|
user_is_protected);
|
|
|
|
if (typeIconRes != 0) {
|
|
|
|
profileTypeView.setImageResource(typeIconRes);
|
|
|
|
profileTypeView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
profileTypeView.setImageDrawable(null);
|
|
|
|
profileTypeView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nameView.setText(user_name);
|
|
|
|
screenNameView.setText("@" + user_screen_name);
|
|
|
|
timeView.setTime(timestamp);
|
|
|
|
|
2015-01-03 16:16:50 +01:00
|
|
|
final int userColor = UserColorNameUtils.getUserColor(context, user_id);
|
2015-01-14 09:47:51 +01:00
|
|
|
itemContent.drawStart(userColor);
|
2015-01-17 19:58:29 +01:00
|
|
|
|
|
|
|
if (adapter.shouldShowAccountsColor()) {
|
|
|
|
itemContent.drawEnd(Utils.getAccountColor(context, account_id));
|
|
|
|
} else {
|
|
|
|
itemContent.drawEnd();
|
|
|
|
}
|
|
|
|
|
2015-01-01 11:38:34 +01:00
|
|
|
profileImageView.setStyle(adapter.getProfileImageStyle());
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2015-03-30 14:24:51 +02:00
|
|
|
if (adapter.isProfileImageEnabled()) {
|
|
|
|
profileTypeView.setVisibility(View.VISIBLE);
|
|
|
|
profileImageView.setVisibility(View.VISIBLE);
|
|
|
|
loader.displayProfileImage(profileImageView, user_profile_image_url);
|
|
|
|
} else {
|
|
|
|
profileTypeView.setVisibility(View.GONE);
|
|
|
|
profileImageView.setVisibility(View.GONE);
|
|
|
|
loader.cancelDisplayTask(profileImageView);
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
final String text_unescaped = cursor.getString(indices.text_unescaped);
|
2015-01-19 18:46:14 +01:00
|
|
|
if (adapter.isMediaPreviewEnabled()) {
|
|
|
|
mediaPreviewContainer.setStyle(adapter.getMediaPreviewStyle());
|
|
|
|
mediaPreviewContainer.setVisibility(media != null && media.length > 0 ? View.VISIBLE : View.GONE);
|
2015-03-29 09:17:42 +02:00
|
|
|
mediaPreviewContainer.displayMedia(media, loader, account_id, this,
|
2015-01-19 18:46:14 +01:00
|
|
|
adapter.getImageLoadingHandler());
|
|
|
|
} else {
|
|
|
|
mediaPreviewContainer.setVisibility(View.GONE);
|
|
|
|
}
|
2014-12-24 05:39:21 +01:00
|
|
|
textView.setText(text_unescaped);
|
2014-12-03 11:27:11 +01:00
|
|
|
|
|
|
|
if (reply_count > 0) {
|
|
|
|
replyCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), reply_count));
|
|
|
|
} else {
|
|
|
|
replyCountView.setText(null);
|
|
|
|
}
|
2014-12-13 16:14:47 +01:00
|
|
|
|
|
|
|
if (twitter.isDestroyingStatus(account_id, my_retweet_id)) {
|
|
|
|
retweetCountView.setActivated(false);
|
|
|
|
retweet_count = Math.max(0, cursor.getLong(indices.retweet_count) - 1);
|
|
|
|
} else {
|
|
|
|
final boolean creatingRetweet = twitter.isCreatingRetweet(account_id, status_id);
|
|
|
|
retweetCountView.setActivated(creatingRetweet || Utils.isMyRetweet(account_id,
|
|
|
|
retweeted_by_id, my_retweet_id));
|
|
|
|
retweet_count = cursor.getLong(indices.retweet_count) + (creatingRetweet ? 1 : 0);
|
|
|
|
}
|
2014-12-03 11:27:11 +01:00
|
|
|
if (retweet_count > 0) {
|
|
|
|
retweetCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), retweet_count));
|
|
|
|
} else {
|
|
|
|
retweetCountView.setText(null);
|
|
|
|
}
|
|
|
|
retweetCountView.setEnabled(!user_is_protected);
|
2014-12-13 16:14:47 +01:00
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
favoriteCountView.setActivated(cursor.getInt(indices.is_favorite) == 1);
|
2014-12-12 14:53:18 +01:00
|
|
|
if (twitter.isDestroyingFavorite(account_id, status_id)) {
|
|
|
|
favoriteCountView.setActivated(false);
|
2014-12-13 16:14:47 +01:00
|
|
|
favorite_count = Math.max(0, cursor.getLong(indices.favorite_count) - 1);
|
2014-12-12 14:53:18 +01:00
|
|
|
} else {
|
2014-12-13 16:14:47 +01:00
|
|
|
final boolean creatingFavorite = twitter.isCreatingFavorite(account_id, status_id);
|
|
|
|
favoriteCountView.setActivated(creatingFavorite || cursor.getInt(indices.is_favorite) == 1);
|
|
|
|
favorite_count = cursor.getLong(indices.favorite_count) + (creatingFavorite ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (favorite_count > 0) {
|
|
|
|
favoriteCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), favorite_count));
|
|
|
|
} else {
|
|
|
|
favoriteCountView.setText(null);
|
2014-12-12 14:53:18 +01:00
|
|
|
}
|
2015-04-03 19:22:00 +02:00
|
|
|
displayExtraTypeIcon(card_name, media, location, place_full_name);
|
2014-12-03 11:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public CardView getCardView() {
|
|
|
|
return (CardView) itemView.findViewById(R.id.card);
|
|
|
|
}
|
|
|
|
|
2014-12-24 05:39:21 +01:00
|
|
|
public ShapedImageView getProfileImageView() {
|
2014-12-03 11:27:11 +01:00
|
|
|
return profileImageView;
|
|
|
|
}
|
|
|
|
|
2014-12-07 16:13:07 +01:00
|
|
|
public ImageView getProfileTypeView() {
|
|
|
|
return profileTypeView;
|
|
|
|
}
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-01-06 16:46:07 +01:00
|
|
|
if (statusClickListener == null) return;
|
2015-03-24 16:40:47 +01:00
|
|
|
final int position = getAdapterPosition();
|
2014-11-21 04:00:46 +01:00
|
|
|
switch (v.getId()) {
|
|
|
|
case R.id.item_content: {
|
2015-01-06 16:46:07 +01:00
|
|
|
statusClickListener.onStatusClick(this, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-12-10 13:15:09 +01:00
|
|
|
case R.id.item_menu: {
|
2015-01-14 09:47:51 +01:00
|
|
|
statusClickListener.onItemMenuClick(this, v, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.profile_image: {
|
2015-01-06 16:46:07 +01:00
|
|
|
statusClickListener.onUserProfileClick(this, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-12-10 13:15:09 +01:00
|
|
|
case R.id.reply_count:
|
|
|
|
case R.id.retweet_count:
|
|
|
|
case R.id.favorite_count: {
|
2015-01-06 16:46:07 +01:00
|
|
|
statusClickListener.onItemActionClick(this, v.getId(), position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 15:27:22 +01:00
|
|
|
|
2015-03-29 09:17:42 +02:00
|
|
|
@Override
|
|
|
|
public void onMediaClick(View view, ParcelableMedia media, long accountId) {
|
|
|
|
if (statusClickListener == null) return;
|
|
|
|
final int position = getAdapterPosition();
|
|
|
|
statusClickListener.onMediaClick(this, media, position);
|
|
|
|
}
|
|
|
|
|
2015-01-30 15:27:22 +01:00
|
|
|
public void setOnClickListeners() {
|
|
|
|
setStatusClickListener(adapter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setStatusClickListener(StatusClickListener listener) {
|
|
|
|
statusClickListener = listener;
|
|
|
|
itemView.findViewById(R.id.item_content).setOnClickListener(this);
|
|
|
|
itemView.findViewById(R.id.item_menu).setOnClickListener(this);
|
|
|
|
|
|
|
|
itemView.setOnClickListener(this);
|
|
|
|
profileImageView.setOnClickListener(this);
|
|
|
|
replyCountView.setOnClickListener(this);
|
|
|
|
retweetCountView.setOnClickListener(this);
|
|
|
|
favoriteCountView.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTextSize(final float textSize) {
|
|
|
|
nameView.setTextSize(textSize);
|
|
|
|
textView.setTextSize(textSize);
|
|
|
|
screenNameView.setTextSize(textSize * 0.85f);
|
|
|
|
timeView.setTextSize(textSize * 0.85f);
|
|
|
|
replyRetweetView.setTextSize(textSize * 0.75f);
|
|
|
|
replyCountView.setTextSize(textSize);
|
|
|
|
replyCountView.setTextSize(textSize);
|
|
|
|
favoriteCountView.setTextSize(textSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setupViewOptions() {
|
|
|
|
setTextSize(adapter.getTextSize());
|
2015-03-20 17:42:44 +01:00
|
|
|
mediaPreviewContainer.setStyle(adapter.getMediaPreviewStyle());
|
2015-01-30 15:27:22 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 19:22:00 +02:00
|
|
|
private void displayExtraTypeIcon(String cardName, ParcelableMedia[] media, ParcelableLocation location, String placeFullName) {
|
2015-01-30 15:27:22 +01:00
|
|
|
if (TwitterCardUtils.CARD_NAME_AUDIO.equals(cardName)) {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_music);
|
|
|
|
extraTypeView.setVisibility(View.VISIBLE);
|
|
|
|
} else if (TwitterCardUtils.CARD_NAME_ANIMATED_GIF.equals(cardName)) {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_movie);
|
|
|
|
extraTypeView.setVisibility(View.VISIBLE);
|
|
|
|
} else if (TwitterCardUtils.CARD_NAME_PLAYER.equals(cardName)) {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_play_circle);
|
|
|
|
extraTypeView.setVisibility(View.VISIBLE);
|
2015-03-14 16:11:20 +01:00
|
|
|
} else if (media != null && media.length > 0) {
|
2015-03-22 18:06:25 +01:00
|
|
|
if (hasVideo(media)) {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_movie);
|
|
|
|
} else {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_gallery);
|
|
|
|
}
|
2015-01-30 15:27:22 +01:00
|
|
|
extraTypeView.setVisibility(View.VISIBLE);
|
2015-03-14 16:11:20 +01:00
|
|
|
} else if (location != null && location.isValid()) {
|
|
|
|
extraTypeView.setImageResource(R.drawable.ic_action_location);
|
|
|
|
extraTypeView.setVisibility(View.VISIBLE);
|
2015-01-30 15:27:22 +01:00
|
|
|
} else {
|
|
|
|
extraTypeView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-22 18:06:25 +01:00
|
|
|
private boolean hasVideo(ParcelableMedia[] media) {
|
|
|
|
for (ParcelableMedia mediaItem : media) {
|
|
|
|
if (mediaItem.type == ParcelableMedia.TYPE_VIDEO) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-30 15:27:22 +01:00
|
|
|
public static interface StatusClickListener extends ContentCardClickListener {
|
|
|
|
|
2015-03-30 14:24:51 +02:00
|
|
|
boolean isProfileImageEnabled();
|
|
|
|
|
2015-01-30 15:27:22 +01:00
|
|
|
void onStatusClick(StatusViewHolder holder, int position);
|
|
|
|
|
2015-03-29 09:17:42 +02:00
|
|
|
void onMediaClick(StatusViewHolder holder, ParcelableMedia media, int position);
|
|
|
|
|
2015-01-30 15:27:22 +01:00
|
|
|
void onUserProfileClick(StatusViewHolder holder, int position);
|
|
|
|
}
|
2014-07-03 07:48:39 +02:00
|
|
|
}
|