Fix large image attachments not showing (#1043)

* fix for too large image attachments not fitting into GL texture

* Don't use context!!
This commit is contained in:
Ondřej Hruška 2019-02-16 14:31:41 +01:00 committed by Konrad Pozniak
parent 1805caaef7
commit fcc67c6918
4 changed files with 35 additions and 1 deletions

View file

@ -284,6 +284,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
final int n = Math.min(attachments.size(), Status.MAX_MEDIA_ATTACHMENTS); final int n = Math.min(attachments.size(), Status.MAX_MEDIA_ATTACHMENTS);
final int maxW = context.getResources().getInteger(R.integer.media_max_width);
final int maxH = context.getResources().getInteger(R.integer.media_max_height);
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
String previewUrl = attachments.get(i).getPreviewUrl(); String previewUrl = attachments.get(i).getPreviewUrl();
String description = attachments.get(i).getDescription(); String description = attachments.get(i).getDescription();
@ -299,6 +302,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (TextUtils.isEmpty(previewUrl)) { if (TextUtils.isEmpty(previewUrl)) {
Picasso.with(context) Picasso.with(context)
.load(mediaPreviewUnloadedId) .load(mediaPreviewUnloadedId)
.resize(maxW, maxH)
.onlyScaleDown()
.centerInside()
.into(mediaPreviews[i]); .into(mediaPreviews[i]);
} else { } else {
MetaData meta = attachments.get(i).getMeta(); MetaData meta = attachments.get(i).getMeta();
@ -310,6 +316,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
Picasso.with(context) Picasso.with(context)
.load(previewUrl) .load(previewUrl)
.placeholder(mediaPreviewUnloadedId) .placeholder(mediaPreviewUnloadedId)
.resize(maxW, maxH)
.onlyScaleDown()
.centerInside()
// Also pass the mediaPreview as a callback to ensure it is called // Also pass the mediaPreview as a callback to ensure it is called
// initially when the image gets loaded: // initially when the image gets loaded:
.into(mediaPreviews[i], mediaPreviews[i]); .into(mediaPreviews[i], mediaPreviews[i]);
@ -319,6 +328,9 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
Picasso.with(context) Picasso.with(context)
.load(previewUrl) .load(previewUrl)
.placeholder(mediaPreviewUnloadedId) .placeholder(mediaPreviewUnloadedId)
.resize(maxW, maxH)
.onlyScaleDown()
.centerInside()
.into(mediaPreviews[i]); .into(mediaPreviews[i]);
} }
} }

View file

@ -301,8 +301,15 @@ class AccountMediaFragment : BaseFragment(), Injectable {
itemBgBaseHSV[2] = random.nextFloat() * (1f - 0.3f) + 0.3f itemBgBaseHSV[2] = random.nextFloat() * (1f - 0.3f) + 0.3f
holder.imageView.setBackgroundColor(Color.HSVToColor(itemBgBaseHSV)) holder.imageView.setBackgroundColor(Color.HSVToColor(itemBgBaseHSV))
val item = items[position] val item = items[position]
val maxW = holder.imageView.context.resources.getInteger(R.integer.media_max_width)
val maxH = holder.imageView.context.resources.getInteger(R.integer.media_max_height)
Picasso.with(holder.imageView.context) Picasso.with(holder.imageView.context)
.load(item.attachment.previewUrl) .load(item.attachment.previewUrl)
.resize(maxW, maxH)
.onlyScaleDown()
.centerInside()
.into(holder.imageView) .into(holder.imageView)
} }

View file

@ -74,6 +74,9 @@ class ViewImageFragment : ViewMediaFragment() {
result result
} }
val maxW = photoView.context.resources.getInteger(R.integer.media_max_width)
val maxH = photoView.context.resources.getInteger(R.integer.media_max_height)
// If we are the view to be shown initially... // If we are the view to be shown initially...
if (arguments!!.getBoolean(ViewMediaFragment.ARG_START_POSTPONED_TRANSITION)) { if (arguments!!.getBoolean(ViewMediaFragment.ARG_START_POSTPONED_TRANSITION)) {
// Try to load image from disk. // Try to load image from disk.
@ -81,6 +84,9 @@ class ViewImageFragment : ViewMediaFragment() {
.load(url) .load(url)
.noFade() .noFade()
.networkPolicy(NetworkPolicy.OFFLINE) .networkPolicy(NetworkPolicy.OFFLINE)
.resize(maxW, maxH)
.onlyScaleDown()
.centerInside()
.into(photoView, object : Callback { .into(photoView, object : Callback {
override fun onSuccess() { override fun onSuccess() {
// if we loaded image from disk, we should check that view is attached. // if we loaded image from disk, we should check that view is attached.
@ -169,10 +175,15 @@ class ViewImageFragment : ViewMediaFragment() {
} }
private fun loadImageFromNetwork(url: String, photoView: ImageView) { private fun loadImageFromNetwork(url: String, photoView: ImageView) {
val maxW = photoView.context.resources.getInteger(R.integer.media_max_width)
val maxH = photoView.context.resources.getInteger(R.integer.media_max_height)
Picasso.with(context) Picasso.with(context)
.load(url) .load(url)
.noPlaceholder() .noPlaceholder()
.networkPolicy(NetworkPolicy.NO_STORE) .networkPolicy(NetworkPolicy.NO_STORE)
.resize(maxW, maxH)
.onlyScaleDown()
.into(photoView, object : Callback { .into(photoView, object : Callback {
override fun onSuccess() { override fun onSuccess() {
finishLoadingSuccessfully() finishLoadingSuccessfully()

View file

@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<integer name="profile_media_column_count">3</integer> <integer name="profile_media_column_count">3</integer>
</resources>
<!-- Images larger than this will be downscaled to avoid OpenGL errors -->
<integer name="media_max_width">1920</integer>
<integer name="media_max_height">1920</integer>
</resources>