aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java497
-rw-r--r--app/src/main/res/layout/item_post_card_2_gallery_type.xml2
-rw-r--r--app/src/main/res/layout/item_post_gallery_gallery_type.xml47
-rw-r--r--app/src/main/res/layout/item_post_gallery_type.xml2
5 files changed, 422 insertions, 138 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
index c9d61bf8..6d98405a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostGalleryTypeImageRecyclerViewAdapter.java
@@ -67,6 +67,17 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
}
((ImageViewHolder) holder).binding.errorTextViewItemGalleryImageInPostFeed.setVisibility(View.GONE);
((ImageViewHolder) holder).binding.progressBarItemGalleryImageInPostFeed.setVisibility(View.VISIBLE);
+
+ ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
+
+ ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.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) {
+ ((ImageViewHolder) holder).binding.imageViewItemGalleryImageInPostFeed.removeOnLayoutChangeListener(this);
+ loadImage(((ImageViewHolder) holder));
+ }
+ });
+
loadImage((ImageViewHolder) holder);
}
}
@@ -82,7 +93,6 @@ public class PostGalleryTypeImageRecyclerViewAdapter extends RecyclerView.Adapte
}
private void loadImage(ImageViewHolder holder) {
- holder.binding.imageViewItemGalleryImageInPostFeed.setRatio(ratio);
RequestBuilder<Drawable> imageRequestBuilder = glide.load(galleryImages.get(holder.getBindingAdapterPosition()).url).listener(new RequestListener<>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
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 c6baefb1..182204e5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -11,7 +11,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -88,6 +87,7 @@ import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface;
import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager;
import ml.docilealligator.infinityforreddit.databinding.ItemPostCard2GalleryTypeBinding;
+import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryGalleryTypeBinding;
import ml.docilealligator.infinityforreddit.databinding.ItemPostGalleryTypeBinding;
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostDetailFragment;
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
@@ -119,10 +119,11 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private static final int VIEW_TYPE_POST_CARD_TEXT_TYPE = 4;
private static final int VIEW_TYPE_POST_COMPACT = 5;
private static final int VIEW_TYPE_POST_GALLERY = 6;
- private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 7;
- private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 8;
- private static final int VIEW_TYPE_POST_CARD_2_GALLERY_TYPE = 9;
- private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 10;
+ private static final int VIEW_TYPE_POST_GALLERY_GALLERY_TYPE = 7;
+ private static final int VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE = 8;
+ private static final int VIEW_TYPE_POST_CARD_2_WITH_PREVIEW_TYPE = 9;
+ private static final int VIEW_TYPE_POST_CARD_2_GALLERY_TYPE = 10;
+ private static final int VIEW_TYPE_POST_CARD_2_TEXT_TYPE = 11;
private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() {
@Override
@@ -416,7 +417,16 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
return VIEW_TYPE_POST_COMPACT;
} else if (mPostLayout == SharedPreferencesUtils.POST_LAYOUT_GALLERY) {
- return VIEW_TYPE_POST_GALLERY;
+ Post post = getItem(position);
+ if (post != null) {
+ if (post.getPostType() == Post.GALLERY_TYPE) {
+ return VIEW_TYPE_POST_GALLERY_GALLERY_TYPE;
+ } else {
+ return VIEW_TYPE_POST_GALLERY;
+ }
+ } else {
+ return VIEW_TYPE_POST_GALLERY;
+ }
} else {
Post post = getItem(position);
if (post != null) {
@@ -475,6 +485,8 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
} else if (viewType == VIEW_TYPE_POST_GALLERY) {
return new PostGalleryViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_gallery, parent, false));
+ } else if (viewType == VIEW_TYPE_POST_GALLERY_GALLERY_TYPE) {
+ return new PostGalleryGalleryTypeViewHolder(ItemPostGalleryGalleryTypeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
} else if (viewType == VIEW_TYPE_POST_CARD_2_VIDEO_AUTOPLAY_TYPE) {
if (mDataSavingMode) {
return new PostCard2WithPreviewViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post_card_2_with_preview, parent, false));
@@ -1398,50 +1410,86 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).titleTextView.setTextColor(mReadPostTitleColor);
}
- switch (post.getPostType()) {
- case Post.IMAGE_TYPE: {
- Post.Preview preview = getSuitablePreview(post.getPreviews());
- ((PostGalleryViewHolder) holder).preview = preview;
- if (preview != null) {
- ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ if (mDataSavingMode && (mDisableImagePreview ||
+ ((post.getPostType() == Post.VIDEO_TYPE || post.getPostType() == Post.GIF_TYPE) && mOnlyDisablePreviewInVideoAndGifPosts))) {
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
+ if (post.getPostType() == Post.VIDEO_TYPE) {
+ ((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);
+ }
+ } else {
+ switch (post.getPostType()) {
+ case Post.IMAGE_TYPE: {
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ ((PostGalleryViewHolder) holder).preview = preview;
+ if (preview != null) {
+ ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- if (mFixedHeightPreviewInCard || (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;
+ if (mFixedHeightPreviewInCard || (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;
+ } else {
+ ((PostGalleryViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ }
+ ((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).imageView
- .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
}
- ((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);
+ break;
+ }
+ case Post.GIF_TYPE: {
+ if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) {
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
+ } else {
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ ((PostGalleryViewHolder) holder).preview = preview;
+ if (preview != null) {
+ ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
+
+ if (mFixedHeightPreviewInCard || (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;
+ } else {
+ ((PostGalleryViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ }
+ ((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);
}
- });
- } else {
- ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- if (post.getPostType() == Post.VIDEO_TYPE) {
- ((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).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;
}
- break;
- }
- case Post.GIF_TYPE: {
- if (post.getPostType() == Post.GIF_TYPE && ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mAutoplay && mAutoplayNsfwVideos)) || (post.isSpoiler() && mNeedBlurSpoiler))) {
- ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
- } else {
+ case Post.VIDEO_TYPE: {
Post.Preview preview = getSuitablePreview(post.getPreviews());
((PostGalleryViewHolder) holder).preview = preview;
if (preview != null) {
@@ -1467,111 +1515,83 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
});
} else {
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_image_24dp);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
}
+ break;
}
- break;
- }
- case Post.VIDEO_TYPE: {
- Post.Preview preview = getSuitablePreview(post.getPreviews());
- ((PostGalleryViewHolder) holder).preview = preview;
- if (preview != null) {
- ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_play_circle_36dp));
+ case Post.LINK_TYPE: {
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ ((PostGalleryViewHolder) holder).preview = preview;
+ if (preview != null) {
+ ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator));
- if (mFixedHeightPreviewInCard || (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;
- } else {
- ((PostGalleryViewHolder) holder).imageView
- .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
- }
- ((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);
+ if (mFixedHeightPreviewInCard || (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;
+ } else {
+ ((PostGalleryViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- });
- } else {
- ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_outline_video_24dp);
- }
- break;
- }
- case Post.LINK_TYPE: {
- Post.Preview preview = getSuitablePreview(post.getPreviews());
- ((PostGalleryViewHolder) holder).preview = preview;
- if (preview != null) {
- ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_link_post_type_indicator));
-
- if (mFixedHeightPreviewInCard || (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;
+ ((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).imageView
- .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_link);
}
- ((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 {
+ break;
+ }
+ 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: {
+ ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE);
+ ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle());
+ break;
}
- break;
- }
- 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: {
- ((PostGalleryViewHolder) holder).titleTextView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).titleTextView.setText(post.getTitle());
- break;
}
- case Post.GALLERY_TYPE: {
- Post.Preview preview = getSuitablePreview(post.getPreviews());
- ((PostGalleryViewHolder) holder).preview = preview;
- if (preview != null) {
- ((PostGalleryViewHolder) holder).imageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setImageDrawable(ContextCompat.getDrawable(mActivity, R.drawable.ic_gallery_24dp));
+ }
+ }
+ } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) {
+ Post post = getItem(position);
+ if (post != null) {
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).post = post;
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition = position;
+ if (post.isRead()) {
+ holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
+ }
- if (mFixedHeightPreviewInCard || (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;
- } else {
- ((PostGalleryViewHolder) holder).imageView
- .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
- }
- ((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);
- }
- });
+ if (mDataSavingMode && mDisableImagePreview) {
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ } else {
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).preview = preview;
+
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.VISIBLE);
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, 1, post.getGallery().size()));
+ if (preview != null) {
+ if (mFixedHeightPreviewInCard || (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0)) {
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
} else {
- ((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.VISIBLE);
- ((PostGalleryViewHolder) holder).noPreviewImageView.setImageResource(R.drawable.ic_gallery_24dp);
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
}
- break;
+ } else {
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setRatio(-1);
}
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setGalleryImages(post.getGallery());
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).adapter.setBlurImage(
+ (post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (post.isSpoiler() && mNeedBlurSpoiler));
}
}
}
@@ -1990,6 +2010,17 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
((PostGalleryViewHolder) holder).errorTextView.setVisibility(View.GONE);
((PostGalleryViewHolder) holder).videoOrGifIndicatorImageView.setVisibility(View.GONE);
((PostGalleryViewHolder) holder).noPreviewImageView.setVisibility(View.GONE);
+ } else if (holder instanceof PostGalleryBaseGalleryTypeViewHolder) {
+ if (mMarkPostsAsReadOnScroll) {
+ int position = ((PostGalleryBaseGalleryTypeViewHolder) holder).currentPosition;
+ if (position < super.getItemCount() && position >= 0) {
+ Post post = getItem(position);
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).markPostRead(post, false);
+ }
+ }
+ holder.itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).frameLayout.setVisibility(View.GONE);
+ ((PostGalleryBaseGalleryTypeViewHolder) holder).noPreviewImageView.setVisibility(View.GONE);
}
}
@@ -3179,6 +3210,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor);
imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor);
+ noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor);
+ noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN);
+
adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
galleryRecyclerView.setAdapter(adapter);
@@ -4236,6 +4270,199 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
}
}
+ class PostGalleryBaseGalleryTypeViewHolder extends RecyclerView.ViewHolder {
+
+ FrameLayout frameLayout;
+ RecyclerView recyclerView;
+ CustomTextView imageIndexTextView;
+ ImageView noPreviewImageView;
+
+ PostGalleryTypeImageRecyclerViewAdapter adapter;
+ private boolean swipeLocked;
+
+ Post post;
+ Post.Preview preview;
+
+ int currentPosition;
+
+ public PostGalleryBaseGalleryTypeViewHolder(@NonNull View itemView,
+ FrameLayout frameLayout,
+ RecyclerView recyclerView,
+ CustomTextView imageIndexTextView,
+ ImageView noPreviewImageView) {
+ super(itemView);
+
+ this.frameLayout = frameLayout;
+ this.recyclerView = recyclerView;
+ this.imageIndexTextView = imageIndexTextView;
+ this.noPreviewImageView = noPreviewImageView;
+
+ if (mActivity.typeface != null) {
+ imageIndexTextView.setTypeface(mActivity.typeface);
+ }
+
+ itemView.setBackgroundTintList(ColorStateList.valueOf(mCardViewBackgroundColor));
+ noPreviewImageView.setBackgroundColor(mNoPreviewPostTypeBackgroundColor);
+ noPreviewImageView.setColorFilter(mNoPreviewPostTypeIconTint, android.graphics.PorterDuff.Mode.SRC_IN);
+
+ imageIndexTextView.setTextColor(mMediaIndicatorIconTint);
+ imageIndexTextView.setBackgroundColor(mMediaIndicatorBackgroundColor);
+ imageIndexTextView.setBorderColor(mMediaIndicatorBackgroundColor);
+
+ adapter = new PostGalleryTypeImageRecyclerViewAdapter(mGlide, mActivity.typeface,
+ mSaveMemoryCenterInsideDownsampleStrategy, mColorAccent, mPrimaryTextColor, mScale);
+ recyclerView.setAdapter(adapter);
+ new PagerSnapHelper().attachToRecyclerView(recyclerView);
+ recyclerView.setRecycledViewPool(mGalleryRecycledViewPool);
+ SwipeLockLinearLayoutManager layoutManager = new SwipeLockLinearLayoutManager(
+ mActivity, RecyclerView.HORIZONTAL, false, new SwipeLockInterface() {
+ @Override
+ public void lockSwipe() {
+ mActivity.lockSwipeRightToGoBack();
+ swipeLocked = true;
+ }
+
+ @Override
+ public void unlockSwipe() {
+ mActivity.unlockSwipeRightToGoBack();
+ swipeLocked = false;
+ }
+
+ @Override
+ public void setSwipeLocked(boolean swipeLocked) {
+ PostGalleryBaseGalleryTypeViewHolder.this.swipeLocked = swipeLocked;
+ }
+ });
+ recyclerView.setLayoutManager(layoutManager);
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
+ super.onScrollStateChanged(recyclerView, newState);
+ }
+
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ imageIndexTextView.setText(mActivity.getString(R.string.image_index_in_gallery, layoutManager.findFirstVisibleItemPosition() + 1, post.getGallery().size()));
+ }
+ });
+ recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
+ private float downX;
+ private float downY;
+ private boolean dragged;
+ private long downTime;
+ private final int minTouchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
+ private final int longClickThreshold = ViewConfiguration.getLongPressTimeout();
+
+ @Override
+ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ int action = e.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ downX = e.getRawX();
+ downY = e.getRawY();
+ downTime = System.currentTimeMillis();
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if(Math.abs(e.getRawX() - downX) > minTouchSlop || Math.abs(e.getRawY() - downY) > minTouchSlop) {
+ dragged = true;
+ }
+ if (!dragged) {
+ if (System.currentTimeMillis() - downTime >= longClickThreshold) {
+ onLongClick();
+ }
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ if (!dragged) {
+ if (System.currentTimeMillis() - downTime < longClickThreshold) {
+ onClick();
+ }
+ }
+ case MotionEvent.ACTION_CANCEL:
+ downX = 0;
+ downY = 0;
+ dragged = false;
+
+ }
+ return false;
+ }
+
+ @Override
+ public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+
+ }
+
+ @Override
+ public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+
+ }
+ });
+
+ noPreviewImageView.setOnClickListener(view -> {
+ onClick();
+ });
+
+ noPreviewImageView.setOnLongClickListener(view -> onLongClick());
+ }
+
+ void onClick() {
+ int position = getBindingAdapterPosition();
+ if (position >= 0 && canStartActivity) {
+ Post post = getItem(position);
+ if (post != null) {
+ markPostRead(post, true);
+
+ if (post.getPostType() == Post.TEXT_TYPE || !mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
+ openViewPostDetailActivity(post, getBindingAdapterPosition());
+ } else {
+ openMedia(post);
+ }
+ }
+ }
+ }
+
+ boolean onLongClick() {
+ int position = getBindingAdapterPosition();
+ if (position >= 0 && canStartActivity) {
+ Post post = getItem(position);
+ if (post != null) {
+ markPostRead(post, true);
+
+ if (post.getPostType() == Post.TEXT_TYPE || mSharedPreferences.getBoolean(SharedPreferencesUtils.CLICK_TO_SHOW_MEDIA_IN_GALLERY_LAYOUT, false)) {
+ openViewPostDetailActivity(post, getBindingAdapterPosition());
+ } else {
+ openMedia(post);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ void markPostRead(Post post, boolean changePostItemColor) {
+ if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
+ post.markAsRead(true);
+ if (changePostItemColor) {
+ itemView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
+ }
+ if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
+ ((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
+ mFragment.markPostAsRead(post);
+ }
+ }
+ }
+ }
+
+ class PostGalleryGalleryTypeViewHolder extends PostGalleryBaseGalleryTypeViewHolder {
+
+ public PostGalleryGalleryTypeViewHolder(@NonNull ItemPostGalleryGalleryTypeBinding binding) {
+ super(binding.getRoot(), binding.galleryFrameLayoutItemPostGalleryGalleryType,
+ binding.galleryRecyclerViewItemPostGalleryGalleryType, binding.imageIndexTextViewItemPostGalleryGalleryType,
+ binding.imageViewNoPreviewItemPostGalleryGalleryType);
+ }
+ }
+
class PostCard2VideoAutoplayViewHolder extends PostBaseViewHolder implements ToroPlayer {
@BindView(R.id.icon_gif_image_view_item_post_card_2_video_autoplay)
AspectRatioGifImageView iconGifImageView;
diff --git a/app/src/main/res/layout/item_post_card_2_gallery_type.xml b/app/src/main/res/layout/item_post_card_2_gallery_type.xml
index 5ad3f24b..1455d1fd 100644
--- a/app/src/main/res/layout/item_post_card_2_gallery_type.xml
+++ b/app/src/main/res/layout/item_post_card_2_gallery_type.xml
@@ -21,7 +21,7 @@
<FrameLayout
android:id="@+id/gallery_frame_layout_item_post_card_2_gallery_type"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
diff --git a/app/src/main/res/layout/item_post_gallery_gallery_type.xml b/app/src/main/res/layout/item_post_gallery_gallery_type.xml
new file mode 100644
index 00000000..d1ee61b6
--- /dev/null
+++ b/app/src/main/res/layout/item_post_gallery_gallery_type.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_marginTop="8dp"
+ android:layout_marginBottom="8dp"
+ app:cardElevation="2dp"
+ app:cardCornerRadius="8dp"
+ style="?attr/materialCardViewElevatedStyle">
+
+ <FrameLayout
+ android:id="@+id/gallery_frame_layout_item_post_gallery_gallery_type"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:visibility="gone">
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/gallery_recycler_view_item_post_gallery_gallery_type"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" />
+
+ <com.libRG.CustomTextView
+ android:id="@+id/image_index_text_view_item_post_gallery_gallery_type"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:textSize="?attr/font_12"
+ android:fontFamily="?attr/font_family"
+ android:padding="4dp"
+ app:lib_setRadius="6dp"
+ app:lib_setRoundedView="true"
+ app:lib_setShape="rectangle" />
+
+ </FrameLayout>
+
+ <ImageView
+ android:id="@+id/image_view_no_preview_item_post_gallery_gallery_type"
+ android:layout_width="match_parent"
+ android:layout_height="150dp"
+ android:scaleType="center"
+ android:background="@drawable/thumbnail_compact_layout_rounded_edge"
+ android:visibility="gone" />
+
+</com.google.android.material.card.MaterialCardView> \ No newline at end of file
diff --git a/app/src/main/res/layout/item_post_gallery_type.xml b/app/src/main/res/layout/item_post_gallery_type.xml
index a817cd40..13bd9517 100644
--- a/app/src/main/res/layout/item_post_gallery_type.xml
+++ b/app/src/main/res/layout/item_post_gallery_type.xml
@@ -198,7 +198,7 @@
<FrameLayout
android:id="@+id/gallery_frame_layout_item_post_gallery_type"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">