refactor(PreviewlessMediaItems): make FileStatusDisplayItem be used only for files
This commit is contained in:
parent
91c7fc64bd
commit
f69ae5e816
|
@ -46,18 +46,14 @@ public class FileStatusDisplayItem extends StatusDisplayItem{
|
||||||
|
|
||||||
public static class Holder extends StatusDisplayItem.Holder<FileStatusDisplayItem>{
|
public static class Holder extends StatusDisplayItem.Holder<FileStatusDisplayItem>{
|
||||||
private final TextView title, domain;
|
private final TextView title, domain;
|
||||||
private final View inner;
|
|
||||||
private final ImageView icon;
|
private final ImageView icon;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
private PhotoViewer currentPhotoViewer;
|
|
||||||
|
|
||||||
public Holder(Context context, ViewGroup parent){
|
public Holder(Context context, ViewGroup parent){
|
||||||
super(context, R.layout.display_item_file, parent);
|
super(context, R.layout.display_item_file, parent);
|
||||||
title=findViewById(R.id.title);
|
title=findViewById(R.id.title);
|
||||||
domain=findViewById(R.id.domain);
|
domain=findViewById(R.id.domain);
|
||||||
icon=findViewById(R.id.imageView);
|
icon=findViewById(R.id.imageView);
|
||||||
inner=findViewById(R.id.inner);
|
|
||||||
this.context=context;
|
this.context=context;
|
||||||
|
|
||||||
findViewById(R.id.inner).setOnClickListener(this::onClick);
|
findViewById(R.id.inner).setOnClickListener(this::onClick);
|
||||||
|
@ -67,42 +63,18 @@ public class FileStatusDisplayItem extends StatusDisplayItem{
|
||||||
public void onBind(FileStatusDisplayItem item) {
|
public void onBind(FileStatusDisplayItem item) {
|
||||||
Uri url = Uri.parse(getUrl());
|
Uri url = Uri.parse(getUrl());
|
||||||
|
|
||||||
if(!item.attachment.type.isImage()) {
|
title.setText(item.attachment.description != null
|
||||||
title.setText(item.attachment.description != null
|
? item.attachment.description
|
||||||
? item.attachment.description
|
: url.getLastPathSegment());
|
||||||
: url.getLastPathSegment());
|
|
||||||
|
|
||||||
title.setEllipsize(item.attachment.description != null ? TextUtils.TruncateAt.END : TextUtils.TruncateAt.MIDDLE);
|
title.setEllipsize(item.attachment.description != null ? TextUtils.TruncateAt.END : TextUtils.TruncateAt.MIDDLE);
|
||||||
domain.setText(url.getHost());
|
domain.setText(url.getHost());
|
||||||
|
|
||||||
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_attach_24_regular));
|
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);
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClick(View v) {
|
private void onClick(View v) {
|
||||||
if(!item.attachment.type.isImage()) {
|
UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl());
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUrl() {
|
private String getUrl() {
|
||||||
|
|
Loading…
Reference in New Issue