2017-08-03 23:26:26 +02:00
|
|
|
package com.keylesspalace.tusky.adapter;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.text.method.LinkMovementMethod;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2022-04-21 18:46:55 +02:00
|
|
|
import androidx.annotation.NonNull;
|
2019-09-03 16:08:13 +02: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;
|
2018-12-20 18:25:36 +01:00
|
|
|
|
2022-08-15 11:00:18 +02:00
|
|
|
public class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|
|
|
private final TextView reblogs;
|
|
|
|
private final TextView favourites;
|
|
|
|
private final View infoDivider;
|
2018-12-27 09:48:24 +01:00
|
|
|
|
2022-08-15 11:00:18 +02:00
|
|
|
public StatusDetailedViewHolder(View view) {
|
2019-12-30 21:37:20 +01:00
|
|
|
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 -> {
|
2021-04-10 20:30:44 +02:00
|
|
|
int position = getBindingAdapterPosition();
|
2018-12-27 09:48:24 +01:00
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
|
|
|
listener.onShowReblogs(position);
|
|
|
|
}
|
|
|
|
});
|
2019-03-04 19:24:27 +01:00
|
|
|
favourites.setOnClickListener(v -> {
|
2021-04-10 20:30:44 +02:00
|
|
|
int position = getBindingAdapterPosition();
|
2018-12-27 09:48:24 +01:00
|
|
|
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
|
2022-04-21 18:46:55 +02:00
|
|
|
public void setupWithStatus(@NonNull final StatusViewData.Concrete status,
|
|
|
|
@NonNull final StatusActionListener listener,
|
|
|
|
@NonNull StatusDisplayOptions statusDisplayOptions,
|
|
|
|
@Nullable Object payloads) {
|
2022-06-24 21:47:49 +02:00
|
|
|
// We never collapse statuses in the detail view
|
|
|
|
StatusViewData.Concrete uncollapsedStatus = (status.isCollapsible() && status.isCollapsed()) ?
|
|
|
|
status.copyWithCollapsed(false) :
|
|
|
|
status;
|
|
|
|
|
|
|
|
super.setupWithStatus(uncollapsedStatus, listener, statusDisplayOptions, payloads);
|
|
|
|
setupCard(uncollapsedStatus, CardViewMode.FULL_WIDTH, statusDisplayOptions, listener); // Always show card for detailed status
|
2019-04-25 19:29:15 +02:00
|
|
|
if (payloads == null) {
|
2022-06-24 21:47:49 +02:00
|
|
|
Status actionable = uncollapsedStatus.getActionable();
|
2020-12-23 19:13:37 +01:00
|
|
|
|
|
|
|
if (!statusDisplayOptions.hideStats()) {
|
2022-06-24 21:47:49 +02:00
|
|
|
setReblogAndFavCount(actionable.getReblogsCount(),
|
|
|
|
actionable.getFavouritesCount(), listener);
|
2020-12-23 19:13:37 +01:00
|
|
|
} else {
|
|
|
|
hideQuantitativeStats();
|
|
|
|
}
|
2019-03-16 14:38:29 +01:00
|
|
|
|
2022-06-24 21:47:49 +02:00
|
|
|
setApplication(actionable.getApplication());
|
2017-10-27 13:20:17 +02:00
|
|
|
}
|
2018-11-28 19:46:10 +01:00
|
|
|
}
|
|
|
|
|
2020-12-23 19:13:37 +01:00
|
|
|
private void hideQuantitativeStats() {
|
|
|
|
reblogs.setVisibility(View.GONE);
|
|
|
|
favourites.setVisibility(View.GONE);
|
|
|
|
infoDivider.setVisibility(View.GONE);
|
|
|
|
}
|
2017-08-03 23:26:26 +02:00
|
|
|
}
|