2017-08-03 23:26:26 +02:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
|
|
|
|
2018-04-22 16:34:02 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2017-08-03 23:26:26 +02:00
|
|
|
import android.content.Context;
|
2018-11-28 19:46:10 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-08-03 23:26:26 +02:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.Spanned;
|
2017-10-27 13:20:17 +02:00
|
|
|
import android.text.TextUtils;
|
2017-08-03 23:26:26 +02:00
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.text.style.URLSpan;
|
|
|
|
import android.view.View;
|
2017-10-27 13:20:17 +02:00
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.LinearLayout;
|
2017-08-03 23:26:26 +02:00
|
|
|
import android.widget.TextView;
|
2018-04-22 16:34:02 +02:00
|
|
|
import android.widget.Toast;
|
2017-08-03 23:26:26 +02:00
|
|
|
|
2019-04-16 21:39:12 +02:00
|
|
|
import com.bumptech.glide.Glide;
|
2019-06-22 08:05:55 +02:00
|
|
|
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
|
2017-08-03 23:26:26 +02:00
|
|
|
import com.keylesspalace.tusky.R;
|
2017-10-27 13:20:17 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Card;
|
2017-08-03 23:26:26 +02:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2017-11-30 20:12:09 +01:00
|
|
|
import com.keylesspalace.tusky.util.CustomURLSpan;
|
2017-10-27 13:20:17 +02:00
|
|
|
import com.keylesspalace.tusky.util.LinkHelper;
|
2017-08-03 23:26:26 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
|
2019-07-27 21:53:28 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2018-12-20 18:25:36 +01:00
|
|
|
import androidx.annotation.Nullable;
|
2018-12-27 09:48:24 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
2018-12-20 18:25:36 +01:00
|
|
|
|
2019-06-22 08:05:55 +02:00
|
|
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|
|
|
private TextView reblogs;
|
|
|
|
private TextView favourites;
|
2017-10-27 13:20:17 +02:00
|
|
|
private LinearLayout cardView;
|
|
|
|
private LinearLayout cardInfo;
|
|
|
|
private ImageView cardImage;
|
|
|
|
private TextView cardTitle;
|
|
|
|
private TextView cardDescription;
|
|
|
|
private TextView cardUrl;
|
2018-12-27 09:48:24 +01:00
|
|
|
private View infoDivider;
|
|
|
|
|
2019-04-25 19:29:15 +02:00
|
|
|
StatusDetailedViewHolder(View view, boolean useAbsoluteTime) {
|
|
|
|
super(view, useAbsoluteTime);
|
2017-10-18 00:20:26 +02:00
|
|
|
reblogs = view.findViewById(R.id.status_reblogs);
|
|
|
|
favourites = view.findViewById(R.id.status_favourites);
|
2017-10-27 13:20:17 +02:00
|
|
|
cardView = view.findViewById(R.id.card_view);
|
|
|
|
cardInfo = view.findViewById(R.id.card_info);
|
|
|
|
cardImage = view.findViewById(R.id.card_image);
|
|
|
|
cardTitle = view.findViewById(R.id.card_title);
|
|
|
|
cardDescription = view.findViewById(R.id.card_description);
|
|
|
|
cardUrl = view.findViewById(R.id.card_link);
|
2018-12-27 09:48:24 +01:00
|
|
|
infoDivider = view.findViewById(R.id.status_info_divider);
|
2019-07-10 06:53:21 +02:00
|
|
|
|
|
|
|
cardView.setClipToOutline(true);
|
2017-08-03 23:26:26 +02:00
|
|
|
}
|
|
|
|
|
2017-11-30 20:12:09 +01:00
|
|
|
@Override
|
|
|
|
protected int getMediaPreviewHeight(Context context) {
|
|
|
|
return context.getResources().getDimensionPixelSize(R.dimen.status_detail_media_preview_height);
|
|
|
|
}
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
@Override
|
2019-07-27 21:53:28 +02:00
|
|
|
protected void setCreatedAt(@NonNull Date createdAt) {
|
|
|
|
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
|
|
|
|
timestampInfo.setText(dateFormat.format(createdAt));
|
2017-08-03 23:26:26 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
private void setReblogAndFavCount(int reblogCount, int favCount, StatusActionListener listener) {
|
2018-12-27 09:48:24 +01:00
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
if (reblogCount > 0) {
|
|
|
|
reblogs.setText(getReblogsText(reblogs.getContext(), reblogCount));
|
2018-12-27 09:48:24 +01:00
|
|
|
reblogs.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
reblogs.setVisibility(View.GONE);
|
|
|
|
}
|
2019-03-04 19:24:27 +01:00
|
|
|
if (favCount > 0) {
|
|
|
|
favourites.setText(getFavsText(favourites.getContext(), favCount));
|
2018-12-27 09:48:24 +01:00
|
|
|
favourites.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
favourites.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
if (reblogs.getVisibility() == View.GONE && favourites.getVisibility() == View.GONE) {
|
2018-12-27 09:48:24 +01:00
|
|
|
infoDivider.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
infoDivider.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2019-03-04 19:24:27 +01:00
|
|
|
reblogs.setOnClickListener(v -> {
|
2018-12-27 09:48:24 +01:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onShowReblogs(position);
|
|
|
|
}
|
|
|
|
});
|
2019-03-04 19:24:27 +01:00
|
|
|
favourites.setOnClickListener(v -> {
|
2018-12-27 09:48:24 +01:00
|
|
|
int position = getAdapterPosition();
|
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onShowFavs(position);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
private void setApplication(@Nullable Status.Application app) {
|
2017-11-30 20:12:09 +01:00
|
|
|
if (app != null) {
|
|
|
|
|
|
|
|
timestampInfo.append(" • ");
|
|
|
|
|
2018-03-03 13:24:03 +01:00
|
|
|
if (app.getWebsite() != null) {
|
|
|
|
URLSpan span = new CustomURLSpan(app.getWebsite());
|
2017-11-30 20:12:09 +01:00
|
|
|
|
2018-03-03 13:24:03 +01:00
|
|
|
SpannableStringBuilder text = new SpannableStringBuilder(app.getName());
|
|
|
|
text.setSpan(span, 0, app.getName().length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
2017-11-30 20:12:09 +01:00
|
|
|
timestampInfo.append(text);
|
|
|
|
timestampInfo.setMovementMethod(LinkMovementMethod.getInstance());
|
2017-08-03 23:26:26 +02:00
|
|
|
} else {
|
2018-03-03 13:24:03 +01:00
|
|
|
timestampInfo.append(app.getName());
|
2017-08-03 23:26:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-12 19:22:37 +01:00
|
|
|
protected void setupWithStatus(final StatusViewData.Concrete status, final StatusActionListener listener,
|
2019-05-26 08:46:08 +02:00
|
|
|
boolean mediaPreviewEnabled, boolean showBotOverlay, boolean animateAvatar,
|
|
|
|
@Nullable Object payloads) {
|
|
|
|
super.setupWithStatus(status, listener, mediaPreviewEnabled, showBotOverlay, animateAvatar, payloads);
|
2019-04-25 19:29:15 +02:00
|
|
|
if (payloads == null) {
|
2019-03-16 14:38:29 +01:00
|
|
|
setReblogAndFavCount(status.getReblogsCount(), status.getFavouritesCount(), listener);
|
|
|
|
|
|
|
|
setApplication(status.getApplication());
|
|
|
|
|
|
|
|
View.OnLongClickListener longClickListener = view -> {
|
|
|
|
TextView textView = (TextView) view;
|
|
|
|
ClipboardManager clipboard = (ClipboardManager) view.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText("toot", textView.getText());
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
|
|
|
|
Toast.makeText(view.getContext(), R.string.copy_to_clipboard_success, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
content.setOnLongClickListener(longClickListener);
|
|
|
|
contentWarningDescription.setOnLongClickListener(longClickListener);
|
|
|
|
|
|
|
|
if (status.getAttachments().size() == 0 && status.getCard() != null && !TextUtils.isEmpty(status.getCard().getUrl())) {
|
|
|
|
final Card card = status.getCard();
|
|
|
|
cardView.setVisibility(View.VISIBLE);
|
|
|
|
cardTitle.setText(card.getTitle());
|
2019-06-22 08:05:55 +02:00
|
|
|
if(TextUtils.isEmpty(card.getDescription()) && TextUtils.isEmpty(card.getAuthorName())) {
|
|
|
|
cardDescription.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
cardDescription.setVisibility(View.VISIBLE);
|
|
|
|
if(TextUtils.isEmpty(card.getDescription())) {
|
|
|
|
cardDescription.setText(card.getAuthorName());
|
|
|
|
} else {
|
|
|
|
cardDescription.setText(card.getDescription());
|
|
|
|
}
|
|
|
|
}
|
2019-03-16 14:38:29 +01:00
|
|
|
|
|
|
|
cardUrl.setText(card.getUrl());
|
|
|
|
|
2019-06-22 08:05:55 +02:00
|
|
|
if (!TextUtils.isEmpty(card.getImage())) {
|
|
|
|
|
|
|
|
RoundedCornersTransformation.CornerType cornertype;
|
2019-03-16 14:38:29 +01:00
|
|
|
|
|
|
|
if (card.getWidth() > card.getHeight()) {
|
|
|
|
cardView.setOrientation(LinearLayout.VERTICAL);
|
2019-06-22 08:05:55 +02:00
|
|
|
|
2019-03-16 14:38:29 +01:00
|
|
|
cardImage.getLayoutParams().height = cardImage.getContext().getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.card_image_vertical_height);
|
|
|
|
cardImage.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.WRAP_CONTENT;
|
2019-06-22 08:05:55 +02:00
|
|
|
cornertype = RoundedCornersTransformation.CornerType.TOP;
|
2019-03-16 14:38:29 +01:00
|
|
|
} else {
|
|
|
|
cardView.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
cardImage.getLayoutParams().width = cardImage.getContext().getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.card_image_horizontal_width);
|
|
|
|
cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
|
cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
2019-06-22 08:05:55 +02:00
|
|
|
cornertype = RoundedCornersTransformation.CornerType.LEFT;
|
2019-03-16 14:38:29 +01:00
|
|
|
}
|
|
|
|
|
2019-06-22 08:05:55 +02:00
|
|
|
int radius = cardImage.getContext().getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.card_radius);
|
2019-03-16 14:38:29 +01:00
|
|
|
|
2019-04-16 21:39:12 +02:00
|
|
|
Glide.with(cardImage)
|
2019-03-16 14:38:29 +01:00
|
|
|
.load(card.getImage())
|
2019-06-22 08:05:55 +02:00
|
|
|
.transform(new CenterCrop(), new RoundedCornersTransformation(radius, 0, cornertype))
|
2019-03-16 14:38:29 +01:00
|
|
|
.into(cardImage);
|
2018-03-03 13:24:03 +01:00
|
|
|
|
2017-10-27 13:20:17 +02:00
|
|
|
} else {
|
2019-06-22 08:05:55 +02:00
|
|
|
cardView.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
cardImage.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
cardImage.getLayoutParams().width = cardImage.getContext().getResources()
|
|
|
|
.getDimensionPixelSize(R.dimen.card_image_horizontal_width);
|
|
|
|
cardInfo.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
|
|
|
cardInfo.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
|
|
|
cardImage.setImageResource(R.drawable.card_image_placeholder);
|
|
|
|
|
2017-10-27 13:20:17 +02:00
|
|
|
}
|
|
|
|
|
2019-03-16 14:38:29 +01:00
|
|
|
cardView.setOnClickListener(v -> LinkHelper.openLink(card.getUrl(), v.getContext()));
|
2017-10-27 13:20:17 +02:00
|
|
|
|
|
|
|
} else {
|
2019-03-16 14:38:29 +01:00
|
|
|
cardView.setVisibility(View.GONE);
|
2017-10-27 13:20:17 +02:00
|
|
|
}
|
|
|
|
|
2019-03-16 14:38:29 +01:00
|
|
|
setStatusVisibility(status.getVisibility());
|
2017-10-27 13:20:17 +02:00
|
|
|
}
|
2018-11-28 19:46:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setStatusVisibility(Status.Visibility visibility) {
|
|
|
|
|
2019-09-12 20:03:07 +02:00
|
|
|
if(visibility == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-28 19:46:10 +01:00
|
|
|
int visibilityIcon;
|
|
|
|
switch (visibility) {
|
|
|
|
case PUBLIC:
|
|
|
|
visibilityIcon = R.drawable.ic_public_24dp;
|
|
|
|
break;
|
|
|
|
case UNLISTED:
|
|
|
|
visibilityIcon = R.drawable.ic_lock_open_24dp;
|
|
|
|
break;
|
|
|
|
case PRIVATE:
|
2018-12-20 18:25:36 +01:00
|
|
|
visibilityIcon = R.drawable.ic_lock_outline_24dp;
|
2018-11-28 19:46:10 +01:00
|
|
|
break;
|
|
|
|
case DIRECT:
|
|
|
|
visibilityIcon = R.drawable.ic_email_24dp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Drawable visibilityDrawable = this.timestampInfo.getContext()
|
|
|
|
.getDrawable(visibilityIcon);
|
|
|
|
if (visibilityDrawable == null) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-27 13:20:17 +02:00
|
|
|
|
2018-11-28 19:46:10 +01:00
|
|
|
final int size = (int) this.timestampInfo.getTextSize();
|
|
|
|
visibilityDrawable.setBounds(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
size,
|
|
|
|
size
|
|
|
|
);
|
|
|
|
visibilityDrawable.setTint(this.timestampInfo.getCurrentTextColor());
|
2019-07-31 19:07:01 +02:00
|
|
|
this.timestampInfo.setCompoundDrawables(
|
2018-11-28 19:46:10 +01:00
|
|
|
visibilityDrawable,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null
|
|
|
|
);
|
2017-08-03 23:26:26 +02:00
|
|
|
}
|
|
|
|
}
|