feat: full implementation of not showing media preview in timelines

This commit is contained in:
LucasGGamerM
2023-09-05 11:56:56 -03:00
parent d7bef67550
commit e239600af6

View File

@@ -1,7 +1,9 @@
package org.joinmastodon.android.ui.displayitems;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.media.Image;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
@@ -14,10 +16,18 @@ import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.Card;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.SingleImagePhotoViewerListener;
import org.joinmastodon.android.ui.drawables.BlurhashCrossfadeDrawable;
import org.joinmastodon.android.ui.photoviewer.PhotoViewer;
import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost;
import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.ArrayList;
import java.util.List;
import me.grishka.appkit.Nav;
import me.grishka.appkit.imageloader.ImageLoaderViewHolder;
import me.grishka.appkit.utils.V;
public class FileStatusDisplayItem extends StatusDisplayItem{
private final Status status;
@@ -36,11 +46,20 @@ public class FileStatusDisplayItem extends StatusDisplayItem{
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);
}
@@ -50,12 +69,28 @@ public class FileStatusDisplayItem extends StatusDisplayItem{
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());
if(!item.attachment.type.isImage()) {
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.setSingleLine(false);
domain.setVisibility(View.GONE);
icon.setImageDrawable(context.getDrawable(R.drawable.ic_fluent_image_24_regular));
}
}
private void onClick(View v) {
UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl());
if(!item.attachment.type.isImage()) {
UiUtils.openURL(itemView.getContext(), item.parentFragment.getAccountID(), getUrl());
} else {
List<Attachment> attachmentArray = new ArrayList<>();
attachmentArray.add(item.attachment);
currentPhotoViewer=new PhotoViewer((Activity) context, attachmentArray, 0,
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() {