mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Load image after the AspectRatioGifImageView's height is determined in PostRecyclerViewAdapter to prevent blurry images.
This commit is contained in:
parent
20e4798d34
commit
3cae2b0dba
@ -15,7 +15,6 @@ import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
@ -40,6 +39,7 @@ import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.RequestBuilder;
|
||||
import com.bumptech.glide.RequestManager;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
import com.bumptech.glide.load.DecodeFormat;
|
||||
import com.bumptech.glide.load.engine.GlideException;
|
||||
import com.bumptech.glide.request.RequestListener;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
@ -816,7 +816,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostWithPreviewTypeViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
@ -970,7 +976,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostCard2WithPreviewViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
|
||||
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
@ -1348,7 +1360,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
@ -1382,7 +1400,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
|
||||
@ -1406,7 +1430,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
|
||||
@ -1430,7 +1460,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
|
||||
@ -1464,7 +1500,13 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
((PostGalleryViewHolder) holder).imageView
|
||||
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
|
||||
}
|
||||
loadImage(holder);
|
||||
((PostGalleryViewHolder) holder).imageView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
((PostGalleryViewHolder) holder).imageView.removeOnLayoutChangeListener(this);
|
||||
loadImage(holder);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
|
||||
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
|
||||
@ -1514,12 +1556,14 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
url = preview.getPreviewUrl();
|
||||
}
|
||||
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(((PostWithPreviewTypeViewHolder) holder).glideRequestListener);
|
||||
|
||||
if (post.getAuthor().startsWith("GLIBG10")) {
|
||||
Log.i("sssssaffd", "s " + url + " " + ((PostWithPreviewTypeViewHolder) holder).imageView.getRatio());
|
||||
}
|
||||
if (blurImage) {
|
||||
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
|
||||
.into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
} else {
|
||||
imageRequestBuilder.downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
imageRequestBuilder.centerInside().downsample(mSaveMemoryCenterInsideDownsampleStrategy).into(((PostWithPreviewTypeViewHolder) holder).imageView);
|
||||
}
|
||||
}
|
||||
} else if (holder instanceof PostCompactBaseViewHolder) {
|
||||
@ -1756,7 +1800,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
if (holder instanceof PostBaseViewHolder) {
|
||||
if (mMarkPostsAsReadOnScroll) {
|
||||
int position = ((PostBaseViewHolder) holder).currentPosition;
|
||||
|
@ -34,7 +34,6 @@ public class AspectRatioGifImageView extends GifImageView {
|
||||
this.ratio = a.getFloat(com.santalu.aspectratioimageview.R.styleable.AspectRatioImageView_ari_ratio, 1.0F);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,4 +51,24 @@ public class AspectRatioGifImageView extends GifImageView {
|
||||
this.setMeasuredDimension(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/*@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
|
||||
int desiredHeight = (int) (widthSize * ratio);
|
||||
int selectedHeight;
|
||||
|
||||
if(heightMode == MeasureSpec.EXACTLY) {
|
||||
selectedHeight = heightSize;
|
||||
} else if(heightMode == MeasureSpec.AT_MOST) {
|
||||
selectedHeight = Math.min(heightSize, desiredHeight);
|
||||
} else {
|
||||
selectedHeight = desiredHeight;
|
||||
}
|
||||
super.onMeasure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY),
|
||||
MeasureSpec.makeMeasureSpec(selectedHeight, MeasureSpec.EXACTLY));
|
||||
}*/
|
||||
}
|
||||
|
@ -216,8 +216,7 @@
|
||||
android:id="@+id/image_view_item_post_detail_gallery"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitStart" />
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/video_or_gif_indicator_image_view_item_post_detail"
|
||||
|
@ -211,8 +211,7 @@
|
||||
android:id="@+id/image_view_item_post_detail_image_and_gif_autoplay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitStart" />
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/load_wrapper_item_post_detail_image_and_gif_autoplay"
|
||||
|
@ -221,8 +221,7 @@
|
||||
android:id="@+id/image_view_item_post_detail_link"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitStart" />
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/load_wrapper_item_post_detail_link"
|
||||
|
@ -213,8 +213,7 @@
|
||||
android:id="@+id/image_view_item_post_detail_video_and_gif_preview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:adjustViewBounds="true"
|
||||
android:scaleType="fitStart" />
|
||||
android:adjustViewBounds="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/video_or_gif_indicator_image_view_item_post_detail"
|
||||
|
@ -221,7 +221,6 @@
|
||||
android:id="@+id/preview_image_view_item_post_detail_video_autoplay"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitStart"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
|
Loading…
Reference in New Issue
Block a user