Skip to content

Commit

Permalink
refactor(PreviewlessMediaItems): make FileStatusDisplayItem be used o…
Browse files Browse the repository at this point in the history
…nly for files
  • Loading branch information
LucasGGamerM committed Sep 17, 2023
1 parent 91c7fc6 commit f69ae5e
Showing 1 changed file with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,14 @@ public Type getType(){

public static class Holder extends StatusDisplayItem.Holder<FileStatusDisplayItem>{
private final TextView title, domain;
private final View inner;
private final ImageView icon;
private final Context context;

private PhotoViewer currentPhotoViewer;

public Holder(Context context, ViewGroup parent){
super(context, R.layout.display_item_file, parent);
title=findViewById(R.id.title);
domain=findViewById(R.id.domain);
icon=findViewById(R.id.imageView);
inner=findViewById(R.id.inner);
this.context=context;

findViewById(R.id.inner).setOnClickListener(this::onClick);
Expand All @@ -67,42 +63,18 @@ public Holder(Context context, ViewGroup parent){
public void onBind(FileStatusDisplayItem item) {
Uri url = Uri.parse(getUrl());

if(!item.attachment.type.isImage()) {
title.setText(item.attachment.description != null
? item.attachment.description
: url.getLastPathSegment());

title.setEllipsize(item.attachment.description != null ? TextUtils.TruncateAt.END : TextUtils.TruncateAt.MIDDLE);
domain.setText(url.getHost());

icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_attach_24_regular));
} else {
title.setText(item.attachment.description != null
? item.attachment.description
: context.getString(R.string.sk_no_alt_text));
title.setSingleLine(false);

domain.setText(item.status.sensitive ? context.getString(R.string.sensitive_content_explain) : null);
domain.setVisibility(item.status.sensitive ? View.VISIBLE : View.GONE);
title.setText(item.attachment.description != null
? item.attachment.description
: url.getLastPathSegment());

if(item.attachment.type == Attachment.Type.IMAGE)
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_image_24_regular));
if(item.attachment.type == Attachment.Type.VIDEO)
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_video_clip_24_regular));
if(item.attachment.type == Attachment.Type.GIFV)
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_gif_24_regular));
title.setEllipsize(item.attachment.description != null ? TextUtils.TruncateAt.END : TextUtils.TruncateAt.MIDDLE);
domain.setText(url.getHost());

}
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_attach_24_regular));
}

private void onClick(View v) {
if(!item.attachment.type.isImage()) {
UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl());
} else {
// TODO make the cool animation work decently with multiple FileStatusDisplayItems
currentPhotoViewer=new PhotoViewer((Activity) context, item.status.mediaAttachments, item.status.mediaAttachments.indexOf(item.attachment),
new SingleImagePhotoViewerListener(title, inner, new int[]{V.dp(28), V.dp(28), V.dp(28), V.dp(28)}, item.parentFragment, ()->currentPhotoViewer=null, ()->context.getDrawable(R.drawable.bg_search_field), null, null));
}
UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl());
}

private String getUrl() {
Expand Down

0 comments on commit f69ae5e

Please sign in to comment.