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

View File

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