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.method.LinkMovementMethod;
|
|
|
|
import android.view.View;
|
|
|
|
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-12-30 21:37:20 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2017-08-03 23:26:26 +02:00
|
|
|
import com.keylesspalace.tusky.R;
|
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
|
|
|
import com.keylesspalace.tusky.interfaces.StatusActionListener;
|
2020-03-02 19:34:31 +01:00
|
|
|
import com.keylesspalace.tusky.util.CardViewMode;
|
2017-10-27 13:20:17 +02:00
|
|
|
import com.keylesspalace.tusky.util.LinkHelper;
|
2019-12-30 21:37:20 +01:00
|
|
|
import com.keylesspalace.tusky.util.StatusDisplayOptions;
|
2017-08-03 23:26:26 +02:00
|
|
|
import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|
|
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|
|
|
private TextView reblogs;
|
|
|
|
private TextView favourites;
|
2018-12-27 09:48:24 +01:00
|
|
|
private View infoDivider;
|
|
|
|
|
2019-12-30 21:37:20 +01:00
|
|
|
StatusDetailedViewHolder(View view) {
|
|
|
|
super(view);
|
2017-10-18 00:20:26 +02:00
|
|
|
reblogs = view.findViewById(R.id.status_reblogs);
|
|
|
|
favourites = view.findViewById(R.id.status_favourites);
|
2018-12-27 09:48:24 +01:00
|
|
|
infoDivider = view.findViewById(R.id.status_info_divider);
|
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
|
2020-01-03 20:22:02 +01:00
|
|
|
protected void setCreatedAt(Date createdAt, StatusDisplayOptions statusDisplayOptions) {
|
|
|
|
if (createdAt == null) {
|
2019-09-15 09:10:07 +02:00
|
|
|
timestampInfo.setText("");
|
|
|
|
} else {
|
|
|
|
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) {
|
2019-12-21 18:56:16 +01:00
|
|
|
CharSequence text = LinkHelper.createClickableText(app.getName(), app.getWebsite());
|
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-12-30 21:37:20 +01:00
|
|
|
protected void setupWithStatus(final StatusViewData.Concrete status,
|
|
|
|
final StatusActionListener listener,
|
|
|
|
StatusDisplayOptions statusDisplayOptions,
|
2019-05-26 08:46:08 +02:00
|
|
|
@Nullable Object payloads) {
|
2019-12-30 21:37:20 +01:00
|
|
|
super.setupWithStatus(status, listener, statusDisplayOptions, payloads);
|
2020-03-02 19:34:31 +01:00
|
|
|
setupCard(status, CardViewMode.FULL_WIDTH); // Always show card for detailed status
|
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);
|
|
|
|
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) {
|
|
|
|
|
2020-01-03 20:22:02 +01:00
|
|
|
if (visibility == null) {
|
2019-09-12 20:03:07 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|