2014-07-03 07:48:39 +02:00
|
|
|
package org.mariotaku.twidere.view.holder;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2014-11-21 04:00:46 +01:00
|
|
|
import android.content.Intent;
|
2014-12-03 11:27:11 +01:00
|
|
|
import android.database.Cursor;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import org.mariotaku.twidere.R;
|
2014-11-21 04:00:46 +01:00
|
|
|
import org.mariotaku.twidere.adapter.iface.IStatusesAdapter;
|
|
|
|
import org.mariotaku.twidere.constant.IntentConstants;
|
|
|
|
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-11-21 04:00:46 +01:00
|
|
|
import org.mariotaku.twidere.util.ImageLoaderWrapper;
|
2014-12-03 11:27:11 +01:00
|
|
|
import org.mariotaku.twidere.util.UserColorNicknameUtils;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.util.Utils;
|
2014-11-21 04:00:46 +01:00
|
|
|
import org.mariotaku.twidere.view.CircularImageView;
|
2014-07-03 07:48:39 +02:00
|
|
|
import org.mariotaku.twidere.view.ShortTimeView;
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-11-22 15:12:54 +01:00
|
|
|
import static org.mariotaku.twidere.util.Utils.getUserTypeIconRes;
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
/**
|
|
|
|
* Created by mariotaku on 14/11/19.
|
|
|
|
*/
|
2014-12-03 11:27:11 +01:00
|
|
|
public class StatusViewHolder<Data> extends RecyclerView.ViewHolder implements OnClickListener {
|
2014-11-21 04:00:46 +01:00
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
private final IStatusesAdapter<Data> adapter;
|
2014-11-21 04:00:46 +01:00
|
|
|
|
|
|
|
private final ImageView retweetProfileImageView;
|
|
|
|
private final CircularImageView profileImageView;
|
|
|
|
private final ImageView profileTypeView;
|
|
|
|
private final ImageView mediaPreviewView;
|
|
|
|
private final TextView textView;
|
|
|
|
private final TextView nameView, screenNameView;
|
|
|
|
private final TextView replyRetweetView;
|
|
|
|
private final ShortTimeView timeView;
|
|
|
|
private final View mediaPreviewContainer;
|
|
|
|
private final TextView replyCountView, retweetCountView, favoriteCountView;
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
public StatusViewHolder(IStatusesAdapter<Data> adapter, View itemView) {
|
2014-11-21 04:00:46 +01:00
|
|
|
super(itemView);
|
|
|
|
this.adapter = adapter;
|
|
|
|
itemView.findViewById(R.id.item_content).setOnClickListener(this);
|
|
|
|
itemView.findViewById(R.id.menu).setOnClickListener(this);
|
|
|
|
profileImageView = (CircularImageView) itemView.findViewById(R.id.profile_image);
|
|
|
|
profileTypeView = (ImageView) itemView.findViewById(R.id.profile_type);
|
|
|
|
textView = (TextView) itemView.findViewById(R.id.text);
|
|
|
|
nameView = (TextView) itemView.findViewById(R.id.name);
|
|
|
|
screenNameView = (TextView) itemView.findViewById(R.id.screen_name);
|
|
|
|
retweetProfileImageView = (ImageView) itemView.findViewById(R.id.retweet_profile_image);
|
|
|
|
replyRetweetView = (TextView) itemView.findViewById(R.id.reply_retweet_status);
|
|
|
|
timeView = (ShortTimeView) itemView.findViewById(R.id.time);
|
|
|
|
|
|
|
|
mediaPreviewContainer = itemView.findViewById(R.id.media_preview_container);
|
|
|
|
mediaPreviewView = (ImageView) itemView.findViewById(R.id.media_preview);
|
|
|
|
|
|
|
|
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-11-21 04:00:46 +01:00
|
|
|
|
|
|
|
itemView.setOnClickListener(this);
|
|
|
|
profileImageView.setOnClickListener(this);
|
|
|
|
mediaPreviewContainer.setOnClickListener(this);
|
|
|
|
retweetCountView.setOnClickListener(this);
|
|
|
|
retweetCountView.setOnClickListener(this);
|
|
|
|
favoriteCountView.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void displayStatus(ParcelableStatus status) {
|
|
|
|
final ImageLoaderWrapper loader = adapter.getImageLoader();
|
|
|
|
final Context context = adapter.getContext();
|
|
|
|
final ParcelableMedia[] media = status.media;
|
|
|
|
|
|
|
|
if (status.retweet_id > 0) {
|
2014-11-22 15:12:54 +01:00
|
|
|
if (status.retweet_count == 2) {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_and_another_retweeted,
|
|
|
|
status.retweeted_by_name));
|
|
|
|
} else if (status.retweet_count > 2) {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_and_count_retweeted,
|
|
|
|
status.retweeted_by_name, status.retweet_count - 1));
|
|
|
|
} else {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_retweeted, status.retweeted_by_name));
|
|
|
|
}
|
2014-11-21 04:00:46 +01:00
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
2014-11-22 15:12:54 +01:00
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
} else if (status.in_reply_to_status_id > 0 && status.in_reply_to_user_id > 0) {
|
2014-11-21 04:00:46 +01:00
|
|
|
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, status.in_reply_to_name));
|
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
replyRetweetView.setText(null);
|
|
|
|
replyRetweetView.setVisibility(View.GONE);
|
|
|
|
replyRetweetView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
final int userColor = UserColorNicknameUtils.getUserColor(context, status.user_id);
|
|
|
|
profileImageView.setBorderColor(userColor);
|
2014-11-21 04:00:46 +01:00
|
|
|
|
|
|
|
loader.displayProfileImage(profileImageView, status.user_profile_image_url);
|
|
|
|
|
|
|
|
if (media != null && media.length > 0) {
|
|
|
|
final ParcelableMedia firstMedia = media[0];
|
|
|
|
if (status.text_plain.codePointCount(0, status.text_plain.length()) == firstMedia.end) {
|
|
|
|
textView.setText(status.text_unescaped.substring(0, firstMedia.start));
|
|
|
|
} else {
|
|
|
|
textView.setText(status.text_unescaped);
|
|
|
|
}
|
|
|
|
loader.displayPreviewImageWithCredentials(mediaPreviewView, firstMedia.media_url,
|
|
|
|
status.account_id, adapter.getImageLoadingHandler());
|
|
|
|
mediaPreviewContainer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
loader.cancelDisplayTask(mediaPreviewView);
|
|
|
|
textView.setText(status.text_unescaped);
|
|
|
|
mediaPreviewContainer.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.reply_count > 0) {
|
|
|
|
replyCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), status.reply_count));
|
|
|
|
} else {
|
|
|
|
replyCountView.setText(null);
|
|
|
|
}
|
|
|
|
if (status.retweet_count > 0) {
|
|
|
|
retweetCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), status.retweet_count));
|
|
|
|
} else {
|
|
|
|
retweetCountView.setText(null);
|
|
|
|
}
|
|
|
|
if (status.favorite_count > 0) {
|
|
|
|
favoriteCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), status.favorite_count));
|
|
|
|
} else {
|
|
|
|
favoriteCountView.setText(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
retweetCountView.setEnabled(!status.user_is_protected);
|
|
|
|
|
2014-11-25 16:15:05 +01:00
|
|
|
retweetCountView.setActivated(Utils.isMyRetweet(status));
|
2014-11-21 04:00:46 +01:00
|
|
|
favoriteCountView.setActivated(status.is_favorite);
|
|
|
|
}
|
|
|
|
|
2014-12-03 11:27:11 +01:00
|
|
|
|
|
|
|
public void displayStatus(Cursor cursor, CursorIndices indices) {
|
|
|
|
final ImageLoaderWrapper loader = adapter.getImageLoader();
|
|
|
|
final Context context = adapter.getContext();
|
|
|
|
|
|
|
|
final int reply_count = cursor.getInt(indices.reply_count);
|
|
|
|
final int retweet_count = cursor.getInt(indices.retweet_count);
|
|
|
|
final int favorite_count = cursor.getInt(indices.favorite_count);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
final String in_reply_to_name = cursor.getString(indices.in_reply_to_user_name);
|
|
|
|
|
|
|
|
final ParcelableMedia[] media = ParcelableMedia.fromJSONString(cursor.getString(indices.media));
|
|
|
|
|
|
|
|
if (retweet_id > 0) {
|
|
|
|
if (retweet_count == 2) {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_and_another_retweeted,
|
|
|
|
retweeted_by_name));
|
|
|
|
} else if (retweet_count > 2) {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_and_count_retweeted,
|
|
|
|
retweeted_by_name, retweet_count - 1));
|
|
|
|
} else {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.name_retweeted, retweeted_by_name));
|
|
|
|
}
|
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
} else if (in_reply_to_status_id > 0 && in_reply_to_user_id > 0) {
|
|
|
|
replyRetweetView.setText(context.getString(R.string.in_reply_to_name, in_reply_to_name));
|
|
|
|
replyRetweetView.setVisibility(View.VISIBLE);
|
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
replyRetweetView.setText(null);
|
|
|
|
replyRetweetView.setVisibility(View.GONE);
|
|
|
|
replyRetweetView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
|
|
|
retweetProfileImageView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
final int userColor = UserColorNicknameUtils.getUserColor(context, user_id);
|
|
|
|
profileImageView.setBorderColor(userColor);
|
|
|
|
|
|
|
|
loader.displayProfileImage(profileImageView, user_profile_image_url);
|
|
|
|
|
|
|
|
if (media != null && media.length > 0) {
|
|
|
|
final String text_plain = cursor.getString(indices.text_plain);
|
|
|
|
final String text_unescaped = cursor.getString(indices.text_unescaped);
|
|
|
|
final ParcelableMedia firstMedia = media[0];
|
|
|
|
if (text_plain.codePointCount(0, text_plain.length()) == firstMedia.end) {
|
|
|
|
textView.setText(text_unescaped.substring(0, firstMedia.start));
|
|
|
|
} else {
|
|
|
|
textView.setText(text_unescaped);
|
|
|
|
}
|
|
|
|
loader.displayPreviewImageWithCredentials(mediaPreviewView, firstMedia.media_url,
|
|
|
|
account_id, adapter.getImageLoadingHandler());
|
|
|
|
mediaPreviewContainer.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
final String text_unescaped = cursor.getString(indices.text_unescaped);
|
|
|
|
loader.cancelDisplayTask(mediaPreviewView);
|
|
|
|
textView.setText(text_unescaped);
|
|
|
|
mediaPreviewContainer.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply_count > 0) {
|
|
|
|
replyCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), reply_count));
|
|
|
|
} else {
|
|
|
|
replyCountView.setText(null);
|
|
|
|
}
|
|
|
|
if (retweet_count > 0) {
|
|
|
|
retweetCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), retweet_count));
|
|
|
|
} else {
|
|
|
|
retweetCountView.setText(null);
|
|
|
|
}
|
|
|
|
if (favorite_count > 0) {
|
|
|
|
favoriteCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), favorite_count));
|
|
|
|
} else {
|
|
|
|
favoriteCountView.setText(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
retweetCountView.setEnabled(!user_is_protected);
|
|
|
|
retweetCountView.setActivated(Utils.isMyRetweet(account_id, retweeted_by_id, my_retweet_id));
|
|
|
|
favoriteCountView.setActivated(cursor.getInt(indices.is_favorite) == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CardView getCardView() {
|
|
|
|
return (CardView) itemView.findViewById(R.id.card);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CircularImageView getProfileImageView() {
|
|
|
|
return profileImageView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-21 04:00:46 +01:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
final Context context = itemView.getContext();
|
2014-12-03 11:27:11 +01:00
|
|
|
final int position = getPosition();
|
|
|
|
final ParcelableStatus status = adapter.getStatus(position);
|
2014-11-21 04:00:46 +01:00
|
|
|
switch (v.getId()) {
|
|
|
|
case R.id.item_content: {
|
2014-12-03 11:27:11 +01:00
|
|
|
adapter.onStatusClick(this, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.menu: {
|
2014-12-03 11:27:11 +01:00
|
|
|
adapter.onItemMenuClick(this, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.profile_image: {
|
2014-12-03 11:27:11 +01:00
|
|
|
adapter.onUserProfileClick(this, position);
|
2014-11-21 04:00:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case R.id.reply_count: {
|
|
|
|
final Intent intent = new Intent(IntentConstants.INTENT_ACTION_REPLY);
|
|
|
|
intent.setPackage(context.getPackageName());
|
|
|
|
intent.putExtra(IntentConstants.EXTRA_STATUS, status);
|
|
|
|
context.startActivity(intent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-03 07:48:39 +02:00
|
|
|
}
|