Fix image loading issue.

This commit is contained in:
Docile-Alligator 2022-03-11 12:15:07 +08:00
parent aab502238d
commit 20e4798d34
2 changed files with 10 additions and 71 deletions

View File

@ -19,7 +19,6 @@ import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
@ -718,13 +717,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostDetailVideoAndGifPreviewHolder) holder).mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
}
});
loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
}
} else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
if (!mHidePostType) {
@ -744,13 +737,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else {
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
}
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage((PostDetailImageAndGifAutoplayViewHolder) holder, preview);
}
});
loadImage((PostDetailImageAndGifAutoplayViewHolder) holder, preview);
}
} else if (holder instanceof PostDetailLinkViewHolder) {
String domain = Uri.parse(mPost.getUrl()).getHost();
@ -758,13 +745,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
((PostDetailLinkViewHolder) holder).mImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostDetailLinkViewHolder) holder).mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage((PostDetailLinkViewHolder) holder, preview);
}
});
loadImage((PostDetailLinkViewHolder) holder, preview);
}
} else if (holder instanceof PostDetailNoPreviewViewHolder) {
@ -831,13 +812,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailGalleryViewHolder) holder).mImageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
((PostDetailGalleryViewHolder) holder).mImageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostDetailGalleryViewHolder) holder).mImageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage((PostDetailGalleryViewHolder) holder, preview);
}
});
loadImage((PostDetailGalleryViewHolder) holder, preview);
loadCaptionPreview((PostDetailGalleryViewHolder) holder, preview);
} else {

View File

@ -816,13 +816,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostWithPreviewTypeViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostWithPreviewTypeViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostWithPreviewTypeViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostWithPreviewTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
if (post.getPostType() == Post.VIDEO_TYPE) {
@ -976,13 +970,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostCard2WithPreviewViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostCard2WithPreviewViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostCard2WithPreviewViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostCard2WithPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
((PostCard2WithPreviewViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
@ -1360,13 +1348,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
if (post.getPostType() == Post.VIDEO_TYPE) {
@ -1424,13 +1406,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
@ -1454,13 +1430,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
@ -1494,13 +1464,7 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).imageView
.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
((PostGalleryViewHolder) holder).imageView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
loadImage(holder);
}
});
loadImage(holder);
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);