refactor: move fake attachment to attachment class

This commit is contained in:
FineFindus 2023-05-23 20:02:43 +02:00
parent f482b4bfe9
commit cb3b893f72
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
3 changed files with 16 additions and 30 deletions

View File

@ -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<Attachment> 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<AccountField> 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<metadataListData.size()){
holder.bind(metadataListData.get(position));
}else{
holder.bind(null);
}
super.onBindViewHolder(holder, position);
}

View File

@ -1143,16 +1143,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
return false;
}
private List<Attachment> 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)));
}
}

View File

@ -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<Attachment> 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)