diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-02-15 16:04:50 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-02-15 16:04:50 +0000 |
commit | 83ffdb5511a30a3fb4ce0e8467b889187819f24b (patch) | |
tree | ff9a35bd26d58232826f05cbaf6e30f25cc6a46a /app/src/main | |
parent | 3fab4fd90d81a7f3e6012c0042135ff6dc5459cd (diff) | |
download | infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar.gz infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar.bz2 infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar.lz infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar.xz infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.tar.zst infinity-for-reddit-83ffdb5511a30a3fb4ce0e8467b889187819f24b.zip |
Continue adding Gallery Layout.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java | 98 |
1 files changed, 90 insertions, 8 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java index d31d777b..ca3ebb2b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java @@ -1057,7 +1057,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView Post post = getItem(position); if (post != null) { switch (post.getPostType()) { - case Post.IMAGE_TYPE: + case Post.IMAGE_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); @@ -1080,39 +1080,121 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.IMAGE_TYPE || post.getPostType() == Post.GIF_TYPE) { - ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE); } else if (post.getPostType() == Post.LINK_TYPE) { ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); } else if (post.getPostType() == Post.GALLERY_TYPE) { ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); } + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); } break; - case Post.GIF_TYPE: + } + case Post.GIF_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + loadImage(holder, post, preview); + } else { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp); + } break; - case Post.VIDEO_TYPE: + } + case Post.VIDEO_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE); + + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + loadImage(holder, post, preview); + } else { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp); + } break; - case Post.LINK_TYPE: + } + case Post.LINK_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + loadImage(holder, post, preview); + } else { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); + } break; - case Post.NO_PREVIEW_LINK_TYPE: + } + case Post.NO_PREVIEW_LINK_TYPE: { ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link); break; - case Post.TEXT_TYPE: + } + case Post.TEXT_TYPE: { ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle()); break; - case Post.GALLERY_TYPE: + } + case Post.GALLERY_TYPE: { ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE); ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE); + + Post.Preview preview = getSuitablePreview(post.getPreviews()); + if (preview != null) { + if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) { + int height = (int) (400 * mScale); + ((PostGalleryViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); + ((PostGalleryViewHolder) holder).imageView.getLayoutParams().height = height; + preview.setPreviewWidth(mImageViewWidth); + preview.setPreviewHeight(height); + } else { + ((PostGalleryViewHolder) holder).imageView + .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth()); + } + loadImage(holder, post, preview); + } else { + ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE); + ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp); + } break; + } } } } |