From cb3b893f722f2ba997f4c67f96dd3adf19334f53 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Tue, 23 May 2023 20:02:43 +0200 Subject: [PATCH] refactor: move fake attachment to attachment class --- .../fragments/InstanceInfoFragment.java | 20 ++----------------- .../android/fragments/ProfileFragment.java | 14 ++----------- .../android/model/Attachment.java | 12 +++++++++++ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/InstanceInfoFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/InstanceInfoFragment.java index f32584f7d..8c00b2195 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/InstanceInfoFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/InstanceInfoFragment.java @@ -365,23 +365,11 @@ public class InstanceInfoFragment extends LoaderFragment { Drawable drawable=cover.getDrawable(); if(drawable==null || drawable instanceof ColorDrawable) return; - new PhotoViewer(getActivity(), createFakeAttachments(instance.thumbnail, drawable), 0, + new PhotoViewer(getActivity(), Attachment.createFakeAttachments(instance.thumbnail, drawable), 0, new SingleImagePhotoViewerListener(cover, cover, null, this, () -> { }, () -> drawable, null, null)); } - private List createFakeAttachments(String url, Drawable drawable){ - Attachment att=new Attachment(); - att.type=Attachment.Type.IMAGE; - att.url=url; - att.meta=new Attachment.Metadata(); - att.meta.width=drawable.getIntrinsicWidth(); - att.meta.height=drawable.getIntrinsicHeight(); - return Collections.singletonList(att); - } - - - public void setFields(ArrayList fields){ metadataListData=fields; if (adapter != null) adapter.notifyDataSetChanged(); @@ -400,11 +388,7 @@ public class InstanceInfoFragment extends LoaderFragment { @Override public void onBindViewHolder(BaseViewHolder holder, int position){ - if(position createFakeAttachments(String url, Drawable drawable){ - Attachment att=new Attachment(); - att.type=Attachment.Type.IMAGE; - att.url=url; - att.meta=new Attachment.Metadata(); - att.meta.width=drawable.getIntrinsicWidth(); - att.meta.height=drawable.getIntrinsicHeight(); - return Collections.singletonList(att); - } - private void onNotifyButtonClick(View v) { UiUtils.performToggleAccountNotifications(getActivity(), account, accountID, relationship, actionButton, this::setNotifyProgressVisible, this::updateRelationship); } @@ -1165,7 +1155,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList if(ava==null) return; int radius=V.dp(25); - currentPhotoViewer=new PhotoViewer(getActivity(), createFakeAttachments(account.avatar, ava), 0, + currentPhotoViewer=new PhotoViewer(getActivity(), Attachment.createFakeAttachments(account.avatar, ava), 0, new SingleImagePhotoViewerListener(avatar, avatarBorder, new int[]{radius, radius, radius, radius}, this, ()->currentPhotoViewer=null, ()->ava, null, null)); } } @@ -1177,7 +1167,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList Drawable drawable=cover.getDrawable(); if(drawable==null || drawable instanceof ColorDrawable) return; - currentPhotoViewer=new PhotoViewer(getActivity(), createFakeAttachments(account.header, drawable), 0, + currentPhotoViewer=new PhotoViewer(getActivity(), Attachment.createFakeAttachments(account.header, drawable), 0, new SingleImagePhotoViewerListener(cover, cover, null, this, ()->currentPhotoViewer=null, ()->drawable, ()->avatarBorder.setTranslationZ(2), ()->avatarBorder.setTranslationZ(0))); } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java b/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java index 999e70733..45eea0fd6 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java @@ -14,6 +14,8 @@ import org.parceler.Parcel; import org.parceler.ParcelConstructor; import org.parceler.ParcelProperty; +import java.util.Collections; +import java.util.List; import java.util.UUID; @Parcel @@ -44,6 +46,16 @@ public class Attachment extends BaseModel{ blurhashPlaceholder=new BlurHashDrawable(placeholder, getWidth(), getHeight()); } } + public static List createFakeAttachments(String url, Drawable drawable){ + Attachment att=new Attachment(); + att.type=Attachment.Type.IMAGE; + att.url=url; + att.meta=new Attachment.Metadata(); + att.meta.width=drawable.getIntrinsicWidth(); + att.meta.height=drawable.getIntrinsicHeight(); + return Collections.singletonList(att); + } + public int getWidth(){ if(meta==null)