mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-09-15 08:20:18 +03:00
Fix a crash with fit preview images when aspect ratio is important
This commit is contained in:
parent
cd995da607
commit
8ff3566498
1 changed files with 80 additions and 69 deletions
|
@ -1631,11 +1631,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
holder.binding.card.setVisibility(View.GONE);
|
holder.binding.card.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (measuredWidth <= 0 && statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
|
if (measuredWidth <= 0 && statusToDeal.media_attachments != null && statusToDeal.media_attachments.size() > 0) {
|
||||||
|
boolean finalFullAttachement = fullAttachement;
|
||||||
holder.binding.mediaContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
holder.binding.mediaContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
holder.binding.mediaContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
holder.binding.mediaContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
if (fullAttachement) {
|
if (finalFullAttachement) {
|
||||||
measuredWidth = holder.binding.mediaContainer.getWidth();
|
measuredWidth = holder.binding.mediaContainer.getWidth();
|
||||||
} else {
|
} else {
|
||||||
measuredWidth = holder.binding.media.mediaContainer.getWidth();
|
measuredWidth = holder.binding.media.mediaContainer.getWidth();
|
||||||
|
@ -1696,6 +1697,43 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
holder.binding.media.mediaContainer.setVisibility(View.VISIBLE);
|
holder.binding.media.mediaContainer.setVisibility(View.VISIBLE);
|
||||||
int mediaPosition = 1;
|
int mediaPosition = 1;
|
||||||
boolean autoplaygif = sharedpreferences.getBoolean(context.getString(R.string.SET_AUTO_PLAY_GIG_MEDIA), false);
|
boolean autoplaygif = sharedpreferences.getBoolean(context.getString(R.string.SET_AUTO_PLAY_GIG_MEDIA), false);
|
||||||
|
|
||||||
|
for (Attachment attachment : statusToDeal.media_attachments) {
|
||||||
|
float ratio = 1.0f;
|
||||||
|
float mediaH = -1.0f;
|
||||||
|
float mediaW = -1.0f;
|
||||||
|
if (attachment.meta != null && attachment.meta.getSmall() != null) {
|
||||||
|
mediaH = attachment.meta.getSmall().height;
|
||||||
|
mediaW = attachment.meta.getSmall().width;
|
||||||
|
if (mediaW != 0) {
|
||||||
|
ratio = measuredWidth > 0 ? measuredWidth / mediaW : 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(ratio >= 5) {
|
||||||
|
fullAttachement = false;
|
||||||
|
}
|
||||||
|
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
|
||||||
|
if ((fullAttachement && (!statusToDeal.sensitive || expand_media))) {
|
||||||
|
holder.binding.mediaContainer.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else {
|
||||||
|
if (mediaPosition == 1) {
|
||||||
|
holder.binding.media.media1Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else if (mediaPosition == 2 && statusToDeal.media_attachments.size() == 3) {
|
||||||
|
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.getSmall() != null && statusToDeal.media_attachments.get(0).meta.getSmall().width < statusToDeal.media_attachments.get(0).meta.getSmall().height) {
|
||||||
|
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else {
|
||||||
|
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
}
|
||||||
|
} else if (mediaPosition == 2) {
|
||||||
|
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else if (mediaPosition == 3 && statusToDeal.media_attachments.size() == 3) {
|
||||||
|
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else if (mediaPosition == 3) {
|
||||||
|
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
} else if (mediaPosition == 4) {
|
||||||
|
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!fullAttachement || statusToDeal.sensitive) {
|
if (!fullAttachement || statusToDeal.sensitive) {
|
||||||
int defaultHeight = (int) Helper.convertDpToPixel(300, context);
|
int defaultHeight = (int) Helper.convertDpToPixel(300, context);
|
||||||
int orientation = context.getResources().getConfiguration().orientation;
|
int orientation = context.getResources().getConfiguration().orientation;
|
||||||
|
@ -1752,42 +1790,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
holder.binding.media.moreMedia.setText(context.getString(R.string.more_media, "+" + (statusToDeal.media_attachments.size() - 4)));
|
holder.binding.media.moreMedia.setText(context.getString(R.string.more_media, "+" + (statusToDeal.media_attachments.size() - 4)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Attachment attachment : statusToDeal.media_attachments) {
|
|
||||||
LayoutMediaBinding layoutMediaBinding = LayoutMediaBinding.inflate(LayoutInflater.from(context));
|
|
||||||
if ((fullAttachement && (!statusToDeal.sensitive || expand_media))) {
|
|
||||||
holder.binding.mediaContainer.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else {
|
|
||||||
if (mediaPosition == 1) {
|
|
||||||
holder.binding.media.media1Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else if (mediaPosition == 2 && statusToDeal.media_attachments.size() == 3) {
|
|
||||||
if (statusToDeal.media_attachments.get(0).meta != null && statusToDeal.media_attachments.get(0).meta.getSmall() != null && statusToDeal.media_attachments.get(0).meta.getSmall().width < statusToDeal.media_attachments.get(0).meta.getSmall().height) {
|
|
||||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else {
|
|
||||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
}
|
|
||||||
} else if (mediaPosition == 2) {
|
|
||||||
holder.binding.media.media2Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else if (mediaPosition == 3 && statusToDeal.media_attachments.size() == 3) {
|
|
||||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else if (mediaPosition == 3) {
|
|
||||||
holder.binding.media.media3Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
} else if (mediaPosition == 4) {
|
|
||||||
holder.binding.media.media4Container.addView(layoutMediaBinding.getRoot());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fullAttachement && (!statusToDeal.sensitive || expand_media)) {
|
if (fullAttachement && (!statusToDeal.sensitive || expand_media)) {
|
||||||
|
|
||||||
float ratio = 1.0f;
|
|
||||||
float mediaH = -1.0f;
|
|
||||||
float mediaW = -1.0f;
|
|
||||||
if (attachment.meta != null && attachment.meta.getSmall() != null) {
|
|
||||||
mediaH = attachment.meta.getSmall().height;
|
|
||||||
mediaW = attachment.meta.getSmall().width;
|
|
||||||
if (mediaW != 0) {
|
|
||||||
ratio = measuredWidth > 0 ? measuredWidth / mediaW : 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (autoplaygif && attachment.type.equalsIgnoreCase("gifv") && mediaPosition == 1) {
|
if (autoplaygif && attachment.type.equalsIgnoreCase("gifv") && mediaPosition == 1) {
|
||||||
|
|
||||||
layoutMediaBinding.media.setVisibility(View.GONE);
|
layoutMediaBinding.media.setVisibility(View.GONE);
|
||||||
|
@ -2883,6 +2888,10 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
if (isArt) {
|
if (isArt) {
|
||||||
fullAttachement = true;
|
fullAttachement = true;
|
||||||
}
|
}
|
||||||
|
float ratio = measuredWidth > 0 ? measuredWidth / mediaW : 1.0f;
|
||||||
|
if(ratio >= 5) {
|
||||||
|
fullAttachement = false;
|
||||||
|
}
|
||||||
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
||||||
RequestBuilder<Drawable> requestBuilder;
|
RequestBuilder<Drawable> requestBuilder;
|
||||||
GlideRequests glideRequests = GlideApp.with(context);
|
GlideRequests glideRequests = GlideApp.with(context);
|
||||||
|
@ -2924,12 +2933,14 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
Status statusToDeal, Attachment attachment) {
|
Status statusToDeal, Attachment attachment) {
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
|
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
|
||||||
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
|
|
||||||
boolean long_press_media = sharedpreferences.getBoolean(context.getString(R.string.SET_LONG_PRESS_STORE_MEDIA), false);
|
boolean long_press_media = sharedpreferences.getBoolean(context.getString(R.string.SET_LONG_PRESS_STORE_MEDIA), false);
|
||||||
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
boolean expand_media = sharedpreferences.getBoolean(context.getString(R.string.SET_EXPAND_MEDIA), false);
|
||||||
|
|
||||||
LinearLayout.LayoutParams lp;
|
LinearLayout.LayoutParams lp;
|
||||||
|
boolean fullAttachement = sharedpreferences.getBoolean(context.getString(R.string.SET_FULL_PREVIEW), false);
|
||||||
|
if(ratio >= 5) {
|
||||||
|
fullAttachement = false;
|
||||||
|
}
|
||||||
if (fullAttachement && mediaH > 0 && (!statusToDeal.sensitive || expand_media)) {
|
if (fullAttachement && mediaH > 0 && (!statusToDeal.sensitive || expand_media)) {
|
||||||
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
|
lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int) (mediaH * ratio));
|
||||||
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
layoutMediaBinding.media.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||||
|
|
Loading…
Reference in a new issue